* [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation [not found] <cover.1792411304.git.mst@redhat.com> @ 2026-10-19 12:03 ` Michael S. Tsirkin 2026-10-19 14:19 ` Björn Töpel 2026-10-20 19:54 ` Willem de Bruijn 0 siblings, 2 replies; 7+ messages in thread From: Michael S. Tsirkin @ 2026-10-19 12:03 UTC (permalink / raw) To: linux-kernel Cc: Willem de Bruijn, Chris Arges, Björn Töpel, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc 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_check The default is validating. Assisted-by: LLM Signed-off-by: Michael S. Tsirkin <mst@redhat.com> --- Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ 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 | 60 ++++++++++++++++++++++++ 6 files changed, 110 insertions(+) diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst index e586e17fc7a5..b1a1c4714b22 100644 --- a/Documentation/admin-guide/sysctl/net.rst +++ b/Documentation/admin-guide/sysctl/net.rst @@ -246,6 +246,25 @@ 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. + +The setting is per network namespace, but only writable by the host +root: root inside a network namespace created by an unprivileged user +cannot disable the validation. + +Default: 1 (on) + + wmem_default ------------ diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 97b554ef7123..25aa95c11e31 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -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 @@ -179,6 +193,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; @@ -516,6 +536,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))) diff --git a/include/net/netns/core.h b/include/net/netns/core.h index 9ef3d70e5e9c..ae8110772c97 100644 --- a/include/net/netns/core.h +++ b/include/net/netns/core.h @@ -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; diff --git a/net/core/dev.c b/net/core/dev.c index e76762e29360..d14950b1af3a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -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; diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index da5f881fbd3b..2d340fafba85 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -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); } diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index eb35da3556f4..c65ff86cc5f9 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -18,6 +18,7 @@ #include <linux/slab.h> #include <linux/sched/isolation.h> #include <linux/hex.h> +#include <linux/jump_label.h> #include <net/ip.h> #include <net/sock.h> @@ -678,6 +679,54 @@ static struct ctl_table net_core_table[] = { }, }; +/* 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; + + /* Root in a user namespace must not be able to weaken the + * validation for the network namespace it controls. + */ + if (write && !capable(CAP_NET_ADMIN)) + return -EPERM; + + /* + * 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 +786,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 +899,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 -- MST ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-19 12:03 ` [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin @ 2026-10-19 14:19 ` Björn Töpel 2026-10-20 14:04 ` Michael S. Tsirkin 2026-10-20 19:54 ` Willem de Bruijn 1 sibling, 1 reply; 7+ messages in thread From: Björn Töpel @ 2026-10-19 14:19 UTC (permalink / raw) To: Michael S. Tsirkin, linux-kernel Cc: Willem de Bruijn, Chris Arges, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc "Michael S. Tsirkin" <mst@redhat.com> writes: > 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_check > > The default is validating. > > Assisted-by: LLM > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > --- > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > 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 | 60 ++++++++++++++++++++++++ > 6 files changed, 110 insertions(+) > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > index e586e17fc7a5..b1a1c4714b22 100644 > --- a/Documentation/admin-guide/sysctl/net.rst > +++ b/Documentation/admin-guide/sysctl/net.rst > @@ -246,6 +246,25 @@ 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. > + > +The setting is per network namespace, but only writable by the host > +root: root inside a network namespace created by an unprivileged user > +cannot disable the validation. > + > +Default: 1 (on) > + > + > wmem_default > ------------ > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h > index 97b554ef7123..25aa95c11e31 100644 > --- a/include/linux/virtio_net.h > +++ b/include/linux/virtio_net.h > @@ -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 > @@ -179,6 +193,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; > > @@ -516,6 +536,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))) > diff --git a/include/net/netns/core.h b/include/net/netns/core.h > index 9ef3d70e5e9c..ae8110772c97 100644 > --- a/include/net/netns/core.h > +++ b/include/net/netns/core.h > @@ -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; > diff --git a/net/core/dev.c b/net/core/dev.c > index e76762e29360..d14950b1af3a 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -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; > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c > index da5f881fbd3b..2d340fafba85 100644 > --- a/net/core/net_namespace.c > +++ b/net/core/net_namespace.c > @@ -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); > } > > diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c > index eb35da3556f4..c65ff86cc5f9 100644 > --- a/net/core/sysctl_net_core.c > +++ b/net/core/sysctl_net_core.c > @@ -18,6 +18,7 @@ > #include <linux/slab.h> > #include <linux/sched/isolation.h> > #include <linux/hex.h> > +#include <linux/jump_label.h> > > #include <net/ip.h> > #include <net/sock.h> > @@ -678,6 +679,54 @@ static struct ctl_table net_core_table[] = { > }, > }; > > +/* 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. > + */ nit: OCD doesn't like mixing old netdev comments with vanilla style... one VVV as well. > +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 */ nit: Redundant comment... > + struct ctl_table tmp = *table; ...and here, can't we instead get rid of tmp, and do something like: | u8 *value = table->data; | u8 old, new; > + u8 old; > + int ret; > + > + /* Root in a user namespace must not be able to weaken the > + * validation for the network namespace it controls. > + */ > + if (write && !capable(CAP_NET_ADMIN)) > + return -EPERM; > + > + /* > + * 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) { and then: | old = READ_ONCE(*value); | ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos); | new = READ_ONCE(*value); | | if (write && !ret && old != new) { at least that's easier to read for me. (No blocker!) Reviewed-by: Björn Töpel <bjorn@kernel.org> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-19 14:19 ` Björn Töpel @ 2026-10-20 14:04 ` Michael S. Tsirkin 0 siblings, 0 replies; 7+ messages in thread From: Michael S. Tsirkin @ 2026-10-20 14:04 UTC (permalink / raw) To: Björn Töpel Cc: linux-kernel, Willem de Bruijn, Chris Arges, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc On Mon, Oct 19, 2026 at 04:19:16PM +0200, Björn Töpel wrote: > "Michael S. Tsirkin" <mst@redhat.com> writes: > > > 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_check > > > > The default is validating. > > > > Assisted-by: LLM > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > --- > > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > > 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 | 60 ++++++++++++++++++++++++ > > 6 files changed, 110 insertions(+) > > > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > > index e586e17fc7a5..b1a1c4714b22 100644 > > --- a/Documentation/admin-guide/sysctl/net.rst > > +++ b/Documentation/admin-guide/sysctl/net.rst > > @@ -246,6 +246,25 @@ 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. > > + > > +The setting is per network namespace, but only writable by the host > > +root: root inside a network namespace created by an unprivileged user > > +cannot disable the validation. > > + > > +Default: 1 (on) > > + > > + > > wmem_default > > ------------ > > > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h > > index 97b554ef7123..25aa95c11e31 100644 > > --- a/include/linux/virtio_net.h > > +++ b/include/linux/virtio_net.h > > @@ -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 > > @@ -179,6 +193,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; > > > > @@ -516,6 +536,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))) > > diff --git a/include/net/netns/core.h b/include/net/netns/core.h > > index 9ef3d70e5e9c..ae8110772c97 100644 > > --- a/include/net/netns/core.h > > +++ b/include/net/netns/core.h > > @@ -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; > > diff --git a/net/core/dev.c b/net/core/dev.c > > index e76762e29360..d14950b1af3a 100644 > > --- a/net/core/dev.c > > +++ b/net/core/dev.c > > @@ -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; > > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c > > index da5f881fbd3b..2d340fafba85 100644 > > --- a/net/core/net_namespace.c > > +++ b/net/core/net_namespace.c > > @@ -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); > > } > > > > diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c > > index eb35da3556f4..c65ff86cc5f9 100644 > > --- a/net/core/sysctl_net_core.c > > +++ b/net/core/sysctl_net_core.c > > @@ -18,6 +18,7 @@ > > #include <linux/slab.h> > > #include <linux/sched/isolation.h> > > #include <linux/hex.h> > > +#include <linux/jump_label.h> > > > > #include <net/ip.h> > > #include <net/sock.h> > > @@ -678,6 +679,54 @@ static struct ctl_table net_core_table[] = { > > }, > > }; > > > > +/* 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. > > + */ > > nit: OCD doesn't like mixing old netdev comments with vanilla style... > one VVV as well. > > > +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 */ > > nit: Redundant comment... > > > + struct ctl_table tmp = *table; > > ...and here, can't we instead get rid of tmp, and do something like: > | u8 *value = table->data; > | u8 old, new; > > > + u8 old; > > + int ret; > > + > > + /* Root in a user namespace must not be able to weaken the > > + * validation for the network namespace it controls. > > + */ > > + if (write && !capable(CAP_NET_ADMIN)) > > + return -EPERM; > > + > > + /* > > + * 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) { > > and then: > | old = READ_ONCE(*value); > | ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos); > | new = READ_ONCE(*value); > | > | if (write && !ret && old != new) { > > at least that's easier to read for me. (No blocker!) > > > Reviewed-by: Björn Töpel <bjorn@kernel.org> Thanks, I'm addressing sashiko review points, will address this in v4. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-19 12:03 ` [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin 2026-10-19 14:19 ` Björn Töpel @ 2026-10-20 19:54 ` Willem de Bruijn 2026-10-20 20:01 ` Michael S. Tsirkin 1 sibling, 1 reply; 7+ messages in thread From: Willem de Bruijn @ 2026-10-20 19:54 UTC (permalink / raw) To: Michael S. Tsirkin, linux-kernel Cc: Willem de Bruijn, Chris Arges, Björn Töpel, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc Michael S. Tsirkin wrote: > 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_check > > The default is validating. > > Assisted-by: LLM > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > --- > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > 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 | 60 ++++++++++++++++++++++++ > 6 files changed, 110 insertions(+) > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > index e586e17fc7a5..b1a1c4714b22 100644 > --- a/Documentation/admin-guide/sysctl/net.rst > +++ b/Documentation/admin-guide/sysctl/net.rst > @@ -246,6 +246,25 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. > Default: 1 (on) > > > +virtio_net_hdr_csum_check > +------------------------- virtio_net_hdr_validate? In case we do have to add more validation later. > + > +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. > + > +The setting is per network namespace, but only writable by the host > +root: root inside a network namespace created by an unprivileged user > +cannot disable the validation. > + > +Default: 1 (on) > + > + > wmem_default > ------------ > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h > index 97b554ef7123..25aa95c11e31 100644 > --- a/include/linux/virtio_net.h > +++ b/include/linux/virtio_net.h > @@ -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 > @@ -179,6 +193,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; virtio_net_csum_partial_ok can apparently be called before this check, which would still drop packets. > + > if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto)) > return false; > > @@ -516,6 +536,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))) > diff --git a/include/net/netns/core.h b/include/net/netns/core.h > index 9ef3d70e5e9c..ae8110772c97 100644 > --- a/include/net/netns/core.h > +++ b/include/net/netns/core.h > @@ -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; > diff --git a/net/core/dev.c b/net/core/dev.c > index e76762e29360..d14950b1af3a 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -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; > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c > index da5f881fbd3b..2d340fafba85 100644 > --- a/net/core/net_namespace.c > +++ b/net/core/net_namespace.c > @@ -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); > } > > diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c > index eb35da3556f4..c65ff86cc5f9 100644 > --- a/net/core/sysctl_net_core.c > +++ b/net/core/sysctl_net_core.c > @@ -18,6 +18,7 @@ > #include <linux/slab.h> > #include <linux/sched/isolation.h> > #include <linux/hex.h> > +#include <linux/jump_label.h> > > #include <net/ip.h> > #include <net/sock.h> > @@ -678,6 +679,54 @@ static struct ctl_table net_core_table[] = { > }, > }; > > +/* 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. it appears that they take the mutex_lock below > + */ > +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; > + > + /* Root in a user namespace must not be able to weaken the > + * validation for the network namespace it controls. > + */ > + if (write && !capable(CAP_NET_ADMIN)) > + return -EPERM; > + > + /* > + * 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 +786,15 @@ static const struct ctl_table netns_core_table[] = { > .extra1 = SYSCTL_ZERO, > .extra2 = SYSCTL_ONE > }, > + { > + .procname = "virtio_net_hdr_csum_check", > + .data = &init_net, &init_net.core.sysctl_virtio_net_hdr_csum_check > + .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 +899,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 > -- > MST > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-20 19:54 ` Willem de Bruijn @ 2026-10-20 20:01 ` Michael S. Tsirkin 2026-10-20 20:19 ` Willem de Bruijn 0 siblings, 1 reply; 7+ messages in thread From: Michael S. Tsirkin @ 2026-10-20 20:01 UTC (permalink / raw) To: Willem de Bruijn Cc: linux-kernel, Chris Arges, Björn Töpel, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc On Tue, Oct 20, 2026 at 03:54:23PM -0400, Willem de Bruijn wrote: > Michael S. Tsirkin wrote: > > 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_check > > > > The default is validating. > > > > Assisted-by: LLM > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > --- > > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > > 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 | 60 ++++++++++++++++++++++++ > > 6 files changed, 110 insertions(+) > > > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > > index e586e17fc7a5..b1a1c4714b22 100644 > > --- a/Documentation/admin-guide/sysctl/net.rst > > +++ b/Documentation/admin-guide/sysctl/net.rst > > @@ -246,6 +246,25 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. > > Default: 1 (on) > > > > > > +virtio_net_hdr_csum_check > > +------------------------- > > virtio_net_hdr_validate? In case we do have to add more validation > later. If you insist. My worry would be what if that validation is again user-visible somehow and we need to distinguish users who want to disable that future thing and users who want to disable just this current thing. Hard to predict the future. But I will go with your intuition. Will check the rest. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-20 20:01 ` Michael S. Tsirkin @ 2026-10-20 20:19 ` Willem de Bruijn 2026-10-20 20:22 ` Michael S. Tsirkin 0 siblings, 1 reply; 7+ messages in thread From: Willem de Bruijn @ 2026-10-20 20:19 UTC (permalink / raw) To: Michael S. Tsirkin, Willem de Bruijn Cc: linux-kernel, Chris Arges, Björn Töpel, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc Michael S. Tsirkin wrote: > On Tue, Oct 20, 2026 at 03:54:23PM -0400, Willem de Bruijn wrote: > > Michael S. Tsirkin wrote: > > > 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_check > > > > > > The default is validating. > > > > > > Assisted-by: LLM > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > > --- > > > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > > > 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 | 60 ++++++++++++++++++++++++ > > > 6 files changed, 110 insertions(+) > > > > > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > > > index e586e17fc7a5..b1a1c4714b22 100644 > > > --- a/Documentation/admin-guide/sysctl/net.rst > > > +++ b/Documentation/admin-guide/sysctl/net.rst > > > @@ -246,6 +246,25 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. > > > Default: 1 (on) > > > > > > > > > +virtio_net_hdr_csum_check > > > +------------------------- > > > > virtio_net_hdr_validate? In case we do have to add more validation > > later. > > If you insist. My worry would be what if that validation is again > user-visible somehow and we need to distinguish users who want > to disable that future thing and users who want to disable > just this current thing. > > Hard to predict the future. But I will go with your intuition. Thanks, but definitely feel free to ignore my suggestions. My intuition would be to define as 0: off 1: everything one 2+: sadly needed fudge values because we keep having to tighten, but some crazy workloads need to opt-out to avoid breakage. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation 2026-10-20 20:19 ` Willem de Bruijn @ 2026-10-20 20:22 ` Michael S. Tsirkin 0 siblings, 0 replies; 7+ messages in thread From: Michael S. Tsirkin @ 2026-10-20 20:22 UTC (permalink / raw) To: Willem de Bruijn Cc: linux-kernel, Chris Arges, Björn Töpel, Phil Sutter, Jason Wang, Eugenio Pérez, Xuan Zhuo, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, virtualization, Max Krasnyansky, Rusty Russell, Jonathan Corbet, Shuah Khan, Randy Dunlap, Simon Horman, linux-doc On Tue, Oct 20, 2026 at 04:19:41PM -0400, Willem de Bruijn wrote: > Michael S. Tsirkin wrote: > > On Tue, Oct 20, 2026 at 03:54:23PM -0400, Willem de Bruijn wrote: > > > Michael S. Tsirkin wrote: > > > > 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_check > > > > > > > > The default is validating. > > > > > > > > Assisted-by: LLM > > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > > > --- > > > > Documentation/admin-guide/sysctl/net.rst | 19 ++++++++ > > > > 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 | 60 ++++++++++++++++++++++++ > > > > 6 files changed, 110 insertions(+) > > > > > > > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > > > > index e586e17fc7a5..b1a1c4714b22 100644 > > > > --- a/Documentation/admin-guide/sysctl/net.rst > > > > +++ b/Documentation/admin-guide/sysctl/net.rst > > > > @@ -246,6 +246,25 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set. > > > > Default: 1 (on) > > > > > > > > > > > > +virtio_net_hdr_csum_check > > > > +------------------------- > > > > > > virtio_net_hdr_validate? In case we do have to add more validation > > > later. > > > > If you insist. My worry would be what if that validation is again > > user-visible somehow and we need to distinguish users who want > > to disable that future thing and users who want to disable > > just this current thing. > > > > Hard to predict the future. But I will go with your intuition. > > Thanks, but definitely feel free to ignore my suggestions. > > My intuition would be to define as > > 0: off > 1: everything one > 2+: sadly needed fudge values because we keep having to tighten, > but some crazy workloads need to opt-out to avoid breakage. yes you said i just do not get how it will work for userspace, maybe u can explain? and what specifically is needed right now, while we just have 1. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-10-20 20:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1792411304.git.mst@redhat.com>
2026-10-19 12:03 ` [PATCH net v3 6/8] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin
2026-10-19 14:19 ` Björn Töpel
2026-10-20 14:04 ` Michael S. Tsirkin
2026-10-20 19:54 ` Willem de Bruijn
2026-10-20 20:01 ` Michael S. Tsirkin
2026-10-20 20:19 ` Willem de Bruijn
2026-10-20 20:22 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox