All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Weijie Yang <weijie.yang@samsung.com>
Cc: 'Minchan Kim' <minchan@kernel.org>,
	'Andrew Morton' <akpm@linux-foundation.org>,
	'Dan Streetman' <ddstreet@ieee.org>,
	'Sergey Senozhatsky' <sergey.senozhatsky@gmail.com>,
	'Nitin Gupta' <ngupta@vflare.org>,
	'Linux-MM' <linux-mm@kvack.org>,
	'linux-kernel' <linux-kernel@vger.kernel.org>,
	'Weijie Yang' <weijie.yang.kh@gmail.com>
Subject: Re: [PATCH 2/2] zram: avoid NULL pointer access when reading mem_used_total
Date: Sun, 26 Oct 2014 14:41:39 +0900	[thread overview]
Message-ID: <20141026054139.GA952@swordfish> (raw)
In-Reply-To: <000101cff035$d9f50480$8ddf0d80$%yang@samsung.com>

On (10/25/14 17:26), Weijie Yang wrote:
> Date: Sat, 25 Oct 2014 17:26:31 +0800
> From: Weijie Yang <weijie.yang@samsung.com>
> To: 'Minchan Kim' <minchan@kernel.org>
> Cc: 'Andrew Morton' <akpm@linux-foundation.org>, 'Dan Streetman'
>  <ddstreet@ieee.org>, 'Sergey Senozhatsky' <sergey.senozhatsky@gmail.com>,
>  'Nitin Gupta' <ngupta@vflare.org>, 'Linux-MM' <linux-mm@kvack.org>,
>  'linux-kernel' <linux-kernel@vger.kernel.org>, 'Weijie Yang'
>  <weijie.yang.kh@gmail.com>
> Subject: [PATCH 2/2] zram: avoid NULL pointer access when reading
>  mem_used_total
> X-Mailer: Microsoft Office Outlook 12.0
> 
> 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, done
> init_done() is true
> access meta->mem_pool, get a NULL pointer BUG
> 
> This patch fixes this issue.
> 	
> Signed-off-by: Weijie Yang <weijie.yang@samsung.com>

Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

	-ss

> ---
>  drivers/block/zram/zram_drv.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 64dd79a..2ffd7d8 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -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);
> -- 
> 1.7.0.4
> 
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Weijie Yang <weijie.yang@samsung.com>
Cc: "'Minchan Kim'" <minchan@kernel.org>,
	"'Andrew Morton'" <akpm@linux-foundation.org>,
	"'Dan Streetman'" <ddstreet@ieee.org>,
	"'Sergey Senozhatsky'" <sergey.senozhatsky@gmail.com>,
	"'Nitin Gupta'" <ngupta@vflare.org>,
	"'Linux-MM'" <linux-mm@kvack.org>,
	"'linux-kernel'" <linux-kernel@vger.kernel.org>,
	"'Weijie Yang'" <weijie.yang.kh@gmail.com>
Subject: Re: [PATCH 2/2] zram: avoid NULL pointer access when reading mem_used_total
Date: Sun, 26 Oct 2014 14:41:39 +0900	[thread overview]
Message-ID: <20141026054139.GA952@swordfish> (raw)
In-Reply-To: <000101cff035$d9f50480$8ddf0d80$%yang@samsung.com>

On (10/25/14 17:26), Weijie Yang wrote:
> Date: Sat, 25 Oct 2014 17:26:31 +0800
> From: Weijie Yang <weijie.yang@samsung.com>
> To: 'Minchan Kim' <minchan@kernel.org>
> Cc: 'Andrew Morton' <akpm@linux-foundation.org>, 'Dan Streetman'
>  <ddstreet@ieee.org>, 'Sergey Senozhatsky' <sergey.senozhatsky@gmail.com>,
>  'Nitin Gupta' <ngupta@vflare.org>, 'Linux-MM' <linux-mm@kvack.org>,
>  'linux-kernel' <linux-kernel@vger.kernel.org>, 'Weijie Yang'
>  <weijie.yang.kh@gmail.com>
> Subject: [PATCH 2/2] zram: avoid NULL pointer access when reading
>  mem_used_total
> X-Mailer: Microsoft Office Outlook 12.0
> 
> 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, done
> init_done() is true
> access meta->mem_pool, get a NULL pointer BUG
> 
> This patch fixes this issue.
> 	
> Signed-off-by: Weijie Yang <weijie.yang@samsung.com>

Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

	-ss

> ---
>  drivers/block/zram/zram_drv.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 64dd79a..2ffd7d8 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -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);
> -- 
> 1.7.0.4
> 
> 

  parent reply	other threads:[~2014-10-26  5:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-25  9:26 [PATCH 2/2] zram: avoid NULL pointer access when reading mem_used_total Weijie Yang
2014-10-25  9:26 ` Weijie Yang
2014-10-26  1:44 ` Minchan Kim
2014-10-26  1:44   ` Minchan Kim
2014-10-26  5:41 ` Sergey Senozhatsky [this message]
2014-10-26  5:41   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141026054139.GA952@swordfish \
    --to=sergey.senozhatsky@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ddstreet@ieee.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=weijie.yang.kh@gmail.com \
    --cc=weijie.yang@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.