Skip to contentSkip to conversation

slab: Fix nodeid bounds check for non-contiguous node IDs

PATCH Superseded Paul Mackerras 2 participants 4 messages Nov 30, 2014 – Dec 1, 2014 Memory management

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slab: Fix nodeid bounds check for non-contiguous node IDs

The bounds check for nodeid in ____cache_alloc_node gives false positives on machines where the node IDs are not contiguous, leading to a panic at boot time. For example, on a POWER8 machine the node IDs are typically 0, 1, 16 and 17. This means that num_online_nodes() returns 4, so when ____cache_alloc_node is called with nodeid = 16 the VM_BUG_ON triggers.

To fix this, we instead compare the nodeid with MAX_NUMNODES, and additionally make sure it isn't negative (since nodeid is an int). The check is there mainly to protect the array dereference in the get_node() call in the next line, and the array being dereferenced is of size MAX_NUMNODES. If the nodeid is in range but invalid, the BUG_ON in the next line will catch that.

---

mm/slab.c +1 -1
index eb2b2ea..f34e053 100644
@@ -3076,7 +3076,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
 	void *obj;
 	int x;
 
-	VM_BUG_ON(nodeid > num_online_nodes());
+	VM_BUG_ON(nodeid < 0 || nodeid >= MAX_NUMNODES);
 	n = get_node(cachep, nodeid);
 	BUG_ON(!n);
 
#1 lore raw
Quoted 6 lines · Paul Mackerras

The bounds check for nodeid in ____cache_alloc_node gives false positives on machines where the node IDs are not contiguous, leading to a panic at boot time. For example, on a POWER8 machine the node IDs are typically 0, 1, 16 and 17. This means that num_online_nodes() returns 4, so when ____cache_alloc_node is called with nodeid = 16 the VM_BUG_ON triggers.

Do you have the call trace? If you have it, please add it in the description.

Quoted 8 lines

To fix this, we instead compare the nodeid with MAX_NUMNODES, and additionally make sure it isn't negative (since nodeid is an int). The check is there mainly to protect the array dereference in the get_node() call in the next line, and the array being dereferenced is of size MAX_NUMNODES. If the nodeid is in range but invalid, the BUG_ON in the next line will catch that.

Do you need to backport it into -stable kernels?

mm/slab.c static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, · line 3080

Quoted 12 lines

---

mm/slab.c +1 -1
index eb2b2ea..f34e053 100644
@@ -3076,7 +3076,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
  	void *obj;
  	int x;
 
 
-	VM_BUG_ON(nodeid > num_online_nodes());
+	VM_BUG_ON(nodeid < 0 || nodeid >= MAX_NUMNODES);

How about use:

	VM_BUG_ON(!node_online(nodeid));

When allocating the memory, the node of the memory being allocated must be online. But your code cannot check the condition.

Thanks,
Yasuaki Ishimatsu

Quoted 10 lines
mm/slab.c +0 -1
  	n = get_node(cachep, nodeid);
  	BUG_ON(!n);
 
 
--

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>

--
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>

#2 lore raw
Quoted 9 lines · Yasuaki Ishimatsu
Quoted 6 lines · Paul Mackerras

The bounds check for nodeid in ____cache_alloc_node gives false positives on machines where the node IDs are not contiguous, leading to a panic at boot time. For example, on a POWER8 machine the node IDs are typically 0, 1, 16 and 17. This means that num_online_nodes() returns 4, so when ____cache_alloc_node is called with nodeid = 16 the VM_BUG_ON triggers.

Do you have the call trace? If you have it, please add it in the description.

I can get it easily enough.

Quoted 10 lines
Quoted 8 lines

To fix this, we instead compare the nodeid with MAX_NUMNODES, and additionally make sure it isn't negative (since nodeid is an int). The check is there mainly to protect the array dereference in the get_node() call in the next line, and the array being dereferenced is of size MAX_NUMNODES. If the nodeid is in range but invalid, the BUG_ON in the next line will catch that.

Do you need to backport it into -stable kernels?

It does need to go to stable, yes, for 3.10 and later.

Quoted 10 lines
Quoted 9 lines

---

mm/slab.c +0 -0
index eb2b2ea..f34e053 100644
@@ -3076,7 +3076,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
 	void *obj;
 	int x;
 
Quoted 5 lines

mm/slab.c static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, · line 3079

Quoted 2 lines
mm/slab.c +1 -1
-	VM_BUG_ON(nodeid > num_online_nodes());
+	VM_BUG_ON(nodeid < 0 || nodeid >= MAX_NUMNODES);

How about use:

	VM_BUG_ON(!node_online(nodeid));

That would not be better, since node_online() doesn't bounds-check its argument.

Quoted 2 lines

When allocating the memory, the node of the memory being allocated must be online. But your code cannot check the condition.

The following two lines:

Quoted 2 lines

mm/slab.c static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, · line 3081

Quoted 2 lines
mm/slab.c +0 -0
 	n = get_node(cachep, nodeid);
 	BUG_ON(!n);

effectively check that condition already, as I tried to explain in the commit message.

Regards,
Paul.

#3 lore raw
Quoted 37 lines · Paul Mackerras
Quoted 9 lines · Yasuaki Ishimatsu
Quoted 6 lines · Paul Mackerras

The bounds check for nodeid in ____cache_alloc_node gives false positives on machines where the node IDs are not contiguous, leading to a panic at boot time. For example, on a POWER8 machine the node IDs are typically 0, 1, 16 and 17. This means that num_online_nodes() returns 4, so when ____cache_alloc_node is called with nodeid = 16 the VM_BUG_ON triggers.

Do you have the call trace? If you have it, please add it in the description.

I can get it easily enough.

Quoted 10 lines
Quoted 8 lines

To fix this, we instead compare the nodeid with MAX_NUMNODES, and additionally make sure it isn't negative (since nodeid is an int). The check is there mainly to protect the array dereference in the get_node() call in the next line, and the array being dereferenced is of size MAX_NUMNODES. If the nodeid is in range but invalid, the BUG_ON in the next line will catch that.

Do you need to backport it into -stable kernels?

It does need to go to stable, yes, for 3.10 and later.

Quoted 10 lines
Quoted 9 lines

---

mm/slab.c +0 -0
index eb2b2ea..f34e053 100644
@@ -3076,7 +3076,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
  	void *obj;
  	int x;
 
Quoted 9 lines
Quoted 5 lines

mm/slab.c static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, · line 3079

Quoted 2 lines
mm/slab.c +1 -1
-	VM_BUG_ON(nodeid > num_online_nodes());
+	VM_BUG_ON(nodeid < 0 || nodeid >= MAX_NUMNODES);

How about use:

	VM_BUG_ON(!node_online(nodeid));

That would not be better, since node_online() doesn't bounds-check its argument.

Ah. You are right.

Quoted 10 lines
Quoted 2 lines

When allocating the memory, the node of the memory being allocated must be online. But your code cannot check the condition.

The following two lines:

Quoted 2 lines

mm/slab.c static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, · line 3081

Quoted 2 lines
mm/slab.c +0 -0
  	n = get_node(cachep, nodeid);
  	BUG_ON(!n);

effectively check that condition already, as I tried to explain in the commit message.

O.K. I understood.

Thansk,
Yasuaki Ishimatsu

Quoted 4 lines

Regards,
Paul.