UPSTREAM: zram: avoid NULL pointer access in concurrent situation
(cherry-pick from commit 5a99e95b8d1cd47f6feddcdca6c71d22060df8a2) There is a rare NULL pointer bug in mem_used_total_show() and mem_used_max_store() in concurrent situation, like this: zram is not initialized, process A is a mem_used_total reader which runs periodically, while process B try to init zram. process A process B access meta, get a NULL value init zram, done init_done() is true access meta->mem_pool, get a NULL pointer BUG This patch fixes this issue. Bug: 25951511 Change-Id: I972d9d7a84e32f791685d55d90ce18ce02e5183a Signed-off-by: Weijie Yang <weijie.yang@samsung.com> Acked-by: Minchan Kim <minchan@kernel.org> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
40ea37de5f
commit
1ac6be903a
|
@ -150,7 +150,7 @@ static ssize_t mem_used_total_show(struct device *dev,
|
|||
down_read(&zram->init_lock);
|
||||
if (init_done(zram)) {
|
||||
struct zram_meta *meta = zram->meta;
|
||||
val = zs_get_total_size_bytes(meta->mem_pool);
|
||||
val = zs_get_total_pages(meta->mem_pool);
|
||||
}
|
||||
up_read(&zram->init_lock);
|
||||
|
||||
|
@ -221,16 +221,17 @@ static ssize_t mem_used_max_store(struct device *dev,
|
|||
int err;
|
||||
unsigned long val;
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
struct zram_meta *meta = zram->meta;
|
||||
|
||||
err = kstrtoul(buf, 10, &val);
|
||||
if (err || val != 0)
|
||||
return -EINVAL;
|
||||
|
||||
down_read(&zram->init_lock);
|
||||
if (init_done(zram))
|
||||
if (init_done(zram)) {
|
||||
struct zram_meta *meta = zram->meta;
|
||||
atomic_long_set(&zram->stats.max_used_pages,
|
||||
zs_get_total_pages(meta->mem_pool));
|
||||
}
|
||||
up_read(&zram->init_lock);
|
||||
|
||||
return len;
|
||||
|
|
Loading…
Reference in New Issue