From: Josef Bacik <josef@toxicpanda.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH net-next v2 0/8] net: skbuff: replace most BUG_ON()s with error returns
Date: Wed, 07 Oct 2026 17:35:59 +0000 [thread overview]
Message-ID: <20261007-b4-skbuff-bug-on-v2-0-b9a5f732895b@toxicpanda.com> (raw)
v1: https://lore.kernel.org/all/20261006-b4-skbuff-bug-on-v1-0-1b4434c5357c@toxicpanda.com/
v1->v2:
- Use DEBUG_NET_WARN_ON_ONCE() instead of WARN_ON_ONCE(), so
panic_on_warn systems take the error path instead of panicking
(Willem, Fernando).
- Split out the skb_copy_and_csum_bits() unreadable-frags fix and sent
it to net on its own with Cc: stable (Willem):
https://lore.kernel.org/all/20261007-b4-skb-copy-csum-stale-bytes-v1-1-adbbde033fb3@toxicpanda.com/
- Rebased onto current net-next.
--- Original email (v1) ---
I'm going through and reducing BUG_ON() usage in areas that have created
the most problems for us. 89 commits in the tree quote "kernel BUG at
net/core/skbuff.c", 31 of them since 2024, and some of those could be
triggered from inside a user namespace.
The first patch is a fix: skb_copy_and_csum_bits() leaves stale bytes
in a buffer headed for the wire when it hits unreadable frags. The
BUG_ON() conversion of the same function needs the same handling, so
it's here rather than sent separately.
The rest of the series converts 17 of the 19 BUG_ON()s in skbuff.c.
Each one becomes
if (WARN_ON_ONCE(cond))
<error path>;
where the error path is a failure return the function already has and
its callers already handle: -EINVAL from pskb_expand_head() and
skb_segment(), NULL from skb_copy(), 0 from skb_shift(), and so on.
Each patch says what its error path is and why it's safe. Anybody who
wants the old behaviour, syzbot included, gets it with panic_on_warn.
A few don't have an obvious error return:
- skb_copy_and_csum_bits() zeroes the part of the caller's buffer it
couldn't fill instead of leaving stale bytes in it.
- skb_copy_and_csum_dev() copies the frame without a checksum. It
also now catches a csum_start before the head and a csum_offset past
the end of the frame, which the BUG_ON() missed.
- skb_shift()'s second check ran after the shift had been committed.
It moves up to just before the commit, where nothing has changed
yet, and returns 0 there.
Two BUG_ON()s are left on purpose. __pskb_pull_tail() and
skb_pull_rcsum() have callers that can't otherwise fail, so they don't
check the return. Some of them would carry on and BUG() somewhere
else, or push back a pull that never happened. Those need their
callers fixed first and will come as separate series.
skb_over_panic() and skb_under_panic() keep their BUG() as well; that's
overflow hardening and should stay fatal.
skbuff.o text on x86_64 defconfig grows by 114 bytes. The fast path
takes the same branch it does today; the extra bytes are the error
paths that BUG() used to replace.
Testing: x86_64 defconfig with CONFIG_WERROR boots, and every patch
builds net/core/skbuff.o on its own with allmodconfig, W=1 and
CONFIG_DEBUG_NET. A test module drives 12 of the 17 converted
BUG_ON()s with a bad argument or a malformed skb, skb_shift() through
a test-only export. Each one warns once and returns its documented
error, and the skbs are left alone. The same module covers the
unreadable-frags fix. test_bpf's skb_segment tests pass. The other
five were only reviewed: skb_crc32c() isn't built in defconfig, and
the four skb_segment() layout checks need a crafted frag_list.
Thanks,
Josef
---
Josef Bacik (8):
net: skbuff: don't BUG() on bad arguments to pskb_expand_head()
net: skbuff: don't BUG() on a bad frag_list layout in skb_segment()
net: skbuff: don't BUG() when skb_copy_bits() fails in copy helpers
net: skbuff: don't BUG() on leftover length in skb_checksum() and friends
net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()
net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits()
net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy()
net: skbuff: remove the BUG_ON()s from skb_shift()
net/core/skbuff.c | 118 +++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 98 insertions(+), 20 deletions(-)
---
base-commit: 45ad84d2800e4a092fb8d96006a533b2d0ab13f6
change-id: 20261006-b4-skbuff-bug-on-b2844a487925
next reply other threads:[~2026-10-07 17:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 17:35 Josef Bacik [this message]
2026-10-07 17:36 ` [PATCH net-next v2 1/8] net: skbuff: don't BUG() on bad arguments to pskb_expand_head() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 2/8] net: skbuff: don't BUG() on a bad frag_list layout in skb_segment() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 3/8] net: skbuff: don't BUG() when skb_copy_bits() fails in copy helpers Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 4/8] net: skbuff: don't BUG() on leftover length in skb_checksum() and friends Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 5/8] net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 6/8] net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 7/8] net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 8/8] net: skbuff: remove the BUG_ON()s from skb_shift() Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261007-b4-skbuff-bug-on-v2-0-b9a5f732895b@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox