net: tighten bad gso csum offset check in virtio_net_hdr
Subsystems (5)
PATCH v2 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.
---
Changes v1->v2:
- Fix Cc:
- Add Acks from v1
--- 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
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 10 Sep 2024 17:35:35 -0400 you wrote:
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.
[...]
Here is the summary with links:
- [net,v2] net: tighten bad gso csum offset check in virtio_net_hdr
https://git.kernel.org/netdev/net/c/6513eb3d3191
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 16 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.
Quoted 7 lines
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.
I see it is already queued and extremely sorry for not testing and getting back earlier. Good news: it does fix the issue in my setup(same as reported at [1])
So, FWIW,
Signature · 4 lines
Regards, Sudeep [1] https://lore.kernel.org/netdev/[email protected]/
Quoted 25 lines · Sudeep Holla
Quoted 16 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.Quoted 7 lines
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.
Quoted 7 lines
I see it is already queued and extremely sorry for not testing and getting back earlier. Good news: it does fix the issue in my
setup(same as reported at [1])So, FWIW,
Tested-by Sudeep Holla <[email protected]>
That is great to hear. Thanks for reporting your results, Sudeep.