diff options
author | Jiang Liu <liuj97@gmail.com> | 2013-06-07 00:07:27 +0800 |
---|---|---|
committer | Andreas Blaesius <skate4life@gmx.de> | 2016-06-05 21:21:36 +0200 |
commit | 5721d2aa8adad2db2df52fffd44a8ea44ead8219 (patch) | |
tree | 7ef64bc569265b25006a1613432cca05287257a9 | |
parent | f53e917a982706fbc1c1e543ad6a64eb6d93d2fb (diff) | |
download | kernel_samsung_espresso10-5721d2aa8adad2db2df52fffd44a8ea44ead8219.zip kernel_samsung_espresso10-5721d2aa8adad2db2df52fffd44a8ea44ead8219.tar.gz kernel_samsung_espresso10-5721d2aa8adad2db2df52fffd44a8ea44ead8219.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 e6a929d..dc76a3d 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -188,8 +188,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); } |