Skip to content

Commit

Permalink
Prevent DM RAID from loading bitmap twice.
Browse files Browse the repository at this point in the history
The life cycle of a device-mapper target is:
1) create
2) resume
3) suspend
*) possibly repeat from 2
4) destroy

The dm-raid target is unconditionally calling MD's bitmap_load function upon
every resume.  If steps 2 & 3 above are repeated, bitmap_load is called
multiple times.  It is only written to be called once; otherwise, it allocates
new memory for the bitmap (without freeing the old) and incrementing the number
of pages it thinks it has without zeroing first.  This ultimately leads to
access beyond allocated memory and lost memory.

Simply avoiding the bitmap_load call upon resume is not sufficient.  If the
target was suspended while the initial recovery was only partially complete,
it needs to be restarted when the target is resumed.  This is why
'md_wakeup_thread' is called before issuing the 'mddev_resume'.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
  • Loading branch information
Jonathan Brassow authored and NeilBrown committed Jan 30, 2012
1 parent 307729c commit 34f8ac6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/md/dm-raid.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct raid_dev {
struct raid_set {
struct dm_target *ti;

uint64_t print_flags;
uint32_t bitmap_loaded;
uint32_t print_flags;

struct mddev md;
struct raid_type *raid_type;
Expand Down Expand Up @@ -1085,7 +1086,7 @@ static int raid_status(struct dm_target *ti, status_type_t type,
raid_param_cnt += 2;
}

raid_param_cnt += (hweight64(rs->print_flags & ~DMPF_REBUILD) * 2);
raid_param_cnt += (hweight32(rs->print_flags & ~DMPF_REBUILD) * 2);
if (rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC))
raid_param_cnt--;

Expand Down Expand Up @@ -1197,7 +1198,12 @@ static void raid_resume(struct dm_target *ti)
{
struct raid_set *rs = ti->private;

bitmap_load(&rs->md);
if (!rs->bitmap_loaded) {
bitmap_load(&rs->md);
rs->bitmap_loaded = 1;
} else
md_wakeup_thread(rs->md.thread);

mddev_resume(&rs->md);
}

Expand Down

0 comments on commit 34f8ac6

Please sign in to comment.