All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chenyuan Yang <chenyuan0y@gmail.com>
To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org, zzjas98@gmail.com
Subject: [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp()
Date: Mon, 18 Mar 2024 14:31:24 -0500	[thread overview]
Message-ID: <ZfiWjOWDs2osFAnX@cy-server> (raw)

Dear TC subsystem maintainers,

We are curious whether the function `tcf_csum_ipv6_icmp()` would have a misuse of `csum_partial()` leading to an out-of-bounds access.

The function `tcf_csum_ipv6_icmp` is https://elixir.bootlin.com/linux/v6.8/source/net/sched/act_csum.c#L183 and the relevant code is
```
static int tcf_csum_ipv6_icmp(struct sk_buff *skb, unsigned int ihl,
			      unsigned int ipl)
{
  ...
	ip6h = ipv6_hdr(skb);
	icmp6h->icmp6_cksum = 0;
	skb->csum = csum_partial(icmp6h, ipl - ihl, 0);
	icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
					      ipl - ihl, IPPROTO_ICMPV6,
					      skb->csum);
  ...
}
```

Based on this patch: https://lore.kernel.org/netdev/20240201083817.12774-1-atenart@kernel.org/T/, it seems that the `skb` here for ICMPv6 could be non-linear, and `csum_partial` is not suitable for non-linear SKBs, which could lead to an out-of-bound access. The correct approach is to use `skb_checksum` which properly handles non-linear SKBs.

Based on the above information, a possible fix would be
```
-	skb->csum = csum_partial(icmp6h, ipl - ihl, 0);
+	skb->csum = skb_checksum(skb, skb_transport_offset(skb), ipl - ihl, 0);
``` 

Please kindly correct us if we missed any key information. Looking forward to your response!

Best,
Chenyuan

             reply	other threads:[~2024-03-18 19:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 19:31 Chenyuan Yang [this message]
2024-03-18 19:46 ` [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp() Eric Dumazet
2024-03-18 19:54   ` Chenyuan Yang

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=ZfiWjOWDs2osFAnX@cy-server \
    --to=chenyuan0y@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=zzjas98@gmail.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 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.