netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	syzbot+9ee20ec1de7b3168db09@syzkaller.appspotmail.com,
	Phillip Potter <phil@philpotter.co.uk>
Subject: Re: [PATCH net] geneve: fix header validation in geneve[6]_xmit_skb
Date: Wed, 3 Apr 2024 18:04:53 +0200	[thread overview]
Message-ID: <Zg1-JQD2tH4Nx3p2@hog> (raw)
In-Reply-To: <CANn89i+EFGdrFUt+JpOPQUfOa7_aHv=G-ChRwHCt18zoJQFEVQ@mail.gmail.com>

2024-04-03, 16:59:52 +0200, Eric Dumazet wrote:
> On Wed, Apr 3, 2024 at 4:55 PM Sabrina Dubroca <sd@queasysnail.net> wrote:
> >
> > 2024-04-03, 16:25:47 +0200, Eric Dumazet wrote:
> > > On Wed, Apr 3, 2024 at 4:21 PM Sabrina Dubroca <sd@queasysnail.net> wrote:
> > > >
> > > > 2024-04-03, 11:38:53 +0000, Eric Dumazet wrote:
> > > > > syzbot is able to trigger an uninit-value in geneve_xmit() [1]
> > > > >
> > > > > Problem : While most ip tunnel helpers (like ip_tunnel_get_dsfield())
> > > > > uses skb_protocol(skb, true), pskb_inet_may_pull() is only using
> > > > > skb->protocol.
> > > > >
> > > > > If anything else than ETH_P_IPV6 or ETH_P_IP is found in skb->protocol,
> > > > > pskb_inet_may_pull() does nothing at all.
> > > > >
> > > > > If a vlan tag was provided by the caller (af_packet in the syzbot case),
> > > > > the network header might not point to the correct location, and skb
> > > > > linear part could be smaller than expected.
> > > > >
> > > > > Add skb_vlan_inet_prepare() to perform a complete validation and pull.
> > > > > If no IPv4/IPv6 header is found, it returns 0.
> > > >
> > > > And then geneve_xmit_skb/geneve6_xmit_skb drops the packet, which
> > > > breaks ARP over a geneve tunnel, and other valid things like macsec.
> > >
> > > geneve_xmit_skb() uses ip_hdr() blindly.
> >
> > Do those actually end up getting used? They get passed to
> > {ip_tunnel_ecn_encap,ip_tunnel_get_ttl,ip_tunnel_get_dsfield}, and
> > those helpers only look at their iph argument when skb_protocol(skb,
> > true) is ETH_P_IP or ETH_P_IPV6. So, definitely not pretty, but I
> > don't see a bug there. Am I missing something?
> 
> Please read my changelog, I explained that skb_protocol(skb, true) is
> parsing the Ethernet header up to the non vlan proto.

I meant in the ARP/MACsec/whatever else case, using ip_hdr is ugly but
won't do anything wrong.

> syzbot buillt a vlan packet with final proto being IPv4.
> 
> So the helpers who are using skb_protocol() do not understand the IP
> header has not been pulled.
> 
> >
> > From a quick look, most users of those helpers seem to pass
> > ip_hdr(skb) (except for ip_tunnel_ecn_encap called from
> > ip_md_tunnel_xmit and ip_tunnel_xmit -- vxlan_xmit_one uses a cached
> > version but I don't think it's needed). Would it be less confusing if
> > we removed that argument and let the helper fetch ip_hdr?
> 
> If you look at the syzbot report, the ip header is definitely dereferenced.

Sure, something is clearly needed to fix what syzbot found (and
pulling more headers is the reasonable way to deal with it).

But AFAICT, if the skb inner contents are not IP/IPv6, the IP header
won't get looked at, even if we have ip_hdr() calls everywhere. That's
what I tried to say with:

    those helpers only look at their iph argument when
    skb_protocol(skb, true) is ETH_P_IP or ETH_P_IPV6

-- 
Sabrina


  reply	other threads:[~2024-04-03 16:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 11:38 [PATCH net] geneve: fix header validation in geneve[6]_xmit_skb Eric Dumazet
2024-04-03 14:21 ` Sabrina Dubroca
2024-04-03 14:25   ` Eric Dumazet
2024-04-03 14:55     ` Sabrina Dubroca
2024-04-03 14:59       ` Eric Dumazet
2024-04-03 16:04         ` Sabrina Dubroca [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-04-04 13:11 Eric Dumazet
2024-04-04 17:00 ` Jakub Kicinski
2024-04-04 17:09   ` Eric Dumazet
2024-04-04 17:47     ` Eric Dumazet
2024-04-04 18:13       ` Eric Dumazet

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=Zg1-JQD2tH4Nx3p2@hog \
    --to=sd@queasysnail.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=phil@philpotter.co.uk \
    --cc=syzbot+9ee20ec1de7b3168db09@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).