net: skbuff: reject invalid pull bounds
Subsystems (3)
PATCH 1/1 net: skbuff: reject invalid pull bounds
skb_maybe_pull_tail() subtracts skb_headlen(skb) from the unsigned max argument and passes the result to __pskb_pull_tail() as a signed int. The function does not ensure that max is at least skb_headlen(skb).
This can happen while parsing IPv6 extension headers when an skb already has a linear area larger than MAX_IPV6_HDR_LEN. Once the parser needs data beyond the linear area, max - skb_headlen(skb) wraps and is converted to a negative delta. __pskb_pull_tail() then passes that negative length to skb_copy_bits(), where it can become a very large copy length.
Reject this inconsistent bound before doing the subtraction. In this case pulling up to max cannot satisfy len because the initial check established that skb_headlen(skb) is smaller than len.
--- net/core/skbuff.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/skbuff.c +3 -0
@@ -5838,6 +5838,9 @@ static int skb_maybe_pull_tail(struct sk_buff *skb, unsigned int len,if (max > skb->len) max = skb->len; +if (max <skb_headlen (skb)) +return -EPROTO ; +if (__pskb_pull_tail (skb, max -skb_headlen (skb)) ==NULL )return -ENOMEM ;
Signature · 1 line
2.43.0
Quoted 29 lines · Shihuang Liu
skb_maybe_pull_tail()subtractsskb_headlen(skb)from the unsigned max argument and passes the result to__pskb_pull_tail()as a signed int. The function does not ensure that max is at leastskb_headlen(skb).This can happen while parsing IPv6 extension headers when an skb already has a linear area larger than
MAX_IPV6_HDR_LEN. Once the parser needs data beyond the linear area, max -skb_headlen(skb)wraps and is converted to a negative delta.__pskb_pull_tail()then passes that negative length toskb_copy_bits(), where it can become a very large copy length.Reject this inconsistent bound before doing the subtraction. In this case pulling up to max cannot satisfy len because the initial check established that
skb_headlen(skb)is smaller than len.Fixes 1431fb31ecba ("xen-netback: fix fragment detection in checksum setup")Assisted-by LLMSigned-off-by Shihuang Liu <[email protected]>--- net/core/skbuff.c | 3 +++ 1 file changed, 3 insertions(+)net/core/skbuff.c +0
-0
net/core/skbuff.c static int skb_maybe_pull_tail(struct sk_buff *skb, unsigned int len, · line 5843
Quoted 6 lines
net/core/skbuff.c +3
-0@@ -5838,6 +5838,9 @@ static int skb_maybe_pull_tail(struct sk_buff *skb, unsigned int len,if (max > skb->len) max = skb->len; +if (max <skb_headlen (skb)) +return -EPROTO ; +
pw-bot: rejected
Please ask your LLM not to slow down the fast path, and find a better fix in skb_checksum_setup_ipv6().
Note how skb_checksum_setup_ip() is fine.
net/core/skbuff.c +0 -0
100644
net/core/skbuff.c +0 -0
@@ -5974,7 +5974,8 @@ static int skb_checksum_setup_ipv6(struct
sk_buff *skb, bool recalculate)
err = skb_maybe_pull_tail(skb,
off + sizeof(struct ipv6_opt_hdr),
- MAX_IPV6_HDR_LEN);
+ off +
+ sizeof(struct ipv6_opt_hdr));
if (err < 0)
goto out;@@ -5989,7 +5990,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate)
err = skb_maybe_pull_tail(skb,
off + sizeof(struct ip_auth_hdr),
- MAX_IPV6_HDR_LEN);
+ off +
+ sizeof(struct ip_auth_hdr));
if (err < 0)
goto out;@@ -6004,7 +6006,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate)
err = skb_maybe_pull_tail(skb,
off + sizeof(struct frag_hdr),
- MAX_IPV6_HDR_LEN);
+ off +
+ sizeof(struct frag_hdr));
if (err < 0)
goto out;Quoted 73 lines · Eric Dumazet
Quoted 29 lines · Shihuang Liu
skb_maybe_pull_tail()subtractsskb_headlen(skb)from the unsigned max argument and passes the result to__pskb_pull_tail()as a signed int. The function does not ensure that max is at leastskb_headlen(skb).This can happen while parsing IPv6 extension headers when an skb already has a linear area larger than
MAX_IPV6_HDR_LEN. Once the parser needs data beyond the linear area, max -skb_headlen(skb)wraps and is converted to a negative delta.__pskb_pull_tail()then passes that negative length toskb_copy_bits(), where it can become a very large copy length.Reject this inconsistent bound before doing the subtraction. In this case pulling up to max cannot satisfy len because the initial check established that
skb_headlen(skb)is smaller than len.Fixes 1431fb31ecba ("xen-netback: fix fragment detection in checksum setup")Assisted-by LLMSigned-off-by Shihuang Liu <[email protected]>--- net/core/skbuff.c | 3 +++ 1 file changed, 3 insertions(+)net/core/skbuff.c +0
-0net/core/skbuff.c static int skb_maybe_pull_tail(struct sk_buff *skb, unsigned int len, · line 5843
Quoted 6 lines
net/core/skbuff.c +3
-0@@ -5838,6 +5838,9 @@ static int skb_maybe_pull_tail(struct sk_buff *skb, unsigned int len,if (max > skb->len) max = skb->len; +if (max <skb_headlen (skb)) +return -EPROTO ; +pw-bot: rejected
Please ask your LLM not to slow down the fast path, and find a better fix in
skb_checksum_setup_ipv6().Note how
skb_checksum_setup_ip()is fine.net/core/skbuff.c +0
-0100644
net/core/skbuff.c +4
-2@@ -5974,7 +5974,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct ipv6_opt_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct ipv6_opt_hdr ));if (err <0 ) goto out;@@ -5989,7 +5990,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct ip_auth_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct ip_auth_hdr ));if (err <0 ) goto out;
net/core/skbuff.c static int skb_checksum_setup_ipv6(struct · line 6013
Quoted 9 lines
net/core/skbuff.c +2
-1@@ -6004,7 +6006,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct frag_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct frag_hdr ));if (err <0 ) goto out;
Following up on this, are you planning to send a V2?
Thanks.
Quoted 1 line
Following up on this, are you planning to send a V2?
Yes, hopefully next week. I have a few other things to take care of first. Sorry for the delay.
Thanks,
Shihuang