* Re: [PATCH net] net/sched: act_csum: bound the IPv6 jumbo payload length
@ 2026-11-16 18:21 Piyus Kedia
2026-11-16 18:21 ` [PATCH net v2] " Piyus Kedia
0 siblings, 1 reply; 3+ messages in thread
From: Piyus Kedia @ 2026-11-16 18:21 UTC (permalink / raw)
To: Jamal Hadi Salim, Jiri Pirko, netdev
Cc: davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-kernel, Kapil Vaswani
> Could the changelog say that TCP and ICMP csum configurations (for
> example "action csum tcp") were also exposed to a bounded over-read? As
> written, it reads as if only TCA_CSUM_UPDATE_FLAG_UDPLITE setups were
> affected.
You are right. v2 follows this mail with the changelog corrected. v1
claimed those handlers were "protected by accident" because csum_partial()
takes an int; that is true only of the kernel it was tested on, and I
should have checked why.
The reason is worth putting in the changelog, because it is also why a
KASAN fuzzer cannot find those three paths. On x86 there are two
implementations of csum_partial() and the configuration chooses between
them:
arch/x86/Kconfig
config GENERIC_CSUM
bool
default y if KMSAN || KASAN
arch/x86/lib/Makefile
ifneq ($(CONFIG_GENERIC_CSUM),y)
lib-y += csum-partial_64.o csum-copy_64.o csum-wrappers_64.o
endif
lib/Makefile
obj-$(CONFIG_GENERIC_CSUM) += checksum.o
So a kernel with KASAN gets lib/checksum.c, whose do_csum() opens with
if (len <= 0)
goto out;
and a negative length reads nothing. A kernel without KASAN - which is
to say a production kernel - gets arch/x86/lib/csum-partial_64.c, which
has no such test and dispatches like this:
if (likely(len >= 80)) { ... } /* signed, false when negative */
if (len >= 40) { ... } /* signed, false */
if (len & 32) { ... } /* bitwise, runs */
if (len & 16) { ... }
if (len & 8) { ... }
if (len & 7) { ... }
The first two tests are signed comparisons and the last four are bitwise,
so a negative length reads whatever its low six bits say, up to
32+16+8+7 = 63 bytes. Your example confirms it exactly: len = -70 is
0xFFFFFFBA, low byte 1011 1010, so the 32, 16, 8 and 2 blocks run and 58
bytes are summed from the transport header.
That is why the KASAN report in the changelog names lib/checksum.c:119
rather than the x86_64 file, and why only the UDP-Lite arm showed up: on
the kernel that found this, the other three paths genuinely did read
nothing, because enabling the sanitiser had replaced the implementation
that would have over-read. The over-read on tcf_csum_ipv6_tcp(),
tcf_csum_ipv6_icmp() and the ul == 0 arm of tcf_csum_ipv6_udp() is real,
it is bounded at 63 bytes rather than 65535, and it is invisible to the
tool that would normally catch it.
This is a new posting rather than a reply in the old thread, so here is
the context. v1 and the review being answered:
https://lore.kernel.org/r/20261112075445.3555341-1-piyus@iiitd.ac.in
and the [BUG] report, with the original KASAN trace and the reproduction
conditions, which went out as its own thread - not threaded with v1, which
is my fault:
https://lore.kernel.org/r/20261112075159.3552470-1-piyus@iiitd.ac.in
I checked your arithmetic and the three call sites before writing this,
on net-next: act_csum.c:245, :196 and :343 respectively, each reached
with the negative value behind only the wrapping pskb_may_pull() in
tcf_csum_skb_nextlayer().
The code change is unchanged in v2 - as you say, bounding *pl in
tcf_csum_ipv6_hopopts() closes all four paths, so the diff is byte-for-byte
the same. Only the changelog grows: it now says that TCP, ICMP and the
ul == 0 UDP-Lite arm were exposed to a bounded over-read of up to 63 bytes
on kernels without KASAN, and that the 65535-byte read is the UDP-Lite case
specifically.
Thank you for the review - the KASAN-swaps-the-implementation part is
something I would not have gone looking for.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net v2] net/sched: act_csum: bound the IPv6 jumbo payload length
2026-11-16 18:21 [PATCH net] net/sched: act_csum: bound the IPv6 jumbo payload length Piyus Kedia
@ 2026-11-16 18:21 ` Piyus Kedia
2026-11-19 6:22 ` netdev-bot+sashiko
0 siblings, 1 reply; 3+ messages in thread
From: Piyus Kedia @ 2026-11-16 18:21 UTC (permalink / raw)
To: Jamal Hadi Salim, Jiri Pirko, netdev
Cc: davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-kernel, Kapil Vaswani, Piyus Kedia
tcf_csum_ipv6_hopopts() takes the payload length out of a hop-by-hop
jumbo option and stores it unchecked:
case IPV6_TLV_JUMBO:
optlen = xh[off + 1] + 2;
if (optlen != 6 || len < 6 || (off & 3) != 2)
/* wrong jumbo option length/alignment */
return 0;
*pl = ntohl(*(__be32 *)(xh + off + 2));
tcf_csum_ipv6() then hands ipl = *pl + sizeof(struct ipv6hdr) to the
per-protocol handlers as the extent of the packet, so a 32-bit value
chosen by whoever built the header reaches the length they read.
Both guards downstream fail on such a value. In
tcf_csum_skb_nextlayer(), ipl + ntkoff is an unsigned int plus an int, so
an ipl just under 2^32 wraps to a small number and pskb_may_pull()
succeeds without pulling anything, while ipl < hl stays false precisely
because ipl is huge. tcf_csum_ipv6_udp()'s UDPLITE arm then admits any
16-bit length, since ul <= ipl - ihl compares against ~4.29e9, and
csum_partial() reads that many bytes off the end of the skb. (The plain
UDP arm is not affected: it requires ul == ipl - ihl.)
Three more paths take the same unbounded ipl. tcf_csum_ipv6_tcp(),
tcf_csum_ipv6_icmp() and the ul == 0 arm of tcf_csum_ipv6_udp() each do
skb->csum = csum_partial(hdr, ipl - ihl, 0);
with only tcf_csum_skb_nextlayer() in front of them. When ipl lies in
[2^32 - ntkoff, 2^32 - 1] the sum there wraps to a v in [0, ntkoff - 1],
pskb_may_pull() succeeds and ipl < hl is false, so ipl - ihl arrives at
csum_partial()'s int len as the negative v - ntkoff - ihl.
Whether a negative length reads anything depends on the configuration,
and that is also why a KASAN fuzzer does not reach these three. x86 has
two implementations of csum_partial() and the config chooses:
arch/x86/Kconfig
config GENERIC_CSUM
bool
default y if KMSAN || KASAN
With KASAN the kernel gets lib/checksum.c, whose do_csum() opens with
"if (len <= 0) goto out;" and reads nothing. Without KASAN it gets
arch/x86/lib/csum-partial_64.c, which has no such test:
if (likely(len >= 80)) { ... } /* signed, false when negative */
if (len >= 40) { ... } /* signed, false */
if (len & 32) { ... } /* bitwise, runs */
if (len & 16) { ... }
if (len & 8) { ... }
if (len & 7) { ... }
The first two tests are signed comparisons and the last four are bitwise,
so a negative length sums whatever its low six bits say, up to
32+16+8+7 = 63 bytes from the transport header. With the payload_len
0xFFFFFFCA used above, a 16-byte hop-by-hop header (ihl = 56) and
ntkoff = 14, len is -70, whose low byte is 1011 1010, so the 32, 16, 8
and 2 blocks run and 58 bytes are read past a 20-byte TCP header. The
folded result is written into tcph->check or icmp6_cksum and transmitted.
So "action csum tcp" and "action csum icmp" setups were exposed to a
bounded over-read of up to 63 bytes on kernels built without KASAN, while
the 65535-byte read reported below is the UDP-Lite case specifically.
With payload_len 0xFFFFFFCA, a UDPLITE header claiming 60000 bytes and a
704-byte skb, KASAN reports:
BUG: KASAN: slab-out-of-bounds in csum_partial+0x103/0x1f0 lib/checksum.c:119
Read of size 4 at addr ffff8880259642c0 by task syz-executor/13111
tcf_csum_ipv6_udp+0x19e/0x250 net/sched/act_csum.c
tcf_csum_ipv6+0x63c/0x780 net/sched/act_csum.c:549
tcf_csum_act+0x34d/0x480 net/sched/act_csum.c:601
tcf_action_exec+0x109/0x390 net/sched/act_api.c:1161
tcf_classify+0x13d/0x440 net/sched/cls_api.c:1875
tc_run+0x31a/0x460 net/core/dev.c:4491
__dev_queue_xmit+0x1a7e/0x2390 net/core/dev.c:4890
ip6_output+0x280/0x400 net/ipv6/ip6_output.c:248
rawv6_send_hdrinc+0xb90/0x1170 net/ipv6/raw.c:663
rawv6_sendmsg+0x10d3/0x1260 net/ipv6/raw.c:908
The buggy address belongs to the object at ffff888025964000
which belongs to the cache skbuff_small_head of size 704
The buggy address is located 0 bytes to the right of
allocated 704-byte region [ffff888025964000, ffff8880259642c0)
The packet is generated locally through a raw AF_INET6 socket with
IPV6_HDRINCL and leaves an Ethernet device, so skb_network_offset() is
non-zero and the sum above wraps. Reaching it needs a clsact qdisc with
a csum action carrying TCA_CSUM_UPDATE_FLAG_UDPLITE, which is
CAP_NET_ADMIN in the network namespace - reachable by an unprivileged
user through a user namespace. The folded checksum of the out-of-bounds
bytes is written into the packet and transmitted.
Bound the length the way nf_ip6_check_hbh_len() already does for the same
option: a jumbogram carries payload_len 0 and more than IPV6_MAXPLEN
bytes, and the length it claims must be backed by the skb. Once *pl is
bounded, ipl cannot exceed skb->len, the sum in
tcf_csum_skb_nextlayer() no longer wraps, and the UDPLITE comparison is a
real bound again.
The [BUG] report for this, with the KASAN trace, the reproduction
conditions and the impact, went to the list as a separate mail and was not
threaded with v1. Both are linked below: the report first, then v1 and the
review of it.
Per Documentation/process/generated-content.rst: the out-of-bounds read
was found by an AI-driven fuzzing harness, developed
jointly by Kapil Vaswani and myself, which exercised the csum action
under KASAN on x86_64. The root-cause analysis, this changelog and the
patch were written with the assistance of a large language model,
and reviewed by hand; the before/after testing below
the --- was run by us. The analysis of the TCP, ICMP and ul == 0 paths
added in this version came from addressing an AI-generated review of v1
on the list; the Kconfig and Makefile behaviour it rests on was checked
against the tree by hand.
Link: https://lore.kernel.org/r/20261112075159.3552470-1-piyus@iiitd.ac.in
Link: https://lore.kernel.org/r/20261112075445.3555341-1-piyus@iiitd.ac.in
Fixes: eb4d40654505 ("net/sched: add ACT_CSUM action to update packets checksums")
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
v2: changelog only; the code change is unchanged.
v1 said the handlers passing ipl - ihl were protected because
csum_partial() takes an int. That was true of the kernel it was
tested on and not of a kernel without KASAN, which links a
csum_partial() with no len <= 0 test. v2 states the exposure of
tcf_csum_ipv6_tcp(), tcf_csum_ipv6_icmp() and the ul == 0 UDP-Lite
arm, bounded at 63 bytes, and why the sanitiser hides it.
Bounding *pl in tcf_csum_ipv6_hopopts() already closed all four
paths in v1, so the diff is byte-for-byte the same.
Tested on 7.3.1 with KASAN, in a single-VM qemu rig, same .config and
same image before and after; only net/sched/act_csum.o and the relink differ
(kernel build #2 unpatched, #3 patched):
jumbo length payload_len before after
variant A 0xFFFFFFCA 16 KASAN, VM lost ok, exit 0
variant B 0xFFFFFFCA 0 KASAN, VM lost ok, exit 0
control none (PadN) 16 not run ok
before, variant A: Read of size 4 at addr ffff888024cb6340, task 11851
before, variant B: Read of size 4 at addr ffff88805fe8e9c0, task 9555
Both faulting runs reach csum_partial() through the trace above. After the
patch both programs run to completion with every setup step succeeding and
all four sendto() calls accepted, so the packets do travel the egress path
and the action simply refuses the length:
ntkoff=14 pl=0xffffffca ipl=0xfffffff2 ipl+ntkoff=0x00000000 \
ipl-ihl=0xffffffc2 ul=60000
The control is the same program with the jumbo option replaced by a PadN and
a UDP-Lite length of 8, which is inside the packet. It was run on the
patched kernel only, since what it is there to show is that the patch did
not break the path: the walker still accepts an ordinary hop-by-hop option
and csum_partial() still runs over the 8 bytes the packet really has. Only
an unbacked jumbo length is rejected.
Reproducer: not included here. This bug was found with AI assistance, which
Documentation/process/security-bugs.rst says to treat as public; the same
paragraph says not to post the reproducer publicly. It is a short shell
script plus a ~40-line C sender, tested, and available on request.
Conditions it needs: a clsact qdisc with a csum action carrying
TCA_CSUM_UPDATE_FLAG_UDPLITE, on an Ethernet-type device, with the packet
locally generated so that skb_network_offset() is 14 and the sum in
tcf_csum_skb_nextlayer() can wrap. CAP_NET_ADMIN in the network namespace,
which CONFIG_USER_NS makes reachable by an unprivileged user.
net/sched/act_csum.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 5fff52a8ca90..eab8cdf6745b 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -449,7 +449,8 @@ static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
return 0;
}
-static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh, unsigned int ixhl,
+static int tcf_csum_ipv6_hopopts(struct sk_buff *skb,
+ struct ipv6_opt_hdr *ip6xh, unsigned int ixhl,
unsigned int *pl)
{
int off, len, optlen;
@@ -463,13 +464,29 @@ static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh, unsigned int ixhl,
case IPV6_TLV_PAD1:
optlen = 1;
break;
- case IPV6_TLV_JUMBO:
+ case IPV6_TLV_JUMBO: {
+ unsigned int avail = skb->len - skb_network_offset(skb);
+ u32 pkt_len;
+
optlen = xh[off + 1] + 2;
if (optlen != 6 || len < 6 || (off & 3) != 2)
/* wrong jumbo option length/alignment */
return 0;
- *pl = ntohl(*(__be32 *)(xh + off + 2));
+ pkt_len = ntohl(*(__be32 *)(xh + off + 2));
+ /* RFC 2675: a jumbogram carries payload_len 0 and more
+ * than IPV6_MAXPLEN bytes. Reject anything else, and
+ * anything the skb cannot back: callers take this as
+ * the extent of the packet and read that far into it.
+ */
+ if (pkt_len <= IPV6_MAXPLEN ||
+ ipv6_hdr(skb)->payload_len)
+ return 0;
+ if (avail < sizeof(struct ipv6hdr) ||
+ pkt_len > avail - sizeof(struct ipv6hdr))
+ return 0;
+ *pl = pkt_len;
goto done;
+ }
default:
optlen = xh[off + 1] + 2;
if (optlen > len)
@@ -521,7 +538,7 @@ static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags)
goto fail;
ip6xh = (void *)(skb_network_header(skb) + hl);
if ((nexthdr == NEXTHDR_HOP) &&
- !(tcf_csum_ipv6_hopopts(ip6xh, ixhl, &pl)))
+ !(tcf_csum_ipv6_hopopts(skb, ip6xh, ixhl, &pl)))
goto fail;
nexthdr = ip6xh->nexthdr;
hl += ixhl;
base-commit: a2fd526d644233d6a892c28173f07c61e21e4c93
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/sched: act_csum: bound the IPv6 jumbo payload length
2026-11-16 18:21 ` [PATCH net v2] " Piyus Kedia
@ 2026-11-19 6:22 ` netdev-bot+sashiko
0 siblings, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 6:22 UTC (permalink / raw)
To: piyus
Cc: jhs, jiri, netdev, davem, edumazet, kuba, pabeni, horms,
linux-kernel, kapil
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The v2 changelog says the TCP, ICMPv6 and UDP-Lite ul == 0
paths were exposed only to "a bounded over-read of up to 63 bytes",…
- [Medium] The changelog understates who can trigger the bug.
--
net/sched: act_csum: bound the IPv6 jumbo payload length
This patch bounds the jumbo payload length parsed by
tcf_csum_ipv6_hopopts(). The length must exceed IPV6_MAXPLEN, the IPv6
payload_len must be zero, and the claimed length must fit within the skb.
This stops the ipl + ntkoff sum in tcf_csum_skb_nextlayer() from wrapping
and keeps csum_partial() from reading past the end of the skb.
Link: https://lore.kernel.org/r/20261112075159.3552470-1-piyus@iiitd.ac.in
Link: https://lore.kernel.org/r/20261112075445.3555341-1-piyus@iiitd.ac.in
> 16-bit length, since ul <= ipl - ihl compares against ~4.29e9, and
> csum_partial() reads that many bytes off the end of the skb. (The plain
> UDP arm is not affected: it requires ul == ipl - ihl.)
[ ... ]
> So "action csum tcp" and "action csum icmp" setups were exposed to a
> bounded over-read of up to 63 bytes on kernels built without KASAN, while
> the 65535-byte read reported below is the UDP-Lite case specifically.
[Severity: Medium]
Is this impact statement complete? It covers only reads, but the same
wrapped-ipl path also seems to allow out-of-bounds header writes.
When ipl + ntkoff wraps, the only check that any transport header bytes
exist is the loop guard in tcf_csum_ipv6(). It covers one byte:
} while (pskb_may_pull(skb, hl + 1 + ntkoff));
tcf_csum_skb_nextlayer() then lets the wrapped ipl through. Also,
skb_try_make_writable() does not check the length:
if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) ||
skb_try_make_writable(skb, hl + ntkoff))
After that, the handlers store to header fields whose offsets were never
checked:
tcf_csum_ipv6_tcp(): tcph->check = 0; (bytes 16-17)
tcf_csum_ipv6_icmp(): icmp6h->icmp6_cksum = 0; (bytes 2-3)
tcf_csum_ipv6_udp(): udph->check = 0; (bytes 6-7)
In tcf_csum_ipv6_udp(), the udph->check store comes before the ul tests:
ul = udp_get_len_short(udph);
udph->check = 0;
if (udplite) {
...
} else {
if (ul != ipl - ihl)
goto ignore_obscure_skb;
So the plain UDP arm cannot do the large read. It still writes at an
unchecked offset, though, and udph->len is read from the same unchecked
header.
On the rawv6_send_hdrinc() path, the skb is allocated with
length + hlen + tlen + 15 bytes. With tlen = 0 and a length of the form
41 + 8k, the tailroom can be exactly 15 bytes. Two examples are 353 bytes
in the 704-byte small head and 673 bytes in kmalloc-1024. With a 1-byte
TCP header, tcph->check then lands on skb_shared_info at skb->end. KASAN
would not flag this because the store stays inside the allocation.
The code change closes all of these paths, since the new bound on *pl
keeps ipl + ntkoff within skb->len. v2 was a changelog-only respin meant
to describe the exposure. Could the changelog also mention these writes,
and qualify the statement that the plain UDP arm is not affected?
[ ... ]
> The packet is generated locally through a raw AF_INET6 socket with
> IPV6_HDRINCL and leaves an Ethernet device, so skb_network_offset() is
> non-zero and the sum above wraps. Reaching it needs a clsact qdisc with
> a csum action carrying TCA_CSUM_UPDATE_FLAG_UDPLITE, which is
> CAP_NET_ADMIN in the network namespace - reachable by an unprivileged
> user through a user namespace. The folded checksum of the out-of-bounds
> bytes is written into the packet and transmitted.
[ ... ]
> Conditions it needs: a clsact qdisc with a csum action carrying
> TCA_CSUM_UPDATE_FLAG_UDPLITE, on an Ethernet-type device, with the packet
> locally generated so that skb_network_offset() is 14 and the sum in
> tcf_csum_skb_nextlayer() can wrap. CAP_NET_ADMIN in the network namespace,
> which CONFIG_USER_NS makes reachable by an unprivileged user.
[Severity: Medium]
Can a wider set of senders trigger this than described here?
CAP_NET_ADMIN is needed to install the csum action, but not to send the
packet that reaches it.
A bridged IPv6 frame from another host also arrives at tc egress with
skb_network_offset() equal to 14:
__netif_receive_skb_core()
skb_reset_network_header(skb);
-> bridge rx_handler -> forward
br_dev_queue_push_xmit()
skb_push(skb, ETH_HLEN);
dev_queue_xmit(skb);
-> tc egress -> tcf_csum_act() -> tcf_csum_ipv6()
-> tcf_csum_ipv6_hopopts()
These frames never pass through ipv6_rcv() or its jumbo option checks.
The only bridge-side check is br_validate_ipv6()->nf_ip6_check_hbh_len(),
and that only runs with br_netfilter.
act_mirred ingress-to-egress redirects also push the MAC header back, so
ntkoff is mac_len at the target device's egress.
Take a bridge, VM tap or container veth host where action csum is
installed on a port's egress. A remote, guest or container sender with no
privilege on the host could send a jumbo length of 0xFFFFFFCA. That would
trigger the UDP-Lite read, or the TCP/ICMP over-read and header writes,
and the folded checksum would be transmitted.
The new bound uses skb->len - skb_network_offset(skb), so the fix covers
these paths too. Since this affects stable and security triage, could the
changelog and the conditions note describe this broader exposure rather
than only locally generated packets?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116182108.2581258-2-piyus%40iiitd.ac.in
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 6:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 18:21 [PATCH net] net/sched: act_csum: bound the IPv6 jumbo payload length Piyus Kedia
2026-11-16 18:21 ` [PATCH net v2] " Piyus Kedia
2026-11-19 6:22 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®