* [PATCH] slub: avoid potential NULL dereference or corruption
@ 2011-11-22 14:53 Eric Dumazet
2011-11-22 14:57 ` Christoph Lameter
0 siblings, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2011-11-22 14:53 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Pekka Enberg, linux-kernel
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>
---
mm/slub.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 7d2a996..e8e6714 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4436,29 +4436,33 @@ 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);
struct page *page;
+ int node;
- if (!c || c->node < 0)
+ if (!c)
continue;
-
- if (c->page) {
- if (flags & SO_TOTAL)
- x = c->page->objects;
+ node = ACCESS_ONCE(c->node);
+ if (node < 0)
+ continue;
+ 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;
+ nodes[node] += x;
}
- per_cpu[c->node]++;
+ per_cpu[node]++;
}
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] slub: avoid potential NULL dereference or corruption
2011-11-22 14:53 [PATCH] slub: avoid potential NULL dereference or corruption Eric Dumazet
@ 2011-11-22 14:57 ` Christoph Lameter
2011-11-22 15:02 ` [PATCH V2] " Eric Dumazet
0 siblings, 1 reply; 10+ messages in thread
From: Christoph Lameter @ 2011-11-22 14:57 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Pekka Enberg, linux-kernel
On Tue, 22 Nov 2011, Eric Dumazet wrote:
> diff --git a/mm/slub.c b/mm/slub.c
> index 7d2a996..e8e6714 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4436,29 +4436,33 @@ 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);
> struct page *page;
> + int node;
>
> - if (!c || c->node < 0)
> + if (!c)
> continue;
Drop the check. c can never be NULL these days.
Otherwiswe it looks okay.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH V2] slub: avoid potential NULL dereference or corruption
2011-11-22 14:57 ` Christoph Lameter
@ 2011-11-22 15:02 ` Eric Dumazet
2011-11-22 15:03 ` Christoph Lameter
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Eric Dumazet @ 2011-11-22 15:02 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Pekka Enberg, linux-kernel
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>
---
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]++;
}
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
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
2 siblings, 0 replies; 10+ messages in thread
From: Christoph Lameter @ 2011-11-22 15:03 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Pekka Enberg, linux-kernel
On Tue, 22 Nov 2011, Eric Dumazet wrote:
> show_slab_objects() can trigger NULL dereferences or memory corruption.
Acked-by: Christoph Lameter <cl@linux.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
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
2 siblings, 0 replies; 10+ messages in thread
From: David Rientjes @ 2011-11-23 5:30 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Christoph Lameter, Pekka Enberg, linux-kernel
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>
>
Acked-by: David Rientjes <rientjes@google.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
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
2011-11-23 15:17 ` Christoph Lameter
2 siblings, 1 reply; 10+ messages in thread
From: Pekka Enberg @ 2011-11-23 8:32 UTC (permalink / raw)
To: Eric Dumazet
Cc: Christoph Lameter, linux-kernel, Christian Kujau, markus, David Rientjes
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]++;
> }
> }
>
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
2011-11-23 8:32 ` Pekka Enberg
@ 2011-11-23 15:17 ` Christoph Lameter
2011-11-23 21:19 ` Pekka Enberg
0 siblings, 1 reply; 10+ messages in thread
From: Christoph Lameter @ 2011-11-23 15:17 UTC (permalink / raw)
To: Pekka Enberg
Cc: Eric Dumazet, linux-kernel, Christian Kujau, markus, David Rientjes
On Wed, 23 Nov 2011, Pekka Enberg wrote:
> 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?
It does not fix any current issues but it is safe against potential
compiler refetching of variables that we have already checked against
bad values.
I thought I acked it already?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
2011-11-23 15:17 ` Christoph Lameter
@ 2011-11-23 21:19 ` Pekka Enberg
2011-11-23 22:29 ` David Rientjes
0 siblings, 1 reply; 10+ messages in thread
From: Pekka Enberg @ 2011-11-23 21:19 UTC (permalink / raw)
To: Christoph Lameter
Cc: Eric Dumazet, linux-kernel, Christian Kujau, markus, David Rientjes
On Wed, 2011-11-23 at 09:17 -0600, Christoph Lameter wrote:
> On Wed, 23 Nov 2011, Pekka Enberg wrote:
>
> > 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?
>
> It does not fix any current issues but it is safe against potential
> compiler refetching of variables that we have already checked against
> bad values.
>
> I thought I acked it already?
Yes, you did. I'm just trying to figure out which ones are going
straight to Linus and which ones can wait for v3.3.
Pekka
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
2011-11-23 21:19 ` Pekka Enberg
@ 2011-11-23 22:29 ` David Rientjes
2011-11-24 6:45 ` Pekka Enberg
0 siblings, 1 reply; 10+ messages in thread
From: David Rientjes @ 2011-11-23 22:29 UTC (permalink / raw)
To: Pekka Enberg
Cc: Christoph Lameter, Eric Dumazet, linux-kernel, Christian Kujau, markus
On Wed, 23 Nov 2011, Pekka Enberg wrote:
> Yes, you did. I'm just trying to figure out which ones are going
> straight to Linus and which ones can wait for v3.3.
>
I think it's 3.2-rc material since it can trigger a NULL pointer by
reading a file from userspace, it's not limited only to debugging.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V2] slub: avoid potential NULL dereference or corruption
2011-11-23 22:29 ` David Rientjes
@ 2011-11-24 6:45 ` Pekka Enberg
0 siblings, 0 replies; 10+ messages in thread
From: Pekka Enberg @ 2011-11-24 6:45 UTC (permalink / raw)
To: David Rientjes
Cc: Christoph Lameter, Eric Dumazet, linux-kernel, Christian Kujau, markus
On Wed, 23 Nov 2011, Pekka Enberg wrote:
>> Yes, you did. I'm just trying to figure out which ones are going
>> straight to Linus and which ones can wait for v3.3.
On Wed, 23 Nov 2011, David Rientjes wrote:
> I think it's 3.2-rc material since it can trigger a NULL pointer by
> reading a file from userspace, it's not limited only to debugging.
Applied, thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-11-24 6:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-22 14:53 [PATCH] slub: avoid potential NULL dereference or corruption 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
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
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®