diff options
author | Minchan Kim <minchan@kernel.org> | 2014-01-30 18:45:58 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-30 19:56:55 -0500 |
commit | da4a04126baa3be03bc566d4a2ee0944c5e783d0 (patch) | |
tree | fec417b4bf836105091c4f32c481442c50cabefb | |
parent | eae70d06846199afc97524ed986b910836c0abe5 (diff) |
zram: fix race between reset and flushing pending work
Dan and Sergey reported that there is a racy between reset and flushing
of pending work so that it could make oops by freeing zram->meta in
reset while zram_slot_free can access zram->meta if new request is
adding during the race window.
This patch moves flush after taking init_lock so it prevents new request
so that it closes the race.
Signed-off-by: Minchan Kim <minchan@kernel.org>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Jerome Marchand <jmarchan@redhat.com>
Tested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/block/zram/zram_drv.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index f9711c520269..213dfc10b783 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -553,14 +553,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) | |||
553 | size_t index; | 553 | size_t index; |
554 | struct zram_meta *meta; | 554 | struct zram_meta *meta; |
555 | 555 | ||
556 | flush_work(&zram->free_work); | ||
557 | |||
558 | down_write(&zram->init_lock); | 556 | down_write(&zram->init_lock); |
559 | if (!zram->init_done) { | 557 | if (!zram->init_done) { |
560 | up_write(&zram->init_lock); | 558 | up_write(&zram->init_lock); |
561 | return; | 559 | return; |
562 | } | 560 | } |
563 | 561 | ||
562 | flush_work(&zram->free_work); | ||
563 | |||
564 | meta = zram->meta; | 564 | meta = zram->meta; |
565 | zram->init_done = 0; | 565 | zram->init_done = 0; |
566 | 566 | ||