* [PATCH net v6 1/3] net: openvswitch: read the datapath features once when sending an upcall
[not found] <20261124145033.627044-1-houminxi@gmail.com>
@ 2026-11-24 14:50 ` Minxi Hou
2026-11-24 14:50 ` [PATCH net v6 2/3] net: openvswitch: do not record user features when the change fails Minxi Hou
1 sibling, 0 replies; 2+ messages in thread
From: Minxi Hou @ 2026-11-24 14:50 UTC (permalink / raw)
To: netdev
Cc: dev, aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, matttbe, shuah, netdev-bot+sashiko, Minxi Hou, stable
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().
Fixes: aea0bb4f8ee5 ("openvswitch: Pad OVS_PACKET_ATTR_PACKET if linear copy was performed")
Cc: stable@vger.kernel.org
Signed-off-by: Minxi Hou <houminxi@gmail.com>
---
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(-)
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index b2a0b09fd4a5..96baa2488c26 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,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;
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH net v6 2/3] net: openvswitch: do not record user features when the change fails
[not found] <20261124145033.627044-1-houminxi@gmail.com>
2026-11-24 14:50 ` [PATCH net v6 1/3] net: openvswitch: read the datapath features once when sending an upcall Minxi Hou
@ 2026-11-24 14:50 ` Minxi Hou
1 sibling, 0 replies; 2+ messages in thread
From: Minxi Hou @ 2026-11-24 14:50 UTC (permalink / raw)
To: netdev
Cc: dev, aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, matttbe, shuah, netdev-bot+sashiko, Minxi Hou, stable
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 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.
Reported-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/netdev/998d522f-e61d-420f-9834-6bdcbaab1361@kernel.org/
Fixes: 35d39fecbc24 ("net/sched: Enable tc skb ext allocation on chain miss only when needed")
Cc: stable@vger.kernel.org
Signed-off-by: Minxi Hou <houminxi@gmail.com>
---
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(-)
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 96baa2488c26..74e78a954b70 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -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;
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
^ permalink raw reply related [flat|nested] 2+ messages in thread