Skip to contentSkip to conversation

mm: slab: Verify the nodeid passed to ____cache_alloc_node

PATCH Superseded Aaron Tomlin 2 participants 3 messages Feb 21, 2013 – Feb 25, 2013 1 message not in the archive Memory management

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 mm: slab: Verify the nodeid passed to ____cache_alloc_node

Hi,

The addition of this BUG_ON should make debugging easier. While I understand that this code path is "hot", surely it is better to assert the condition than to wait until some random NULL pointer dereference or page fault. If the caller passes an invalid nodeid, at this stage in my opinion it's already a BUG.

Cheers,
Aaron

---8<---
mm: slab: Verify the nodeid passed to ____cache_alloc_node

If the nodeid is > num_online_nodes() this can cause an Oops and a panic(). The purpose of this patch is to assert if this condition is true to aid debugging efforts rather than some random NULL pointer dereference or page fault.

 slab.c |    1 +
 1 file changed, 1 insertion(+)
mm/slab.c +1 -0
index e7667a3..735e8bd 100644
@@ -3412,6 +3412,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
 	void *obj;
 	int x;
 
+	BUG_ON(nodeid > num_online_nodes());
 	l3 = cachep->nodelists[nodeid];
 	BUG_ON(!l3);
 

--
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 6 lines · Aaron Tomlin

The addition of this BUG_ON should make debugging easier. While I understand that this code path is "hot", surely it is better to assert the condition than to wait until some random NULL pointer dereference or page fault. If the caller passes an invalid nodeid, at this stage in my opinion it's already a BUG.

If you assert with VM_BUG_ON, it will be active on debugging kernels only, which I believe is better suited for a hotpath.

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