FAILED: patch "[PATCH] net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()" failed to apply to 5.10-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 56453199d28f0072a8196fba14b2d702632e2219
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 56453199d28f0072a8196fba14b2d702632e2219 Mon Sep 17 00:00:00 2001
From: Josef Bacik <[email protected]>
Date: Wed, 7 Oct 2026 17:36:04 +0000
Subject: [PATCH] net: skbuff: don't BUG() on a bad csum_start in
skb_copy_and_csum_dev()
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3981,7 +3981,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +DEBUG_NET_WARN_ON_ONCE (1 ); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()
From: Josef Bacik <[email protected]>
[ Upstream commit 56453199d28f0072a8196fba14b2d702632e2219 ]
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3149,7 +3149,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +WARN_ON_ONCE (IS_ENABLED (CONFIG_DEBUG_NET )); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0