more virtio-net csum hardening
Subsystems (11)
Michael S. Tsirkin
maintainerv2 cover more virtio-net csum hardening
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users):
allowing untrusted hardware to specify csum start/offset for CHECKSUM_PARTIAL was not a good idea, because, if it edits the packet outside the actual checksum, and depending on the setup, the networking stack could be looking at the packet both before and after the edit, and seeing different results.
Previously, commit 6785011f8b16 ("ipv4: validate checksum_start before completing checksum") validated all known instances where this causes the most grief, but the real fix is to make sure that either only actual checksum fields are ever edited,
or the checksum is completed before the net stack looks at it, so it is always consistent.
This basically goes back to
what we did before f43798c27684 ("tun: Allow GSO using virtio_net_hdr"), except in a narrow list of specified known good cases.
Summary of the patchset:
net: account for ingress-resolved virtio net hdr state
- accounting, not the fix itself, dependency of the next one
net: resolve uncommon partial checksums at ingress
- fix itself
net: add a sysctl to opt out of virtio net hdr checksum validation
- reducing risk of the fix by adding a sysctl to disable it
net: add ip4_parse()
virtio_net: cleanup protocol calculation
- cleanup resulting code duplication
(kept separate to simplify backporting)
Changes since v1:
- reorder patches to fix bisectability, addressing a comment by Björn Töpel.
- code refactoring, different patch splitup,
a sysctl knob to disable as suggested by Willem de Bruijn.
- fix a bunch of minor issues spotted by LLMs
Michael S. Tsirkin (7):
net: account for ingress-resolved virtio net hdr state
um: vector: honor virtio net hdr conversion failures
um: vector: trim skbs before verifying the header
net: resolve uncommon partial checksums at ingress
net: add a sysctl to opt out of virtio net hdr checksum validation
net: add ip4_parse()
virtio_net: cleanup protocol calculation
Documentation/admin-guide/sysctl/net.rst | 15 ++ arch/um/drivers/vector_kern.c | 6 +- arch/um/drivers/vector_transports.c | 4 +- drivers/net/tap.c | 4 +- drivers/net/tun.c | 41 +++- drivers/net/virtio_net.c | 2 +- include/linux/ip.h | 24 +++ include/linux/virtio_net.h | 249 ++++++++++++++++++++++- include/net/netns/core.h | 1 + net/bridge/br_netfilter_hooks.c | 15 +- net/core/dev.c | 6 + net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 +++++ net/ipv4/ip_input.c | 13 +- net/ipv4/netfilter/nf_reject_ipv4.c | 13 +- net/packet/af_packet.c | 4 +- 16 files changed, 404 insertions(+), 48 deletions(-)
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v2 1/7 net: account for ingress-resolved virtio net hdr state
The following patch will add ingress resolution of uncommon virtio net hdr checksum metadata (software checksum completion at ingress) which adds performance overhead to the packet processing.
We should make it visible, so a hypothetical workload relying on uncommon metadata can be distinguished from none at all. This way issues in the parsing will be reported and not quietly pay the host-CPU checksum overhead instead of offload.
Flip every call to virtio_net_hdr_to_skb to test for negative errno only, and have tun count these events per device as rx_csum_sw, exposed via ethtool -S.
--- drivers/net/tap.c | 4 ++-- drivers/net/tun.c | 41 ++++++++++++++++++++++++++++++++++++++-- drivers/net/virtio_net.c | 2 +- net/packet/af_packet.c | 4 ++-- 4 files changed, 44 insertions(+), 7 deletions(-)
drivers/net/tap.c +2 -2
@@ -649,7 +649,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,if (vnet_hdr_len) { err =tun_vnet_hdr_to_skb (q->flags, skb, &vnet_hdr); -if (err) { +if (err <0 ) {rcu_read_unlock (); drop_reason =SKB_DROP_REASON_DEV_HDR ; goto err_kfree;
@@ -1084,7 +1084,7 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)if (vnet_hdr_len) { err =tun_vnet_hdr_to_skb (q->flags, skb, gso); -if (err) { +if (err <0 ) {rcu_read_unlock (); goto err_kfree; }
drivers/net/tun.c +39 -2
75 lines not on this page · raw message
drivers/net/virtio_net.c +1 -1
@@ -2519,7 +2519,7 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *skb_set_network_header (skb,ETH_HLEN );if (virtio_net_hdr_tnl_to_skb (skb, &hdr->tnl_hdr, vi->rx_tnl, vi->rx_tnl_csum, -virtio_is_little_endian (vi->vdev))) { +virtio_is_little_endian (vi->vdev)) <0 ) { net_warn_ratelimited("%s: bad gso: type: %x, size: %u, flags %x tunnel %d tnl csum %d\n", dev->name, hdr->hdr.gso_type, hdr->hdr.gso_size, hdr->hdr.flags,
net/packet/af_packet.c +2 -2
@@ -2913,7 +2913,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) }if (has_vnet_hdr) { -if (virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ())) { +if (virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ()) <0 ) { tp_len = -EINVAL ; goto tpacket_error; }
@@ -3136,7 +3136,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)if (vnet_hdr_sz) { err =virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ()); -if (err) +if (err <0 ) goto out_free; len += vnet_hdr_sz; }
Signature · 1 line
MST
[email protected]
AI reviewRe: [PATCH net-next v2 1/7] net: account for ingress-resolved virtio net hdr state
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
The following patch will add ingress resolution of uncommon virtio net hdr checksum metadata (software checksum completion at ingress) which adds performance overhead to the packet processing.
We should make it visible, so a hypothetical workload relying on uncommon metadata can be distinguished from none at all. This way issues in the parsing will be reported and not quietly pay the host-CPU checksum overhead instead of offload.
Quoted 6 lines
Flip every call to
virtio_net_hdr_to_skbto test for negative errno only, and have tun count these events per device asrx_csum_sw, exposed via ethtool -S.Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Michael S. Tsirkin
maintainerPATCH v2 2/7 um: vector: honor virtio net hdr conversion failures
In reply to Michael S. Tsirkinvirtio_net_hdr_to_skb() refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.
Propagate the failure.
--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/um/drivers/vector_transports.c +3 -1
@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ; }
Signature · 1 line
MST
Johannes Berg
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0
arch/um/drivers/vector_transports.c static int raw_verify_header( · line 217
Quoted 9 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;
Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);
As far as I can tell, the function only returns -EINVAL or 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?
johannes
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 31 lines · Johannes Berg
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0arch/um/drivers/vector_transports.c static int raw_verify_header( · line 217
Quoted 9 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
Quoted 7 lines
return virtio_net_hdr_to_skb(...);As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?johannes
if raw_verify_header can safely return any errno - i did not want to audit it.
Signature · 1 line
MST
Johannes Berg
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Johannes Berg
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0arch/um/drivers/vector_transports.c static int raw_verify_header( · line 217
Quoted 9 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);
Quoted 8 lines
Quoted 5 lines
As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?johannes
if
raw_verify_headercan safely return any errno - i did not want to audit it.
You already used an LLM and still didn't want to? ;-)
I checked briefly (by hand) and it seems fine, it's assigned to the function pointer, which only has two callers on the _kern.c side.
johannes
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 39 lines · Johannes Berg
Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Johannes Berg
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0arch/um/drivers/vector_transports.c static int raw_verify_header( · line 217
Quoted 9 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
johannes
if
raw_verify_headercan safely return any errno - i did not want to audit it.You already used an LLM and still didn't want to? ;-)
I don't really trust it to do code audits especially in code I do not test.
Quoted 4 lines
I checked briefly (by hand) and it seems fine, it's assigned to the function pointer, which only has two callers on the
_kern.cside.johannes
Thanks, will make the change.
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
In reply to Johannes BergQuoted 44 lines · Johannes Berg
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Johannes Berg
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0arch/um/drivers/vector_transports.c static int raw_verify_header( · line 217
Quoted 9 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);Quoted 8 lines
Quoted 5 lines
As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?johannes
if
raw_verify_headercan safely return any errno - i did not want to audit it.
Quoted 6 lines
You already used an LLM and still didn't want to? ;-)
I checked briefly (by hand) and it seems fine, it's assigned to the function pointer, which only has two callers on the
_kern.cside.johannes
header_check = vp->verify_header(
mmsg_vector->msg_hdr.msg_iov->iov_base,
skb,
vp
);
if (header_check < 0) {
/* Overlay header failed to verify - discard.
* We can actually keep this skb and reuse it,
* but that will make the prep logic too
* complex.
*/
dev_kfree_skb_irq(skb);
vp->estats.rx_encaps_errors++;
(*skbuff_vector) = NULL;
mmsg_vector++;
skbuff_vector++;
continue;
}
if (header_check > 0) {
vp->estats.rx_csum_offload_good++;
skb->ip_summed = CHECKSUM_UNNECESSARY;
}so any negative is fine, but if we return 1 then it will force to CHECKSUM_UNNECESSARY which I am not sure is what was intended?
Signature · 1 line
MST
Johannes Berg
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 54 lines · Michael S. Tsirkin
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
arch/um/drivers/vector_transports.c static int raw_verify_header( · line 216
Quoted 7 lines
arch/um/drivers/vector_transports.c +3
-1-virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);Quoted 8 lines
Quoted 5 lines
As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?johannes
if
raw_verify_headercan safely return any errno - i did not want to audit it.Quoted 6 lines
You already used an LLM and still didn't want to? ;-)
I checked briefly (by hand) and it seems fine, it's assigned to the function pointer, which only has two callers on the
_kern.cside.johannes
header_check = vp->verify_header( mmsg_vector->msg_hdr.msg_iov->iov_base, skb, vp ); if (header_check < 0) { /* Overlay header failed to verify - discard. * We can actually keep this skb and reuse it, * but that will make the prep logic too * complex. */ dev_kfree_skb_irq(skb); vp->estats.rx_encaps_errors++; (*skbuff_vector) = NULL; mmsg_vector++; skbuff_vector++; continue; } if (header_check > 0) { vp->estats.rx_csum_offload_good++; skb->ip_summed = CHECKSUM_UNNECESSARY; }
Quoted 3 lines
so any negative is fine, but if we return 1 then it will force to
CHECKSUM_UNNECESSARYwhich I am not sure is what was intended?
Right, but virtio_net_hdr_to_skb() cannot return 1, only 0 on success and -ERROR on failure?
johannes
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 55 lines · Johannes Berg
Quoted 54 lines · Michael S. Tsirkin
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
arch/um/drivers/vector_transports.c static int raw_verify_header( · line 216
Quoted 7 lines
arch/um/drivers/vector_transports.c +3
-1-virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;return 0 ;Seems it'd be simpler to just
return virtio_net_hdr_to_skb(...);Quoted 8 lines
Quoted 5 lines
As far as I can tell, the function only returns
-EINVALor 0 (never a positive value), and the caller only cares about negative (error) or positive (no checksum needed), so that'd be equivalent?johannes
if
raw_verify_headercan safely return any errno - i did not want to audit it.Quoted 6 lines
You already used an LLM and still didn't want to? ;-)
I checked briefly (by hand) and it seems fine, it's assigned to the function pointer, which only has two callers on the
_kern.cside.johannes
header_check = vp->verify_header( mmsg_vector->msg_hdr.msg_iov->iov_base, skb, vp ); if (header_check < 0) { /* Overlay header failed to verify - discard. * We can actually keep this skb and reuse it, * but that will make the prep logic too * complex. */ dev_kfree_skb_irq(skb); vp->estats.rx_encaps_errors++; (*skbuff_vector) = NULL; mmsg_vector++; skbuff_vector++; continue; } if (header_check > 0) { vp->estats.rx_csum_offload_good++; skb->ip_summed = CHECKSUM_UNNECESSARY; }
Quoted 7 lines
Quoted 3 lines
so any negative is fine, but if we return 1 then it will force to
CHECKSUM_UNNECESSARYwhich I am not sure is what was intended?Right, but
virtio_net_hdr_to_skb()cannot return 1, only 0 on success and-ERRORon failure?johannes
After this patchset, it can, to signal slow path software checksum. I'm changing callers first so that changing the function itself does not break bisect. I should mention this in the commit log.
Signature · 1 line
MST
Johannes Berg
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines
Quoted 1 line
Right, but
virtio_net_hdr_to_skb()cannot return 1, only 0 on success and-ERRORon failure?After this patchset, it can, to signal slow path software checksum. I'm changing callers first so that changing the function itself does not break bisect. I should mention this in the commit log.
Oh, OK, that I clearly missed, but also was only CC'ed on patches 2 and 3 :)
johannes
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 5 lines · Johannes Berg
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines
Quoted 1 line
Right, but
virtio_net_hdr_to_skb()cannot return 1, only 0 on success and-ERRORon failure?
Quoted 8 lines
Quoted 3 lines
After this patchset, it can, to signal slow path software checksum. I'm changing callers first so that changing the function itself does not break bisect. I should mention this in the commit log.
Oh, OK, that I clearly missed, but also was only CC'ed on patches 2 and 3 :)
johannes
Right, I am trying not to spam too widely.
Indeed, this is why commit log should explain.
Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
In reply to Michael S. TsirkinQuoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0
arch/um/drivers/vector_transports.c static int raw_verify_header( · line 215
Quoted 7 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;
Should this return 1, like the above?
Not sure whether the verify_header return value is well defined beyond just boolean.
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
Quoted 29 lines · Willem de Bruijn
Quoted 18 lines · Michael S. Tsirkin
virtio_net_hdr_to_skb()refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.Propagate the failure.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- arch/um/drivers/vector_transports.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/um/drivers/vector_transports.c +0
-0arch/um/drivers/vector_transports.c static int raw_verify_header( · line 215
Quoted 7 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;Should this return 1, like the above?
Quoted 2 lines
Not sure whether the
verify_headerreturn value is well defined beyond just boolean.
header_check = vp->verify_header(
vp->header_rxbuffer, skb, vp);
if (header_check < 0) {
dev_kfree_skb_irq(skb);
vp->dev->stats.rx_dropped++;
vp->estats.rx_encaps_errors++;
return 0;
}
if (header_check > 0) {
vp->estats.rx_csum_offload_good++;
skb->ip_summed = CHECKSUM_UNNECESSARY;
}apparently? maybe i misunderstand.
Signature · 1 line
MST
[email protected]
AI reviewRe: [PATCH net-next v2 2/7] um: vector: honor virtio net hdr conversion failures
In reply to Michael S. TsirkinThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] um: vector: GSO metadata lost for packets with VIRTIO_NET_HDR_F_DATA_VALID --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] um: vector: GSO metadata lost for packets with VIRTIO_NET_HDR_F_DATA_VALID --
commit 7c2ce8bab142738766afdbfe57333f1e8eb84738
Author: Michael S. Tsirkin <[email protected]>
um: vector: honor virtio net hdr conversion failures
virtio_net_hdr_to_skb() refuses packets whose checksum metadata it cannot make sense of, but the vector raw transport ignored its return value: rejected packets went on into the stack with their metadata unvalidated.
Propagate the failure.
arch/um/drivers/vector_transports.c static int raw_verify_header( · line 215
Quoted 12 lines
arch/um/drivers/vector_transports.c +3
-1@@ -210,7 +210,9 @@ static int raw_verify_header(return 1 ;skb_set_network_header (skb,ETH_HLEN ); -virtio_net_hdr_to_skb (skb, vheader,virtio_legacy_is_little_endian ()); +if (virtio_net_hdr_to_skb (skb, vheader, +virtio_legacy_is_little_endian ()) <0 ) +return -1 ;
[Severity: High]
Does the early return above this block cause GSO packets to lose metadata?
Looking at raw_verify_header(), if VIRTIO_NET_HDR_F_DATA_VALID is set in the virtio network header, the function returns 1 early:
if ((vheader->flags & VIRTIO_NET_HDR_F_DATA_VALID) > 0) return 1;
This skips the call to virtio_net_hdr_to_skb(), which is responsible for parsing and populating GSO metadata like gso_size and gso_type.
For large GSO packets that happen to have VIRTIO_NET_HDR_F_DATA_VALID set (such as fully checksummed GSO frames from host TAP devices), would skipping this setup cause the SKB to be passed up to the network stack as an unsegmented giant packet?
The network stack would likely drop these oversized packets since they exceed the device MTU and lack GSO segmentation metadata, causing silent data loss and breaking TCP/UDP connectivity for these specific offloaded flows.
Quoted 2 lines
arch/um/drivers/vector_transports.c +0
-0return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Michael S. Tsirkin
maintainerPATCH v2 3/7 um: vector: trim skbs before verifying the header
In reply to Michael S. TsirkinThe vector receive path over-allocates the skb and only trims it to the received length after the transport header is verified.
A follow up patch will complete the packet checksum in software within virtio_net_hdr_to_skb so we need the packet trimmed (otherwise the checksum would be computed incorrectly over the unreceived tail of the buffer).
Trim first, so the import sees the packet as it was received.
--- arch/um/drivers/vector_kern.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/um/drivers/vector_kern.c +3 -3
@@ -865,6 +865,7 @@ static int vector_legacy_rx(struct vector_private *vp)if (skb !=NULL ) {if (pkt_len > vp->header_size) { +pskb_trim (skb, pkt_len - vp->rx_header_size);if (vp->header_size >0 ) { header_check = vp->verify_header ( vp->header_rxbuffer, skb, vp);
@@ -879,7 +880,6 @@ static int vector_legacy_rx(struct vector_private *vp) skb->ip_summed =CHECKSUM_UNNECESSARY ; } } -pskb_trim (skb, pkt_len - vp->rx_header_size); skb->protocol =eth_type_trans (skb, skb->dev); vp->dev->stats.rx_bytes += skb->len; vp->dev->stats.rx_packets++;
@@ -981,6 +981,8 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget)for (i =0 ; i < packet_count; i++) { skb = (*skbuff_vector);if (mmsg_vector->msg_len > vp->header_size) { +pskb_trim (skb, + mmsg_vector->msg_len - vp->rx_header_size);if (vp->header_size >0 ) { header_check = vp->verify_header( mmsg_vector->msg_hdr.msg_iov->iov_base,
@@ -1005,8 +1007,6 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget) skb->ip_summed =CHECKSUM_UNNECESSARY ; } } -pskb_trim (skb, - mmsg_vector->msg_len - vp->rx_header_size); skb->protocol =eth_type_trans (skb, skb->dev);/* * We do not need to lock on updating stats here
Signature · 1 line
MST
[email protected]
AI reviewRe: [PATCH net-next v2 3/7] um: vector: trim skbs before verifying the header
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] net: vector: integer underflow in pskb_trim leads to info leak - [High] um: vector: OOB read and…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: vector: integer underflow in pskb_trim leads to info leak
- [High] um: vector: OOB read and packet corruption in vector_legacy_rx
--
commit 7f2cd5c3a1fb41cfaea6c03500daa85a7433a386
Author: Michael S. Tsirkin <[email protected]>
um: vector: trim skbs before verifying the header
This commit modifies the vector receive path to trim the SKB before verifying the transport header. This is done to prepare for computing the packet checksum in software, which requires the packet to be trimmed correctly.
arch/um/drivers/vector_kern.c static int vector_legacy_rx(struct vector_private *vp) · line 868
Quoted 9 lines
arch/um/drivers/vector_kern.c +1
-0@@ -865,6 +865,7 @@ static int vector_legacy_rx(struct vector_private *vp)if (skb !=NULL ) {if (pkt_len > vp->header_size) { +pskb_trim (skb, pkt_len - vp->rx_header_size);
[Severity: High]
Can this subtraction underflow if pkt_len is smaller than vp->rx_header_size?
For GRE and L2TPv3 over IPv4, vp->rx_header_size (e.g., 24) is strictly greater than vp->header_size (e.g., 4). If a packet is received with a length between these two values (e.g., 20 bytes), the check pkt_len > vp->header_size passes, but pkt_len - vp->rx_header_size underflows to a very large unsigned value.
Because the length would exceed the pre-allocated skb->len, pskb_trim() fails silently. The SKB retains its maximum allocated size containing uninitialized memory.
If vp->verify_header() randomly succeeds on the undersized IOV buffer, could this leak uninitialized kernel memory up the network stack via napi_gro_receive()?
[Severity: High]
Does this sequence cause an out-of-bounds read and inner packet corruption?
Earlier in vector_legacy_rx(), iov[0].iov_len is restricted to vp->header_size:
if (vp->header_size > 0) {
iov[0].iov_base = vp->header_rxbuffer;
iov[0].iov_len = vp->header_size;
}For raw IPv4 GRE/L2TPv3 tunnels where vp->header_size (4) differs from vp->rx_header_size (24), recvmsg() reads only the first 4 bytes of the IP header into vp->header_rxbuffer. The remaining IP header, GRE header, and inner packet spill into iov[1] (skb->data).
When gre_verify_header() runs, it advances its pointer by sizeof(struct iphdr) and reads uninitialized memory from the 4-byte header_rxbuffer to verify the header.
Additionally, because the headers spilled into the SKB, does trimming by the full vp->rx_header_size here incorrectly truncate the payload from the tail instead of the head, silently destroying the inner packet before it reaches eth_type_trans()?
[ ... ]
arch/um/drivers/vector_kern.c static int vector_mmsg_rx(struct vector_private *vp, int budget) · line 985
Quoted 6 lines
arch/um/drivers/vector_kern.c +2
-0@@ -981,6 +981,8 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget)for (i =0 ; i < packet_count; i++) { skb = (*skbuff_vector);if (mmsg_vector->msg_len > vp->header_size) { +pskb_trim (skb, + mmsg_vector->msg_len - vp->rx_header_size);
[Severity: High]
Like the vector_legacy_rx() path, does this subtraction also underflow if msg_len is between vp->header_size and vp->rx_header_size?
Quoted 3 lines
arch/um/drivers/vector_kern.c +0
-0if (vp->header_size >0 ) { header_check = vp->verify_header( mmsg_vector->msg_hdr.msg_iov->iov_base,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Michael S. Tsirkin
maintainerPATCH v2 4/7 net: resolve uncommon partial checksums at ingress
In reply to Michael S. TsirkinAs reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place CHECKSUM_PARTIAL at any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.
Let's fix that: let's validate csum_start and csum_offset and only keep CHECKSUM_PARTIAL when csum_start and csum_offset match a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.
We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever csum_start and csum_offset say, but that seems like an overkill for something that shouldn't happen.
There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get dropped
To mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without VIRTIO_NET_HDR_F_NEEDS_CSUM are unaffected.
--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)
include/linux/virtio_net.h +241 -10
@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h>
@@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; } +/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ +static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph; +} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/ +static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) { +if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto; +if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb); + *proto = skb->protocol; + } +return true; +} + +/* Walk the L3 header at @nhoff: where does its transport header +* start, and which protocol is it? Returns false if the header +* is truncated, malformed or fragmented. +*/ +static inline bool +virtio_net_l4_start (struct sk_buff *skb,unsigned int nhoff,__be16 proto, +unsigned int *thoff,int *ip_proto) +{ +if (proto ==htons (ETH_P_IP )) { +const struct iphdr *iph =virtio_net_ip4_parse (skb, nhoff, thoff); + +if (!iph ||ip_is_fragment (iph)) +return false; + *ip_proto = iph->protocol; +return true; + } + +if (proto ==htons (ETH_P_IPV6 )) { +const struct ipv6hdr *iph; +int flags =0 ; + +if (!pskb_may_pull (skb, nhoff +sizeof (*iph))) +return false; + iph = (const void *)(skb->data + nhoff); +if (iph->version !=6 ) +return false; + *thoff = nhoff +sizeof (*iph); + *ip_proto = iph->nexthdr; +if (*ip_proto !=IPPROTO_TCP && *ip_proto !=IPPROTO_UDP ) { + *thoff = nhoff; + *ip_proto =ipv6_find_hdr (skb, thoff,-1 ,NULL , + &flags); +if (*ip_proto <0 || flags &IP6_FH_F_FRAG ) +return false; + } +return true; + } + +return false; +} + +/* Does checksum metadata match a known TCP or UDP header? */ +static inline bool +virtio_net_csum_partial_ok_at_offset (struct sk_buff *skb,u8 hdr_gso_type, +unsigned int nhoff,__be16 proto) +{ +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +if (skb_checksum_start_offset (skb) != thoff) +return false; + +switch (ip_proto) { +case IPPROTO_TCP : +if (skb->csum_offset != offsetof(struct tcphdr , check) || + !pskb_may_pull (skb, thoff +sizeof (struct tcphdr ))) +return false; +break ; +case IPPROTO_UDP : +if (skb->csum_offset != offsetof(struct udphdr , check) || + !pskb_may_pull (skb, thoff +sizeof (struct udphdr ))) +return false; +break ; +default : +return false; + } + +switch (hdr_gso_type & ~VIRTIO_NET_HDR_GSO_ECN ) { +case VIRTIO_NET_HDR_GSO_NONE : +return true; +case VIRTIO_NET_HDR_GSO_TCPV4 : +return proto ==htons (ETH_P_IP ) && ip_proto ==IPPROTO_TCP ; +case VIRTIO_NET_HDR_GSO_TCPV6 : +return proto ==htons (ETH_P_IPV6 ) && ip_proto ==IPPROTO_TCP ; +case VIRTIO_NET_HDR_GSO_UDP : +case VIRTIO_NET_HDR_GSO_UDP_L4 : +return ip_proto ==IPPROTO_UDP ; +default : +return false; + } +} + +static inline bool +virtio_net_csum_partial_ok (struct sk_buff *skb,u8 hdr_gso_type) +{ +int nhoff; +__be16 proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; + +return virtio_net_csum_partial_ok_at_offset (skb, hdr_gso_type, nhoff, + proto); +} + +/* +* Handle a packet whose checksum metadata does not match the packet: +* GSO packets are dropped, as segmentation needs one checksum per +* segment; others are completed in software. +* +* Return 1 if the checksum was completed in software, else a negative +* errno. +*/ +static inline int virtio_net_resolve_csum_partial_mismatch (struct sk_buff *skb) +{ +if (skb_is_gso (skb)) +return -EINVAL ; + +return skb_checksum_help (skb) ?:1 ; +} +static inline int __virtio_net_hdr_to_skb (struct sk_buff *skb,const struct virtio_net_hdr *hdr,bool little_endian,u8 hdr_gso_type)
@@ -158,8 +327,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,case SKB_GSO_UDP_L4 :if (!(hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ))return -EINVAL ; -if (skb->csum_offset != offsetof(struct udphdr , check)) -return -EINVAL ;if (skb->len - p_off > gso_size *UDP_MAX_SEGMENTS )return -EINVAL ;if (gso_type !=SKB_GSO_UDP_L4 )
@@ -167,10 +334,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,break ;case SKB_GSO_TCPV4 :case SKB_GSO_TCPV6 : -if (skb->ip_summed ==CHECKSUM_PARTIAL && - skb->csum_offset != offsetof(struct tcphdr , check)) -return -EINVAL ; -BUILD_BUG_ON (TCP_MIN_GSO_SIZE *GSO_MAX_SEGS <GSO_MAX_SIZE ); gso_size =max (gso_size,TCP_MIN_GSO_SIZE );break ;
@@ -194,11 +357,36 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,return 0 ; } +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_to_skb (struct sk_buff *skb,const struct virtio_net_hdr *hdr,bool little_endian) { -return __virtio_net_hdr_to_skb (skb, hdr, little_endian, hdr->gso_type); + typeof(skb->transport_header) old_transport = skb->transport_header; +int ret =__virtio_net_hdr_to_skb (skb, hdr, little_endian, + hdr->gso_type); + +if (ret <0 ) +return ret; + +if (skb->ip_summed !=CHECKSUM_PARTIAL || +virtio_net_csum_partial_ok (skb, hdr->gso_type)) +return 0 ; + +/* +* Here we do not trust the checksum metadata. +* __virtio_net_hdr_to_skb set the transport header to csum_start +* from virtio hdr, restore it to a known good value. +*/ + skb->transport_header = old_transport; + ret =virtio_net_resolve_csum_partial_mismatch (skb); + +return ret; }/* This function must be called after virtio_net_hdr_from_skb(). */
@@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,
@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;
@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and
@@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;
@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb +* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }/* Checksum-related fields validation for the driver */
Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
Quoted 60 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +4
-0@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> @@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; }
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 63
Quoted 10 lines
include/linux/virtio_net.h +9
-0+/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/
nit: comment basically describes the code (what), which is quite self explanatory. I'd drop. Or else consider converting to kdoc fmt.
Quoted 16 lines
include/linux/virtio_net.h +16
-0+static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph;
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 89
Quoted 10 lines
include/linux/virtio_net.h +10
-0+} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/ +static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) {
Only since recent commit 44378d02c5aa ("net: always dissect GSO packets in __virtio_net_hdr_to_skb()") can skb->dev be relied on to be non-zero.
We'll have to be careful that this does not get backported to stable without that.
Perhaps an explicit precondition test and error return (and DEBUG_NET_WARN_ON_ONCE) if a NULL skb->dev is encountered.
OTOH, it results in a hard crash so will be discoverd fast without that too.
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 93
Quoted 4 lines
include/linux/virtio_net.h +4
-0+if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto;
When called from virtio_net_hdr_tnl_to_skb, according to my LLM mac header may not be set yet. Have not verified yet.
skb_reset_mac_header(skb) is called inside __virtio_net_hdr_to_skb, which is then not called yet.
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 100
Quoted 7 lines
include/linux/virtio_net.h +7
-0+if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb);
The same is true for skb->network_header. Since an uninitialized/zero value there causes more subtle issues, here an explicit check may be more valuable (even) than for skb->dev.
Quoted 98 lines
include/linux/virtio_net.h +51
-3+ *proto = skb->protocol; + } +return true; +} +/* This function must be called after virtio_net_hdr_from_skb(). */ @@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and @@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb +* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }/* Checksum-related fields validation for the driver */ Signature · 1 line
MST
Re: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
Quoted 124 lines · Willem de Bruijn
Quoted 60 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +4
-0@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> @@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; }include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 63
Quoted 10 lines
include/linux/virtio_net.h +9
-0+/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ nit: comment basically describes the code (what), which is quite self explanatory. I'd drop. Or else consider converting to kdoc fmt.
Quoted 16 lines
include/linux/virtio_net.h +16
-0+static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph;include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 89
Quoted 10 lines
include/linux/virtio_net.h +10
-0+} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/ +static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) {Only since recent commit
44378d02c5aa("net: always dissect GSO packets in__virtio_net_hdr_to_skb()") canskb->devbe relied on to be non-zero.We'll have to be careful that this does not get backported to stable without that.
Perhaps an explicit precondition test and error return (and
DEBUG_NET_WARN_ON_ONCE) if a NULLskb->devis encountered.OTOH, it results in a hard crash so will be discoverd fast without that too.
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 93
Quoted 4 lines
include/linux/virtio_net.h +4
-0+if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto;When called from
virtio_net_hdr_tnl_to_skb, according to my LLM mac header may not be set yet. Have not verified yet.
Quoted 3 lines
skb_reset_mac_header(skb)is called inside__virtio_net_hdr_to_skb, which is then not called yet.
I am able to confirm this in my testing. I have KASAN enabled, and it triggered when testing leading me to this change.
Adding skb_reset_mac_header(skb); before calling virtio_net_tnl_offsets_ok mitigates this issue.
--chris
Quoted 112 lines
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 100
Quoted 7 lines
include/linux/virtio_net.h +7
-0+if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb);The same is true for
skb->network_header. Since an uninitialized/zero value there causes more subtle issues, here an explicit check may be more valuable (even) than forskb->dev.Quoted 98 lines
include/linux/virtio_net.h +51
-3+ *proto = skb->protocol; + } +return true; +} +/* This function must be called after virtio_net_hdr_from_skb(). */ @@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and @@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb +* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }/* Checksum-related fields validation for the driver */ Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
Quoted 129 lines · Chris Arges
Quoted 124 lines · Willem de Bruijn
Quoted 60 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +4
-0@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> @@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; }include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 63
Quoted 10 lines
include/linux/virtio_net.h +9
-0+/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ nit: comment basically describes the code (what), which is quite self explanatory. I'd drop. Or else consider converting to kdoc fmt.
Quoted 16 lines
include/linux/virtio_net.h +16
-0+static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph;include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 89
Quoted 10 lines
include/linux/virtio_net.h +10
-0+} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/ +static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) {Only since recent commit
44378d02c5aa("net: always dissect GSO packets in__virtio_net_hdr_to_skb()") canskb->devbe relied on to be non-zero.We'll have to be careful that this does not get backported to stable without that.
Perhaps an explicit precondition test and error return (and
DEBUG_NET_WARN_ON_ONCE) if a NULLskb->devis encountered.OTOH, it results in a hard crash so will be discoverd fast without that too.
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 93
Quoted 4 lines
include/linux/virtio_net.h +4
-0+if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto;When called from
virtio_net_hdr_tnl_to_skb, according to my LLM mac header may not be set yet. Have not verified yet.Quoted 3 lines
skb_reset_mac_header(skb)is called inside__virtio_net_hdr_to_skb, which is then not called yet.
Quoted 7 lines
I am able to confirm this in my testing. I have KASAN enabled, and it triggered when testing leading me to this change.
Adding
skb_reset_mac_header(skb);before callingvirtio_net_tnl_offsets_okmitigates this issue.--chris
I was sure I run that test. Facepalm. Thanks a lot, I'll go over this again.
Quoted 113 lines
Quoted 113 lines
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 100
Quoted 8 lines
include/linux/virtio_net.h +7
-0+if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb);The same is true for
skb->network_header. Since an uninitialized/zero value there causes more subtle issues, here an explicit check may be more valuable (even) than forskb->dev.Quoted 98 lines
include/linux/virtio_net.h +51
-3+ *proto = skb->protocol; + } +return true; +} +/* This function must be called after virtio_net_hdr_from_skb(). */ @@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and @@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb +* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }/* Checksum-related fields validation for the driver */ Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
In reply to Willem de BruijnQuoted 97 lines · Willem de Bruijn
Quoted 60 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +4
-0@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> @@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; }include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 63
Quoted 10 lines
include/linux/virtio_net.h +9
-0+/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ nit: comment basically describes the code (what), which is quite self explanatory. I'd drop. Or else consider converting to kdoc fmt.
Quoted 22 lines
include/linux/virtio_net.h +22
-0+static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph; +} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/
Quoted 8 lines
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 89
Quoted 4 lines
include/linux/virtio_net.h +4
-0+static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) {Only since recent commit
44378d02c5aa("net: always dissect GSO packets in__virtio_net_hdr_to_skb()") canskb->devbe relied on to be non-zero.
Yea that commit's pretty important) I'll add that to the commit log.
Quoted 133 lines
We'll have to be careful that this does not get backported to stable without that.
Perhaps an explicit precondition test and error return (and
DEBUG_NET_WARN_ON_ONCE) if a NULLskb->devis encountered.OTOH, it results in a hard crash so will be discoverd fast without that too.
include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 93
Quoted 4 lines
include/linux/virtio_net.h +4
-0+if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto;When called from
virtio_net_hdr_tnl_to_skb, according to my LLM mac header may not be set yet. Have not verified yet.
skb_reset_mac_header(skb)is called inside__virtio_net_hdr_to_skb, which is then not called yet.include/linux/virtio_net.h static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, · line 100
Quoted 7 lines
include/linux/virtio_net.h +7
-0+if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb);The same is true for
skb->network_header. Since an uninitialized/zero value there causes more subtle issues, here an explicit check may be more valuable (even) than forskb->dev.Quoted 98 lines
include/linux/virtio_net.h +51
-3+ *proto = skb->protocol; + } +return true; +} +/* This function must be called after virtio_net_hdr_from_skb(). */ @@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and @@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb +* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }/* Checksum-related fields validation for the driver */ Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
In reply to Michael S. TsirkinQuoted 71 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +4
-0@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> static inline int __virtio_net_hdr_to_skb(struct
sk_buff*skb,include/linux/virtio_net.h +0
-2const struct virtio_net_hdr *hdr, bool little_endian, u8 hdr_gso_type)@@ -158,8 +327,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,case SKB_GSO_UDP_L4 :if (!(hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ))return -EINVAL ; -if (skb->csum_offset != offsetof(struct udphdr , check)) -return -EINVAL ;if (skb->len - p_off > gso_size *UDP_MAX_SEGMENTS )return -EINVAL ;if (gso_type !=SKB_GSO_UDP_L4 )
include/linux/virtio_net.h static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb, · line 173
Quoted 7 lines
include/linux/virtio_net.h +0
-4@@ -167,10 +334,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,break ;case SKB_GSO_TCPV4 :case SKB_GSO_TCPV6 : -if (skb->ip_summed ==CHECKSUM_PARTIAL && - skb->csum_offset != offsetof(struct tcphdr , check)) -return -EINVAL ; -
Maybe keep this and the above check, to keep things exactly as is when the sysctl is disabled.
Removing these checks weakens validation vs the present state.
Willem de Bruijn
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
In reply to Michael S. TsirkinQuoted 17 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.
Quoted 4 lines
There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get dropped
The biggest risk I see of valid packets reaching this path is packet sockets that are not bound to a specific protocol (ETH_P_ALL) over a non Ethernet device.
Iff proto is 0 we could try to infer from the first nibble at the network header:
+ iph = (const void *)(skb->data + nhoff);
+ if (!proto) {
+ if (iph->version == 4)
+ proto = htons(ETH_P_IP);
+ else if (iph->version == 6)
+ proto = htons(ETH_P_IPV6);
+ }
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
In reply to Michael S. TsirkinQuoted 363 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users) a virtio net header can place
CHECKSUM_PARTIALat any in-packet offset. If that state is retained, later checksum completion can modify the packet after protocol processing has made decisions from it.Let's fix that: let's validate
csum_startandcsum_offsetand only keepCHECKSUM_PARTIALwhencsum_startandcsum_offsetmatch a parsed TCP or UDP header, while handling VLAN headers, IPv4 options and IPv6 extension headers. Complete other non-GSO checksums immediately, before any protocol processing runs.We can't easily "complete the checksum" for GSO we don't recognize - GSO assumes knowledge of the protocol. We could segment ignoring the checksum then do whatever
csum_startandcsum_offsetsay, but that seems like an overkill for something that shouldn't happen.There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in software, adding performance overhead
- gso packets which can't be parsed get droppedTo mitigate the risks, the following patch will add a sysctl knob to bypass the resolution. This is reasonable if the setup is such that there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without
VIRTIO_NET_HDR_F_NEEDS_CSUMare unaffected.Assisted-by LLMReported-by Paulos Yibelo <[email protected]>Reported-by Chris Arges <[email protected]>Tested-by Chris Arges <[email protected]>Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Suggested-by Willem de Bruijn <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/linux/virtio_net.h | 251 +++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 10 deletions(-)include/linux/virtio_net.h +233
-10@@ -5,7 +5,11 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/netdevice.h> #include <linux/udp.h> +#include <net/gso.h> +#include <net/ip.h> +#include <net/ipv6.h> #include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h> @@ -48,6 +52,171 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; } +/* TODO: nothing virtio specific here, move to ip.h */ + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ +static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || + iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph; +} + +/* Where does the L3 header start, and what protocol is it? +* Handles Ethernet and VLAN headers; other devices use the +* network header offset the caller set up. +*/ +static inline bool +virtio_net_l3_start (struct sk_buff *skb,int *nhoff,__be16 *proto) +{ +if (skb->dev->type ==ARPHRD_ETHER ) { +if (!pskb_may_pull (skb,ETH_HLEN )) +return false; + *nhoff =ETH_HLEN ; + *proto =eth_hdr (skb)->h_proto; +if (eth_type_vlan (*proto)) { + *proto =__vlan_get_protocol (skb, *proto, nhoff); +if (!*proto) +return false; + } + }else { + *nhoff =skb_network_offset (skb); + *proto = skb->protocol; + } +return true; +} + +/* Walk the L3 header at @nhoff: where does its transport header +* start, and which protocol is it? Returns false if the header +* is truncated, malformed or fragmented. +*/ +static inline bool +virtio_net_l4_start (struct sk_buff *skb,unsigned int nhoff,__be16 proto, +unsigned int *thoff,int *ip_proto) +{ +if (proto ==htons (ETH_P_IP )) { +const struct iphdr *iph =virtio_net_ip4_parse (skb, nhoff, thoff); + +if (!iph ||ip_is_fragment (iph)) +return false; + *ip_proto = iph->protocol; +return true; + } + +if (proto ==htons (ETH_P_IPV6 )) { +const struct ipv6hdr *iph; +int flags =0 ; + +if (!pskb_may_pull (skb, nhoff +sizeof (*iph))) +return false; + iph = (const void *)(skb->data + nhoff); +if (iph->version !=6 ) +return false; + *thoff = nhoff +sizeof (*iph); + *ip_proto = iph->nexthdr; +if (*ip_proto !=IPPROTO_TCP && *ip_proto !=IPPROTO_UDP ) { + *thoff = nhoff; + *ip_proto =ipv6_find_hdr (skb, thoff,-1 ,NULL , + &flags); +if (*ip_proto <0 || flags &IP6_FH_F_FRAG ) +return false; + } +return true; + } + +return false; +} + +/* Does checksum metadata match a known TCP or UDP header? */ +static inline bool +virtio_net_csum_partial_ok_at_offset (struct sk_buff *skb,u8 hdr_gso_type, +unsigned int nhoff,__be16 proto) +{ +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +if (skb_checksum_start_offset (skb) != thoff) +return false; + +switch (ip_proto) { +case IPPROTO_TCP : +if (skb->csum_offset != offsetof(struct tcphdr , check) || + !pskb_may_pull (skb, thoff +sizeof (struct tcphdr ))) +return false; +break ; +case IPPROTO_UDP : +if (skb->csum_offset != offsetof(struct udphdr , check) || + !pskb_may_pull (skb, thoff +sizeof (struct udphdr ))) +return false; +break ; +default : +return false; + } + +switch (hdr_gso_type & ~VIRTIO_NET_HDR_GSO_ECN ) { +case VIRTIO_NET_HDR_GSO_NONE : +return true; +case VIRTIO_NET_HDR_GSO_TCPV4 : +return proto ==htons (ETH_P_IP ) && ip_proto ==IPPROTO_TCP ; +case VIRTIO_NET_HDR_GSO_TCPV6 : +return proto ==htons (ETH_P_IPV6 ) && ip_proto ==IPPROTO_TCP ; +case VIRTIO_NET_HDR_GSO_UDP : +case VIRTIO_NET_HDR_GSO_UDP_L4 : +return ip_proto ==IPPROTO_UDP ; +default : +return false; + } +} + +static inline bool +virtio_net_csum_partial_ok (struct sk_buff *skb,u8 hdr_gso_type) +{ +int nhoff; +__be16 proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; + +return virtio_net_csum_partial_ok_at_offset (skb, hdr_gso_type, nhoff, + proto); +} + +/* +* Handle a packet whose checksum metadata does not match the packet: +* GSO packets are dropped, as segmentation needs one checksum per +* segment; others are completed in software. +* +* Return 1 if the checksum was completed in software, else a negative +* errno. +*/ +static inline int virtio_net_resolve_csum_partial_mismatch (struct sk_buff *skb) +{ +if (skb_is_gso (skb)) +return -EINVAL ; + +return skb_checksum_help (skb) ?:1 ; +} +static inline int __virtio_net_hdr_to_skb (struct sk_buff *skb,const struct virtio_net_hdr *hdr,bool little_endian,u8 hdr_gso_type)@@ -158,8 +327,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,case SKB_GSO_UDP_L4 :if (!(hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ))return -EINVAL ; -if (skb->csum_offset != offsetof(struct udphdr , check)) -return -EINVAL ;if (skb->len - p_off > gso_size *UDP_MAX_SEGMENTS )return -EINVAL ;if (gso_type !=SKB_GSO_UDP_L4 )@@ -167,10 +334,6 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,break ;case SKB_GSO_TCPV4 :case SKB_GSO_TCPV6 : -if (skb->ip_summed ==CHECKSUM_PARTIAL && - skb->csum_offset != offsetof(struct tcphdr , check)) -return -EINVAL ; -BUILD_BUG_ON (TCP_MIN_GSO_SIZE *GSO_MAX_SEGS <GSO_MAX_SIZE ); gso_size =max (gso_size,TCP_MIN_GSO_SIZE );break ;@@ -194,11 +357,36 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,return 0 ; } +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_to_skb (struct sk_buff *skb,const struct virtio_net_hdr *hdr,bool little_endian) { -return __virtio_net_hdr_to_skb (skb, hdr, little_endian, hdr->gso_type); + typeof(skb->transport_header) old_transport = skb->transport_header; +int ret =__virtio_net_hdr_to_skb (skb, hdr, little_endian, + hdr->gso_type); + +if (ret <0 ) +return ret; + +if (skb->ip_summed !=CHECKSUM_PARTIAL || +virtio_net_csum_partial_ok (skb, hdr->gso_type)) +return 0 ; + +/* +* Here we do not trust the checksum metadata. +* __virtio_net_hdr_to_skb set the transport header to csum_start +* from virtio hdr, restore it to a known good value. +*/ + skb->transport_header = old_transport; + ret =virtio_net_resolve_csum_partial_mismatch (skb); + +return ret; }/* This function must be called after virtio_net_hdr_from_skb(). */ @@ -282,6 +470,35 @@ static inline unsigned int virtio_l3min(bool is_ipv6)return is_ipv6 ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Do the tunnel offsets match the outer headers in the frame? +* The L3 header the tunnel claims must be the one the frame +* carries, with UDP following it at @outer_th. +*/ +static inline bool +virtio_net_tnl_offsets_ok (struct sk_buff *skb,bool outer_isv6, +unsigned int outer_th) +{ +int nhoff; +__be16 proto; +unsigned int thoff; +int ip_proto; + +if (!virtio_net_l3_start (skb, &nhoff, &proto)) +return false; +if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +return false; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto)) +return false; + +return ip_proto ==IPPROTO_UDP && outer_th == thoff; +} + +/* +* Return value: +* 0 - success +* >0 - checksum was completed in software (slow path) +* <0 - failure +*/ static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr,@@ -293,6 +510,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,unsigned int inner_nh, outer_th, inner_th;unsigned int inner_l3min, outer_l3min;u8 gso_inner_type, gso_tunnel_type; +__be16 inner_proto;bool outer_isv6, inner_isv6;int ret;@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;/* In case of USO, the inner protocol is still unknown and @@ -353,7 +574,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, }skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); +htons (ETH_P_IP ));if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;@@ -368,7 +589,17 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, skb->inner_mac_header = inner_nh +skb_headroom (skb); skb->transport_header = outer_th +skb_headroom (skb); skb->encapsulation =1 ; -return 0 ; + +/* +* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb
include/linux/virtio_net.h virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, · line 604
Quoted 10 lines
include/linux/virtio_net.h +8
-0+* set CHECKSUM_PARTIAL. +*/ + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, + inner_proto)) +return 0 ; + +return virtio_net_resolve_csum_partial_mismatch (skb); }
Damn. I went over my testing and it was using qemu from the fedora install, all the tunnels features were not there and were not tested (
That will need more work. I will send v3 in a couple of days.
Quoted 4 lines
include/linux/virtio_net.h +0
-0/* Checksum-related fields validation for the driver */ Signature · 1 line
MST
[email protected]
AI reviewRe: [PATCH net-next v2 4/7] net: resolve uncommon partial checksums at ingress
In reply to Michael S. TsirkinThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: OOB read in virtio_net_l3_start due to uninitialized mac_header --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: OOB read in virtio_net_l3_start due to uninitialized mac_header --
commit 7b948a860070205bb3211c20ccd737b2f0e9cfad
Author: Michael S. Tsirkin <[email protected]>
net: resolve uncommon partial checksums at ingress
This commit updates virtio net header parsing to validate checksum offsets and only retain CHECKSUM_PARTIAL when they match parsed TCP or UDP headers. It also introduces early tunnel offset validation.
Quoted 4 lines
include/linux/virtio_net.h +0
-0
[ ... ]
include/linux/virtio_net.h virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, · line 555
Quoted 7 lines
include/linux/virtio_net.h +3
-0@@ -332,10 +550,13 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, inner_th < inner_nh + inner_l3min)return -EINVAL ; +if (!virtio_net_tnl_offsets_ok (skb, outer_isv6, outer_th)) +return -EINVAL ; +
[Severity: High]
Does this sequence result in accessing an uninitialized MAC header?
Tracing the call sequence starting here:virtio_net_hdr_tnl_to_skb()
-> virtio_net_tnl_offsets_ok()
-> virtio_net_l3_start()
Inside virtio_net_l3_start(), if the device type is ARPHRD_ETHER (which is true for IFF_TAP and virtio_net), the code evaluates eth_hdr(skb)->h_proto:
include/linux/virtio_net.h:virtio_net_l3_start() {
if (skb->dev->type == ARPHRD_ETHER) {
if (!pskb_may_pull(skb, ETH_HLEN))
return false;
*nhoff = ETH_HLEN;
*proto = eth_hdr(skb)->h_proto;...
}
However, eth_hdr(skb) strictly evaluates to skb->head + skb->mac_header. Callers like tun_get_user() and virtnet_receive_done() do not appear to initialize the MAC header before calling virtio_net_hdr_tnl_to_skb().
The MAC header is normally initialized via skb_reset_mac_header(skb), which happens in __virtio_net_hdr_to_skb() located just below this check.
Because virtio_net_tnl_offsets_ok() is called before __virtio_net_hdr_to_skb(), skb->mac_header retains its default allocation value of 0xFFFF. Could this cause an out-of-bounds memory read (skb->head + 0xFFFF + offsetof(h_proto)) and a potential kernel panic?
Quoted 6 lines
include/linux/virtio_net.h +1
-1/* Let the basic parsing deal with plain GSO features. */ ret =__virtio_net_hdr_to_skb (skb, hdr, true, hdr->gso_type & ~gso_tunnel_type); -if (ret) +if (ret <0 )return ret;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Michael S. Tsirkin
maintainerPATCH v2 5/7 net: add a sysctl to opt out of virtio net hdr checksum validation
In reply to Michael S. TsirkinThe ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.
I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 > /proc/sys/net/core/virtio_net_hdr_csum_check
The default is validating.
--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)
Documentation/admin-guide/sysctl/net.rst +15 -0
@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on) +virtio_net_hdr_csum_check +------------------------- + +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------
include/linux/virtio_net.h +23 -0
@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h>
@@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, *thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ +DECLARE_STATIC_KEY_FALSE (virtio_net_hdr_csum_check_disabled_key); + +/* Failsafe: a namespace can disable the check with +* net.core.virtio_net_hdr_csum_check. +*/ +static inline bool virtio_net_hdr_csum_check_disabled (struct sk_buff *skb) +{ +return static_branch_unlikely (&virtio_net_hdr_csum_check_disabled_key) && + !READ_ONCE (dev_net (skb->dev)->core.sysctl_virtio_net_hdr_csum_check); +}/* Where does the L3 header start, and what protocol is it? * Handles Ethernet and VLAN headers; other devices use the
@@ -152,6 +166,12 @@ virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,unsigned int thoff;int ip_proto; +/* Failsafe: a namespace opted out of the validation, +* trust the checksum metadata as before. +*/ +if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto))return false;
@@ -483,6 +503,9 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool outer_isv6,unsigned int thoff;int ip_proto; +if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l3_start (skb, &nhoff, &proto))return false;if (outer_isv6 != (proto ==htons (ETH_P_IPV6 )))
include/net/netns/core.h +1 -0
@@ -18,6 +18,7 @@ struct netns_core {u8 sysctl_txrehash;u8 sysctl_tstamp_allow_data;u8 sysctl_bypass_prot_mem; +u8 sysctl_virtio_net_hdr_csum_check;#ifdef CONFIG_PROC_FS struct prot_inuse __percpu *prot_inuse;
net/core/dev.c +6 -0
@@ -2389,6 +2389,12 @@ EXPORT_SYMBOL(tcf_sw_enabled_key);DEFINE_STATIC_KEY_FALSE (netstamp_needed_key);EXPORT_SYMBOL (netstamp_needed_key); + +/* Enabled while any network namespace has net.core.virtio_net_hdr_csum_check +* set to 0. +*/ +DEFINE_STATIC_KEY_FALSE (virtio_net_hdr_csum_check_disabled_key); +EXPORT_SYMBOL (virtio_net_hdr_csum_check_disabled_key);#ifdef CONFIG_JUMP_LABEL static atomic_t netstamp_needed_deferred;static atomic_t netstamp_wanted;
net/core/net_namespace.c +1 -0
@@ -396,6 +396,7 @@ static __net_init void preinit_net_sysctl(struct net *net) net->core.sysctl_optmem_max =128 *1024 ; net->core.sysctl_txrehash =SOCK_TXREHASH_ENABLED ; net->core.sysctl_tstamp_allow_data =1 ; + net->core.sysctl_virtio_net_hdr_csum_check =1 ; net->core.sysctl_txq_reselection =msecs_to_jiffies (1000 ); }
net/core/sysctl_net_core.c +54 -0
78 lines not on this page · raw message
Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 31 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 5 lines
Documentation/admin-guide/sysctl/net.rst +2
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on) +virtio_net_hdr_csum_check +-------------------------
Make more generic, virtio_net_hdr_validate?
In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h>
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0@@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, *thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/
Should this be a global sysctl, rather than per netns?
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.
A global sysctl also allows using proc_do_static_key and avoids the custom logic in virtio_net_hdr_csum_check_sysctl.
include/linux/virtio_net.h virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type, · line 171
Quoted 9 lines
include/linux/virtio_net.h +3
-0/* Where does the L3 header start, and what protocol is it? * Handles Ethernet and VLAN headers; other devices use the @@ -152,6 +166,12 @@ virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,unsigned int thoff;int ip_proto; +/* Failsafe: a namespace opted out of the validation, +* trust the checksum metadata as before. +*/
nit: as before, imho the code here is clear and comment unnecessary.
Quoted 90 lines
include/linux/virtio_net.h +59
-0+if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto))return false;@@ -483,6 +503,9 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool outer_isv6,unsigned int thoff;int ip_proto; +if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l3_start (skb, &nhoff, &proto))return false;if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +/* Defined in net/core/dev.c, declared for the gate in +* include/linux/virtio_net.h. +*/ +DECLARE_STATIC_KEY_FALSE (virtio_net_hdr_csum_check_disabled_key); + +/* +* Protects changes to virtio_net_hdr_csum_check_disabled_key and each +* net->core.sysctl_virtio_net_hdr_csum_check. Readers don't use a lock. +*/ +static DEFINE_MUTEX (virtio_net_hdr_csum_check_mutex); + +static int virtio_net_hdr_csum_check_sysctl (const struct ctl_table *table, +int write,void *buffer, +size_t *lenp,loff_t *ppos) +{ +struct net *net = (struct net *)table->data; +/* checkpatch warns but this can't be const: tmp.data is set below */ +struct ctl_table tmp = *table; +u8 old; +int ret; + +/* +* Make sure virtio_net_hdr_csum_check_disabled_key counts zero values of +* net->core.sysctl_virtio_net_hdr_csum_check. +*/ +mutex_lock (&virtio_net_hdr_csum_check_mutex); + + old = net->core.sysctl_virtio_net_hdr_csum_check; + tmp.data = &net->core.sysctl_virtio_net_hdr_csum_check; + ret =proc_dou8vec_minmax (&tmp, write, buffer, lenp, ppos); +if (write && !ret && old != net->core.sysctl_virtio_net_hdr_csum_check) { +if (net->core.sysctl_virtio_net_hdr_csum_check) +static_branch_dec (&virtio_net_hdr_csum_check_disabled_key); +else +static_branch_inc (&virtio_net_hdr_csum_check_disabled_key); + } + +mutex_unlock (&virtio_net_hdr_csum_check_mutex); + +return ret; +} +static const struct ctl_table netns_core_table[] = { #if IS_ENABLED(CONFIG_RPS) {@@ -737,6 +780,15 @@ static const struct ctl_table netns_core_table[] = { .extra1 = SYSCTL_ZERO, .extra2 =SYSCTL_ONE }, + { + .procname = "virtio_net_hdr_csum_check", + .data = &init_net, + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = virtio_net_hdr_csum_check_sysctl, + .extra1 = SYSCTL_ZERO, + .extra2 =SYSCTL_ONE + },/* sysctl_core_net_init() will set the values after this * to readonly in network namespaces */ @@ -841,6 +893,8 @@ static __net_exit void sysctl_core_net_exit(struct net *net) tbl = net->core.sysctl_hdr->ctl_table_arg;unregister_net_sysctl_table (net->core.sysctl_hdr);BUG_ON (tbl == netns_core_table); +if (!net->core.sysctl_virtio_net_hdr_csum_check) +static_branch_dec (&virtio_net_hdr_csum_check_disabled_key);#if IS_ENABLED (CONFIG_RPS )kfree (net->core.rps_default_mask);#endif Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)
Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,
Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
For customers I work with, it would be much less useful.
Quoted 5 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.
Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
Quoted 9 lines
A global sysctl also allows using
proc_do_static_keyand avoids the custom logic invirtio_net_hdr_csum_check_sysctl.Quoted 6 lines
include/linux/virtio_net.h +0
-0/* Where does the L3 header start, and what protocol is it? * Handles Ethernet and VLAN headers; other devices use the @@ -152,6 +166,12 @@ virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,unsigned int thoff;int ip_proto;
Quoted 5 lines
include/linux/virtio_net.h virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type, · line 171
Quoted 3 lines
include/linux/virtio_net.h +3
-0+/* Failsafe: a namespace opted out of the validation, +* trust the checksum metadata as before. +*/ nit: as before, imho the code here is clear and comment unnecessary.
Ugh. One of these got through. Absolutely.
Quoted 91 lines
Quoted 90 lines
include/linux/virtio_net.h +59
-0+if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l4_start (skb, nhoff, proto, &thoff, &ip_proto))return false;@@ -483,6 +503,9 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool outer_isv6,unsigned int thoff;int ip_proto; +if (virtio_net_hdr_csum_check_disabled (skb)) +return true; +if (!virtio_net_l3_start (skb, &nhoff, &proto))return false;if (outer_isv6 != (proto ==htons (ETH_P_IPV6 ))) +/* Defined in net/core/dev.c, declared for the gate in +* include/linux/virtio_net.h. +*/ +DECLARE_STATIC_KEY_FALSE (virtio_net_hdr_csum_check_disabled_key); + +/* +* Protects changes to virtio_net_hdr_csum_check_disabled_key and each +* net->core.sysctl_virtio_net_hdr_csum_check. Readers don't use a lock. +*/ +static DEFINE_MUTEX (virtio_net_hdr_csum_check_mutex); + +static int virtio_net_hdr_csum_check_sysctl (const struct ctl_table *table, +int write,void *buffer, +size_t *lenp,loff_t *ppos) +{ +struct net *net = (struct net *)table->data; +/* checkpatch warns but this can't be const: tmp.data is set below */ +struct ctl_table tmp = *table; +u8 old; +int ret; + +/* +* Make sure virtio_net_hdr_csum_check_disabled_key counts zero values of +* net->core.sysctl_virtio_net_hdr_csum_check. +*/ +mutex_lock (&virtio_net_hdr_csum_check_mutex); + + old = net->core.sysctl_virtio_net_hdr_csum_check; + tmp.data = &net->core.sysctl_virtio_net_hdr_csum_check; + ret =proc_dou8vec_minmax (&tmp, write, buffer, lenp, ppos); +if (write && !ret && old != net->core.sysctl_virtio_net_hdr_csum_check) { +if (net->core.sysctl_virtio_net_hdr_csum_check) +static_branch_dec (&virtio_net_hdr_csum_check_disabled_key); +else +static_branch_inc (&virtio_net_hdr_csum_check_disabled_key); + } + +mutex_unlock (&virtio_net_hdr_csum_check_mutex); + +return ret; +} +static const struct ctl_table netns_core_table[] = { #if IS_ENABLED(CONFIG_RPS) {@@ -737,6 +780,15 @@ static const struct ctl_table netns_core_table[] = { .extra1 = SYSCTL_ZERO, .extra2 =SYSCTL_ONE }, + { + .procname = "virtio_net_hdr_csum_check", + .data = &init_net, + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = virtio_net_hdr_csum_check_sysctl, + .extra1 = SYSCTL_ZERO, + .extra2 =SYSCTL_ONE + },/* sysctl_core_net_init() will set the values after this * to readonly in network namespaces */ @@ -841,6 +893,8 @@ static __net_exit void sysctl_core_net_exit(struct net *net) tbl = net->core.sysctl_hdr->ctl_table_arg;unregister_net_sysctl_table (net->core.sysctl_hdr);BUG_ON (tbl == netns_core_table); +if (!net->core.sysctl_virtio_net_hdr_csum_check) +static_branch_dec (&virtio_net_hdr_csum_check_disabled_key);#if IS_ENABLED (CONFIG_RPS )kfree (net->core.rps_default_mask);#endif Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it later
Not pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 9 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 105 lines · Willem de Bruijn
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it laterNot pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 7 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.
Quoted 6 lines
Quoted 2 lines
Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
As I tried to explain: a specific container breaks, you decide to trust it, you do not need to trust all.
Quoted 2 lines
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Right. So I envision along the lines of:
net.core.virtio_net_hdr_validate_all - validate packets from any netns, netns root can not change it, only host root
net.core.virtio_net_hdr_validate - per netns
both set by default, validation runs if either is set.
Signature · 1 line
MST
Willem de Bruijn
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 109 lines · Michael S. Tsirkin
Quoted 108 lines · Willem de Bruijn
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it laterNot pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 9 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
Quoted 6 lines
Quoted 3 lines
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
As I tried to explain: a specific container breaks, you decide to trust it, you do not need to trust all.
Ok
Quoted 10 lines
Quoted 2 lines
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Right. So I envision along the lines of:
net.core.virtio_net_hdr_validate_all - validate packets from any netns, netns root can not change it, only host root
net.core.virtio_net_hdr_validate - per netns
Then skip the global option, as it's just a convenience: the same can be achieved by iterating over all the per-netns settings.
Per netns validation, but only settable by root, not by root-in-namespace.
Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 128 lines · Willem de Bruijn
Quoted 109 lines · Michael S. Tsirkin
Quoted 108 lines · Willem de Bruijn
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it laterNot pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 9 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
Quoted 6 lines
Quoted 3 lines
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
As I tried to explain: a specific container breaks, you decide to trust it, you do not need to trust all.
Ok
Quoted 9 lines
Quoted 2 lines
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Right. So I envision along the lines of:
net.core.virtio_net_hdr_validate_all - validate packets from any netns, netns root can not change it, only host root
Quoted 6 lines
Quoted 1 line
net.core.virtio_net_hdr_validate - per netns
Then skip the global option, as it's just a convenience: the same can be achieved by iterating over all the per-netns settings.
Per netns validation, but only settable by root, not by root-in-namespace.
Hmm I don't know how to achieve that. Are there examples of such options?
Willem de Bruijn
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 44 lines
Quoted 44 lines
Quoted 24 lines
Quoted 24 lines
Quoted 4 lines
Quoted 1 line
Should this be a global sysctl, rather than per netns?
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it laterNot pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 9 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
Quoted 6 lines
Quoted 3 lines
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
As I tried to explain: a specific container breaks, you decide to trust it, you do not need to trust all.
Ok
Quoted 10 lines
Quoted 2 lines
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Right. So I envision along the lines of:
net.core.virtio_net_hdr_validate_all - validate packets from any netns, netns root can not change it, only host root
net.core.virtio_net_hdr_validate - per netns
Quoted 7 lines
Quoted 4 lines
Then skip the global option, as it's just a convenience: the same can be achieved by iterating over all the per-netns settings.
Per netns validation, but only settable by root, not by root-in-namespace.
Hmm I don't know how to achieve that. Are there examples of such options?
Two examples, both basically make the sysctl writable by root-in-ns, but then add an extra capable() check in the write handler.
ipvs max_conn: in proc_do_conn_max()
if (write && !rc && val != unset) {
struct netns_ipvs *ipvs = table->extra2;
bool priv = capable(CAP_NET_ADMIN);
int max;
mutex_lock(&ipvs->service_mutex);
/* Unprivileged admins can not go above the hard limit */
max = priv ? IP_VS_CONN_MAX : ipvs->conn_max_limit;
if (val < 0 || val > max) {
rc = -EINVAL;ns_last_pid, which in its original commit b8f566b04d3c ("sysctl: add the kernel.ns_last_pid control")had a direct capable check (it was later relaxed):
static int pid_ns_ctl_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
struct ctl_table tmp = *table;
if (write && !capable(CAP_SYS_ADMIN))
return -EPERM;Michael S. Tsirkin
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
In reply to Willem de BruijnQuoted 87 lines · Willem de Bruijn
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 37 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0@@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, *thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 7 lines
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
0: no validation
1: current level of validation
2 and beyond: if we have to extend it later
Oh that's an interesting idea. Issue: userspace learns about 1, then someone sets it to 1 thinking this is the highest level and in fact disables some security.
Quoted 19 lines
Not pretty, I'll admit. So fine to keep as is too if you prefer. But I do foresee more changes in this area, if history is a guide.
Quoted 9 lines
Quoted 6 lines
Even if per-netns, most likely do not want it writable by netns root with user namespaces.
That is the equivalent of
ns_capable(CAP_NET_RAW), which is the cause of many crashes due to bad packets ingested by, e.g., a packet socket.Hmm, yes i get that. Two knobs? a. verify b. the per netns value ro? Both on by default?
A single system wide field is simplest.
Is there a benefit to making this configurable on a per netns basis?
If so, that's fine too. As long as root-in-namespace cannot modify it, so readonly indeed.
Willem de Bruijn
maintainerRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Quoted 92 lines · Michael S. Tsirkin
Quoted 91 lines · Willem de Bruijn
Quoted 86 lines · Michael S. Tsirkin
Quoted 35 lines · Willem de Bruijn
Quoted 34 lines · Michael S. Tsirkin
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>--- Documentation/admin-guide/sysctl/net.rst | 15 +++++++ include/linux/virtio_net.h | 23 ++++++++++ include/net/netns/core.h | 1 + net/core/dev.c | 6 +++ net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+)Documentation/admin-guide/sysctl/net.rst +0
-0@@ -246,6 +246,21 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. Default: 1 (on)Quoted 7 lines
Documentation/admin-guide/sysctl/net.rst processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. · line 250
Quoted 2 lines
Documentation/admin-guide/sysctl/net.rst +2
-0+virtio_net_hdr_csum_check +-------------------------Make more generic,
virtio_net_hdr_validate?In case we add more validation in the future (as we have in the past), without having to introduce multiple such knobs.
But it's uapi, are you sure we'll be able to change the meaning of an existing knob, even if we keep the name vague?
Quoted 29 lines
Quoted 29 lines
Documentation/admin-guide/sysctl/net.rst +13
-0+ +When processing packets with a virtio net header (through tun, tap, a +packet socket or a virtio network device) that request checksum offload +(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum +in software, or drop the packet where the header does not match it. + +When disabled, the header is trusted not to corrupt the packet, and the +checksum is offloaded to hardware (or not verified if it never reaches +hardware). This is only safe if no protocol is processing the packets. + +Default: 1 (on) + + wmem_default ------------include/linux/virtio_net.h +1
-0@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/jump_label.h> #include <linux/netdevice.h> #include <linux/udp.h> #include <net/gso.h> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,Quoted 8 lines
include/linux/virtio_net.h static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, · line 84
Quoted 6 lines
include/linux/virtio_net.h +3
-0*thoff = nhoff + iph->ihl *sizeof (u32);return iph; } +/* Defined in net/core/dev.c, enabled while any network namespace +* has net.core.virtio_net_hdr_csum_check set to 0. +*/ Should this be a global sysctl, rather than per netns?
Quoted 1 line
For customers I work with, it would be much less useful.
Third option: make it an integer rather than a boolean.
Quoted 8 lines
Quoted 3 lines
0: no validation
1: current level of validation
2 and beyond: if we have to extend it laterOh that's an interesting idea. Issue: userspace learns about 1, then someone sets it to 1 thinking this is the highest level and in fact disables some security.
True. If concerned about that we could change the interpretation, keep 1 the highest, subsequent for legacy.
[email protected]
AI reviewRe: [PATCH net-next v2 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
In reply to Michael S. TsirkinSashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
The ingress validation as implemented by the previous patch is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are dropped, and non-GSO ones get their checksum completed in place. Such packets used to pass with the metadata unvalidated, and with no overhead.I judge that this should not affect any deployments, but there is still some risk that it does. In case a deployment depends on them anyway, provide a per-netns switch to get the old behavior back:
Quoted 6 lines
echo 0 >
/proc/sys/net/core/virtio_net_hdr_csum_checkThe default is validating.
Assisted-by LLMSigned-off-by Michael S. Tsirkin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Michael S. Tsirkin
maintainerPATCH v2 6/7 net: add ip4_parse()
In reply to Michael S. TsirkinMultiple places in the net stack open-code the same minimal IPv4 header
validation: pull the fixed header, check version 4 and IHL >= 5 (where 5 is the fixed header size in 32-bit units) - and locate the transport header at IHL * 4 past the network header.
Add a helper for doing that: it returns the validated header and the transport header offset, or NULL if truncated or malformed.
--- include/linux/ip.h | 24 ++++++++++++++++++++++++ include/linux/virtio_net.h | 28 +--------------------------- net/bridge/br_netfilter_hooks.c | 15 +++++---------- net/ipv4/ip_input.c | 13 +++++-------- net/ipv4/netfilter/nf_reject_ipv4.c | 13 +++++-------- 5 files changed, 40 insertions(+), 53 deletions(-)
include/linux/ip.h +24 -0
@@ -56,4 +56,28 @@ static inline void iph_set_totlen(struct iphdr *iph, unsigned int len) { iph->tot_len = len <=IP_MAX_MTU ?htons (len) :0 ; } + +/* +* Pull and minimally validate the IPv4 header at @nhoff. +* Returns the header and stores the transport header offset in +* @thoff, or NULL if truncated or malformed. Only the fixed header +* is guaranteed linear; callers that need the options or the +* transport header must pull further. +*/ +static inline struct iphdr *ip4_parse (struct sk_buff *skb, +unsigned int nhoff, +unsigned int *thoff) +{ +struct iphdr *iph; + +if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) +return NULL ; + + iph = (struct iphdr *)(skb->data + nhoff); +if (iph->version !=4 || iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) +return NULL ; + + *thoff = nhoff + iph->ihl *sizeof (u32); +return iph; +}#endif /* _LINUX_IP_H */
include/linux/virtio_net.h +1 -27
@@ -53,32 +53,6 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,return 0 ; } -/* TODO: nothing virtio specific here, move to ip.h */ - -/* -* Pull and minimally validate the IPv4 header at @nhoff. -* Returns the header and stores the transport header offset in -* @thoff, or NULL if truncated or malformed. Only the fixed header -* is guaranteed linear; callers that need the options or the -* transport header must pull further. -*/ -static inline struct iphdr *virtio_net_ip4_parse (struct sk_buff *skb, -unsigned int nhoff, -unsigned int *thoff) -{ -struct iphdr *iph; - -if (!pskb_may_pull (skb, nhoff +sizeof (struct iphdr ))) -return NULL ; - - iph = (struct iphdr *)(skb->data + nhoff); -if (iph->version !=4 || - iph->ihl <sizeof (struct iphdr ) /sizeof (u32)) -return NULL ; - - *thoff = nhoff + iph->ihl *sizeof (u32); -return iph; -}/* Defined in net/core/dev.c, enabled while any network namespace * has net.core.virtio_net_hdr_csum_check set to 0. */
@@ -126,7 +100,7 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto, unsigned int *thoff, int *ip_proto) {if (proto ==htons (ETH_P_IP )) { -const struct iphdr *iph =virtio_net_ip4_parse (skb, nhoff, thoff); +const struct iphdr *iph =ip4_parse (skb, nhoff, thoff);if (!iph ||ip_is_fragment (iph))return false;
net/bridge/br_netfilter_hooks.c +5 -10
@@ -206,18 +206,13 @@ static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)static int br_validate_ipv4 (struct net *net,struct sk_buff *skb) {const struct iphdr *iph; -u32 len; +u32 len, thoff; -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) + iph =ip4_parse (skb,0 , &thoff); +if (!iph) goto inhdr_error; - iph =ip_hdr (skb); - -/* Basic sanity checks */ -if (iph->ihl <5 || iph->version !=4 ) - goto inhdr_error; - -if (!pskb_may_pull (skb, iph->ihl*4 )) +if (!pskb_may_pull (skb, thoff)) goto inhdr_error; iph =ip_hdr (skb);
@@ -228,7 +223,7 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb)if (skb->len < len) {__IP_INC_STATS (net,IPSTATS_MIB_INTRUNCATEDPKTS ); goto drop; - }else if (len < (iph->ihl*4 )) + }else if (len < thoff) goto inhdr_error;if (pskb_trim_rcsum (skb, len)) {
net/ipv4/ip_input.c +5 -8
@@ -500,7 +500,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) {const struct iphdr *iph;int drop_reason; -u32 len; +u32 len, thoff;/* When the interface is in promisc. mode, drop all the crap * that it receives, do not try to analyse it.
@@ -520,10 +520,6 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) } drop_reason =SKB_DROP_REASON_NOT_SPECIFIED ; -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) - goto inhdr_error; - - iph =ip_hdr (skb);/* * RFC1122: 3.2.1.2 MUST silently discard any IP frame that fails the checksum.
@@ -536,7 +532,8 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)* 4. Doesn't have a bogus length */ -if (iph->ihl <5 || iph->version !=4 ) + iph =ip4_parse (skb,0 , &thoff); +if (!iph) goto inhdr_error;BUILD_BUG_ON (IPSTATS_MIB_ECT1PKTS !=IPSTATS_MIB_NOECTPKTS +INET_ECN_ECT_1 );
@@ -546,7 +543,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)IPSTATS_MIB_NOECTPKTS + (iph->tos &INET_ECN_MASK ), max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs)); -if (!pskb_may_pull (skb, iph->ihl*4 )) +if (!pskb_may_pull (skb, thoff)) goto inhdr_error; iph =ip_hdr (skb);
@@ -559,7 +556,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) drop_reason =SKB_DROP_REASON_PKT_TOO_SMALL ;__IP_INC_STATS (net,IPSTATS_MIB_INTRUNCATEDPKTS ); goto drop; - }else if (len < (iph->ihl*4 )) + }else if (len < thoff) goto inhdr_error;/* Our transport medium may have padded the buffer out. Now we know it
net/ipv4/netfilter/nf_reject_ipv4.c +5 -8
@@ -25,22 +25,19 @@ nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,static int nf_reject_iphdr_validate (struct sk_buff *skb) {struct iphdr *iph; -u32 len; +u32 len, thoff; -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) -return 0 ; - - iph =ip_hdr (skb); -if (iph->ihl <5 || iph->version !=4 ) + iph =ip4_parse (skb,0 , &thoff); +if (!iph)return 0 ; len =ntohs (iph->tot_len);if (skb->len < len)return 0 ; -else if (len < (iph->ihl*4 )) +else if (len < thoff)return 0 ; -if (!pskb_may_pull (skb, iph->ihl*4 )) +if (!pskb_may_pull (skb, thoff))return 0 ;return 1 ;
Signature · 1 line
MST
Re: [PATCH net-next v2 6/7] net: add ip4_parse()
Hi Michael,
Quoted 10 lines · Michael S. Tsirkin
Multiple places in the net stack open-code the same minimal IPv4 header
validation: pull the fixed header, check version 4 and IHL >= 5 (where 5 is the fixed header size in 32-bit units) - and locate the transport header at IHL * 4 past the network header.Add a helper for doing that: it returns the validated header and the transport header offset, or NULL if truncated or malformed.
Signed-off-by Michael S. Tsirkin <[email protected]>Assisted-by LLM
Did you consider nft_inner_parse_l2l3 in net/netfilter/nft_inner.c and ip_mc_check_iphdr in net/ipv4/igmp.c as well?
Cheers, Phil
Re: [PATCH net-next v2 6/7] net: add ip4_parse()
In reply to Michael S. TsirkinQuoted 10 lines · Michael S. Tsirkin
Multiple places in the net stack open-code the same minimal IPv4 header
validation: pull the fixed header, check version 4 and IHL >= 5 (where 5 is the fixed header size in 32-bit units) - and locate the transport header at IHL * 4 past the network header.Add a helper for doing that: it returns the validated header and the transport header offset, or NULL if truncated or malformed.
Signed-off-by Michael S. Tsirkin <[email protected]>Assisted-by LLM
[email protected]
AI reviewRe: [PATCH net-next v2 6/7] net: add ip4_parse()
In reply to Michael S. TsirkinSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Multiple places in the net stack open-code the same minimal IPv4 header
validation: pull the fixed header, check version 4 and IHL >= 5 (where 5 is the fixed header size in 32-bit units) - and locate the transport header at IHL * 4 past the network header.Add a helper for doing that: it returns the validated header and the transport header offset, or NULL if truncated or malformed.
Signed-off-by Michael S. Tsirkin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Michael S. Tsirkin
maintainerPATCH v2 7/7 virtio_net: cleanup protocol calculation
In reply to Michael S. TsirkinA trivial cleanup removing a duplicated code line.
--- include/linux/virtio_net.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
include/linux/virtio_net.h +2 -3
@@ -570,8 +570,8 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,return -EINVAL ; } -skb_set_inner_protocol (skb, inner_isv6 ?htons (ETH_P_IPV6 ) : -htons (ETH_P_IP )); + inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP ); +skb_set_inner_protocol (skb, inner_proto);if (hdr->flags &VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM ) {if (!tnl_csum_negotiated)return -EINVAL ;
@@ -591,7 +591,6 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,* We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb * set CHECKSUM_PARTIAL. */ - inner_proto = inner_isv6 ?htons (ETH_P_IPV6 ) :htons (ETH_P_IP );if (virtio_net_csum_partial_ok_at_offset (skb, gso_inner_type, inner_nh, inner_proto))return 0 ;
Signature · 1 line
MST
Re: [PATCH net-next v2 7/7] virtio_net: cleanup protocol calculation
Quoted 3 lines · Michael S. Tsirkin
A trivial cleanup removing a duplicated code line.
Signed-off-by Michael S. Tsirkin <[email protected]>
[email protected]
AI reviewRe: [PATCH net-next v2 7/7] virtio_net: cleanup protocol calculation
In reply to Michael S. TsirkinSashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines
A trivial cleanup removing a duplicated code line.
Signed-off-by Michael S. Tsirkin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Quoted 63 lines · Michael S. Tsirkin
As reported first by Paulos Yibelo <[email protected]> (after which others, credited below, found more ways the bug can affect users):
allowing untrusted hardware to specify csum start/offset for
CHECKSUM_PARTIALwas not a good idea, because, if it edits the packet outside the actual checksum, and depending on the setup, the networking stack could be looking at the packet both before and after the edit, and seeing different results.Previously, commit
6785011f8b16("ipv4: validatechecksum_startbefore completing checksum") validated all known instances where this causes the most grief, but the real fix is to make sure that either only actual checksum fields are ever edited,
or the checksum is completed before the net stack looks at it, so it is always consistent.This basically goes back to
what we did beforef43798c27684("tun: Allow GSO usingvirtio_net_hdr"), except in a narrow list of specified known good cases.Summary of the patchset:
net: account for ingress-resolved virtio net hdr state
- accounting, not the fix itself, dependency of the next one
net: resolve uncommon partial checksums at ingress
- fix itself
net: add a sysctl to opt out of virtio net hdr checksum validation
- reducing risk of the fix by adding a sysctl to disable it
net: addip4_parse()
virtio_net: cleanup protocol calculation
- cleanup resulting code duplication
(kept separate to simplify backporting)Fixes f43798c27684 ("tun: Allow GSO using virtio_net_hdr")Changes since v1:
- reorder patches to fix bisectability, addressing a comment by Björn Töpel.
- code refactoring, different patch splitup,
a sysctl knob to disable as suggested by Willem de Bruijn.
- fix a bunch of minor issues spotted by LLMsMichael S. Tsirkin (7):
net: account for ingress-resolved virtio net hdr state
um: vector: honor virtio net hdr conversion failures
um: vector: trim skbs before verifying the header
net: resolve uncommon partial checksums at ingress
net: add a sysctl to opt out of virtio net hdr checksum validation
net: addip4_parse()
virtio_net: cleanup protocol calculationDocumentation/admin-guide/sysctl/net.rst | 15 ++ arch/um/drivers/vector_kern.c | 6 +- arch/um/drivers/vector_transports.c | 4 +- drivers/net/tap.c | 4 +- drivers/net/tun.c | 41 +++- drivers/net/virtio_net.c | 2 +- include/linux/ip.h | 24 +++ include/linux/virtio_net.h | 249 ++++++++++++++++++++++- include/net/netns/core.h | 1 +
Quoted 12 lines
net/bridge/br_netfilter_hooks.c | 15 +- net/core/dev.c | 6 + net/core/net_namespace.c | 1 + net/core/sysctl_net_core.c | 54 +++++ net/ipv4/ip_input.c | 13 +- net/ipv4/netfilter/nf_reject_ipv4.c | 13 +- net/packet/af_packet.c | 4 +- 16 files changed, 404 insertions(+), 48 deletions(-)Signature · 1 line
MST
Aside from the KASAN issue described in the other thread, I was able to test this series and it fixes my local testcases.