diff options
author | Jiang Liu <liuj97@gmail.com> | 2013-06-07 00:07:27 +0800 |
---|---|---|
committer | Simon Shields <keepcalm444@gmail.com> | 2016-06-12 21:19:42 +1000 |
commit | c067ed4a8a5d6bdaf3ce3ac5fc12e88ddce78af3 (patch) | |
tree | 628ea97a440bce2ad655f5781a893ad72c08ff05 | |
parent | 996624881997fbbfe6c815a052142bf854e096f6 (diff) | |
download | kernel_samsung_smdk4412-c067ed4a8a5d6bdaf3ce3ac5fc12e88ddce78af3.zip kernel_samsung_smdk4412-c067ed4a8a5d6bdaf3ce3ac5fc12e88ddce78af3.tar.gz kernel_samsung_smdk4412-c067ed4a8a5d6bdaf3ce3ac5fc12e88ddce78af3.tar.bz2 |
zram: protect sysfs handler from invalid memory access
Use zram->init_lock to protect access to zram->meta, otherwise it
may cause invalid memory access if zram->meta has been freed by
zram_reset_device().
This issue may be triggered by:
Thread 1:
while true; do cat mem_used_total; done
Thread 2:
while true; do echo 8M > disksize; echo 1 > reset; done
Change-Id: Id6105b37f083cfd41d9885a251aeef61f72bb92f
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 5863e10b441e7ea4b492f930f1be180a97d026f3
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
-rw-r--r-- | drivers/staging/zram/zram_sysfs.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 68ccad1..55d5281 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -195,8 +195,10 @@ static ssize_t mem_used_total_show(struct device *dev, struct zram *zram = dev_to_zram(dev); struct zram_meta *meta = zram->meta; + down_read(&zram->init_lock); if (zram->init_done) val = zs_get_total_size_bytes(meta->mem_pool); + up_read(&zram->init_lock); return sprintf(buf, "%llu\n", val); } |