Skip to contentSkip to conversation

- Fix slab corruption caused by alloc_cpumask_var_node()

PATCH In review Jack Steiner 4 participants 6 messages Apr 2, 2009 – Apr 5, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 - Fix slab corruption caused by alloc_cpumask_var_node()

Fix for slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

Acked-by Mike Travis <travis.sgi.com>

---

Corrruption was found in latest linux-next (4/1)

	v2.6.29-12081-g421a9f3
 lib/cpumask.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/cpumask.c +2 -2
Index: linux/lib/cpumask.c
===================================================================
@@ -109,10 +109,10 @@ bool alloc_cpumask_var_node(cpumask_var_
 #endif
 	/* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
 	if (*mask) {
+		unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
 		unsigned int tail;
 		tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
-		memset(cpumask_bits(*mask) + cpumask_size() - tail,
-		       0, tail);
+		memset(ptr + cpumask_size() - tail, 0, tail);
 	}
 
 	return *mask != NULL;
maintainer
#1 lore raw
Quoted 2 lines · On Thu, 2 Apr 2009 16:27:51 -0500 Jack Steiner <[email protected]> wrote:

Fix for slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

changelog is crappy.

Quoted 4 lines
lib/cpumask.c +0 -0
@@ -109,10 +109,10 @@ bool alloc_cpumask_var_node(cpumask_var_
 #endif

lib/cpumask.c bool alloc_cpumask_var_node(cpumask_var_ · line 117

Quoted 10 lines
lib/cpumask.c +2 -2
 	/* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
 	if (*mask) {
+		unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
 		unsigned int tail;
 		tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
-		memset(cpumask_bits(*mask) + cpumask_size() - tail,
-		       0, tail);
+		memset(ptr + cpumask_size() - tail, 0, tail);
 	}
 

It appears that the bug is that cpumask_bits() returns an `unsigned long *', except the pointer arithmetic in there is designed to operate on char*/void*/etc, correct?

This fix is needed in 2.6.29 as well, correct?

Acked-by on v1 1/1
#4 lore raw
In reply to Jack Steiner
Quoted 22 lines · Jack Steiner

Fix for slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

Acked-by Mike Travis <travis.sgi.com>

---

Corrruption was found in latest linux-next (4/1)

	v2.6.29-12081-g421a9f3
 lib/cpumask.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux/lib/cpumask.c
===================================================================

lib/cpumask.c bool alloc_cpumask_var_node(cpumask_var_ · line 115

Quoted 9 lines
lib/cpumask.c +2 -2
@@ -109,10 +109,10 @@ bool alloc_cpumask_var_node(cpumask_var_
 #endif
 	/* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
 	if (*mask) {
+		unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
 		unsigned int tail;
 		tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
-		memset(cpumask_bits(*mask) + cpumask_size() - tail,
-		       0, tail);
+		memset(ptr + cpumask_size() - tail, 0, tail);

Nice,

Note: it also needs a Cc: <[email protected]> tag as v2.6.29 is affected by this bug too.

Ingo

author Acked-by Mike Travis Acked-by Ingo Molnar
#2 lore raw

Re: [PATCH] - Updated: Fix slab corruption caused by alloc_cpumask_var_node()

In reply to Andrew Morton

Fix slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

The function zeros out cpumask bits beyond the last possible cpu. The starting point for zeroing should be the beginning
of the mask offset by a byte count derived from the number of possible cpus. The offset was calculated in bits instead of bytes. This resulted in overwriting the end of the cpumask.

v2.6.29 is also affected by this bug.

Acked-by Mike Travis <travis.sgi.com>

---

Corrruption was found in latest linux-next (4/1)

	v2.6.29-12081-g421a9f3
 lib/cpumask.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/cpumask.c +2 -2
Index: linux/lib/cpumask.c
===================================================================
@@ -109,10 +109,10 @@ bool alloc_cpumask_var_node(cpumask_var_
 #endif
 	/* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
 	if (*mask) {
+		unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
 		unsigned int tail;
 		tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
-		memset(cpumask_bits(*mask) + cpumask_size() - tail,
-		       0, tail);
+		memset(ptr + cpumask_size() - tail, 0, tail);
 	}
 
 	return *mask != NULL;
#3 lore raw

Re: [PATCH] - Updated: Fix slab corruption caused by alloc_cpumask_var_node()

Quoted 10 lines · Jack Steiner

Fix slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

The function zeros out cpumask bits beyond the last possible cpu. The starting point for zeroing should be the beginning
of the mask offset by a byte count derived from the number of possible cpus. The offset was calculated in bits instead of bytes. This resulted in overwriting the end of the cpumask.

Quoted 6 lines

v2.6.29 is also affected by this bug.

Acked-by Mike Travis <travis.sgi.com>

In the future you can add:

to the signoff/ack section of the changlog in such cases - then the -stable folks will notice the commit automatically.

Thanks,

Ingo

#5 lore raw
In reply to Ingo Molnar
Quoted 5 lines · On Friday 03 April 2009 08:12:19 Ingo Molnar wrote:
Quoted 2 lines · Jack Steiner

Fix for slab corruption caused by alloc_cpumask_var_node() overwriting the tail end of an off-stack cpumask.

Ouch. Thanks for this!

And I see it's already in Linus' tree while I was away, thanks all! Rusty.