mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Christoph Lameter <cl@linux.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Christian Kujau <lists@nerdbynature.de>,
	markus@trippelsdorf.de, David Rientjes <rientjes@google.com>
Subject: Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
Date: Wed, 23 Nov 2011 10:32:21 +0200 (EET)	[thread overview]
Message-ID: <alpine.LFD.2.02.1111231030370.14209@tux.localdomain> (raw)
In-Reply-To: <1321974122.2474.21.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

On Tue, 22 Nov 2011, Eric Dumazet wrote:
> show_slab_objects() can trigger NULL dereferences or memory corruption.
>
> Another cpu can change its c->page to NULL or c->node to NUMA_NO_NODE
> while we use them.
>
> Use ACCESS_ONCE(c->page) and ACCESS_ONCE(c->node) to make sure this
> cannot happen.
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Did someone test this patch? Does it fix any of the reported issues?

> ---
> V2: remove a not needed "if (!c)" test
>
> mm/slub.c |   21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 7d2a996..9deef7d 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4435,30 +4435,31 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
>
> 		for_each_possible_cpu(cpu) {
> 			struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);
> +			int node = ACCESS_ONCE(c->node);
> 			struct page *page;
>
> -			if (!c || c->node < 0)
> +			if (node < 0)
> 				continue;
> -
> -			if (c->page) {
> -					if (flags & SO_TOTAL)
> -						x = c->page->objects;
> +			page = ACCESS_ONCE(c->page);
> +			if (page) {
> +				if (flags & SO_TOTAL)
> +					x = page->objects;
> 				else if (flags & SO_OBJECTS)
> -					x = c->page->inuse;
> +					x = page->inuse;
> 				else
> 					x = 1;
>
> 				total += x;
> -				nodes[c->node] += x;
> +				nodes[node] += x;
> 			}
> 			page = c->partial;
>
> 			if (page) {
> 				x = page->pobjects;
> -                                total += x;
> -                                nodes[c->node] += x;
> +				total += x;
> +				nodes[node] += x;
> 			}
> -			per_cpu[c->node]++;
> +			per_cpu[node]++;
> 		}
> 	}
>
>
>
>

  parent reply	other threads:[~2011-11-23  8:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-22 14:53 [PATCH] " Eric Dumazet
2011-11-22 14:57 ` Christoph Lameter
2011-11-22 15:02   ` [PATCH V2] " Eric Dumazet
2011-11-22 15:03     ` Christoph Lameter
2011-11-23  5:30     ` David Rientjes
2011-11-23  8:32     ` Pekka Enberg [this message]
2011-11-23 15:17       ` Christoph Lameter
2011-11-23 21:19         ` Pekka Enberg
2011-11-23 22:29           ` David Rientjes
2011-11-24  6:45             ` Pekka Enberg

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=alpine.LFD.2.02.1111231030370.14209@tux.localdomain \
    --to=penberg@kernel.org \
    --cc=cl@linux.com \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=markus@trippelsdorf.de \
    --cc=rientjes@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®