* [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
@ 2024-09-10 0:38 Willem de Bruijn
2024-09-10 4:34 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Willem de Bruijn @ 2024-09-10 0:38 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, edumazet, pabeni, stable, nsz, mst, jasowang,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
From: Willem de Bruijn <willemb@google.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@google.com>
Cc: <stable@vger.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
Fixes tag.
---
include/linux/virtio_net.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 6c395a2600e8d..276ca543ef44d 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -173,7 +173,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
break;
case SKB_GSO_TCPV4:
case SKB_GSO_TCPV6:
- if (skb->csum_offset != offsetof(struct tcphdr, check))
+ if (skb->ip_summed == CHECKSUM_PARTIAL &&
+ skb->csum_offset != offsetof(struct tcphdr, check))
return -EINVAL;
break;
}
--
2.46.0.598.g6f2099f65c-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 0:38 [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr Willem de Bruijn
@ 2024-09-10 4:34 ` Greg KH
2024-09-10 7:45 ` Michael S. Tsirkin
2024-09-10 14:35 ` Willem de Bruijn
2024-09-10 6:12 ` Jason Wang
2024-09-10 7:45 ` Michael S. Tsirkin
2 siblings, 2 replies; 10+ messages in thread
From: Greg KH @ 2024-09-10 4:34 UTC (permalink / raw)
To: Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst, jasowang,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
On Mon, Sep 09, 2024 at 08:38:52PM -0400, Willem de Bruijn wrote:
> Cc: <stable@vger.kernel.net>
This is not a correct email address :(
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 0:38 [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr Willem de Bruijn
2024-09-10 4:34 ` Greg KH
@ 2024-09-10 6:12 ` Jason Wang
2024-09-10 14:39 ` Willem de Bruijn
2024-09-10 7:45 ` Michael S. Tsirkin
2 siblings, 1 reply; 10+ messages in thread
From: Jason Wang @ 2024-09-10 6:12 UTC (permalink / raw)
To: Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
On Tue, Sep 10, 2024 at 8:40 AM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> From: Willem de Bruijn <willemb@google.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@google.com>
> Cc: <stable@vger.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.
> Fixes tag.
> ---
> include/linux/virtio_net.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index 6c395a2600e8d..276ca543ef44d 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -173,7 +173,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> break;
> case SKB_GSO_TCPV4:
> case SKB_GSO_TCPV6:
> - if (skb->csum_offset != offsetof(struct tcphdr, check))
> + if (skb->ip_summed == CHECKSUM_PARTIAL &&
> + skb->csum_offset != offsetof(struct tcphdr, check))
> return -EINVAL;
> break;
> }
> --
> 2.46.0.598.g6f2099f65c-goog
>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 0:38 [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr Willem de Bruijn
2024-09-10 4:34 ` Greg KH
2024-09-10 6:12 ` Jason Wang
@ 2024-09-10 7:45 ` Michael S. Tsirkin
2 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2024-09-10 7:45 UTC (permalink / raw)
To: Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, jasowang,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
On Mon, Sep 09, 2024 at 08:38:52PM -0400, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.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@google.com>
> Cc: <stable@vger.kernel.net>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
But I think netdev maintainers ask contributors not to CC
stable directly.
> ---
>
> 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
> Fixes tag.
> ---
> include/linux/virtio_net.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index 6c395a2600e8d..276ca543ef44d 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -173,7 +173,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> break;
> case SKB_GSO_TCPV4:
> case SKB_GSO_TCPV6:
> - if (skb->csum_offset != offsetof(struct tcphdr, check))
> + if (skb->ip_summed == CHECKSUM_PARTIAL &&
> + skb->csum_offset != offsetof(struct tcphdr, check))
> return -EINVAL;
> break;
> }
> --
> 2.46.0.598.g6f2099f65c-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 4:34 ` Greg KH
@ 2024-09-10 7:45 ` Michael S. Tsirkin
2024-09-10 7:54 ` Eric Dumazet
2024-09-10 14:35 ` Willem de Bruijn
1 sibling, 1 reply; 10+ messages in thread
From: Michael S. Tsirkin @ 2024-09-10 7:45 UTC (permalink / raw)
To: Greg KH
Cc: Willem de Bruijn, netdev, davem, kuba, edumazet, pabeni, stable,
nsz, jasowang, yury.khrustalev, broonie, sudeep.holla,
Willem de Bruijn, stable
On Tue, Sep 10, 2024 at 06:34:46AM +0200, Greg KH wrote:
> On Mon, Sep 09, 2024 at 08:38:52PM -0400, Willem de Bruijn wrote:
> > Cc: <stable@vger.kernel.net>
>
> This is not a correct email address :(
I think netdev does its own stable thing, no need to CC stable at all.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 7:45 ` Michael S. Tsirkin
@ 2024-09-10 7:54 ` Eric Dumazet
0 siblings, 0 replies; 10+ messages in thread
From: Eric Dumazet @ 2024-09-10 7:54 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Greg KH, Willem de Bruijn, netdev, davem, kuba, pabeni, stable,
nsz, jasowang, yury.khrustalev, broonie, sudeep.holla,
Willem de Bruijn, stable
On Tue, Sep 10, 2024 at 9:45 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Sep 10, 2024 at 06:34:46AM +0200, Greg KH wrote:
> > On Mon, Sep 09, 2024 at 08:38:52PM -0400, Willem de Bruijn wrote:
> > > Cc: <stable@vger.kernel.net>
> >
> > This is not a correct email address :(
>
> I think netdev does its own stable thing, no need to CC stable at all.
This is no longer the case.
commit dbbe7c962c3a8163bf724dbc3c9fdfc9b16d3117
Author: Jakub Kicinski <kuba@kernel.org>
Date: Tue Mar 2 18:46:43 2021 -0800
docs: networking: drop special stable handling
Leave it to Greg.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 4:34 ` Greg KH
2024-09-10 7:45 ` Michael S. Tsirkin
@ 2024-09-10 14:35 ` Willem de Bruijn
1 sibling, 0 replies; 10+ messages in thread
From: Willem de Bruijn @ 2024-09-10 14:35 UTC (permalink / raw)
To: Greg KH, Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst, jasowang,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
Greg KH wrote:
> On Mon, Sep 09, 2024 at 08:38:52PM -0400, Willem de Bruijn wrote:
> > Cc: <stable@vger.kernel.net>
>
> This is not a correct email address :(
>
Sorry. I'll resend with that fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 6:12 ` Jason Wang
@ 2024-09-10 14:39 ` Willem de Bruijn
2024-09-10 14:53 ` Willem de Bruijn
0 siblings, 1 reply; 10+ messages in thread
From: Willem de Bruijn @ 2024-09-10 14:39 UTC (permalink / raw)
To: Jason Wang, Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
Jason Wang wrote:
> On Tue, Sep 10, 2024 at 8:40 AM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > From: Willem de Bruijn <willemb@google.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@google.com>
> > Cc: <stable@vger.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 == ?
> > Fixes tag.
> > ---
> > include/linux/virtio_net.h | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > index 6c395a2600e8d..276ca543ef44d 100644
> > --- a/include/linux/virtio_net.h
> > +++ b/include/linux/virtio_net.h
> > @@ -173,7 +173,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> > break;
> > case SKB_GSO_TCPV4:
> > case SKB_GSO_TCPV6:
> > - if (skb->csum_offset != offsetof(struct tcphdr, check))
> > + if (skb->ip_summed == CHECKSUM_PARTIAL &&
> > + skb->csum_offset != offsetof(struct tcphdr, check))
> > return -EINVAL;
> > break;
> > }
> > --
> > 2.46.0.598.g6f2099f65c-goog
> >
>
> Acked-by: Jason Wang <jasowang@redhat.com>
Thanks for reviewing
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 14:39 ` Willem de Bruijn
@ 2024-09-10 14:53 ` Willem de Bruijn
2024-09-11 3:41 ` Jason Wang
0 siblings, 1 reply; 10+ messages in thread
From: Willem de Bruijn @ 2024-09-10 14:53 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
Willem de Bruijn wrote:
> Jason Wang wrote:
> > On Tue, Sep 10, 2024 at 8:40 AM Willem de Bruijn
> > <willemdebruijn.kernel@gmail.com> wrote:
> > >
> > > From: Willem de Bruijn <willemb@google.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@google.com>
> > > Cc: <stable@vger.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.
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.
One missing piece is that TCP GSO will fix up non CHECKSUM_PARTIAL
skbs. UDP GSO does not have the same logic.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
2024-09-10 14:53 ` Willem de Bruijn
@ 2024-09-11 3:41 ` Jason Wang
0 siblings, 0 replies; 10+ messages in thread
From: Jason Wang @ 2024-09-11 3:41 UTC (permalink / raw)
To: Willem de Bruijn
Cc: netdev, davem, kuba, edumazet, pabeni, stable, nsz, mst,
yury.khrustalev, broonie, sudeep.holla, Willem de Bruijn, stable
On Tue, Sep 10, 2024 at 10:54 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> Willem de Bruijn wrote:
> > Jason Wang wrote:
> > > On Tue, Sep 10, 2024 at 8:40 AM Willem de Bruijn
> > > <willemdebruijn.kernel@gmail.com> wrote:
> > > >
> > > > From: Willem de Bruijn <willemb@google.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@google.com>
> > > > Cc: <stable@vger.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
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-09-11 3:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10 0:38 [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr Willem de Bruijn
2024-09-10 4:34 ` Greg KH
2024-09-10 7:45 ` Michael S. Tsirkin
2024-09-10 7:54 ` Eric Dumazet
2024-09-10 14:35 ` Willem de Bruijn
2024-09-10 6:12 ` Jason Wang
2024-09-10 14:39 ` Willem de Bruijn
2024-09-10 14:53 ` Willem de Bruijn
2024-09-11 3:41 ` Jason Wang
2024-09-10 7:45 ` Michael S. Tsirkin
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).