zram: avoid NULL pointer access when reading mem_used_total
Subsystems (3)
PATCH 2/2 zram: avoid NULL pointer access when reading mem_used_total
There is a rare NULL pointer bug in mem_used_total_show() in concurrent situation, like this:
zram is not initialized, process A is a mem_used_total reader which runs periodicity, while process B try to init zram.
process A process B
access meta, get a NULL value
init zram, doneinit_done() is true
access meta->mem_pool, get a NULL pointer BUG
This patch fixes this issue.
--- drivers/block/zram/zram_drv.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/block/zram/zram_drv.c +3 -2
@@ -99,11 +99,12 @@ static ssize_t mem_used_total_show(struct device *dev, {u64 val =0 ;struct zram *zram =dev_to_zram (dev); -struct zram_meta *meta = zram->meta;down_read (&zram->init_lock); -if (init_done (zram)) +if (init_done (zram)) { +struct zram_meta *meta = zram->meta; val =zs_get_total_pages (meta->mem_pool); + }up_read (&zram->init_lock);return scnprintf (buf,PAGE_SIZE ,"%llu\n" , val <<PAGE_SHIFT );
Signature · 8 lines
1.7.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Weijie Yang
There is a rare NULL pointer bug in
mem_used_total_show()in concurrent situation, like this:
zram is not initialized, process A is amem_used_totalreader which runs periodicity, while process B try to init zram.process A process B
access meta, get a NULL value
init zram, doneinit_done()is true
accessmeta->mem_pool, get a NULL pointer BUG
Quoted 3 lines
This patch fixes this issue.
Signed-off-by Weijie Yang <[email protected]>
Thanks!
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 23 lines · Weijie Yang
Date: Sat, 25 Oct 2014 17:26:31 +0800
From: Weijie Yang <[email protected]>
To: 'Minchan Kim' <[email protected]>
Cc: 'Andrew Morton' <[email protected]>, 'Dan Streetman'
<[email protected]>, 'Sergey Senozhatsky' <[email protected]>, 'Nitin Gupta' <[email protected]>, 'Linux-MM' <[email protected]>, 'linux-kernel' <[email protected]>, 'Weijie Yang' <[email protected]>
Subject: [PATCH 2/2] zram: avoid NULL pointer access when reading
mem_used_total
X-Mailer: Microsoft Office Outlook 12.0There is a rare NULL pointer bug in
mem_used_total_show()in concurrent situation, like this:
zram is not initialized, process A is amem_used_totalreader which runs periodicity, while process B try to init zram.process A process B
access meta, get a NULL value
init zram, doneinit_done()is true
accessmeta->mem_pool, get a NULL pointer BUG
Quoted 3 lines
This patch fixes this issue.
Signed-off-by Weijie Yang <[email protected]>
-ss
Quoted 27 lines
--- drivers/block/zram/zram_drv.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)drivers/block/zram/zram_drv.c +3
-2@@ -99,11 +99,12 @@ static ssize_t mem_used_total_show(struct device *dev, {u64 val =0 ;struct zram *zram =dev_to_zram (dev); -struct zram_meta *meta = zram->meta;down_read (&zram->init_lock); -if (init_done (zram)) +if (init_done (zram)) { +struct zram_meta *meta = zram->meta; val =zs_get_total_pages (meta->mem_pool); + }up_read (&zram->init_lock);return scnprintf (buf,PAGE_SIZE ,"%llu\n" , val <<PAGE_SHIFT );Signature · 1 line
1.7.0.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>