netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp()
@ 2024-03-18 19:31 Chenyuan Yang
  2024-03-18 19:46 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Chenyuan Yang @ 2024-03-18 19:31 UTC (permalink / raw)
  To: jhs, xiyou.wangcong, jiri; +Cc: davem, edumazet, kuba, pabeni, netdev, zzjas98

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp()
  2024-03-18 19:31 [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp() Chenyuan Yang
@ 2024-03-18 19:46 ` Eric Dumazet
  2024-03-18 19:54   ` Chenyuan Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2024-03-18 19:46 UTC (permalink / raw)
  To: Chenyuan Yang
  Cc: jhs, xiyou.wangcong, jiri, davem, kuba, pabeni, netdev, zzjas98

On Mon, Mar 18, 2024 at 8:31 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
>
> 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);
> ```

Why would this code be an issue only in  tcf_csum_ipv6_icmp(), and not
in other functions ?

It seems we have proper pskb_may_pull() calls.

If you have a syzbot/syzkaller trace, please share it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp()
  2024-03-18 19:46 ` Eric Dumazet
@ 2024-03-18 19:54   ` Chenyuan Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Chenyuan Yang @ 2024-03-18 19:54 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: jhs, xiyou.wangcong, jiri, davem, kuba, pabeni, netdev, zzjas98

Thank you very much for your swift response.

> It seems we have proper pskb_may_pull() calls.
I realized that I had overlooked verifying the suitability of the SKB
in this context. Your observation is indeed correct, and I now
understand that this should not present any concerns.

Thank you once again for your valuable feedback.

Best,
Chenyuan

On Mon, Mar 18, 2024 at 2:46 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Mon, Mar 18, 2024 at 8:31 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> >
> > 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);
> > ```
>
> Why would this code be an issue only in  tcf_csum_ipv6_icmp(), and not
> in other functions ?
>
> It seems we have proper pskb_may_pull() calls.
>
> If you have a syzbot/syzkaller trace, please share it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-18 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 19:31 [net/sched] Question about possible misuse checksum in tcf_csum_ipv6_icmp() Chenyuan Yang
2024-03-18 19:46 ` Eric Dumazet
2024-03-18 19:54   ` Chenyuan Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).