]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
zram: fix race between reset and flushing pending work
authorMinchan Kim <minchan@kernel.org>
Wed, 15 Jan 2014 05:56:11 +0000 (16:56 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 16 Jan 2014 05:54:03 +0000 (16:54 +1100)
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>
drivers/block/zram/zram_drv.c

index f9711c520269e0e2765d1004467b2cfc71421957..213dfc10b78354885c7283a0e2ee5ff39d4b4f5e 100644 (file)
@@ -553,14 +553,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
        size_t index;
        struct zram_meta *meta;
 
-       flush_work(&zram->free_work);
-
        down_write(&zram->init_lock);
        if (!zram->init_done) {
                up_write(&zram->init_lock);
                return;
        }
 
+       flush_work(&zram->free_work);
+
        meta = zram->meta;
        zram->init_done = 0;