All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jun Yang <juny24602@gmail.com>
To: jhs@mojatatu.com, jiri@resnulli.us
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, hadi@cyberus.ca,
	baronchon@n7mm.org, netdev@vger.kernel.org,
	junvyyang@tencent.com, corvus@tencent.com, stable@kernel.org
Subject: [PATCH net] net/sched: act_csum: reject over-long packets before adding the offset
Date: Wed, 25 Nov 2026 15:14:29 +0800	[thread overview]
Message-ID: <20261125071432.53293-1-juny24602@gmail.com> (raw)

From: Jun Yang <junvyyang@tencent.com>

tcf_csum_skb_nextlayer() validates the claimed packet length @ipl by
calling pskb_may_pull(skb, ipl + ntkoff), where @ntkoff is the offset of
the network header from skb->data and @ipl is taken from the packet
itself.

For IPv6 the action honours the jumbo payload option, so @ipl is derived
from an attacker controlled 32-bit value and can be made to wrap when
@ntkoff is added:

  ipl = 0xFFFFFFF2, ntkoff = 14  ->  ipl + ntkoff = 0

pskb_may_pull(skb, 0) then succeeds and the ipl < hl check is also
defeated, so tcf_csum_ipv6_udp() hands the packet's own (u16) UDPLITE
length to csum_partial(), which reads up to 65535 bytes from an skb that
is only a few dozen bytes long.  The ICMPv6, TCP and SCTP branches pass
ipl - ihl, which is negative as an int, so they do not read.

Reject any @ipl that does not fit in the skb before adding @ntkoff.

BUG: KASAN: slab-use-after-free in do_csum (lib/checksum.c:64)
Read of size 4 at addr ffff88803506ed88 by task act_csum/9648

Call Trace:
 do_csum (lib/checksum.c:64)
 csum_partial (lib/checksum.c:119)
 tcf_csum_ipv6_udp (net/sched/act_csum.c:346)
 tcf_csum_act (net/sched/act_csum.c:601)
 tcf_action_exec (net/sched/act_api.c:1149)
 mall_classify (net/sched/cls_matchall.c:42)
 tcf_classify (net/sched/cls_api.c:1875)
 tc_run (net/core/dev.c:4635)
 __dev_queue_xmit (net/core/dev.c:5034)

Fixes: eb4d40654505 ("net/sched: add ACT_CSUM action to update packets checksums")
Cc: stable@kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Jun Yang <junvyyang@tencent.com>
---
A KASAN reproducer for this issue is available if requested.

 net/sched/act_csum.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 5fff52a8ca90..64002a4bebac 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -135,8 +135,14 @@ static void *tcf_csum_skb_nextlayer(struct sk_buff *skb,
 				    unsigned int ihl, unsigned int ipl,
 				    unsigned int jhl)
 {
-	int ntkoff = skb_network_offset(skb);
-	int hl = ihl + jhl;
+	unsigned int ntkoff = skb_network_offset(skb);
+	unsigned int hl = ihl + jhl;
+
+	/* @ipl comes from the packet and may exceed the skb; reject it before
+	 * adding @ntkoff, which would otherwise wrap.
+	 */
+	if (ntkoff > skb->len || ipl > skb->len - ntkoff)
+		return NULL;
 
 	if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) ||
 	    skb_try_make_writable(skb, hl + ntkoff))

base-commit: c5de2ce2fccdb7d3b48946179634eaa3d7ce2e7e
-- 
2.56.1


                 reply	other threads:[~2026-11-25  7:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125071432.53293-1-juny24602@gmail.com \
    --to=juny24602@gmail.com \
    --cc=baronchon@n7mm.org \
    --cc=corvus@tencent.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hadi@cyberus.ca \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=junvyyang@tencent.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.