[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACGkMEt9NLqwLB-fyUi0qNW7ZKO2o7rgC1Y+=UTHw8eXf=Coqw@mail.gmail.com>
Date: Wed, 11 Sep 2024 11:41:28 +0800
From: Jason Wang <jasowang@...hat.com>
To: Willem de Bruijn <willemdebruijn.kernel@...il.com>
Cc: netdev@...r.kernel.org, davem@...emloft.net, kuba@...nel.org,
edumazet@...gle.com, pabeni@...hat.com, stable@...r.kernel.org,
nsz@...t70.net, mst@...hat.com, yury.khrustalev@....com, broonie@...nel.org,
sudeep.holla@....com, Willem de Bruijn <willemb@...gle.com>, stable@...r.kernel.net
Subject: Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
On Tue, Sep 10, 2024 at 10:54 PM Willem de Bruijn
<willemdebruijn.kernel@...il.com> wrote:
>
> Willem de Bruijn wrote:
> > Jason Wang wrote:
> > > On Tue, Sep 10, 2024 at 8:40 AM Willem de Bruijn
> > > <willemdebruijn.kernel@...il.com> wrote:
> > > >
> > > > From: Willem de Bruijn <willemb@...gle.com>
> > > >
> > > > The referenced commit drops bad input, but has false positives.
> > > > Tighten the check to avoid these.
> > > >
> > > > The check detects illegal checksum offload requests, which produce
> > > > csum_start/csum_off beyond end of packet after segmentation.
> > > >
> > > > But it is based on two incorrect assumptions:
> > > >
> > > > 1. virtio_net_hdr_to_skb with VIRTIO_NET_HDR_GSO_TCP[46] implies GSO.
> > > > True in callers that inject into the tx path, such as tap.
> > > > But false in callers that inject into rx, like virtio-net.
> > > > Here, the flags indicate GRO, and CHECKSUM_UNNECESSARY or
> > > > CHECKSUM_NONE without VIRTIO_NET_HDR_F_NEEDS_CSUM is normal.
> > > >
> > > > 2. TSO requires checksum offload, i.e., ip_summed == CHECKSUM_PARTIAL.
> > > > False, as tcp[46]_gso_segment will fix up csum_start and offset for
> > > > all other ip_summed by calling __tcp_v4_send_check.
> > > >
> > > > Because of 2, we can limit the scope of the fix to virtio_net_hdr
> > > > that do try to set these fields, with a bogus value.
> > > >
> > > > Link: https://lore.kernel.org/netdev/20240909094527.GA3048202@port70.net/
> > > > Fixes: 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")
> > > > Signed-off-by: Willem de Bruijn <willemb@...gle.com>
> > > > Cc: <stable@...r.kernel.net>
> > > >
> > > > ---
> > > >
> > > > Verified that the syzbot repro is still caught.
> > > >
> > > > An equivalent alternative would be to move the check for csum_offset
> > > > to where the csum_start check is in segmentation:
> > > >
> > > > - if (unlikely(skb_checksum_start(skb) != skb_transport_header(skb)))
> > > > + if (unlikely(skb_checksum_start(skb) != skb_transport_header(skb) ||
> > > > + skb->csum_offset != offsetof(struct tcphdr, check)))
> > > >
> > > > Cleaner, but messier stable backport.
> > > >
> > > > We'll need an equivalent patch to this for VIRTIO_NET_HDR_GSO_UDP_L4.
> > > > But that csum_offset test was in a different commit, so different
> > >
> > > Not for this patch, but I see this in UDP_L4:
> > >
> > > if (!(hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM))
> > > return -EINVAL;
> > >
> > > This seems to forbid VIRTIO_NET_HDR_F_DATA_VALID. I wonder what's the
> > > reason for doing this.
> >
> > It tests &, not == ?
>
> Oh you mean as alternative, for receive of GRO from hypervisor.
Or it could be a physical device that can do GRO HW.
>
> Yes, fair point.
>
> Then we also trust a privileged process over tun, like syzkaller.
> When it comes to checksums, I suppose that is fine: it cannot harm
> kernel integrity.
Yes.
>
> One missing piece is that TCP GSO will fix up non CHECKSUM_PARTIAL
> skbs. UDP GSO does not have the same logic.
>
Thanks
Powered by blists - more mailing lists