net: tighten bad gso csum offset check in virtio_net_hdr
Subsystems (5)
PATCH 1/1 net: tighten bad gso csum offset check in virtio_net_hdr
From: Willem de Bruijn <[email protected]>
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.
---
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(-)
include/linux/virtio_net.h +2 -1
@@ -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 ; }
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
kernel test robot
build botFYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1
Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH net] net: tighten bad gso csum offset check in virtio_net_hdr
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Greg KH
maintainerQuoted 1 line · Willem de Bruijn
Cc <[email protected]>
This is not a correct email address :(
Quoted 40 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
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_skbwith 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, andCHECKSUM_UNNECESSARYorCHECKSUM_NONEwithoutVIRTIO_NET_HDR_F_NEEDS_CSUMis normal.2. TSO requires checksum offload, i.e.,
ip_summed==CHECKSUM_PARTIAL. False, as tcp[46]_gso_segment will fix upcsum_startand offset for all otherip_summedby calling__tcp_v4_send_check.Because of 2, we can limit the scope of the fix to
virtio_net_hdrthat do try to set these fields, with a bogus value.Fixes 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")Signed-off-by Willem de Bruijn <[email protected]>Cc <[email protected]>---
Verified that the syzbot repro is still caught.
An equivalent alternative would be to move the check for
csum_offsetto where thecsum_startcheck is in segmentation:(quoted diff) +2
-1- 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)))
Quoted 4 lines
Cleaner, but messier stable backport.
We'll need an equivalent patch to this for
VIRTIO_NET_HDR_GSO_UDP_L4. But thatcsum_offsettest 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.
Quoted 20 lines
Fixes tag.
--- include/linux/virtio_net.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/linux/virtio_net.h +2
-2@@ -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 ; } --
Quoted 2 lines
2.46.0.598.g6f2099f65c-goog
Thanks
Quoted 20 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
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_skbwith 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, andCHECKSUM_UNNECESSARYorCHECKSUM_NONEwithoutVIRTIO_NET_HDR_F_NEEDS_CSUMis normal.2. TSO requires checksum offload, i.e.,
ip_summed==CHECKSUM_PARTIAL. False, as tcp[46]_gso_segment will fix upcsum_startand offset for all otherip_summedby calling__tcp_v4_send_check.
Quoted 7 lines
Because of 2, we can limit the scope of the fix to
virtio_net_hdrthat do try to set these fields, with a bogus value.Fixes 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")Signed-off-by Willem de Bruijn <[email protected]>Cc <[email protected]>
But I think netdev maintainers ask contributors not to CC stable directly.
Quoted 36 lines
---
Verified that the syzbot repro is still caught.
An equivalent alternative would be to move the check for
csum_offsetto where thecsum_startcheck is in segmentation:(quoted diff) +2
-1- 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 thatcsum_offsettest was in a different commit, so different Fixes tag.--- include/linux/virtio_net.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/linux/virtio_net.h +2
-1@@ -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 ; }Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Michael S. Tsirkin
maintainerQuoted 4 lines · Greg KH
Quoted 1 line · Willem de Bruijn
Cc <[email protected]>This is not a correct email address :(
I think netdev does its own stable thing, no need to CC stable at all.
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Greg KH
Quoted 1 line · Willem de Bruijn
Cc <[email protected]>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 <[email protected]> Date: Tue Mar 2 18:46:43 2021 -0800
docs: networking: drop special stable handling
Leave it to Greg.
Quoted 5 lines · Greg KH
Quoted 1 line · Willem de Bruijn
Cc <[email protected]>This is not a correct email address :(
Sorry. I'll resend with that fixed.
Quoted 47 lines · Jason Wang
Quoted 40 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
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_skbwith 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, andCHECKSUM_UNNECESSARYorCHECKSUM_NONEwithoutVIRTIO_NET_HDR_F_NEEDS_CSUMis normal.2. TSO requires checksum offload, i.e.,
ip_summed==CHECKSUM_PARTIAL. False, as tcp[46]_gso_segment will fix upcsum_startand offset for all otherip_summedby calling__tcp_v4_send_check.Because of 2, we can limit the scope of the fix to
virtio_net_hdrthat do try to set these fields, with a bogus value.Fixes 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")Signed-off-by Willem de Bruijn <[email protected]>Cc <[email protected]>---
Verified that the syzbot repro is still caught.
An equivalent alternative would be to move the check for
csum_offsetto where thecsum_startcheck is in segmentation:(quoted diff) +2
-1- 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)))Quoted 4 lines
Cleaner, but messier stable backport.
We'll need an equivalent patch to this for
VIRTIO_NET_HDR_GSO_UDP_L4. But thatcsum_offsettest was in a different commit, so different
Quoted 7 lines
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 == ?
Quoted 16 lines
Quoted 16 lines
Fixes tag.
--- include/linux/virtio_net.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/linux/virtio_net.h +2
-1@@ -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))
Quoted 8 lines
Quoted 6 lines
include/linux/virtio_net.h +0
-1return -EINVAL ;break ; } --2.46.0.598.g6f2099f65c-goog
Acked-by Jason Wang <[email protected]>
Thanks for reviewing
Quoted 50 lines · Willem de Bruijn
Quoted 49 lines · Jason Wang
Quoted 40 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
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_skbwith 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, andCHECKSUM_UNNECESSARYorCHECKSUM_NONEwithoutVIRTIO_NET_HDR_F_NEEDS_CSUMis normal.2. TSO requires checksum offload, i.e.,
ip_summed==CHECKSUM_PARTIAL. False, as tcp[46]_gso_segment will fix upcsum_startand offset for all otherip_summedby calling__tcp_v4_send_check.Because of 2, we can limit the scope of the fix to
virtio_net_hdrthat do try to set these fields, with a bogus value.Fixes 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")Signed-off-by Willem de Bruijn <[email protected]>Cc <[email protected]>---
Verified that the syzbot repro is still caught.
An equivalent alternative would be to move the check for
csum_offsetto where thecsum_startcheck is in segmentation:(quoted diff) +2
-1- 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)))Quoted 4 lines
Cleaner, but messier stable backport.
We'll need an equivalent patch to this for
VIRTIO_NET_HDR_GSO_UDP_L4. But thatcsum_offsettest was in a different commit, so differentNot for this patch, but I see this in
UDP_L4:
Quoted 7 lines
Quoted 5 lines
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.
Quoted 55 lines · Willem de Bruijn
Quoted 53 lines · Willem de Bruijn
Quoted 52 lines · Jason Wang
Quoted 40 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
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_skbwith 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, andCHECKSUM_UNNECESSARYorCHECKSUM_NONEwithoutVIRTIO_NET_HDR_F_NEEDS_CSUMis normal.2. TSO requires checksum offload, i.e.,
ip_summed==CHECKSUM_PARTIAL. False, as tcp[46]_gso_segment will fix upcsum_startand offset for all otherip_summedby calling__tcp_v4_send_check.Because of 2, we can limit the scope of the fix to
virtio_net_hdrthat do try to set these fields, with a bogus value.Fixes 89add40066f9 ("net: drop bad gso csum_start and offset in virtio_net_hdr")Signed-off-by Willem de Bruijn <[email protected]>Cc <[email protected]>---
Verified that the syzbot repro is still caught.
An equivalent alternative would be to move the check for
csum_offsetto where thecsum_startcheck is in segmentation:(quoted diff) +2
-1- 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)))Quoted 4 lines
Cleaner, but messier stable backport.
We'll need an equivalent patch to this for
VIRTIO_NET_HDR_GSO_UDP_L4. But thatcsum_offsettest was in a different commit, so differentNot for this patch, but I see this in
UDP_L4:if (!(hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM)) return -EINVAL;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
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.
Quoted 6 lines
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.
Quoted 4 lines
One missing piece is that TCP GSO will fix up non
CHECKSUM_PARTIALskbs. UDP GSO does not have the same logic.
Thanks