Skip to contentSkip to conversation

Kernel panic after patch f3994eceebf64cf356a82ffb2718ef538eb8d4f4

Bug 11633 Applied Herbert Xu 2 participants 4 messages Sep 25, 2008 – Oct 1, 2008 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

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

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

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

Herbert Xu

author maintainer
#3 lore raw
Quoted 29 lines · Herbert Xu
Quoted 4 lines · Herbert Xu

Perhaps something somewhere is creating an skb with the old way while someone else is assuming that it has the amount of space set out by needed_*room.

This changeset looks very suspicious:

commit f5184d267c1aedb9b7a8cc44e08ff6b8d382c3b5

Author: Johannes Berg <[email protected]>
Date:   Mon May 12 20:48:31 2008 -0700

net: Allow netdevices to specify needed head/tailroom

net/xfrm/xfrm_output.c +3 -2
index 09cd9c0..3f964db 100644
@@ -25,11 +25,11 @@ static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb)
 	struct dst_entry *dst = skb->dst;
 	int nhead = dst->header_len + LL_RESERVED_SPACE(dst->dev)
 		- skb_headroom(skb);
+	int ntail = dst->dev->needed_tailroom - skb_tailroom(skb);
 
-	if (nhead > 0)
-		return pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
+	if (nhead > 0 || ntail > 0)
+		return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC);
 
Quoted 1 line

If nhead < 0 and ntail > 0 we'll go boom...

Here's the fix.

ipsec: Fix pskb_expand_head corruption in xfrm_state_check_space

We're never supposed to shrink the headroom or tailroom. In fact, shrinking the headroom is a fatal action.

net/xfrm/xfrm_output.c +8 -4
index ac25b4c..dc50f1e 100644
@@ -27,10 +27,14 @@ static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb)
 		- skb_headroom(skb);
 	int ntail = dst->dev->needed_tailroom - skb_tailroom(skb);
 
-	if (nhead > 0 || ntail > 0)
-		return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC);
-
-	return 0;
+	if (nhead <= 0) {
+		if (ntail <= 0)
+			return 0;
+		nhead = 0;
+	} else if (ntail < 0)
+		ntail = 0;
+
+	return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC);
 }
 
 static int xfrm_output_one(struct sk_buff *skb, int err)

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw

From: Herbert Xu <[email protected]>
Date: Thu, 25 Sep 2008 10:36:22 +0800

Quoted 8 lines

Here's the fix.

ipsec: Fix pskb_expand_head corruption in xfrm_state_check_space

We're never supposed to shrink the headroom or tailroom. In fact, shrinking the headroom is a fatal action.

Thanks a lot for diagnosing this and writing the patch Herbert.

I'll integrate this when I next get a chance.

author maintainer
#5 lore raw
Quoted 2 lines · David Miller

I'll integrate this when I next get a chance.

Thanks!

Oh and to make it more obvious in future:

net: BUG instead of corrupting memory in pskb_expand_head

If the caller of pskb_expand_head specifies a negative nhead we'll silently overwrite other people's memory. This patch makes it BUG instead.

net/core/skbuff.c +2 -0
index ca1ccdf..3fad166 100644
@@ -701,6 +701,8 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
 #endif
 	long off;
 
+	BUG_ON(nhead < 0);
+
 	if (skb_shared(skb))
 		BUG();
 

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Applied
#6 lore raw

From: Herbert Xu <[email protected]>
Date: Thu, 25 Sep 2008 11:25:54 +0800

Quoted 7 lines

net: BUG instead of corrupting memory in pskb_expand_head

If the caller of pskb_expand_head specifies a negative nhead we'll silently overwrite other people's memory. This patch makes it BUG instead.

Applied to net-next-2.6, thanks!