net/sched: sch_teql: fix header-cloned write and retry strip

Started by Jamal Hadi Salim on Nov 1, 2026 · 5 messages from 2 authors · Last reply Nov 3, 2026

Series

2 patches, 2 files

+23 −6

Subsystems (3)

Maintainers (7)

Show 3 more
COOLING12d SUPERSEDED

Status: Superseded by v3 (posted 2026-11-03). [go to v3]

Revision v2 (3 revisions archived).

Revisions (3)
  1. v1
  2. v2 current [diff against previous]
  3. v3 [diff against previous]

open the first message on its own page

  1. [PATCH net v2 1/2] net/sched: sch_teql: unshare the header before writing and fix retry strip
    Revisions and related patches
    Revisions (3)
    1. v1
    2. v2 current [diff against previous]
    3. v3 [diff against previous]
  2. [PATCH net v2 2/2] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path
    Revisions and related patches
    Revisions (3)
    1. v1
    2. v2 current [diff against previous]
    3. v3 [diff against previous]
Message details and related content
Two pre-existing defects on the teql transmit path, both around
teql_master_xmit() -> teql_resolve().

Patch 1 makes the headroom private before the slave's header write and
pulls back only the header that slave added, so a header-cloned skb is not
corrupted and a userspace-supplied link header survives a retry.

Patch 2 moves skb->dev = slave ahead of teql_resolve() so a skb parked on
a slave's neighbour arp_queue names the device whose neighbour took it, and
restores skb->dev at the arp-queue reinjection point so the parked skb goes
back through the master and leaves with a link header.

Both are follow-ups to commit dc4b95b8fee9 ("net/sched: sch_teql: restore
skb->dev on the slave failure path") by Victor Nogueira.

The pre-existing teql issues reported alongside this series are fixed
separately, not here.  In particular, the lower-qdisc drop use-after-free
(`NETDEV_TX_OK` vs `dev_xmit_complete()`) is fixed by:
https://lore.kernel.org/netdev/QDISC-Y0BY.v2.r0.20261024060625-2@mojatatu.com/

Changes v1-> v2:
- patch1, no code changes.
- patch 2 limits the reinjection restore to a top-level neighbour
whose device has no header_ops, the shaper/eql/sch_teql class.
Commit message also describes how a master is freed (sashikos)

Jamal Hadi Salim (2):
  net/sched: sch_teql: unshare the header before writing and fix retry
    strip
  net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

 net/core/neighbour.c |  3 +++
 net/sched/sch_teql.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 6 deletions(-)

-- 
2.43.0

[PATCH net v2 1/2] net/sched: sch_teql: unshare the header before writing and fix retry strip

Message details and related content
The issue:
teql_master_xmit() writes the slave's link header into the skb in
teql_resolve() and on retry pulls it back with __skb_pull().  Two bugs:

1. When the skb's header is cloned (e.g. a tc-mirred action on a
   physical device's clsact egress redirects to the teql master), the
   write corrupts the other clone.  Call skb_cow_head() first.

2. The pull always removes skb_network_offset() bytes.  For an
   AF_PACKET/SOCK_RAW frame with no dst entry, teql_resolve() adds no
   header, so the retry strips the user-supplied one.  Pull back only
   the length this slave added.

The Fix:
Track the added length per iteration; a header-cloned skb is unshared
before the write and an AF_PACKET frame retries with its header intact.

Conditions to recreate the bug:
CONFIG_NET_SCH_TEQL=y and CONFIG_VETH=y, run as root. A teql master with
two veth slaves, the first slave returning NETDEV_TX_BUSY without
consuming the skb so that teql retries the frame on the second one:

  ip link add vethBAD type veth peer name vethBADp
  ip link add vethGOOD type veth peer name vethGOODp
  ip link set vethBAD up;  ip link set vethBADp up
  ip link set vethGOOD up; ip link set vethGOODp up
  tc qdisc add dev vethBAD root teql0
  tc qdisc add dev vethGOOD root teql0
  ip link set teql0 up

Send a SOCK_RAW frame that carries its own link header on teql0 and
capture it on the second slave's peer. A veth transmit does not return
NETDEV_TX_BUSY on its own; to hold the skb pending this reproduction used
a test-only IFF_DEBUG accelerator in veth_xmit(), which is not part of
this patch and was applied to both the unfixed and the fixed build.

On the unfixed tree the captured frame arrives with its header stripped
(176 of the 208 bytes sent, starting at the payload) because the retry
pulls skb_network_offset() bytes while this slave added none. With the
patch the frame arrives intact.

17 more lines

diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index 70c948a26f80..ed8faa848f18 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -257,7 +257,7 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt,
 static int
 __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
 	       struct net_device *dev, struct netdev_queue *txq,
-	       struct dst_entry *dst)
+	       struct dst_entry *dst, int *hlen)
 {
 	struct neighbour *n;
 	int err = 0;
@@ -288,15 +288,24 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
 	}
 
 	if (neigh_event_send(n, skb_res) == 0) {
+		int off = skb_network_offset(skb);
 		char haddr[MAX_ADDR_LEN];
 
 		neigh_ha_snapshot(haddr, n, dev);
+		/* Unshare the header before dev_hard_header() writes to it. */
+		if (skb_cow_head(skb, LL_RESERVED_SPACE(dev)) < 0) {
+			err = -ENOMEM;
+			goto out;
+		}
 		if (dev_hard_header(skb, dev, ntohs(skb_protocol(skb, false)),
 				    haddr, NULL, skb->len) < 0)
 			err = -EINVAL;
+		/* The bytes prepended above skb->data, pulled back on retry. */
+		*hlen = skb_network_offset(skb) - off;
 	} else {
 		err = (skb_res == NULL) ? -EAGAIN : 1;
 	}
+out:
 	neigh_release(n);
 	return err;
 }
@@ -304,11 +313,13 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
 static inline int teql_resolve(struct sk_buff *skb,
 			       struct sk_buff *skb_res,
 			       struct net_device *dev,
-			       struct netdev_queue *txq)
+			       struct netdev_queue *txq,
+			       int *hlen)
 {
 	struct dst_entry *dst = skb_dst(skb);
 	int res;
 
+	*hlen = 0;
 	if (rcu_access_pointer(txq->qdisc) == &noop_qdisc)
 		return -ENODEV;
 
@@ -316,7 +327,7 @@ static inline int teql_resolve(struct sk_buff *skb,
 		return 0;
 
 	rcu_read_lock();
-	res = __teql_resolve(skb, skb_res, dev, txq, dst);
+	res = __teql_resolve(skb, skb_res, dev, txq, dst, hlen);
 	rcu_read_unlock();
 
 	return res;
@@ -330,6 +341,7 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct Qdisc *start, *q;
 	unsigned long flags;
 	int nores;
+	int hlen;
 	int busy;
 
 restart:
@@ -356,7 +368,7 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
 			continue;
 		}
 
-		switch (teql_resolve(skb, skb_res, slave, slave_txq)) {
+		switch (teql_resolve(skb, skb_res, slave, slave_txq, &hlen)) {
 		case 0:
 			if (__netif_tx_trylock(slave_txq)) {
 				unsigned int length = qdisc_pkt_len(skb);
@@ -403,8 +415,10 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
 			nores = 1;
 			break;
 		}
+		/* Pull back only the header this slave added. */
+		if (hlen > 0)
+			__skb_pull(skb, hlen);
 		skb->dev = dev;
-		__skb_pull(skb, skb_network_offset(skb));
 	} while ((q = rcu_dereference(NEXT_SLAVE(q))) != start);
 
 	if (nores && skb_res == NULL) {
-- 
2.43.0

[PATCH net v2 2/2] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

Message details and related content
This is a follow-up to commit dc4b95b8fee9 ("net/sched: sch_teql: restore
skb->dev on the slave failure path") by Victor Nogueira, which covered the
slave side of the same mismatch.

The issue:
teql_master_xmit() sets skb->dev = slave only right before the slave's
ndo_start_xmit(). If the slave's neighbour is unresolved, teql_resolve()
parks the skb on the slave's arp_queue with skb->dev still naming the teql
master. teql_exit() frees the masters on module unload and a slave can
outlive them, so a queued skb can be reinjected through freed memory.

The Fix:
Set skb->dev = slave before teql_resolve() so the parked skb names the
device whose neighbour owns it, and restore skb->dev = n1->dev at the
neigh_update_process_arp_queue() reinjection point so the skb goes back
through teql_master_xmit() instead of leaving headerless.

The restore is limited to a top-level neighbour whose device has no
header_ops, which is the shaper/eql/sch_teql class: those devices get
neigh_direct_output() from arp_constructor() and ndisc_constructor(), an
output that transmits on skb->dev and builds no link header, so the skb
has to be moved back.

A forward that steers the skb to another device, nft fwd ... neigh or
bpf_redirect_neigh() with explicit nexthop parameters, parks it with the
dst of the original route still attached. The drain looks the neighbour
up from that dst and not from the forwarding device, so when the original
route is itself a headerless device this gate matches there and the skb
goes back out the original device, running its egress hook a second time.
Those forwards supply their own device and nexthop and do not consult the
retained dst, so dropping it at those two sites is where that is fixed;
that is a separate change to the producers, not part of this series.

Some context:
Only a module unload frees a master. teql_master_setup() installs no
rtnl_link_ops and default_device_exit_net() moves the device to init_net
when its namespace exits, so the window is a parked skb plus CAP_SYS_MODULE
on an unloaded sch_teql.

Conditions to recreate the bug:

42 more lines

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index d6e9c7c59a89..541cf699abae 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1339,6 +1339,9 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh)
 			if (n2)
 				n1 = n2;
 		}
+		/* headerless outputs (teql, shaper) transmit on skb->dev */
+		if (!n1->dev->header_ops)
+			skb->dev = n1->dev;
 		READ_ONCE(n1->output)(n1, skb);
 		if (n2)
 			neigh_release(n2);
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index ed8faa848f18..4eac1f9c8ddf 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -368,13 +368,13 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
 			continue;
 		}
 
+		skb->dev = slave;
 		switch (teql_resolve(skb, skb_res, slave, slave_txq, &hlen)) {
 		case 0:
 			if (__netif_tx_trylock(slave_txq)) {
 				unsigned int length = qdisc_pkt_len(skb);
 				int rc = NETDEV_TX_BUSY;
 
-				skb->dev = slave;
 				if (!netif_xmit_frozen_or_stopped(slave_txq))
 					rc = netdev_start_xmit(skb, slave, slave_txq, false);
 				__netif_tx_unlock(slave_txq);
-- 
2.43.0

Re: [PATCH net v2 2/2] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

Message details and related content
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 2 · Low: 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 new gate in neigh_update_process_arp_queue()
  (net/core/neighbour.c:1343-1344), `if (!n1->dev->header_ops) skb->dev…
- [Medium] teql_master_xmit() now sets skb->dev = slave before
  teql_resolve() (sch_teql.c:371).
- [Low] The commit message's reproducer cannot show the use-after-free
  the patch says it fixes.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  teql_qdisc_init() (net/sched/sch_teql.c:194-253) never checks that the…

--

net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

This patch moves skb->dev = slave ahead of teql_resolve(). An skb parked
on the slave's arp_queue then names the slave instead of the teql master.
It also restores skb->dev = n1->dev in neigh_update_process_arp_queue()
when the top-level neighbour's device has no header_ops, so the skb goes
back through teql_master_xmit().

Link: https://lore.kernel.org/netdev/20260824115928.4099988-1-victor@mojatatu.com/
Link: https://lore.kernel.org/netdev/20261026160747.283702-1-horms@kernel.org/
Link: https://lore.kernel.org/netdev/20261031165925.780930-1-horms@kernel.org/
Conditions to recreate the bug:
CONFIG_NET_SCH_TEQL=y, CONFIG_VETH=y, run as root. Create a veth pair,
make one end a teql slave, give the master an address and a route, flush
the slave's neighbour entry and send one packet:
[ ... ]
On the unfixed tree the skb is parked on v0's arp_queue while skb->dev
still names teql0, so the reinjection can reach a master that teql_exit()
has freed.
[Severity: Low]
Can this recipe reach the use-after-free it describes?

With CONFIG_NET_SCH_TEQL=y, teql_exit() is __exit and never runs, so no
master is ever freed:

net/sched/sch_teql.c:teql_exit() {
    ...
		unregister_qdisc(&master->qops);
		unregister_netdev(master->dev);
		free_netdev(master->dev);
    ...
}

teql_master_setup() installs no rtnl_link_ops, so "ip link del teql0"
can't free the master either.

Building sch_teql as a module doesn't change this. teql_master_setup()
sets ops->owner = THIS_MODULE, and qdisc_lookup_ops() takes a module
reference through bpf_try_module_get() for each slave qdisc. rmmod
therefore fails while the slave qdisc on v0 exists.

To reach a freed master you seem to need sch_teql as a module, then
"tc qdisc del dev v0 root", then "rmmod sch_teql". All of this has to
happen while the skb is still parked on v0's arp_queue. None of these
steps are in the recipe. Could the recipe be updated to match?

Also, the message only names the reinjection path. Commit dc4b95b8fee9
showed this KASAN-confirmed path for a stale skb->dev:

neigh_invalidate()->arp_error_report()->ipv4_link_failure()->__icmp_send()

Here __icmp_send() reads skb_in->dev. This patch covers that path too,
because the parked skb now names the slave. Would it be worth saying so
in the message?
quoted hunk
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index d6e9c7c59a892..541cf699abae4 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1339,6 +1339,9 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh)
 			if (n2)
 				n1 = n2;
 		}
+		/* headerless outputs (teql, shaper) transmit on skb->dev */
+		if (!n1->dev->header_ops)
+			skb->dev = n1->dev;
 		READ_ONCE(n1->output)(n1, skb);
[Severity: Medium]
Is this check narrow enough to match only teql?

n1 comes from dst_neigh_lookup_skb() on the skb's retained dst. It does
not come from neigh, the neighbour the skb was parked on. Nothing checks
that neigh->dev is a teql slave of n1->dev, so any headerless route
device matches.

Two producers park the skb on another device Y's neighbour while keeping
the original route's dst:

- nft "fwd ... neigh", via nft_fwd_neigh_eval(). nft_fwd_validate()
  allows it at NF_NETDEV_EGRESS.
- bpf_redirect_neigh() with an explicit nexthop.
  __bpf_redirect_neigh_v4/v6 only replace the dst when nh == NULL.

Suppose such a forward runs at the egress hook of a headerless device X
and the neighbour on Y is unresolved:

__neigh_event_send()
  skb_dst_force(skb)                    /* dst->dev is still X */
  queue on Y's arp_queue

neigh_update_process_arp_queue()
  n1 = dst_neigh_lookup_skb(dst, skb)   /* X's neighbour */
  skb->dev = n1->dev                    /* X */
  neigh_direct_output()->dev_queue_xmit(X)

nf_skip_egress was reset after sch_handle_egress(), so nf_hook_egress()
runs X's egress chain a second time.

The forward then runs twice. nft_fwd_neigh_eval() decrements TTL again,
so a TTL=2 packet that should leave Y with TTL 1 is dropped here on the
second pass:

		if (iph->ttl <= 1) {
			verdict = NF_DROP;
			goto out;
		}

22 more lines

quoted hunk
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index ed8faa848f184..4eac1f9c8ddf6 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -368,13 +368,13 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
 			continue;
 		}
 
+		skb->dev = slave;
 		switch (teql_resolve(skb, skb_res, slave, slave_txq, &hlen)) {
[Severity: Medium]
What happens to an skb parked here if the neighbour then fails?

In case 1 of teql_resolve(), teql_master_xmit() returns before the
skb->dev = dev restore at the bottom of the loop. The skb therefore sits
on the slave's arp_queue with skb->dev = slave.

Only neigh_update_process_arp_queue() was changed to put the master back.
The other consumer of the queue passes the skb on unchanged:

net/core/neighbour.c:neigh_invalidate() {
    ...
	while (neigh->nud_state == NUD_FAILED &&
	       (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
		write_unlock(&neigh->lock);
		neigh->ops->error_report(neigh, skb);
    ...
}

For IPv6 the call chain is:

ndisc_error_report()->dst_link_failure()->ip6_link_failure()->
icmpv6_send()->icmp6_send()

icmp6_send() takes its context from skb->dev:

	net = dev_net_rcu(skb->dev);
	...
		iif = l3mdev_master_ifindex(skb->dev);

It also uses ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0), and
icmp6_iif(skb) for link-local sources. That iif becomes flowi6_oif for
the route lookup of the error.

These values used to come from the teql master. Now they come from the
slave, which changes the result in these setups:

- teql0 in a VRF with the slave outside it: the ICMPv6 Destination
  Unreachable is routed in the main table instead of the VRF table.

50 more lines

Re: [PATCH net v2 2/2] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

Message details and related content
On Mon, Nov 2, 2026 at 11:30 AM [off-list ref] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 2 · Low: 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 new gate in neigh_update_process_arp_queue()
  (net/core/neighbour.c:1343-1344), `if (!n1->dev->header_ops) skb->dev…
This is by design. Covers every headerless neigh_direct_output user.
Nothing to fix.
- [Medium] teql_master_xmit() now sets skb->dev = slave before
  teql_resolve() (sch_teql.c:371).
No (that renames the master again. Nothing to fix.
- [Low] The commit message's reproducer cannot show the use-after-free
  the patch says it fixes.
Sigh. I will send a v3 to fix the messaging. Dammit, dont whine about
something else after you rat bastard.
pw-bot:cr
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  teql_qdisc_init() (net/sched/sch_teql.c:194-253) never checks that the…
Separate thread. see:
 https://lore.kernel.org/netdev/SER-NSBD.v2.r0.20261101171325-3@mojatatu.com/

cheers,
jamal
--

net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

This patch moves skb->dev = slave ahead of teql_resolve(). An skb parked
on the slave's arp_queue then names the slave instead of the teql master.
It also restores skb->dev = n1->dev in neigh_update_process_arp_queue()
when the top-level neighbour's device has no header_ops, so the skb goes
back through teql_master_xmit().

Link: https://lore.kernel.org/netdev/20260824115928.4099988-1-victor@mojatatu.com/
Link: https://lore.kernel.org/netdev/20261026160747.283702-1-horms@kernel.org/
Link: https://lore.kernel.org/netdev/20261031165925.780930-1-horms@kernel.org/
quoted
Conditions to recreate the bug:
CONFIG_NET_SCH_TEQL=y, CONFIG_VETH=y, run as root. Create a veth pair,
make one end a teql slave, give the master an address and a route, flush
the slave's neighbour entry and send one packet:
[ ... ]
quoted
On the unfixed tree the skb is parked on v0's arp_queue while skb->dev
still names teql0, so the reinjection can reach a master that teql_exit()
has freed.
[Severity: Low]
Can this recipe reach the use-after-free it describes?

With CONFIG_NET_SCH_TEQL=y, teql_exit() is __exit and never runs, so no
master is ever freed:

net/sched/sch_teql.c:teql_exit() {
    ...
                unregister_qdisc(&master->qops);
                unregister_netdev(master->dev);
                free_netdev(master->dev);
    ...
}

teql_master_setup() installs no rtnl_link_ops, so "ip link del teql0"

195 more quoted lines

Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help