diff options
author | Jerome Marchand <jmarchan@redhat.com> | 2016-01-15 19:54:48 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-15 20:56:32 -0500 |
commit | 17ec4cd985780a7e30aa45bb8f272237c12502a4 (patch) | |
tree | b92ceba1c365778b13c02a10b98bb1418d039323 /drivers/block/zram/zram_drv.c | |
parent | 8749cfea11f3fffe8f7cad891470a77b36e0185f (diff) |
zram: don't call idr_remove() from zram_remove()
The use of idr_remove() is forbidden in the callback functions of
idr_for_each(). It is therefore unsafe to call idr_remove in
zram_remove().
This patch moves the call to idr_remove() from zram_remove() to
hot_remove_store(). In the detroy_devices() path, idrs are removed by
idr_destroy(). This solves an use-after-free detected by KASan.
[akpm@linux-foundation.org: fix coding stype, per Sergey]
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: <stable@vger.kernel.org> [4.2+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram/zram_drv.c')
-rw-r--r-- | drivers/block/zram/zram_drv.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 47915d736f8d..370c2f76016d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -1325,7 +1325,6 @@ static int zram_remove(struct zram *zram) | |||
1325 | 1325 | ||
1326 | pr_info("Removed device: %s\n", zram->disk->disk_name); | 1326 | pr_info("Removed device: %s\n", zram->disk->disk_name); |
1327 | 1327 | ||
1328 | idr_remove(&zram_index_idr, zram->disk->first_minor); | ||
1329 | blk_cleanup_queue(zram->disk->queue); | 1328 | blk_cleanup_queue(zram->disk->queue); |
1330 | del_gendisk(zram->disk); | 1329 | del_gendisk(zram->disk); |
1331 | put_disk(zram->disk); | 1330 | put_disk(zram->disk); |
@@ -1367,10 +1366,12 @@ static ssize_t hot_remove_store(struct class *class, | |||
1367 | mutex_lock(&zram_index_mutex); | 1366 | mutex_lock(&zram_index_mutex); |
1368 | 1367 | ||
1369 | zram = idr_find(&zram_index_idr, dev_id); | 1368 | zram = idr_find(&zram_index_idr, dev_id); |
1370 | if (zram) | 1369 | if (zram) { |
1371 | ret = zram_remove(zram); | 1370 | ret = zram_remove(zram); |
1372 | else | 1371 | idr_remove(&zram_index_idr, dev_id); |
1372 | } else { | ||
1373 | ret = -ENODEV; | 1373 | ret = -ENODEV; |
1374 | } | ||
1374 | 1375 | ||
1375 | mutex_unlock(&zram_index_mutex); | 1376 | mutex_unlock(&zram_index_mutex); |
1376 | return ret ? ret : count; | 1377 | return ret ? ret : count; |