Reported by shaos with a reproducer for the 32-bit case, which was reproduced and verified in our test environment. The issue: ife_check_meta_u32() and ife_check_meta_u16() both reserve eight bytes of metadata for a configured value even when that value is zero, but the matching encoder returns without calling ife_tlv_meta_encode(). The encoder therefore writes neither the TLV header nor its value, while the enclosing IFE length still includes the reserved bytes, exposing stale skb headroom contents to the peer. The 32-bit helper has been present since the IFE action was introduced (v4.6); the 16-bit helper was added with the 16-bit metadata helpers used by the skbtcindex callback (v4.9). Both defects predate the oldest supported stable kernel (5.10), so they are fixed together in this patch. Each hunk keeps its own Fixes: tag for provenance. The fix: Encode any configured value, including zero; skip the TLV only when there is neither a configured nor a runtime value. The runtime fallback is unchanged. A raw TCA_IFE_METALST netlink request is needed to express the configured zero: the IFE_META_SKBMARK attribute carries four zero payload bytes for the u32 helper, and IFE_META_TCINDEX two zero payload bytes for the 16-bit helper (not an absent or zero-length attribute). Stock tc cannot build these requests; "use mark 0x0" emits no mark attribute and "allow mark" emits a zero-length one. Conditions to recreate the bug: CONFIG_NET_ACT_IFE=y, CONFIG_NET_IFE_SKBMARK=y, CONFIG_NET_IFE_SKBTCINDEX=y, CONFIG_NET_CLS_MATCHALL=y, CONFIG_NET_SCH_INGRESS=y, CONFIG_USER_NS=y, CONFIG_NET_NS=y, CONFIG_VETH=y. In a fresh user and network namespace create a veth pair and attach clsact to the egress side. Install a matchall filter whose ife encode action carries a zero skb mark (or a zero tcindex) in TCA_IFE_METALST. Send a frame through the veth and inspect the IFE metadata in the received frame. The metadata region is eight bytes but holds neither a valid TLV header nor a value; it exposes prior headroom contents. Setting the value to a nonzero one does not trigger the leak. The namespace needs CAP_NET_ADMIN; no additional privilege is required. With the fix the zero TLVs are 0001000800000000 (u32) and 0005000600000000 (u16). Fixes: ef6980b6becb ("introduce IFE action") Fixes: 6a5d58b67e20 ("net sched ife action: add 16 bit helpers") Reported-by: shaos Link: https://lore.kernel.org/netdev/20261022144739.61342-1-shawnq1@163.com/ Cc: stable@vger.kernel.org Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim --- net/sched/act_ife.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c index 3946a9589bb8..6b23a3965121 100644 --- a/net/sched/act_ife.c +++ b/net/sched/act_ife.c @@ -50,8 +50,7 @@ int ife_encode_meta_u16(u16 metaval, void *skbdata, struct tcf_meta_info *mi) edata = *(u16 *)mi->metaval; else if (metaval) edata = metaval; - - if (!edata) /* will not encode */ + else return 0; edata = htons(edata); @@ -94,8 +93,7 @@ int ife_encode_meta_u32(u32 metaval, void *skbdata, struct tcf_meta_info *mi) edata = *(u32 *)mi->metaval; else if (metaval) edata = metaval; - - if (!edata) /* will not encode */ + else return 0; edata = htonl(edata); -- 2.43.0 This is a followup of commit 5b483f7791b0 ("net/sched: act_ife: Only operate on Ethernet frames") as reported by Sashiko. The finding was raised by both Sashiko providers (nipa and gemini) while reviewing the parent patchset. shaos independently reported the same undersized-egress path with a reproducer, which was reproduced and verified in our test environment. The issue: On egress tcf_ife_is_eth_skb() only checks the device type; it does not check that the skb carries a full Ethernet header. For an Ethernet or loopback device it returns true even when the skb has no Ethernet header. tcf_ife_encode() then calls ife_encode(), which copies ETH_HLEN bytes from skb->data. A short skb therefore reads past its linear data and the copied bytes, including stale kernel memory, are emitted in the outer Ethernet header. The parent commit fixed the reported ingress mac_len case but left the egress path without a length check. A total-length test is not sufficient: a non-GSO TUN skb can have a large total length while only a single byte sits in the linear area, so ife_encode() still reads past the linear header. Require instead that the Ethernet header the encoder copies is present in the linear part of the skb. The Fix: On egress require pskb_may_pull(skb, ETH_HLEN) before encoding, which ensures the Ethernet header is present in the linear data ife_encode() copies from; the ingress mac_len check is unchanged. A short egress skb is now dropped instead of being encoded. Conditions to recreate the bug: CONFIG_NET_ACT_IFE=y, CONFIG_NET_CLS_MATCHALL=y, CONFIG_NET_SCH_INGRESS=y, CONFIG_TUN=y, CONFIG_NET_ACT_MIRRED=y. In two user and network namespaces (a victim and an attacker), open a TUN device in IFF_TUN mode and attach clsact to it and to lo. Redirect ingress traffic from the TUN device to lo egress with mirred, and install an ife encode action on lo egress: tc qdisc add dev clsact tc qdisc add dev lo clsact tc filter add dev ingress matchall action mirred egress \ redirect dev lo tc filter add dev lo egress matchall action ife encode use mark 1 \ action ok Send a TUN packet shorter than ETH_HLEN (a one-byte payload is enough) and receive the emitted frame on the other side. Without the fix the outer Ethernet header contains bytes copied past the short packet; with the fix the short skb is dropped. The attacker needs CAP_NET_ADMIN in its user namespace; no init-net privilege is required. The same path is reachable when the total length is large but the Ethernet header is not linear: write a non-GSO virtio header with hdr_len=1 followed by an 8192-byte packet so that only one byte stays linear. Without the fix the copied header reads past the linear data; with the fix the header is pulled into the linear area before the copy. Fixes: 295a6e06d21e ("net/sched: act_ife: Change to use ife module") Reported-by: Sashiko (nipa) Reported-by: Sashiko (gemini) Reported-by: shaos Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260821164031.32824-1-victor%40mojatatu.com Link: https://sashiko.dev/#/patchset/20260821164031.32824-1-victor@mojatatu.com Link: https://lore.kernel.org/netdev/20261022144736.61227-1-shawnq1@163.com/ Cc: stable@vger.kernel.org Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim --- v2 -> v3: no change to the diff; the Fixes: tag now names the commit that introduced the unguarded copy. This series revision considers comments from Sashiko (nipa) on the v2 posting: https://lore.kernel.org/netdev/179366641863.488856.17368571591466000274@kernel.org/ The tc-testing coverage of the teql rejections is reworked in 4/4 so that each case exercises exactly one check. net/sched/act_ife.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c index 6b23a3965121..5a527da00566 100644 --- a/net/sched/act_ife.c +++ b/net/sched/act_ife.c @@ -878,13 +878,16 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, * is an Ethernet header because the skb could've been redirected with mirred * from a non-Ethernet device. */ -static bool tcf_ife_is_eth_skb(const struct sk_buff *skb) +static bool tcf_ife_is_eth_skb(struct sk_buff *skb) { if (skb->dev->type != ARPHRD_ETHER && skb->dev->type != ARPHRD_LOOPBACK) return false; - return !skb_at_tc_ingress(skb) || skb->mac_len == ETH_HLEN; + if (skb_at_tc_ingress(skb)) + return skb->mac_len == ETH_HLEN; + + return pskb_may_pull(skb, ETH_HLEN); } TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb, -- 2.43.0 Reported by shaos with a reproducer, which was reproduced and verified in our test environment. The issue: The teql master devices are created once in the initial network namespace and their Qdisc_ops are global. teql_qdisc_init() takes the teql_master embedded in the registered sch->ops and uses it without checking whether the new qdisc's device lives in the same network namespace as the master. A qdisc created in another netns can therefore attach to the init-net master and change its MTU and flags. The Fix: Reject a teql qdisc whose device is not in the master's network namespace with -EOPNOTSUPP and an extack message; same-netns teql still works. Initialize the private skb queue before any validation so every constructor failure path, including qdisc_create_dflt(), which resets the qdisc before destroying it, sees an initialized empty queue. Conditions to recreate the bug: CONFIG_NET_SCH_TEQL=y, CONFIG_DUMMY=y, CONFIG_USER_NS=y, CONFIG_NET_NS=y. As an unprivileged UID, unshare a user and network namespace, create a dummy device, set its MTU to 60000, and add a root teql0 qdisc: unshare -Urn ip link add dummy0 type dummy ip link set dummy0 mtu 60000 tc qdisc add dev dummy0 root teql0 The init-net teql0 device changes from MTU 1500 to 60000. A pfifo control on the same device leaves the MTU unchanged, and a direct MTU change on init-net teql0 is denied. The namespace needs CAP_NET_ADMIN; no init-net privilege is required. With the fix the attach fails with "Operation not supported" and the init-net MTU stays 1500. Fixes: 7316ae88c43d ("net_sched: make traffic control network namespace aware") Reported-by: shaos Link: https://lore.kernel.org/netdev/20261022144830.67948-1-shawnq1@163.com/ Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/SER-NSBD.v1.r2.20261031160050-3%40mojatatu.com Link: https://lore.kernel.org/netdev/179366641863.488856.17368571591466000274@kernel.org/ Cc: stable@vger.kernel.org Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim --- v1 -> v2: considers comments from Sashiko (nipa) on the repost2 posting: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/SER-NSBD.v1.r2.20261031160050-3%40mojatatu.com The cross-netns check ran before the "teql can only be used as root" check, so every case it did not catch was answered by that check, masking the assertion that tc-testing case 124e makes. The root-parent validation now runs first and the namespace check second; 4/4 adds a case that covers the namespace rejection on its own. net/sched/sch_teql.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index 70c948a26f80..dc21cd9704a2 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c @@ -200,6 +200,8 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt, struct Qdisc *first; unsigned long flags; + skb_queue_head_init(&q->q); + if (dev->hard_header_len > m->dev->hard_header_len) return -EINVAL; @@ -211,9 +213,12 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt, return -EOPNOTSUPP; } - q->m = m; + if (dev_net(dev) != dev_net(m->dev)) { + NL_SET_ERR_MSG_MOD(extack, "teql master is in a different network namespace"); + return -EOPNOTSUPP; + } - skb_queue_head_init(&q->q); + q->m = m; raw_spin_lock_irqsave(&m->slaves_lock, flags); first = rcu_dereference_protected(m->slaves, lockdep_is_held(&m->slaves_lock)); -- 2.43.0 Found by Sashiko (nipa) while reviewing the previous posting of this series: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/SER-NSBD.v2.r0.20261101171325-4%40mojatatu.com The issue: Case 124e attaches teql as a child qdisc and expects the attach to be refused. It requires nsPlugin, so its device sits in the test network namespace while the teql0 master is in init_net. Both the root-only check and the namespace check refuse the attach with -EOPNOTSUPP, and the case checks the exit code and an empty dump only, so it passes whichever check answers it. It no longer proves that a child attach is refused as such, and the case added in the previous posting covers the namespace check alone. The Fix: Run 124e in the initial namespace, creating its own device the way the other teql cases do, so that only the root-only check can refuse it. Attach a root qdisc from the test namespace in the second case, so that only the namespace check can refuse that one. Link: https://lore.kernel.org/netdev/179366641863.488856.17368571591466000274@kernel.org/ Link: https://lore.kernel.org/netdev/179366641986.488856.2193313144081673076@kernel.org/ Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim --- v2 -> v3: considers comments from Sashiko (nipa) on the v2 posting: https://lore.kernel.org/netdev/179366641986.488856.2193313144081673076@kernel.org/ Case 124e now runs in the initial namespace and creates its own device, so only the root-only rejection can answer it. The case added in v2 keeps the namespace rejection covered. Each case now witnesses exactly one check. v1 -> v2: new case covering the cross-netns attach rejection, following a Sashiko (nipa) review of the v2 posting of 3/4: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/SER-NSBD.v1.r2.20261031160050-3%40mojatatu.com .../tc-testing/tc-tests/qdiscs/teql.json | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json index 0179c57104ad..ab5d0881c007 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json @@ -90,12 +90,8 @@ "ets", "tbf" ], - "plugins": { - "requires": [ - "nsPlugin" - ] - }, "setup": [ + "$IP link add dev $DUMMY type dummy", "$TC qdisc add dev $DUMMY root handle 1: qfq", "$TC class add dev $DUMMY parent 1: classid 1:1 qfq weight 15 maxpkt 16384" ], @@ -104,7 +100,35 @@ "verifyCmd": "$TC -s -j qdisc ls dev $DUMMY parent 1:1", "matchJSON": [], "teardown": [ - "$TC qdisc del dev $DUMMY root handle 1:" + "$TC qdisc del dev $DUMMY root handle 1:", + "$IP link del dev $DUMMY" + ] + }, + { + "id": "6a06", + "name": "Reject TEQL attach from a different network namespace", + "category": [ + "qdisc", + "teql" + ], + "plugins": { + "requires": [ + "nsPlugin" + ] + }, + "setup": [], + "cmdUnderTest": "$TC qdisc add dev $DUMMY root handle 3: teql0", + "expExitCode": "2", + "verifyCmd": "$TC qdisc show dev $DUMMY", + "matchPattern": "qdisc teql0 3: root", + "matchCount": "0", + "teardown": [ + [ + "$TC qdisc del dev $DUMMY root handle 3:", + 0, + 1, + 2 + ] ] } ] -- 2.43.0