From d96d14b14733c557d11768ebfe3f92d858b0a79f Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Fri, 25 Mar 2022 14:48:23 +0100 Subject: [PATCH] openvswitch.h: Align uAPI definition with the kernel. Upstream commit: commit 1926407a4ab0e59d5a27bed7b82029b356d80fa0 Author: Ilya Maximets Date: Wed Mar 9 23:20:33 2022 +0100 net: openvswitch: fix uAPI incompatibility with existing user space Few years ago OVS user space made a strange choice in the commit [1] to define types only valid for the user space inside the copy of a kernel uAPI header. '#ifndef __KERNEL__' and another attribute was added later. This leads to the inevitable clash between user space and kernel types when the kernel uAPI is extended. The issue was unveiled with the addition of a new type for IPv6 extension header in kernel uAPI. When kernel provides the OVS_KEY_ATTR_IPV6_EXTHDRS attribute to the older user space application, application tries to parse it as OVS_KEY_ATTR_PACKET_TYPE and discards the whole netlink message as malformed. Since OVS_KEY_ATTR_IPV6_EXTHDRS is supplied along with every IPv6 packet that goes to the user space, IPv6 support is fully broken. Fixing that by bringing these user space attributes to the kernel uAPI to avoid the clash. Strictly speaking this is not the problem of the kernel uAPI, but changing it is the only way to avoid breakage of the older user space applications at this point. These 2 types are explicitly rejected now since they should not be passed to the kernel. Additionally, OVS_KEY_ATTR_TUNNEL_INFO moved out from the '#ifdef __KERNEL__' as there is no good reason to hide it from the userspace. And it's also explicitly rejected now, because it's for in-kernel use only. Comments with warnings were added to avoid the problem coming back. (1 << type) converted to (1ULL << type) to avoid integer overflow on OVS_KEY_ATTR_IPV6_EXTHDRS, since it equals 32 now. [1] beb75a40fdc2 ("userspace: Switching of L3 packets in L2 pipeline") Fixes: 28a3f0601727 ("net: openvswitch: IPv6: Add IPv6 extension header support") Link: https://lore.kernel.org/netdev/3adf00c7-fe65-3ef4-b6d7-6d8a0cad8a5f@nvidia.com Link: https://github.com/openvswitch/ovs/commit/beb75a40fdc295bfd6521b0068b4cd12f6de507c Reported-by: Roi Dayan Signed-off-by: Ilya Maximets Acked-by: Nicolas Dichtel Acked-by: Aaron Conole Link: https://lore.kernel.org/r/20220309222033.3018976-1-i.maximets@ovn.org Signed-off-by: Jakub Kicinski Not adding OVS_KEY_ATTR_IPV6_EXTHDRS in this commit as this is not necessary. Will be added along with the actual userspace implementation. This change should help avoiding incompatibility issues in the future. Acked-by: Aaron Conole Signed-off-by: Ilya Maximets --- datapath/flow_netlink.c | 9 ++++++++- .../linux/compat/include/linux/openvswitch.h | 20 ++++++++++--------- lib/odp-execute.c | 2 ++ lib/odp-util.c | 4 ++++ ofproto/ofproto-dpif-sflow.c | 1 + 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c index 996041602cd..caed443863e 100644 --- a/datapath/flow_netlink.c +++ b/datapath/flow_netlink.c @@ -359,7 +359,7 @@ size_t ovs_key_attr_size(void) /* Whenever adding new OVS_KEY_ FIELDS, we should consider * updating this function. */ - BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 29); + BUILD_BUG_ON(OVS_KEY_ATTR_MAX != 31); return nla_total_size(4) /* OVS_KEY_ATTR_PRIORITY */ + nla_total_size(0) /* OVS_KEY_ATTR_TUNNEL */ @@ -491,6 +491,13 @@ static int __parse_flow_nlattrs(const struct nlattr *attr, return -EINVAL; } + if (type == OVS_KEY_ATTR_PACKET_TYPE || + type == OVS_KEY_ATTR_ND_EXTENSIONS || + type == OVS_KEY_ATTR_TUNNEL_INFO) { + OVS_NLERR(log, "Key type %d is not supported", type); + return -EINVAL; + } + if (attrs & (1ULL << type)) { OVS_NLERR(log, "Duplicate key (type %d).", type); return -EINVAL; diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index 8d930009174..8bb5abdc834 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -388,17 +388,19 @@ enum ovs_key_attr { OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6, /* struct ovs_key_ct_tuple_ipv6 */ OVS_KEY_ATTR_NSH, /* Nested set of ovs_nsh_key_* */ -#ifdef __KERNEL__ - /* Only used within kernel data path. */ - OVS_KEY_ATTR_TUNNEL_INFO, /* struct ovs_tunnel_info */ -#endif - -#ifndef __KERNEL__ - /* Only used within userspace data path. */ - OVS_KEY_ATTR_PACKET_TYPE, /* be32 packet type */ + /* User space decided to squat on types 29 and 30. They are defined + * below, but should not be sent to the kernel. + * + * WARNING: No new types should be added unless they are defined + * for both kernel and user space (no 'ifdef's). It's hard + * to keep compatibility otherwise. + */ + OVS_KEY_ATTR_PACKET_TYPE, /* be32 packet type */ OVS_KEY_ATTR_ND_EXTENSIONS, /* struct ovs_key_nd_extensions */ -#endif + OVS_KEY_ATTR_TUNNEL_INFO, /* struct ip_tunnel_info. + * For in-kernel use only. + */ __OVS_KEY_ATTR_MAX }; diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 2f4cdd92c6c..7da56793d0f 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -553,6 +553,7 @@ odp_execute_set_action(struct dp_packet *packet, const struct nlattr *a) case OVS_KEY_ATTR_CT_ZONE: case OVS_KEY_ATTR_CT_MARK: case OVS_KEY_ATTR_CT_LABELS: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: OVS_NOT_REACHED(); @@ -665,6 +666,7 @@ odp_execute_masked_set_action(struct dp_packet *packet, case OVS_KEY_ATTR_ICMP: case OVS_KEY_ATTR_ICMPV6: case OVS_KEY_ATTR_TCP_FLAGS: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: OVS_NOT_REACHED(); diff --git a/lib/odp-util.c b/lib/odp-util.c index 3ae850b669c..073fc20d9f7 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -193,6 +193,7 @@ ovs_key_attr_to_string(enum ovs_key_attr attr, char *namebuf, size_t bufsize) case OVS_KEY_ATTR_PACKET_TYPE: return "packet_type"; case OVS_KEY_ATTR_NSH: return "nsh"; + case OVS_KEY_ATTR_TUNNEL_INFO: return ""; case __OVS_KEY_ATTR_MAX: default: snprintf(namebuf, bufsize, "key%u", (unsigned int) attr); @@ -3261,6 +3262,7 @@ odp_mask_is_constant__(enum ovs_key_attr attr, const void *mask, size_t size, switch (attr) { case OVS_KEY_ATTR_UNSPEC: case OVS_KEY_ATTR_ENCAP: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: return false; @@ -4412,6 +4414,7 @@ format_odp_key_attr__(const struct nlattr *a, const struct nlattr *ma, break; } case OVS_KEY_ATTR_UNSPEC: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: format_generic_odp_key(a, ds); @@ -6616,6 +6619,7 @@ odp_key_to_dp_packet(const struct nlattr *key, size_t key_len, case OVS_KEY_ATTR_MPLS: case OVS_KEY_ATTR_PACKET_TYPE: case OVS_KEY_ATTR_NSH: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: break; diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c index 30e7caf54a6..0b2c79e320c 100644 --- a/ofproto/ofproto-dpif-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -1065,6 +1065,7 @@ sflow_read_set_action(const struct nlattr *attr, case OVS_KEY_ATTR_UNSPEC: case OVS_KEY_ATTR_PACKET_TYPE: case OVS_KEY_ATTR_NSH: + case OVS_KEY_ATTR_TUNNEL_INFO: case __OVS_KEY_ATTR_MAX: default: break;