* [PATCH net v6 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip
2026-11-19 12:40 [PATCH net v6 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact Jamal Hadi Salim
@ 2026-11-19 12:40 ` Jamal Hadi Salim
2026-11-23 13:01 ` netdev-bot+sashiko
2026-11-19 12:40 ` [PATCH net v6 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
2026-11-19 12:40 ` [PATCH net v6 3/3] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path Jamal Hadi Salim
2 siblings, 1 reply; 7+ messages in thread
From: Jamal Hadi Salim @ 2026-11-19 12:40 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Victor Nogueira, Jiri Pirko, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, stable,
sashiko-bot
This is a followup of commit dc4b95b8fee9 ("net/sched: sch_teql: restore
skb->dev on the slave failure path") as reported by Sashiko.
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:
Unshare the header before the neighbour is asked to send the skb, so the
skb is private whether the neighbour writes the link header at once or
parks it on its arp_queue and writes it when the entry resolves. Start
every attempt from the network header, as neigh_resolve_output() does,
so an skb that arrives with link-layer bytes in front of its network
header is given one link header rather than a second one. Track the
added length per iteration; 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.
The shared headroom case needs a second reference to the skb to survive
the transmit. A PF_PACKET tap on the master whose socket is never
drained keeps one alive; a kprobe on eth_header then reports cloned=1
without the patch and cloned=0 with it. The parked path needs the
unshare before the queue: a tc-mirred mirror on a physical device's
clsact egress parks the clone on the teql slave's unresolved neighbour,
so hold the original frame in a netem delay on that device and then
resolve the slave's neighbour through a changed lladdr. Without the
unshare the arp-queue drain writes the new link header over the original
frame's first bytes, and a listener on the peer sees a frame addressed
to the new lladdr instead of to itself; with the patch the queued frame
keeps its own destination address.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260824115928.4099988-1-victor@mojatatu.com
Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v4.r0.20261111094338-1%40mojatatu.com
Link: https://lore.kernel.org/netdev/20260824115928.4099988-1-victor@mojatatu.com/
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
Cc: stable@vger.kernel.org
Reviewed-by: Victor Nogueira <victor@mojatatu.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
v5 -> v6:
- every attempt now starts from the network header, as
neigh_resolve_output() does, so an skb that arrives with link-layer
bytes in front of its network header gets one link header rather than
a second one. The header length is recorded as the offset the
neighbour built, and only that much is pulled back on retry.
Considered comments from Sashiko (nipa).
net/sched/sch_teql.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index dc21cd9704a2..44730a5e8917 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -262,7 +262,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;
@@ -292,6 +292,18 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
n = mn;
}
+ /* Unshare the head before the neighbour can write or queue it. */
+ if (skb_cow_head(skb, LL_RESERVED_SPACE(dev)) < 0) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ /* Each attempt starts from the network header, as
+ * neigh_resolve_output() does.
+ */
+ if (skb_network_offset(skb) > 0)
+ __skb_pull(skb, skb_network_offset(skb));
+
if (neigh_event_send(n, skb_res) == 0) {
char haddr[MAX_ADDR_LEN];
@@ -299,9 +311,12 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
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);
} else {
err = (skb_res == NULL) ? -EAGAIN : 1;
}
+out:
neigh_release(n);
return err;
}
@@ -309,11 +324,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;
@@ -321,7 +338,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;
@@ -335,6 +352,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:
@@ -361,7 +379,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);
@@ -408,8 +426,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.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net v6 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip
2026-11-19 12:40 ` [PATCH net v6 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip Jamal Hadi Salim
@ 2026-11-23 13:01 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 13:01 UTC (permalink / raw)
To: jhs
Cc: netdev, victor, jiri, davem, edumazet, kuba, pabeni, horms,
stable, sashiko-bot
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] The new comment in __teql_resolve() ("Each attempt starts from
the network header, as neigh_resolve_output() does.") and the matching…
--
net/sched: sch_teql: unshare the header before writing and fix retry strip
This patch calls skb_cow_head() in __teql_resolve() before the neighbour
can write or queue the skb, so a cloned header is not corrupted. It also
pulls the skb to its network header before resolving. On retry,
teql_master_xmit() now pulls back only the link header length the slave
added.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v4.r0.20261111094338-1%40mojatatu.com
Link: https://lore.kernel.org/netdev/20260824115928.4099988-1-victor@mojatatu.com/
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
> diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
> index dc21cd9704a25..44730a5e89178 100644
> --- a/net/sched/sch_teql.c
> +++ b/net/sched/sch_teql.c
[ ... ]
> @@ -292,6 +292,18 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
> n = mn;
> }
>
> + /* Unshare the head before the neighbour can write or queue it. */
> + if (skb_cow_head(skb, LL_RESERVED_SPACE(dev)) < 0) {
> + err = -ENOMEM;
> + goto out;
> + }
> +
> + /* Each attempt starts from the network header, as
> + * neigh_resolve_output() does.
> + */
> + if (skb_network_offset(skb) > 0)
> + __skb_pull(skb, skb_network_offset(skb));
> +
> if (neigh_event_send(n, skb_res) == 0) {
[Severity: Low]
Is this comment accurate? The commit message makes the same claim:
"Start every attempt from the network header, as neigh_resolve_output()
does"
The pull only runs when three things hold: the slave has header_ops, the
skb has a dst, and the neighbour lookup succeeds. teql_resolve() still
returns early, before it calls __teql_resolve():
net/sched/sch_teql.c:teql_resolve() {
...
if (!dev->header_ops || !dst)
return 0;
...
}
Also, __teql_resolve() returns -ENOENT or PTR_ERR(mn) before it reaches
the pull.
Take an skb that has a dst and skb_network_offset() > 0. One example is
the tc-mirred redirect from a physical device's clsact egress that the
commit message mentions.
If a slave without header_ops is tried first, it transmits the skb with
the incoming link-layer bytes still in front of the network header.
If a header_ops slave was tried earlier in the same round and failed or
was busy, that same slave gets the skb starting at the network header.
So what goes on the wire still depends on slave order.
The comparison with neigh_resolve_output() is also not exact. That
function only pulls once the neighbour has resolved:
net/core/neighbour.c:neigh_resolve_output() {
if (!neigh_event_send(neigh, skb)) {
...
do {
__skb_pull(skb, skb_network_offset(skb));
...
}
Here the pull runs before neigh_event_send(), whatever that returns. On
the -EAGAIN and queued paths the leading bytes are dropped while *hlen
stays 0.
The retry comment in teql_master_xmit() is accurate about the header
that was pushed:
/* Pull back only the header this slave added. */
if (hlen > 0)
__skb_pull(skb, hlen);
However, the link-layer bytes that the earlier pull in __teql_resolve()
removed are never restored. So the skb does not go back to the state it
was in before the attempt, and neither comment says so.
The old unconditional retry pull already behaved in this order-dependent
way, so this is only about the wording. Could the comments and the commit
message be changed to describe what the code actually does?
> @@ -299,9 +311,12 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v6.r0.20261119070330%40mojatatu.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v6 2/3] net: neighbour: reinject a parked skb through a headerless output device
2026-11-19 12:40 [PATCH net v6 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact Jamal Hadi Salim
2026-11-19 12:40 ` [PATCH net v6 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip Jamal Hadi Salim
@ 2026-11-19 12:40 ` Jamal Hadi Salim
2026-11-23 13:01 ` netdev-bot+sashiko
2026-11-19 12:40 ` [PATCH net v6 3/3] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path Jamal Hadi Salim
2 siblings, 1 reply; 7+ messages in thread
From: Jamal Hadi Salim @ 2026-11-19 12:40 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, David Ahern, Ido Schimmel, Victor Nogueira,
Jiri Pirko, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Kuniyuki Iwashima, Simon Horman, bpf, stable
The issue:
neigh_update_process_arp_queue() drains a neighbour's arp_queue and
reinjects every skb through READ_ONCE(n1->output)(n1, skb), where n1 is
the top-level neighbour re-looked-up from the skb's dst, not the neighbour
the skb was queued on. skb->dev is whatever the producer left there.
Note: skb->dev and n1->dev are not guaranteed to be equal.
When n1->dev has no header_ops, arp_constructor() and ndisc_constructor()
install neigh_direct_output(), a plain dev_queue_xmit() that transmits on
skb->dev and builds no link header. Such an output sends the skb out
whatever device skb->dev names, not out n1->dev, so a producer that
parked the skb naming a lower device has it leave without the link header
its own transmit path builds.
sch_teql is the producer that hits this: it parks the skb on the slave's
neighbour while the top-level neighbour is the master's, so skb->dev and
n1->dev differ and the reinjection has to come back through the master to
leave with a header. It names the slave on purpose, so that a parked skb
does not outlive the master it came from.
This was split out of the sch_teql fix on review, so that the neighbour
restore carries its own commit log and its own Cc set. It is the first
half of that pair and is applied first. The behaviour it describes
exists once the second half, "net/sched: sch_teql: keep skb->dev
consistent on the arp-queue path", moves skb->dev = slave ahead of
teql_resolve(): until then the parked skb still names the master, so the
assignment is a no-op and the recipe below does not reproduce on this
patch alone. The two are taken together.
The Fix:
Put skb->dev back to n1->dev before the output call when that device
builds no link header, so a headerless output transmits on the device the
neighbour belongs to, whatever the producer left in skb->dev.
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. 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.
Conditions to recreate the bug:
CONFIG_NET_SCH_TEQL=m and CONFIG_VETH=y, run as root. This is the
neighbour half of the sch_teql parked-skb fix, reached once the sch_teql
half parks the skb naming the slave: 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:
ip link add v0 type veth peer name v0p
ip link set v0 up; ip link set v0p up
tc qdisc add dev v0 root teql0
ip link set teql0 up
ip addr add 10.0.0.1/24 dev teql0
ip route add 10.0.0.99/32 dev teql0
ip neigh flush dev v0
ping -I teql0 -c 1 10.0.0.99
The packet parks on v0's arp_queue. When the solicitation resolves,
neigh_update_process_arp_queue() reinjects it; without this change it
leaves v0 directly, with no link header, and never reaches the peer.
The window that frees the master, and the unload recipe that shows it,
are in the sch_teql patch.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
Cc: stable@vger.kernel.org
Reviewed-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
v5 -> v6:
- the commit log names the sch_teql half this neighbour restore is
applied before. Considered comments from Sashiko (nipa).
net/core/neighbour.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index ae2db3912454..d36d86cfc441 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1342,6 +1342,9 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh)
if (n2)
n1 = n2;
}
+ /* headerless output transmits on skb->dev, not n1->dev */
+ if (!n1->dev->header_ops)
+ skb->dev = n1->dev;
READ_ONCE(n1->output)(n1, skb);
if (n2)
neigh_release(n2);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net v6 2/3] net: neighbour: reinject a parked skb through a headerless output device
2026-11-19 12:40 ` [PATCH net v6 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
@ 2026-11-23 13:01 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 13:01 UTC (permalink / raw)
To: jhs
Cc: netdev, victor, jiri, davem, edumazet, kuba, pabeni, horms,
stable, sashiko-bot
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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:1345-1347) trusts the neighbour found through…
- [Low] The patch carries 'Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")' and
'Cc: stable', but the commit message says it fixes nothing reachable…
- [Low] The new comment ('headerless output transmits on skb->dev, not
n1->dev') and the commit message ('Such an output sends the skb out…
--
net: neighbour: reinject a parked skb through a headerless output device
This commit changes neigh_update_process_arp_queue() so that, before the
output call, skb->dev is set back to n1->dev when n1->dev has no
header_ops. It is the neighbour half of a pair with the sch_teql patch
"net/sched: sch_teql: keep skb->dev consistent on the arp-queue path",
which moves skb->dev = slave ahead of teql_resolve().
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
> exists once the second half, "net/sched: sch_teql: keep skb->dev
> consistent on the arp-queue path", moves skb->dev = slave ahead of
> teql_resolve(): until then the parked skb still names the master, so the
> assignment is a no-op and the recipe below does not reproduce on this
> patch alone. The two are taken together.
[ ... ]
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
> Cc: stable@vger.kernel.org
[Severity: Low]
Do the Fixes: and Cc: stable tags fit this patch when it is applied alone?
In this tree teql_master_xmit() in net/sched/sch_teql.c calls teql_resolve()
before it sets 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;
So an skb parked by __teql_resolve() still names the master. The master has
no header_ops, so n1->dev == skb->dev and the new assignment does nothing
for teql.
The stable tag carries no prerequisite note. Could Fixes-driven stable
selection pull this into a tree where the sch_teql companion patch isn't
applied? In that tree the only visible effect would be the nft fwd /
bpf_redirect_neigh() side effect that the commit message describes.
Would a stable prerequisite annotation naming the sch_teql patch help here?
> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> index ae2db3912454a..d36d86cfc441c 100644
> --- a/net/core/neighbour.c
> +++ b/net/core/neighbour.c
> @@ -1342,6 +1342,9 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh)
> if (n2)
> n1 = n2;
> }
> + /* headerless output transmits on skb->dev, not n1->dev */
[Severity: Low]
Is this comment accurate? It reads as if only the headerless output
transmits on skb->dev.
neigh_resolve_output() and neigh_connected_output() use neigh->dev only for
dev_hard_header(), and then call dev_queue_xmit(skb):
neigh_resolve_output():
if (err >= 0)
rc = dev_queue_xmit(skb);
neigh_connected_output():
if (err >= 0)
err = dev_queue_xmit(skb);
Both of these transmit on skb->dev too, the same as neigh_direct_output().
The real difference is whether n1->dev's link header gets written, not which
device sends the frame.
Could the comment, and the matching sentence in the commit message ("Such
an output sends the skb out whatever device skb->dev names, not out
n1->dev"), say that instead?
> + if (!n1->dev->header_ops)
> + skb->dev = n1->dev;
[Severity: Medium]
Can this gate send a redirected skb back out the original device, so that
its egress hook runs a second time?
Two producers steer an skb to another device but leave the original route's
dst attached. nft_fwd_neigh_eval() in net/netfilter/nft_fwd_netdev.c does
not drop the dst:
skb->dev = dev;
skb_clear_tstamp(skb);
nf_dev_xmit_recursion_inc();
neigh_xmit(neigh_table, dev, addr, skb);
__bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6() in net/core/filter.c
replace the dst only in the !nh branch:
skb_dst_drop(skb);
skb_dst_set(skb, &rt->dst);
Suppose one of these runs on egress of a device A that has NULL
header_ops, such as the teql master (teql_master_setup() never sets
header_ops). It redirects to an Ethernet device B whose neighbour is
unresolved:
neigh_resolve_output() on B's neighbour
__neigh_event_send()
skb_dst_force(skb); /* A's dst is kept */
__skb_queue_tail(&neigh->arp_queue, skb);
B resolves:
neigh_update_process_arp_queue()
n2 = dst_neigh_lookup_skb(dst, skb); /* A's neighbour */
if (!n1->dev->header_ops)
skb->dev = n1->dev; /* skb->dev = A */
neigh_direct_output()
dev_queue_xmit() /* A's egress hook runs again */
For nft fwd, TTL/hop_limit is lowered a second time. A packet that arrived
with TTL 2 would then hit the iph->ttl <= 1 drop. Stateful nft expressions
and BPF map side effects would also run twice.
If the second pass does not redirect (a quota or limit is used up, or a
conditional rule no longer matches), the packet leaves via A instead of B.
The commit message acknowledges this and calls the producer fix "a
separate change to the producers". That change doesn't appear in this
series: after this commit only sch_teql.c changes, and nft_fwd_netdev.c and
filter.c still keep the dst. With Cc: stable, does this patch ship that
behaviour on its own?
Common L3 tunnels such as ipip, sit, ip6tnl, vti, L3 tun and wireguard set
ip_tunnel_header_ops, so the gate does not match them. Before this patch the
same path was already broken in a different way: the frame left B without a
link header.
> READ_ONCE(n1->output)(n1, skb);
> if (n2)
> neigh_release(n2);
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v6.r0.20261119070330%40mojatatu.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v6 3/3] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path
2026-11-19 12:40 [PATCH net v6 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact Jamal Hadi Salim
2026-11-19 12:40 ` [PATCH net v6 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip Jamal Hadi Salim
2026-11-19 12:40 ` [PATCH net v6 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
@ 2026-11-19 12:40 ` Jamal Hadi Salim
2026-11-23 13:01 ` netdev-bot+sashiko
2 siblings, 1 reply; 7+ messages in thread
From: Jamal Hadi Salim @ 2026-11-19 12:40 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Victor Nogueira, Jiri Pirko, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, stable,
sashiko-bot
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.
The parked skb has a second consumer: when the neighbour fails instead of
resolving, neigh_invalidate() hands it to error_report() and
dst_link_failure(), which read skb->dev to report the failure, so it names
the slave on that path too.
A parked skb is reinjected by neigh_update_process_arp_queue(), and a
device that transmits straight on skb->dev has to be handed its skb back
there. That is the previous patch, "net: neighbour: reinject a parked
skb through a headerless output device", which has to be applied before
this one: without it the parked packet leaves the slave directly, with
no link header, because teql_master_xmit() has already pulled it. The
helper it changes, neigh_update_process_arp_queue(), was split out of
__neigh_update() by commit 705ef89ac986 ("net: core: neighbour: Extract
ARP queue processing to a helper function"), so the previous patch does
not apply to stable trees older than that.
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.
The error now names the slave, so it is also routed for the slave: IPv4
takes the ICMP output interface from icmp_get_route_lookup_dev() and IPv6
from skb->dev. A teql master enslaved to a VRF had its host-unreachable
looked up in the VRF and now has it looked up in the main tables with
oif 0. The parked skb cannot keep naming the master there, because
naming it is what lets teql_exit() free it under this path.
Conditions to recreate the bug:
CONFIG_NET_SCH_TEQL=m and 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:
ip link add v0 type veth peer name v0p
ip link set v0 up; ip link set v0p up
tc qdisc add dev v0 root teql0
ip link set teql0 up
ip addr add 10.0.0.1/24 dev teql0
ip route add 10.0.0.99/32 dev teql0
ip neigh flush dev v0
ping -I teql0 -c 1 10.0.0.99 &
sleep 1
The skb waits on v0's arp_queue while the solicitation is in flight.
Remove the qdisc, which drops the module reference it holds, and unload
the module while the skb still waits:
tc qdisc del dev v0 root
rmmod sch_teql
teql_exit() frees teql0 there. When the solicitation then fails,
neigh_invalidate() drains the queue through arp_error_report() and
ipv4_link_failure(), whose __icmp_send() reads skb_in->dev; that is the
freed master before this patch and v0 after it. A resolved neighbour
drains the same queue through neigh_update_process_arp_queue().
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.
The park and the headerless delivery reproduce without the unload.
Freeing the master while the skb waits needs sch_teql built as a module,
as above.
An unfixed kernel reports this when the timer drains that queue:
==================================================================
BUG: KASAN: slab-use-after-free in __icmp_send+0x3f9/0x1680
Read of size 4 at addr ffff8880039bc0b0 by task swapper/3/0
CPU: 3 UID: 0 PID: 0 Comm: swapper/3
Call Trace:
<IRQ>
...
__icmp_send+0x3f9/0x1680
ipv4_link_failure+0x3a0/0x5b0
arp_error_report+0x5b/0xc0
neigh_invalidate+0x125/0x240
neigh_timer_handler+0x47d/0x750
call_timer_fn+0x138/0x410
...
Allocated by task 307:
alloc_netdev_mqs+0x81/0x930
...
Freed by task 335:
netdev_release+0x45/0x60
device_release+0x7d/0x120
kobject_put+0xf3/0x2e0
put_device+0x13/0x30
free_netdev+0x3b3/0x4a0
...
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824115928.4099988-1-victor@mojatatu.com
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/
Link: https://lore.kernel.org/netdev/179363700308.3131.11778179538290251434@kernel.org/
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
Cc: stable@vger.kernel.org
Reviewed-by: Victor Nogueira <victor@mojatatu.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
v5 -> v6:
- the commit log names the neighbour patch this one has to be applied
after, and the ICMP error routing the skb->dev move also changes.
Considered comments from Sashiko (nipa).
net/sched/sch_teql.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index 44730a5e8917..d1c66bd039d1 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -379,13 +379,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.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net v6 3/3] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path
2026-11-19 12:40 ` [PATCH net v6 3/3] net/sched: sch_teql: keep skb->dev consistent on the arp-queue path Jamal Hadi Salim
@ 2026-11-23 13:01 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 13:01 UTC (permalink / raw)
To: jhs
Cc: netdev, victor, jiri, davem, edumazet, kuba, pabeni, horms,
stable, sashiko-bot
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 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).
- [High] The use-after-free class this patch claims to close is still
reachable, and is now easier to trigger.
- [Medium] Wrong egress device when a parked skb whose dst points at a
third device is reinjected.
- [Medium] The stable tags do not record that this patch depends on
another.
- [Low] The commit message understates how the move changes ICMPv6 error
generation.
--
net/sched: sch_teql: keep skb->dev consistent on the arp-queue path
This patch moves the skb->dev = slave assignment in teql_master_xmit()
ahead of teql_resolve(). An skb parked on the slave neighbour's arp_queue
then names the slave rather than the teql master, which avoids a
use-after-free when teql_exit() frees the master on module unload. It
depends on an earlier patch that changes neigh_update_process_arp_queue()
to reinject parked skbs through a headerless output device.
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/
Link: https://lore.kernel.org/netdev/179363700308.3131.11778179538290251434@kernel.org/
Link: https://lore.kernel.org/netdev/20261110101908.2e64e8e9@kernel.org/
> The error now names the slave, so it is also routed for the slave: IPv4
> takes the ICMP output interface from icmp_get_route_lookup_dev() and IPv6
> from skb->dev. A teql master enslaved to a VRF had its host-unreachable
> looked up in the VRF and now has it looked up in the main tables with
> oif 0.
[Severity: Low]
Does this cover everything that changes on the IPv6 side? On the
neigh_invalidate()->ndisc_error_report()->dst_link_failure()->
ip6_link_failure() path, icmp6_send() takes more than the l3mdev from
skb->dev:
net/ipv6/icmp.c:icmp6_send() {
...
net = dev_net_rcu(skb->dev);
...
if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) ||
ipv6_chk_acast_addr_src(net, skb->dev, &hdr->daddr))
saddr = &hdr->daddr;
...
if (__ipv6_addr_needs_scope_id(addr_type)) {
iif = icmp6_iif(skb);
...
}
teql_qdisc_init() checks that master and slave share a netns only when the
slave is attached. teql_master_setup() does not set netns_immutable. If the
master is moved later, the error is now generated, rate-limited and routed
in the slave's namespace.
For a source that needs a scope id (link-local), iif is now the slave's
ifindex rather than 0, so "oif 0" doesn't hold there.
The saddr check through ipv6_chk_addr() and ipv6_chk_acast_addr_src() also
runs against the slave now.
Could the commit message describe these effects as well?
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
[ ... ]
> Cc: stable@vger.kernel.org
[Severity: Medium]
The patch has a plain Cc: stable and a Fixes tag that points at the initial
git import. Stable tooling will therefore pick this one-line move for nearly
every stable tree, and it will apply cleanly.
The commit message says this patch is only correct on top of "net:
neighbour: reinject a parked skb through a headerless output device". That
prerequisite changes neigh_update_process_arp_queue(), which only exists
since 705ef89ac986. In older trees the loop is open coded in
__neigh_update(), so the prerequisite won't apply there.
If this patch is backported alone, the parked skb with skb->dev = slave is
reinjected through the master's neighbour. teql_master_setup() sets
ARPHRD_VOID and installs no header_ops, so the output is
neigh_direct_output(). dev_queue_xmit() then sends the skb straight out the
slave with no link header, because __teql_resolve() already pulled it to
the network header.
Would it make sense to record the dependency in the stable tag (for example
"Cc: stable@vger.kernel.org # <version>: <sha>: <subject>"), limit the
versions, or provide a backport of the prerequisite for the open-coded loop
in __neigh_update()?
> diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
> index 44730a5e89178..d1c66bd039d1d 100644
> --- a/net/sched/sch_teql.c
> +++ b/net/sched/sch_teql.c
> @@ -379,13 +379,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 when teql0 gets an skb whose dst->dev is another device X
that has header_ops? One way this happens is a tc mirred redirect or mirror
from X's clsact egress. tcf_mirred_to_dev() keeps the dst for egress to
egress, and only drops it for want_ingress && !at_ingress.
The skb is parked like this:
teql_master_xmit()
skb->dev = slave;
teql_resolve()
__teql_resolve() /* dst->dev != dev branch */
neigh_event_send(n, skb_res) /* parks on the slave's neighbour */
When the slave's neighbour resolves:
neigh_update_process_arp_queue()
n1 = neighbour looked up from the dst /* X's neighbour */
if (!n1->dev->header_ops)
skb->dev = n1->dev; /* not taken, X has header_ops */
n1->output(n1, skb)
neigh_resolve_output() / neigh_connected_output()
dev_hard_header(skb, X, ...) /* X's MAC and lladdr */
dev_queue_xmit(skb) /* sends on skb->dev == slave */
Does the frame then leave the slave carrying X's link header?
Before this patch skb->dev was still teql0 at that point. dev_queue_xmit()
went back through teql_master_xmit(), which pulled to the network header
and built the slave's own header.
This looks like the mirror-parking scenario that "net/sched: sch_teql:
unshare the header before writing and fix retry strip" uses as its
reproducer. Is that queued frame now sent with the wrong addresses at the
end of the series?
[Severity: High]
Can the same path still lead to a use-after-free, now of the slave instead
of the master?
Continuing from the reinjection above, X's neighbour may not be valid at
that moment. It could be NONE, INCOMPLETE or FAILED, for example after ip
neigh flush dev X, a carrier-down flush, or gc:
neigh_resolve_output()
neigh_event_send(neigh, skb) /* queued on X's arp_queue,
skb->dev == slave */
skb->dev holds no device reference. If the slave is then deleted with ip
link del:
neigh_ifdown(slave)
neigh_flush_dev() /* walks only the slave's own neighbours */
The skb on X's arp_queue survives this, and the slave's net_device is
freed. When X's neighbour then fails:
neigh_invalidate()
arp_error_report() / ndisc_error_report()
dst_link_failure()
__icmp_send() / icmp6_send() /* reads skb->dev, the freed slave */
That gives the same KASAN signature as the one in the commit message. If
X's neighbour resolves instead, dev_queue_xmit() would run on the freed
slave.
Before this patch the skb on X's queue named teql0, which only module
unload can free.
The commit message says the parked skb "names the device whose neighbour
owns it". Does that still hold once the skb moves to a different
neighbour's queue? If not, the trigger seems to change from
CAP_SYS_MODULE plus rmmod to an ordinary link deletion.
> 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);
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v6.r0.20261119070330%40mojatatu.com
^ permalink raw reply [flat|nested] 7+ messages in thread