BPF List
 help / color / mirror / Atom feed
* [PATCH net v5 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact
@ 2026-11-16 10:36 Jamal Hadi Salim
  2026-11-16 10:36 ` [PATCH net v5 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
  0 siblings, 1 reply; 3+ messages in thread
From: Jamal Hadi Salim @ 2026-11-16 10:36 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,
	sashiko-bot

Three pre-existing defects on the teql transmit path, all around
teql_master_xmit() -> teql_resolve(), plus the core helper they depend on
all derived from sashiko reports.

Patch 1 makes the headroom private before the neighbour can write or queue
the skb, 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 restores skb->dev at the arp-queue reinjection point when the
neighbour's device builds no link header. It is the neighbour half of the
version 3 patch 2, split out on review so it gets its own commit
log and its own Cc set; requested by Jakub.

Patch 3 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
so cannot outlive the master it came from.  With patch 2 in place it is
reinjected through the master and leaves with a link header.  Its commit
log carries the KASAN report the unfixed kernel prints when that queue is
drained.

Patch 3 is a follow-up to commit dc4b95b8fee9 ("net/sched: sch_teql:
restore skb->dev on the slave failure path") by Victor. Patch 1 is the
same commit's sibling on the successful-transmit path.

To prempt the sashikos:
- The pre-existing teql issues reported alongside this series are fixed
separately. For "the lower-qdisc drop use-after-free" see:
https://lore.kernel.org/netdev/QDISC-Y0BY.v2.r0.20261024060625-2@mojatatu.com/

- For the pre-existing consumer nft/bpf complaint see:
https://lore.kernel.org/netdev/CORE-9NOG.v1.r0.20261111073528@mojatatu.com/
Note: nft/bpf combination _has never worked_: it is a producer-side
mismatch on two separate entry points, not a regression of anything here -
hence the net-next target.

Hope the sashikos read these and dont complain again about those issues.

Note also: part of the testing of patch 2 runs for packets that reach
neigh_xmit() from nft's `fwd ... neigh` statement, or from
bpf_redirect_neigh() with explicit nexthop parameters. Both keep the
route's dst attached while replacing skb->dev, so the neighbour that
queues the packet is not the one the dst names.

Changes v4 -> v5:
- patch 1 closes the finding Sashiko (nipa) raised on the v4 posting.  The
  head is unshared before neigh_event_send(), so a skb parked on the
  slave's neighbour arp_queue is already private when that queue is
  drained and the neighbour writes the link header into it.  The retry
  strip fix is unchanged.  Considered comments from Sashiko (nipa).
- patches 2 and 3 are unchanged; this resend is for patch 1.
- patch 2 adds Kuniyuki Iwashima in its Cc set (nipa CI).

Changes v3 -> v4:
- patch 1, no code changes. Reviewed-by from Simon Horman stays, and a
  Link to the review of the v3 posting is added.
- patch 2 is new: the net/core/neighbour.c hunk of the v3 patch 2 is split
  out into its own fix, with the neighbour maintainers Cc'd.  Asked for on
  the v3 posting by Jakub.
- patch 3 is the v3 patch 2 with that hunk removed; the sch_teql change is
  unchanged in approach. Reviewed-by from Simon Horman stays.

Changes v2 -> v3:
- patch 1, no code changes.
- patch 2 corrects the conditions to recreate the bug: reaching a freed
  master needs sch_teql built as a module, the slave qdisc removed and the
  module unloaded while the skb still waits.  The message now says which
  part of it reproduces without the unload, and names the neighbour failure
  path that drains the same parked skb.  Considered comments from
  Sashiko (nipa).

Changes v1 -> v2:
- patch 1, 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.  Considered comments from
  Sashiko (nipa) and Sashiko (gemini).

Jamal Hadi Salim (3):
  net/sched: sch_teql: unshare the header before writing and fix retry
    strip
  net: neighbour: reinject a parked skb through a headerless output
    device
  net/sched: sch_teql: keep skb->dev consistent on the arp-queue path

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

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v5 2/3] net: neighbour: reinject a parked skb through a headerless output device
  2026-11-16 10:36 [PATCH net v5 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact Jamal Hadi Salim
@ 2026-11-16 10:36 ` Jamal Hadi Salim
  2026-11-17 10:36   ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Jamal Hadi Salim @ 2026-11-16 10:36 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 half 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.

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 sch_teql 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
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/core/neighbour.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index d6e9c7c59a89..1b556fa17c57 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 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] 3+ messages in thread

* Re: [PATCH net v5 2/3] net: neighbour: reinject a parked skb through a headerless output device
  2026-11-16 10:36 ` [PATCH net v5 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
@ 2026-11-17 10:36   ` sashiko-bot
  0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-17 10:36 UTC (permalink / raw)
  To: Jamal Hadi Salim; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: neighbour: reinjecting skb onto n1->dev misroutes
  redirected packets
- [Low] net: neighbour: unresolvable commit SHA 1da177e4c3f4 in Fixes
  trailer
--

commit c144e3e967eef24fc933621e8fea6beda200db16
Author: Jamal Hadi Salim <jhs@mojatatu.com>

> net: neighbour: reinject a parked skb through a headerless output device
>
> 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 half 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.
>
> 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 sch_teql 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
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>

[Severity: Low]
The commit sha 1da177e4c3f4 ("Linux-2.6.12-rc2") in the Fixes: trailer cannot
be resolved in the repository.

> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> index d6e9c7c59a892..1b556fa17c57c 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 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);

[Severity: Medium]
Can setting skb->dev = n1->dev misroute packets redirected by
nft_fwd_neigh_eval() or __bpf_redirect_neigh_v4() / __bpf_redirect_neigh_v6()
when the original dst points to a headerless device?

As noted in the commit message, those paths leave the original skb_dst(skb)
attached when queuing on an unresolved target neighbour, and neither producer
has been updated to drop the dst yet:

net/netfilter/nft_fwd_netdev.c:nft_fwd_neigh_eval() {
	...
	skb->dev = dev;
	skb_clear_tstamp(skb);

	nf_dev_xmit_recursion_inc();
	neigh_xmit(neigh_table, dev, addr, skb);
	...
}

When the target neighbour resolves, dst_neigh_lookup_skb(dst, skb) finds n2 on
the original headerless device, overwrites skb->dev with n1->dev, and
reinjects the packet through neigh_direct_output() -> dev_queue_xmit() onto
the original device instead of the redirected target.  If the redirect ran in
n1->dev's egress hook, nft_fwd_neigh_eval() runs a second time and decrements
iph->ttl or ip6h->hop_limit again; if the redirect happened outside n1->dev's
egress hook, the redirect is lost and the packet transmits out n1->dev.
Similarly, tcf_mirred_to_dev() retains skb_dst() on egress redirect or mirror.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/QDISC-6HS9.v5.r0.20261116052927@mojatatu.com?part=2

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17 10:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:36 [PATCH net v5 0/3] net/sched: sch_teql: keep the transmit path's skb geometry and device lifetime intact Jamal Hadi Salim
2026-11-16 10:36 ` [PATCH net v5 2/3] net: neighbour: reinject a parked skb through a headerless output device Jamal Hadi Salim
2026-11-17 10:36   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox