Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Minxi Hou
Wed, 18 Nov 2026 06:54
[PATCH net v5 1/2] net: openvswitch: do not record user features when the change fails
Author: Minxi Hou
Date: Wed, 18 Nov 2026 06:54
Date: Wed, 18 Nov 2026 06:54
218 lines
19875 bytes
19875 bytes
ovs_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 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.
Fixes: 35d39fecbc24 ("net/sched: Enable tc skb ext allocation on chain miss only when needed")
Cc: stable@vger.kernel.org
__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. queue_userspace_packet() decides from
OVS_DP_F_UNALIGNED whether to build a nonlinear skb, and pad_packet() reads
the same field again, so a store that clears every bit can change that
decision between the two reads. Clear only the recirc bit, which is the one
this path dropped before.
The store goes through WRITE_ONCE() because the receive path reads the
field without ovs_mutex.
The receive path read the field twice as well, once to size the head room
and once to decide whether to pad, so a set that changed the bit in
between could make it pad a nonlinear skb. It reads the field once now and
uses that value for both.
Signed-off-by: Minxi Hou <houminxi@gmail.com>
---
net/openvswitch/datapath.c | 58 +++++++++++++++++++++++++++-----------
net/openvswitch/datapath.h | 7 ++++-
2 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index b2a0b09fd4a5..7c1af21f74df 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -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,16 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
(err = skb_csum_hwoffload_help(skb, 0)))
goto out;
+ /* The features can be changed while this runs, so read them once and
+ * use that value for both the head room and the padding.
+ */
+ 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 +604,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;
@@ -1704,6 +1710,24 @@ static struct datapath *lookup_datapath(struct net *net,
return dp ? dp : ERR_PTR(-ENODEV);
}
+/* Called with ovs_mutex. The receive path reads the field without it, so
+ * the store is single and goes through WRITE_ONCE(). The store happens
+ * before the reference is taken or dropped, the order ovs_dp_change() used
+ * before this helper existed.
+ */
+static void ovs_dp_set_user_features(struct datapath *dp, u32 features)
+{
+ bool was = dp->user_features & 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();
+}
+
static void ovs_dp_reset_user_features(struct sk_buff *skb,
struct genl_info *info)
{
@@ -1716,7 +1740,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,
@@ -1773,7 +1797,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]) {
@@ -1801,9 +1825,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,
@@ -1812,12 +1834,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;
}
@@ -1939,6 +1956,9 @@ 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_set_user_features(dp, dp->user_features &
+ ~OVS_DP_F_TC_RECIRC_SHARING);
ovs_unlock();
ovs_meters_exit(dp);
err_destroy_ports:
@@ -1961,8 +1981,12 @@ 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_set_user_features(dp, dp->user_features &
+ ~OVS_DP_F_TC_RECIRC_SHARING);
for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
struct vport *vport;
diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h
index 7a7afaeceee5..55db1e635c74 100644
--- a/net/openvswitch/datapath.h
+++ b/net/openvswitch/datapath.h
@@ -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.
--
2.56.1
Re: [PATCH net v5 1/2] net: openvswitch: do not record user features when the change fails
Author: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 07:29
Date: Sun, 22 Nov 2026 07:29
225 lines
16404 bytes
16404 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2 (1)
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] The patch also fixes a second, unrelated and older crash, and
the subject, Fixes tag and impact description all leave it out.
- [Low] The `Fixes: 35d39fecbc24 (...)` and `Cc: stable@vger.kernel.org`
lines sit in the middle of the commit message.
- [Low] The patch makes ovs_dp_set_user_features() the only writer and
has it store with `WRITE_ONCE(dp->user_features, features)`.
Pre-existing issues:
- [Low] datapath_policy[] in net/openvswitch/datapath.c has entries for
NAME, UPCALL_PID, USER_FEATURES, MASKS_CACHE_SIZE and IFINDEX, but…
--
net: openvswitch: do not record user features when the change fails
The patch moves the store of dp->user_features in ovs_dp_change() to after
the per-cpu upcall pid update. Every change now goes through a new
ovs_dp_set_user_features() helper, which keeps OVS_DP_F_TC_RECIRC_SHARING
and the tc skb extension reference in step. It also fixes reference leaks
in the ovs_dp_cmd_new() error path and in ovs_dp_reset_user_features(),
and has queue_userspace_packet() read the features once for both the
head room and the padding.
> Fixes: 35d39fecbc24 ("net/sched: Enable tc skb ext allocation on chain miss only when needed")
> Cc: stable@vger.kernel.org
> __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
[ ... ]
> uses that value for both.
>
> Signed-off-by: Minxi Hou <houminxi@gmail.com>
[Severity: Low]
The Fixes: and Cc: stable lines sit in the middle of the commit message.
Four more paragraphs follow them, and only then comes the Signed-off-by:
line.
git interpret-trailers, b4 and patchwork only read trailers from the last
paragraph of the message, and here that paragraph holds only
Signed-off-by:. Won't those tools treat the Fixes: and Cc: stable tags as
ordinary body text?
Could the paragraphs after the tags move above the trailer block? If they
are revision notes, they could go below the --- line instead.
> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index b2a0b09fd4a56..7c1af21f74df4 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
[ ... ]
> @@ -494,11 +495,16 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
> (err = skb_csum_hwoffload_help(skb, 0)))
> goto out;
>
> + /* The features can be changed while this runs, so read them once and
> + * use that value for both the head room and the padding.
> + */
> + features = READ_ONCE(dp->user_features);
> +
[Severity: Medium]
This single read also fixes a separate, older crash. The subject, the
Fixes: tag and the impact description don't mention it.
Before this patch, the hlen choice and pad_packet() each read
dp->user_features. If OVS_DP_F_UNALIGNED is set at the first read,
skb_zerocopy() can attach frags and leave user_skb nonlinear.
An OVS_DP_CMD_SET needs only CAP_NET_ADMIN, which a user namespace can
provide. If one cleared the bit before the second read, the path was:
queue_userspace_packet()
pad_packet()
skb_put_zero()
skb_put()
SKB_LINEAR_ASSERT(skb); /* BUG() on a nonlinear skb */
The commit message only says a concurrent set "could make it pad a
nonlinear skb". It doesn't say the result is a BUG().
The double read is older than 35d39fecbc24. pad_packet() was split out in
7f8a436eaa2c ("openvswitch: Add conntrack action") in 2015, and the double
read dates from 2014/2015 code. Stable trees picked by the only Fixes: tag
would miss this fix. A backporter who drops or reworks this hunk would not
know it is a crash fix.
Would this work better as its own patch, with a Fixes: tag for the commit
that introduced the double read and a description of the BUG()?
> /* 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;
[ ... ]
> @@ -1704,6 +1710,24 @@ static struct datapath *lookup_datapath(struct net *net,
> return dp ? dp : ERR_PTR(-ENODEV);
> }
>
> +/* Called with ovs_mutex. The receive path reads the field without it, so
> + * the store is single and goes through WRITE_ONCE(). The store happens
> + * before the reference is taken or dropped, the order ovs_dp_change() used
> + * before this helper existed.
> + */
> +static void ovs_dp_set_user_features(struct datapath *dp, u32 features)
> +{
> + bool was = dp->user_features & OVS_DP_F_TC_RECIRC_SHARING;
> + bool now = features & OVS_DP_F_TC_RECIRC_SHARING;
> +
> + WRITE_ONCE(dp->user_features, features);
[Severity: Low]
The comment says the receive path reads the field without ovs_mutex, but
only queue_userspace_packet() was switched to READ_ONCE(). Other readers
that run without ovs_mutex 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)
...
}
ovs_dp_process_packet() runs under rcu_read_lock() only. The kernel-doc
for ovs_vport_get_upcall_portids() allows either ovs_mutex or
rcu_read_lock().
A plain load racing with a WRITE_ONCE() store is still a data race, and
KCSAN will report it. Each of these readers tests the field only once, so
there is no functional effect.
Should these readers also use READ_ONCE(), or should the comment be
limited to queue_userspace_packet()?
> +
> + if (now && !was)
> + tc_skb_ext_tc_enable();
> + else if (!now && was)
> + tc_skb_ext_tc_disable();
> +}
[ ... ]
> @@ -1801,9 +1825,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,
[Severity: Low]
This is a pre-existing issue and was not introduced by this patch.
datapath_policy[] has no entry for OVS_DP_ATTR_PER_CPU_PIDS:
static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = {
[OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
[OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 },
[OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 },
[OVS_DP_ATTR_MASKS_CACHE_SIZE] = NLA_POLICY_RANGE(NLA_U32, 0,
PCPU_MIN_UNIT_SIZE / sizeof(struct mask_cache_entry)),
[OVS_DP_ATTR_IFINDEX] = NLA_POLICY_MIN(NLA_S32, 0),
};
Documentation/netlink/specs/ovs_datapath.yaml declares per-cpu-pids as
binary with sub-type u32. The ops use GENL_DONT_VALIDATE_STRICT, so the
only check that rejects an empty or misaligned attribute is the
open-coded one in ovs_dp_set_upcall_portids():
if (!nla_len(ids) || nla_len(ids) % sizeof(u32))
return -EINVAL;
By then, ovs_dp_change() may already have resized the masks cache.
The spec has a separate gap. Its new operation lists only name,
upcall-pid and user-features, and it defines no set operation. Both
ovs_dp_cmd_new() and ovs_dp_cmd_set() accept per-cpu-pids,
masks-cache-size and ifindex through ovs_dp_change().
With the reordering in this patch, a malformed attribute no longer
corrupts the features. Could a follow-up add a policy entry for the
attribute and bring the spec in line?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118065435.2367014-1-houminxi%40gmail.com
Re: [PATCH net v5 1/2] net: openvswitch: do not record user features when the change fails
Author: Minxi Hou
Date: Mon, 23 Nov 2026 16:05
Date: Mon, 23 Nov 2026 16:05
17 lines
11349 bytes
11349 bytes
The Medium finding is right, and it changes the series. The single read of dp->user_features in queue_userspace_packet() is a separate crash with its own history, so v6 carries it as patch 1 with its own Fixes: tag naming aea0bb4f8ee5, the commit that added the second read. This patch keeps 35d39fecbc24 and is patch 2 of 3. The cover says the count changed. The two Low findings are also taken. The Fixes: and Cc: lines are in the trailer block now, and the comment on ovs_dp_set_user_features() says only what the helper guarantees: every write goes through it under ovs_mutex, and it stores once with WRITE_ONCE(). The plain reads that remain are on the receive path, which takes no lock, as before. The helper now reads the field with READ_ONCE() too, so both sides access it the same way. pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads