net: openvswitch: fix a feature leak on a failed change
Subsystems (5)
v6 cover net: openvswitch: fix a feature leak on a failed change
ovs_dp_change() records the requested features in dp->user_features before it updates the per-cpu upcall port IDs, and that update fails with -EINVAL when the per-cpu-pids attribute is empty or its length is not a multiple of four. The request fails with the new features already recorded, while the code that takes the reference for TC_RECIRC_SHARING never ran, so a later request that clears the bit drops a reference that was never taken.
The first two patches are the fix, split so that the single read of dp->user_features in queue_userspace_packet() stands on its own: it closes a separate and older oops and carries its own Fixes: tag. The third patch adds the selftest. The series is three patches; v5 had two.
v6:
- Split the single read of dp->user_features out of the fix. It closes a crash that aea0bb4f8ee5 introduced in 2014, and folding it into a patch whose Fixes: tag points at 35d39fecbc24 hid that from a stable backport.
- Move Fixes: and Cc: into the trailer block; they had prose below them.
- Read the field with READ_ONCE() in ovs_dp_set_user_features(), now that every write to it is a single WRITE_ONCE(), and clear only the recirc bit through one helper instead of repeating the mask at two sites.
- Carry a changelog per patch in the notes under ---, as Matthieu asked.
- Quote the variables the new selftest helpers pass to subprocesses, and name both conditions that make the kernel reject the per-cpu-pids attribute.
- Move Reported-by: to the kernel fix, with the link to the report.
v5: https://lore.kernel.org/netdev/[email protected]/
- Use an empty per-cpu-pids attribute to make the update fail, instead of relying on the masks cache path. Suggested by Matthieu Baerts.
- Report the datapath that cannot be read as that, and not as a feature mismatch.
v4: https://lore.kernel.org/netdev/[email protected]/
- Take and drop the reference in one setter, and call it from every path that changes or clears the recirc bit, including ovs_dp_reset_user_features() and __dp_destroy().
- Clear only the recirc bit in __dp_destroy(), so an upcall that is reading the other bits keeps seeing them.
v3: https://lore.kernel.org/netdev/[email protected]/
- Describe the user namespace path in the commit message.
- Check the feature bit and the reference count in the selftest instead of only the return value.
v2: https://lore.kernel.org/netdev/[email protected]/
- Split the selftest into its own patch.
- Add the ovs-dpctl set-dp command the selftest needs.
Minxi Hou (3):
net: openvswitch: read the datapath features once when sending an
upcall
net: openvswitch: do not record user features when the change fails selftests/net/openvswitch: check that a failed set keeps the features
net/openvswitch/datapath.c | 70 +++++-- net/openvswitch/datapath.h | 7 +- .../testing/selftests/net/openvswitch/config | 3 + .../selftests/net/openvswitch/openvswitch.sh | 195 ++++++++++++++++++ .../selftests/net/openvswitch/ovs-dpctl.py | 74 +++++++ 5 files changed, 331 insertions(+), 18 deletions(-)
base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
Signature · 1 line
2.56.1
PATCH v6 1/3 net: openvswitch: read the datapath features once when sending an upcall
queue_userspace_packet() decides from OVS_DP_F_UNALIGNED whether to copy the packet with skb_zerocopy(), and pad_packet() reads the same field again after the copy. A concurrent OVS_DP_CMD_SET can clear the bit between the two reads, so the copy leaves a nonlinear skb and the padding calls skb_put_zero() on it. skb_put() asserts that the skb is linear, so the kernel oopses, and a host built with panic_on_oops goes down.
OVS_DP_CMD_SET needs CAP_NET_ADMIN, which a user namespace that owns a network namespace provides, so the window is reachable without privileges on the host.
Read the field once and pass that value to pad_packet().
---
v6: split out of the fix v5 carried as one patch. Reading the field
once is an older and separate crash, so it stands as its own patch with its own Fixes: tag (aea0bb4f8ee5, the commit that added the second read).
net/openvswitch/datapath.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
net/openvswitch/datapath.c +12 -4
@@ -439,9 +439,9 @@ static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info,return size; } -static void pad_packet (struct datapath *dp,struct sk_buff *skb) +static void pad_packet (struct sk_buff *skb,u32 features) { -if (!(dp->user_features &OVS_DP_F_UNALIGNED )) { +if (!(features &OVS_DP_F_UNALIGNED )) {size_t plen =NLA_ALIGN (skb->len) - skb->len;if (plen >0 )
@@ -461,6 +461,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,size_t msg_size;size_t skb_len;unsigned int hlen; +u32 features;int err, dp_ifindex;u64 hash;
@@ -494,11 +495,18 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, (err = skb_csum_hwoffload_help(skb, 0))) goto out; +/* A concurrent change to the features can land between the head room +* decision below and the padding after the copy, which would pad a +* nonlinear skb and trip SKB_LINEAR_ASSERT. Read the field once and use +* that value for both. +*/ + features =READ_ONCE (dp->user_features); +/* Older versions of OVS user space enforce alignment of the last * Netlink attribute to NLA_ALIGNTO which would require extensive * padding logic. Only perform zerocopy if padding is not required. */ -if (dp->user_features &OVS_DP_F_UNALIGNED ) +if (features &OVS_DP_F_UNALIGNED ) hlen =min (skb_zerocopy_headlen (skb), cutlen);else hlen = skb_len;
@@ -598,7 +606,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, goto out;/* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */ -pad_packet (dp, user_skb); +pad_packet (user_skb, features); ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len;
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH net v6 1/3] net: openvswitch: read the datapath features once when sending an upcall
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In net/openvswitch/datapath.c, the comment added to queue_userspace_packet() above `features =…
--
net: openvswitch: read the datapath features once when sending an upcall
queue_userspace_packet() reads dp->user_features once to decide whether the packet is copied linearly. pad_packet() reads it again after the copy. A concurrent OVS_DP_CMD_SET can change the bit between the two reads, and pad_packet() can then call skb_put_zero() on a nonlinear skb. The patch reads the field once and passes that value to pad_packet().
Quoted 4 lines
net/openvswitch/datapath.c +0
-0
[ ... ]
net/openvswitch/datapath.c static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, · line 502
Quoted 9 lines
net/openvswitch/datapath.c +5
-0@@ -494,11 +495,18 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, (err = skb_csum_hwoffload_help(skb, 0))) goto out; +/* A concurrent change to the features can land between the head room +* decision below and the padding after the copy, which would pad a +* nonlinear skb and trip SKB_LINEAR_ASSERT. Read the field once and use +* that value for both. +*/
[Severity: Low]
This isn't a bug, but is "head room decision" the right term for this comment in queue_userspace_packet()?
The code below doesn't decide any headroom. It picks hlen, the number of bytes skb_zerocopy() copies into the linear part of user_skb:
if (features & OVS_DP_F_UNALIGNED) hlen = min(skb_zerocopy_headlen(skb), cutlen); else hlen = skb_len;
hlen then sizes the message in upcall_msg_size() and is passed as the linear copy length to skb_zerocopy(user_skb, skb, skb_len, hlen).
In skb code, headroom usually means skb_headroom(). struct datapath also has a separate max_headroom field, which isn't involved here.
Could the comment say "linear copy length (hlen)" instead? The later patches in the series don't change this comment.
Quoted 11 lines
net/openvswitch/datapath.c +3
-1+ features =READ_ONCE (dp->user_features); +/* Older versions of OVS user space enforce alignment of the last * Netlink attribute to NLA_ALIGNTO which would require extensive * padding logic. Only perform zerocopy if padding is not required. */ -if (dp->user_features &OVS_DP_F_UNALIGNED ) +if (features &OVS_DP_F_UNALIGNED ) hlen =min (skb_zerocopy_headlen (skb), cutlen);else hlen = skb_len;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124145033.627044-1-houminxi%40gmail.com
Re: [PATCH net v6 1/3] net: openvswitch: read the datapath features once when sending an upcall
The comment now says "linear copy length (hlen)" rather than "head room". That is the value selected before skb_zerocopy(), not skb_headroom(). This change is in the local v7 candidate; v7 has not been sent.
PATCH v6 2/3 net: openvswitch: do not record user features when the change fails
In reply to Minxi Houovs_dp_change() stores the new features in dp->user_features before it updates the per-cpu upcall port IDs, and that update fails when the per-cpu-pids attribute is empty or its length is not a multiple of four. The update runs only when the same request also sets OVS_DP_F_DISPATCH_UPCALL_PER_CPU, which is what user space that wants per-cpu upcalls sends.
The request returns -EINVAL with the new features already recorded, while the code that enables or disables the tc skb extension key never ran.
The datapath then claims TC_RECIRC_SHARING without holding the reference the bit stands for. A later request that clears the bit drops a reference that was never taken, and a datapath destroyed with the bit clear never drops the one it did take. The key is shared with the other users of recirc sharing, so the count can reach zero while one of them still reads it, and a disable on a count of zero warns from static_key_dec_not_one(), which panics a host that runs with panic_on_warn.
The request only needs CAP_NET_ADMIN, which a user namespace that owns a network namespace provides. datapath_policy has no entry for OVS_DP_ATTR_PER_CPU_PIDS and the operation skips strict validation, so an empty attribute reaches the check that fails.
Record the features last, in one setter that also takes and drops the reference, and use it from every place that changes or clears the bit. Two of those places leaked a reference: a datapath that fails after ovs_dp_change() enabled the key was freed without a disable, and ovs_dp_reset_user_features() cleared the bit without one. The reset runs when an outdated user space instance sends OVS_DP_CMD_NEW for a name that already exists, and after it the datapath's packets no longer share the tc skb extension.
__dp_destroy() clears the bit before the ports are detached and before the datapath leaves the list, so an upcall can still be reading the other bits from the receive path, and the clear goes through the same setter.
---
v6: ovs_dp_set_user_features() reads the field with READ_ONCE() rather
than a plain load, now that every write to it is a single WRITE_ONCE(), and the two paths that clear only the recirc bit call one helper instead of repeating the mask expression. The tag block also moved to the end of the message, with no prose after it.
net/openvswitch/datapath.c | 54 +++++++++++++++++++++++++++++--------- net/openvswitch/datapath.h | 7 ++++- 2 files changed, 47 insertions(+), 14 deletions(-)
net/openvswitch/datapath.c +41 -13
@@ -1712,6 +1712,36 @@ static struct datapath *lookup_datapath(struct net *net,return dp ? dp :ERR_PTR (-ENODEV ); } +/* Called with ovs_mutex, which every writer holds. The field is a single +* WRITE_ONCE() so a reader on the receive path, which takes no lock, never +* sees a value stitched together from two stores; this helper reads it with +* READ_ONCE() for the same reason. The store happens before the reference is +* taken or dropped, the order ovs_dp_change() used. +*/ +static void ovs_dp_set_user_features (struct datapath *dp,u32 features) +{ +u32 previous =READ_ONCE (dp->user_features); +bool was = previous &OVS_DP_F_TC_RECIRC_SHARING ; +bool now = features &OVS_DP_F_TC_RECIRC_SHARING ; + +WRITE_ONCE (dp->user_features, features); + +if (now && !was) +tc_skb_ext_tc_enable (); +else if (!now && was) +tc_skb_ext_tc_disable (); +} + +/* Give up the reference for the recirc bit without touching the other bits, so +* an upcall that is reading them keeps seeing what it saw. +*/ +static void ovs_dp_clear_recirc_sharing (struct datapath *dp) +{ +u32 features =READ_ONCE (dp->user_features); + +ovs_dp_set_user_features (dp, features & ~OVS_DP_F_TC_RECIRC_SHARING ); +} +static void ovs_dp_reset_user_features (struct sk_buff *skb,struct genl_info *info) {
@@ -1724,7 +1754,7 @@ static void ovs_dp_reset_user_features(struct sk_buff *skb,pr_warn ("%s: Dropping previously announced user features\n" ,ovs_dp_name (dp)); - dp->user_features =0 ; +ovs_dp_set_user_features (dp,0 ); } static int ovs_dp_set_upcall_portids(struct datapath *dp,
@@ -1781,7 +1811,7 @@ u32 ovs_dp_get_upcall_portid(const struct datapath *dp, uint32_t cpu_id)static int ovs_dp_change (struct datapath *dp,struct nlattr *a[]) { -u32 user_features =0 , old_features = dp->user_features; +u32 user_features =0 ;int err;if (a[OVS_DP_ATTR_USER_FEATURES ]) {
@@ -1809,9 +1839,7 @@ static int ovs_dp_change(struct datapath *dp, struct nlattr *a[])return err; } - dp->user_features = user_features; - -if (dp->user_features &OVS_DP_F_DISPATCH_UPCALL_PER_CPU && +if (user_features &OVS_DP_F_DISPATCH_UPCALL_PER_CPU && a[OVS_DP_ATTR_PER_CPU_PIDS ]) {/* Upcall Netlink Port IDs have been updated */ err = ovs_dp_set_upcall_portids(dp,
@@ -1820,12 +1848,7 @@ static int ovs_dp_change(struct datapath *dp, struct nlattr *a[])return err; } -if ((dp->user_features &OVS_DP_F_TC_RECIRC_SHARING ) && - !(old_features &OVS_DP_F_TC_RECIRC_SHARING )) -tc_skb_ext_tc_enable (); -else if (!(dp->user_features &OVS_DP_F_TC_RECIRC_SHARING ) && - (old_features &OVS_DP_F_TC_RECIRC_SHARING )) -tc_skb_ext_tc_disable (); +ovs_dp_set_user_features (dp, user_features);return 0 ; }
@@ -1947,6 +1970,8 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) err_destroy_portids:kfree (rcu_dereference_raw (dp->upcall_portids)); err_unlock_and_destroy_meters: +/* The datapath is freed here and never reaches __dp_destroy(). */ +ovs_dp_clear_recirc_sharing (dp);ovs_unlock ();ovs_meters_exit (dp); err_destroy_ports:
@@ -1969,8 +1994,11 @@ static void __dp_destroy(struct datapath *dp)struct flow_table *table = &dp->table;int i; -if (dp->user_features &OVS_DP_F_TC_RECIRC_SHARING ) -tc_skb_ext_tc_disable (); +/* Only the recirc bit goes here. The datapath is still on the list and +* its ports are still attached, so an upcall can be reading the other +* bits from the receive path while this runs. +*/ +ovs_dp_clear_recirc_sharing (dp);for (i =0 ; i <DP_VPORT_HASH_BUCKETS ; i++) {struct vport *vport;
net/openvswitch/datapath.h +6 -1
@@ -76,7 +76,12 @@ struct dp_nlsk_pids {* ovs_mutex and RCU. * @stats_percpu: Per-CPU datapath statistics. * @net: Reference to net namespace. -* @user_features: Bitmap of enabled %OVS_DP_F_* features. +* @user_features: Bitmap of enabled %OVS_DP_F_* features. A datapath +* that has %OVS_DP_F_TC_RECIRC_SHARING set holds one reference to the tc +* skb extension. ovs_dp_set_user_features() keeps the bit and the +* reference in step, and every change goes through it with ovs_mutex +* held. ovs_dp_change() calls it after the per-cpu pid update, which can +* fail, so a request that fails leaves the features alone. * @max_headroom: The maximum headroom of all vports in this datapath; it will * be used by all the internal vports in this dp. * @meter_tbl: Meter table.
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH net v6 2/3] net: openvswitch: do not record user features when the change fails
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Part of the commit message is wrong.
- [Low] The comment on the new ovs_dp_set_user_features() says the field is written with a single WRITE_ONCE() so that "a reader on the receive…
--
net: openvswitch: do not record user features when the change fails
This patch moves the store to dp->user_features in ovs_dp_change() so it happens after the per-cpu upcall port ID update. A failed request then no longer leaves the TC_RECIRC_SHARING bit out of step with the tc skb extension reference. A new helper, ovs_dp_set_user_features(), keeps the bit and the reference in step. It is used from the reset path, the ovs_dp_cmd_new() error path and __dp_destroy().
Quoted 6 lines
Two of those places leaked a reference: a datapath that fails after
ovs_dp_change()enabled the key was freed without a disable, andovs_dp_reset_user_features()cleared the bit without one. The reset runs when an outdated user space instance sendsOVS_DP_CMD_NEWfor a name that already exists, and after it the datapath's packets no longer share the tc skb extension.
[Severity: Low]
Is the last sentence accurate? No packet path in net/openvswitch reads the per-datapath OVS_DP_F_TC_RECIRC_SHARING bit. ovs_flow_key_extract() checks only the global static key:
net/openvswitch/flow.c:ovs_flow_key_extract() {
...
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
if (tc_skb_ext_tc_enabled()) {
tc_ext = skb_ext_find(skb, TC_SKB_EXT);
...
}In net/sched/cls_api.c, tc_skb_ext_tc_enable() and tc_skb_ext_tc_disable() increment and decrement the single global tc_skb_ext_tc key. cls_flower and every other OVS datapath hold references to the same key.
Clearing the bit in ovs_dp_reset_user_features() drops this datapath's reference, which used to leak. The datapath's packets still use the tc skb extension as long as any other holder keeps the key enabled.
Could the commit message describe this as a reference counting fix rather than a change in how this datapath handles packets?
Quoted 11 lines
net/openvswitch/datapath.c +3
-0@@ -1712,6 +1712,36 @@ static struct datapath *lookup_datapath(struct net *net,return dp ? dp :ERR_PTR (-ENODEV ); } +/* Called with ovs_mutex, which every writer holds. The field is a single +* WRITE_ONCE() so a reader on the receive path, which takes no lock, never +* sees a value stitched together from two stores; this helper reads it with
net/openvswitch/datapath.c static struct datapath *lookup_datapath(struct net *net, · line 1727
Quoted 10 lines
net/openvswitch/datapath.c +10
-0+* READ_ONCE() for the same reason. The store happens before the reference is +* taken or dropped, the order ovs_dp_change() used. +*/ +static void ovs_dp_set_user_features (struct datapath *dp,u32 features) +{ +u32 previous =READ_ONCE (dp->user_features); +bool was = previous &OVS_DP_F_TC_RECIRC_SHARING ; +bool now = features &OVS_DP_F_TC_RECIRC_SHARING ; + +WRITE_ONCE (dp->user_features, features);
[Severity: Low]
This comment says the lockless readers are covered by this WRITE_ONCE(). Is that true for most of them?
queue_userspace_packet() uses READ_ONCE(), which came from the earlier series patch "net: openvswitch: read the datapath features once when sending an upcall". These lockless readers still use plain loads:
net/openvswitch/datapath.c:ovs_dp_process_packet() {
...
else if (dp->user_features & OVS_DP_F_DISPATCH_UPCALL_PER_CPU)
...
}net/openvswitch/actions.c:output_userspace() {
...
else if (dp->user_features &
OVS_DP_F_DISPATCH_UPCALL_PER_CPU)
...
}net/openvswitch/vport.c:ovs_vport_get_upcall_portids() {
...
if (vport->dp->user_features & OVS_DP_F_VPORT_PIDS)
...
}The last one is reached from ovs_vport_cmd_get() and ovs_vport_cmd_dump(), which hold only rcu_read_lock().
Under the kernel memory model, a WRITE_ONCE() that races with a plain load is still a data race, so KCSAN could report these readers.
The patch also adds a store on a live datapath. __dp_destroy() used to only read the field. It now writes dp->user_features through ovs_dp_clear_recirc_sharing() while the datapath is still on the list and its ports are still attached.
Each of these readers loads an aligned u32 once and tests one bit, so no functional failure is expected.
Should the remaining lockless readers switch to READ_ONCE()? Otherwise, could this comment and the @user_features kernel-doc in struct datapath be narrowed to match what is actually marked?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124145033.627044-1-houminxi%40gmail.com
Re: [PATCH net v6 2/3] net: openvswitch: do not record user features when the change fails
I rewrote the commit message to describe the leaked tc skb extension reference, not a change to this datapath's packet handling. The static key is global, so other holders can keep it enabled.
The helper comment now names the readers that still use plain loads. The @user_features documentation describes the reference lifetime and no longer makes a blanket claim about lockless readers. Those readers remain unchanged. These changes are in the local v7 candidate; v7 has not been sent.
PATCH v6 3/3 selftests/net/openvswitch: check that a failed set keeps the features
In reply to Minxi HouAdd a set-dp command to ovs-dpctl for the kernel's datapath SET command, and two tests that use it.
The first test clears the features of a fresh datapath, sets the dispatch bit with a valid pid list, and clears them again. It then sends a set that would set that bit with an empty per-cpu-pids. The request has to fail with EINVAL, and the datapath has to keep reporting the features it had, which a kernel that records them before the change reads as 0x8 instead of 0x0. A second request sends OVS_DP_CMD_NEW for that name from an outdated client, which makes the kernel drop the features, and a further set has to work.
The second test covers the recirc bit. It sets that bit on a fresh datapath and sends a set that would set the dispatch bit with an empty per-cpu-pids. The rejected request has to leave the recirc bit in place. A kernel that records the features first reads 0x8 there instead of 0x4. A datapath holds that bit only when the tc skb extension is compiled in, so the test prints the reason and skips when the kernel answers EOPNOTSUPP, and any other failure of that request fails the test. CONFIG_NET_TC_SKB_EXT depends on CONFIG_NET_CLS_ACT and both sit under CONFIG_NET_SCHED, so the selftest config fragment selects all three.
The reference count itself is not visible from user space, so the steps that use an outdated client only show that those paths run and that a datapath keeps working across them.
set-dp sends the features it is given. When --features is left out it sends the features the datapath reports, and it refuses to send the request when the datapath reports none. A pid list that is not a list of numbers is reported as such, and empty entries are dropped.
A failing run deletes debug.log, and ovs_sbx sends a command's stdout into that same file, so the tests report a failure reason on stderr. stderr still reaches the test runner from inside ovs_sbx, and unlike a duplicated stdout it is not a second handle on the runner's pipe. The daemons the suite starts outlive the script, and one that inherits such a handle keeps the pipe open after the script exits, which leaves the run hanging until the harness times out.
Every step that can fail says why it did. A datapath that cannot be read is reported as that rather than as a feature mismatch: ovs-dpctl prints a missing datapath and exits 0, and it leaves the features line out when the kernel does not report them, so the check reads both cases from the output.
---
v6: the variables the new helpers pass around are quoted, the help
text and one message fit in the file's 79 columns, and the note in the set-dp branch of main() names the two conditions the kernel rejects an empty attribute with: a length of zero, or a length that is not a multiple of four.
.../testing/selftests/net/openvswitch/config | 3 + .../selftests/net/openvswitch/openvswitch.sh | 195 ++++++++++++++++++ .../selftests/net/openvswitch/ovs-dpctl.py | 74 +++++++ 3 files changed, 272 insertions(+)
tools/testing/selftests/net/openvswitch/config +3 -0
@@ -2,10 +2,13 @@ CONFIG_GENEVE=m CONFIG_INET_DIAG=y CONFIG_IP_SCTP=y CONFIG_IPV6=y +CONFIG_NET_CLS_ACT=y CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NET_IPGRE=m CONFIG_NET_IPGRE_DEMUX=m +CONFIG_NET_SCHED=y +CONFIG_NET_TC_SKB_EXT=y CONFIG_NF_CONNTRACK=m CONFIG_NF_CONNTRACK_OVS=y CONFIG_NF_CT_PROTO_SCTP=y
tools/testing/selftests/net/openvswitch/openvswitch.sh +195 -0
207 lines not on this page · raw message
tools/testing/selftests/net/openvswitch/ovs-dpctl.py +74 -0
92 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH net v6 3/3] selftests/net/openvswitch: check that a failed set keeps the features
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In tools/testing/selftests/net/openvswitch/openvswitch.sh, both new tests guard datapath creation with `ovs_add_dp "$t" "$dp" ||…
--
selftests/net/openvswitch: check that a failed set keeps the features
This adds a set-dp command to ovs-dpctl.py and two openvswitch selftests that use it. The tests check that a set with an empty per-cpu-pids is rejected with EINVAL and leaves the datapath features unchanged, and that an outdated OVS_DP_CMD_NEW request drops the features. The config fragment also gains NET_SCHED, NET_CLS_ACT and NET_TC_SKB_EXT for the recirc bit.
Quoted 4 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +0
-0
[ ... ]
tools/testing/selftests/net/openvswitch/openvswitch.sh test_netlink_checks () { · line 1495
Quoted 6 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +6
-0+test_dp_features() { + local t="test_dp_features" + local dp="dpfeat0" + + sbx_add "$t" || return $? + ovs_add_dp "$t" "$dp" || return 1
[Severity: Medium]
Can this "|| return 1" ever trigger when add-dp fails?
ovs_add_dp() runs add-dp and then calls on_exit():
ovs_add_dp () {
...
ovs_sbx "$sbxname" python3 $ovs_base/ovs-dpctl.py add-dp $* on_exit "ovs_sbx $sbxname python3 $ovs_base/ovs-dpctl.py del-dp $1;"
}
on_exit() {
echo "$1" > ${ovs_dir}/cleanup.tmp
cat ${ovs_dir}/cleanup >> ${ovs_dir}/cleanup.tmp
mv ${ovs_dir}/cleanup.tmp ${ovs_dir}/cleanup
}The function returns the status of the final mv, so the exit status of add-dp is lost. OvsDatapath.create() swallows only EEXIST and re-raises any other NetlinkError, so add-dp can exit non-zero.
If that happens, the first failure the test sees is the next step:
tools/testing/selftests/net/openvswitch/openvswitch.sh test_netlink_checks () { · line 1499
Quoted 4 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +4
-0+ + info "clear the datapath features" + ovs_sbx "$t" ovs_dp_features_set "$dp" --features 0 || + { ovs_fail "the datapath features could not be cleared"; return 1; }
Here set-dp prints "DP 'dpfeat0' not found." to stdout. ovs_sbx sends that into debug.log, and run_test removes $ovs_dir on FAIL. The only reason left on stderr is "the datapath features could not be cleared", while the real cause was that the datapath was never created.
The commit message says:
Every step that can fail says why it did.
The datapath creation step doesn't seem to meet that. Could add-dp's status be checked, either with "|| return 1" on the add-dp line in ovs_add_dp() before on_exit, or by calling add-dp directly in the new tests with an ovs_fail message?
The ovs_add_dp() behaviour is older than this patch, but the new tests depend on a return status that the helper never gives.
[ ... ]
tools/testing/selftests/net/openvswitch/openvswitch.sh test_netlink_checks () { · line 1564
Quoted 9 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +9
-0+test_dp_features_recirc() { + local t="test_dp_features_recirc" + local dp="dpfeat1" + + sbx_add "$t" || return $? + ovs_add_dp "$t" "$dp" || return 1 + + ovs_sbx "$t" ovs_dp_features_set "$dp" --features 0 || + { ovs_fail "the datapath features could not be cleared"; return 1; }
The same applies here. A failed add-dp for dpfeat1 would be reported as "the datapath features could not be cleared".
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124145033.627044-1-houminxi%40gmail.com
Re: [PATCH net v6 3/3] selftests/net/openvswitch: check that a failed set keeps the features
ovs_add_dp() returned on_exit()'s status, so the caller's failure guard could not detect an add-dp failure.
The local v7 candidate saves add-dp's return status, registers cleanup, and returns the saved status. Both new tests then report "the datapath was not created" if creation fails.
v7 is prepared locally and has not been sent.
pw-bot: cr
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Both answers, per patch.
1/3, the single read of dp->user_features:
Found by manual code inspection of how the datapath features are read:queue_userspace_packet() decides from OVS_DP_F_UNALIGNED whether to copy with skb_zerocopy(), and pad_packet() reads the same field again after the copy. The second read comes from aea0bb4f8ee5.
Not triggered. The window needs an OVS_DP_CMD_SET to land between the head room decision and the padding of the same upcall, which is a race I could not turn into a deterministic test, so there is no trace to show. What the code gives is the order of the two reads and the assert itself:skb_put() asserts the skb is linear, and skb_zerocopy() leaves it nonlinear when the bit is cleared between them.
2/3, the features recorded on a failed change:
Found the same way, by reading ovs_dp_change() against ovs_dp_set_upcall_portids(), and then triggered from user space with no privileges on the host: the datapath lives in a network namespace owned by a user namespace, which is all CAP_NET_ADMIN there needs.
The recorded-features half has a running symptom. On 2a324a58a084, the parent of this series, the selftest added in 3/3 reports:
# the rejected set changed the features TEST: ovsdp: failed set keeps bits [FAIL]
ovs-dpctl set-dp with an empty per-cpu-pids asks for the dispatch bit along with a pids list the kernel rejects with -EINVAL, and the datapath still reports the features that the failed request asked for. With this series the same command leaves the features as they were and the test passes.
The reference half is not triggered. A datapath that holds TC_RECIRC_SHARING without the tc skb extension reference, then cleared, drops a reference that was never taken, and a disable on a count of zero warns from static_key_dec_not_one(). I did not build the sequence that reaches it, so that part rests on the code and not on a trace.
Neither patch comes from syzbot or from a static analysis tool. The review that found them was done with an LLM assistant, and the recorded-features half was then confirmed by running the new selftest against the unfixed parent.