Skip to contentSkip to conversation

ipv4: cipso potential BUG()

PATCH Applied Will Rosenberg 3 participants 5 messages Jan 19 – Jan 22

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

Previously, it was discussed that skb_cow() has a bug due to implicit integer casting that can lead to a BUG when headroom < -NET_SKB_PAD. We concluded that it was not worthwhile to fix the root cause and to instead fix the symptom found in calipso. The thread for this issue can be found here:

https://lore.kernel.org/netdev/CAHC9VhQmR8A2vz0W-VrrhYNQ2wgCYxHbAmdgmM2yTL-uh4qiOg@mail.gmail.com/

I recently reviewed the use cases of skb_cow() throughout the kernel and found that cipso_v4_skbuff_setattr() comes very close to triggering the same BUG. However, I concluded this was not triggerable. Even though len_delta can become negative, leading to a negative headroom passed to skb_cow(), we do not satisfy the condition headroom < -NET_SKB_PAD.

Nonetheless, I believe cipso is using skb_cow() dangerously, but since the issue is not triggerable, would it still make sense to patch it? I figured I would throw out a quick email. Please let me know and I can make a similar patch for cipso if necessary.

--
Will Rosenberg

maintainer
#1 lore raw
Quoted 15 lines · Will Rosenberg

Previously, it was discussed that skb_cow() has a bug due to implicit integer casting that can lead to a BUG when headroom < -NET_SKB_PAD. We concluded that it was not worthwhile to fix the root cause and to instead fix the symptom found in calipso. The thread for this issue can be found here:

https://lore.kernel.org/netdev/CAHC9VhQmR8A2vz0W-VrrhYNQ2wgCYxHbAmdgmM2yTL-uh4qiOg@mail.gmail.com/

I recently reviewed the use cases of skb_cow() throughout the kernel and found that cipso_v4_skbuff_setattr() comes very close to triggering the same BUG. However, I concluded this was not triggerable. Even though len_delta can become negative, leading to a negative headroom passed to skb_cow(), we do not satisfy the condition headroom < -NET_SKB_PAD.

Quoted 4 lines

Nonetheless, I believe cipso is using skb_cow() dangerously, but since the issue is not triggerable, would it still make sense to patch it? I figured I would throw out a quick email. Please let me know and I can make a similar patch for cipso if necessary.

Sometimes the easiest way to get an answer to questions like this is to send a patch; since I would expect this particular patch to be of limited scope and very small, I think this advice holds true here.

Signature · 1 line
paul-moore.com
#2 lore raw

PATCH 1/1 cipso: harden use of skb_cow() in cipso_v4_skbuff_setattr()

If skb_cow() is passed a headroom <= -NET_SKB_PAD, it will trigger a BUG. As a result, use cases should avoid calling with a headroom that is negative to prevent triggering this issue.

This is the same code pattern fixed in Commit 58fc7342b529 ("ipv6:
BUG() in pskb_expand_head() as part of calipso_skbuff_setattr()").

In cipso_v4_skbuff_setattr(), len_delta can become negative, leading to a negative headroom passed to skb_cow(). However, the BUG is not triggerable because the condition headroom <= -NET_SKB_PAD cannot be satisfied due to limits on the IPv4 options header size.

Avoid potential problems in the future by only using skb_cow() to grow the skb headroom.

---

Notes:
Given that IPv4 option length should not change, this may not be a worthwhile patch.

Apologies in advance if this ends up being a waste of time.

 net/ipv4/cipso_ipv4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/cipso_ipv4.c +2 -1
index 709021197e1c..32b951ebc0c2 100644
@@ -2196,7 +2196,8 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb,
 	/* if we don't ensure enough headroom we could panic on the skb_push()
 	 * call below so make sure we have enough, we are also "mangling" the
 	 * packet so we should probably do a copy-on-write call anyway */
-	ret_val = skb_cow(skb, skb_headroom(skb) + len_delta);
+	ret_val = skb_cow(skb,
+			  skb_headroom(skb) + (len_delta > 0 ? len_delta : 0));
 	if (ret_val < 0)
 		return ret_val;
 

base-commit: 58bae918d73e3b6cd57d1e39fcf7c75c7dd1a8fe

Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] cipso: harden use of skb_cow() in cipso_v4_skbuff_setattr()

Quoted 23 lines · Will Rosenberg

If skb_cow() is passed a headroom <= -NET_SKB_PAD, it will trigger a BUG. As a result, use cases should avoid calling with a headroom that is negative to prevent triggering this issue.

This is the same code pattern fixed in Commit 58fc7342b529 ("ipv6:
BUG() in pskb_expand_head() as part of calipso_skbuff_setattr()").

In cipso_v4_skbuff_setattr(), len_delta can become negative, leading to a negative headroom passed to skb_cow(). However, the BUG is not triggerable because the condition headroom <= -NET_SKB_PAD cannot be satisfied due to limits on the IPv4 options header size.

Avoid potential problems in the future by only using skb_cow() to grow the skb headroom.

---

Notes:
Given that IPv4 option length should not change, this may not be a worthwhile patch.

Quoted 5 lines

Apologies in advance if this ends up being a waste of time.

 net/ipv4/cipso_ipv4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

I think it's a reasonable thing to do in an effort to avoid future problems. Thanks Will.

Quoted 18 lines
net/ipv4/cipso_ipv4.c +2 -1
index 709021197e1c..32b951ebc0c2 100644
@@ -2196,7 +2196,8 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb,
        /* if we don't ensure enough headroom we could panic on the skb_push()
         * call below so make sure we have enough, we are also "mangling" the
         * packet so we should probably do a copy-on-write call anyway */
-       ret_val = skb_cow(skb, skb_headroom(skb) + len_delta);
+       ret_val = skb_cow(skb,
+                         skb_headroom(skb) + (len_delta > 0 ? len_delta : 0));
        if (ret_val < 0)
                return ret_val;
 

base-commit: 58bae918d73e3b6cd57d1e39fcf7c75c7dd1a8fe --
2.34.1

Signature · 1 line
paul-moore.com
#4 lore raw

Re: [PATCH] cipso: harden use of skb_cow() in cipso_v4_skbuff_setattr()

In reply to Will Rosenberg
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Tue, 20 Jan 2026 08:57:38 -0700 you wrote:

If skb_cow() is passed a headroom <= -NET_SKB_PAD, it will trigger a BUG. As a result, use cases should avoid calling with a headroom that is negative to prevent triggering this issue.

This is the same code pattern fixed in Commit 58fc7342b529 ("ipv6:
BUG() in pskb_expand_head() as part of calipso_skbuff_setattr()").

[...]

Here is the summary with links:
- cipso: harden use of skb_cow() in cipso_v4_skbuff_setattr()

    https://git.kernel.org/netdev/net-next/c/40cb4cb77ea2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html