Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Jamal Hadi Salim
Wed, 11 Nov 2026 15:17
[PATCH net v4 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip
Author: Jamal Hadi Salim
Date: Wed, 11 Nov 2026 15:17
Date: Wed, 11 Nov 2026 15:17
159 lines
16637 bytes
16637 bytes
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.
The shared headroom case needs a cloned skb: a PF_PACKET tap on the
master whose socket is never drained keeps the clone alive across the
transmit. A kprobe on eth_header then reports cloned=1 on the unfixed
tree and cloned=0 with the patch.
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
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>
---
v3 -> v4:
- added Simon Horman's Reviewed-by, given on the v3 posting. The patch
itself is unchanged; the series is resent because 2/2 had to be split
as asked in the review of that patch.
net/sched/sch_teql.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
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
Re: [PATCH net v4 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip
Author: netdev-bot+sashiko
Date: Sun, 15 Nov 2026 15:47
Date: Sun, 15 Nov 2026 15:47
156 lines
13007 bytes
13007 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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 fix leaves a gap: `skb_cow_head()` in `__teql_resolve()`
(net/sched/sch_teql.c) only runs when `neigh_event_send(n, skb_res) ==…
--
net/sched: sch_teql: unshare the header before writing and fix retry strip
This patch calls skb_cow_head() in __teql_resolve() before
dev_hard_header() writes the slave's link header, so that a header-cloned
skb does not corrupt the other clone. It also records how many header bytes
each slave added in teql_master_xmit() and pulls back only that many on
retry. As a result, an AF_PACKET frame with no dst keeps its user-supplied
header.
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..3f781a3ffb41a 100644
> --- a/net/sched/sch_teql.c
> +++ b/net/sched/sch_teql.c
[ ... ]
> @@ -293,15 +293,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;
> }
[Severity: Medium]
The skb_cow_head() only runs when neigh_event_send() returns 0. What
happens to a header-cloned skb that takes the else branch instead?
Suppose every slave neighbour is unresolved on the first pass of
teql_master_xmit(). Then neigh_event_send(n, NULL) fails, teql_resolve()
returns -EAGAIN and nores is set, and no unshare has run. teql then
restarts with the same skb as skb_res:
teql_master_xmit() {
...
if (nores && skb_res == NULL) {
skb_res = skb;
rcu_read_unlock();
goto restart;
}
...
}
On the restart, neigh_event_send(n, skb_res) parks the skb on the slave
neighbour's arp_queue with its header still cloned:
net/core/neighbour.c:__neigh_event_send() {
...
skb_dst_force(skb);
__skb_queue_tail(&neigh->arp_queue, skb);
...
}
The usual reinjection path is covered. The skb's dst resolves to teql0's
own neighbour, whose output is neigh_direct_output(). That re-enters
teql_master_xmit(), where the new skb_cow_head() runs.
However, neigh_update_process_arp_queue() can fall back to a different
neighbour:
net/core/neighbour.c:neigh_update_process_arp_queue() {
...
n2 = NULL;
if (dst &&
READ_ONCE(dst->obsolete) != DST_OBSOLETE_DEAD) {
n2 = dst_neigh_lookup_skb(dst, skb);
if (n2)
n1 = n2;
}
READ_ONCE(n1->output)(n1, skb);
...
}
This happens in two cases:
- The dst became DST_OBSOLETE_DEAD while the skb was parked (for example,
a route delete that ends in dst_dev_put()), or dst_neigh_lookup_skb()
fails. Then n1 stays the slave's neighbour.
- In the tc-mirred setup from the commit message, the dst belongs to the
physical device, so n1 is that device's neighbour.
In both cases neigh_resolve_output() writes the link header without
checking skb_header_cloned():
net/core/neighbour.c:neigh_resolve_output() {
...
__skb_pull(skb, skb_network_offset(skb));
seq = read_seqbegin(&neigh->ha_lock);
err = dev_hard_header(skb, dev, ntohs(skb->protocol),
neigh->ha, NULL, skb->len);
...
}
Can this overwrite the link header of the other clone, such as the mirred
original still pending on the physical device or a PF_PACKET tap clone? In
the mirred case the bytes written are usually identical, but they differ if
the lladdr changed in the meantime.
The commit message says "a header-cloned skb is unshared before the write",
but the arp_queue handoff does not seem to be covered.
The later patches in the series don't add an unshare on this path either:
- "net: neighbour: reinject a parked skb through a headerless output
device" only rewrites skb->dev for a headerless n1.
- "net/sched: sch_teql: keep skb->dev consistent on the arp-queue path"
only moves the skb->dev = slave assignment.
Would it work to call skb_cow_head() before neigh_event_send(n, skb_res),
or once at the top of teql_master_xmit()?
> +out:
> neigh_release(n);
> return err;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v4.r0.20261111094338%40mojatatu.com
Re: [PATCH net v4 1/3] net/sched: sch_teql: unshare the header before writing and fix retry strip
Author: Jamal Hadi Salim
Date: Sun, 15 Nov 2026 23:26
Date: Sun, 15 Nov 2026 23:26
182 lines
18124 bytes
18124 bytes
On Sun, Nov 15, 2026 at 10:47 AM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> 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 fix leaves a gap: `skb_cow_head()` in `__teql_resolve()`
> (net/sched/sch_teql.c) only runs when `neigh_event_send(n, skb_res) ==…
I think this one deserves a respin. Will send a v5 in the morning.
pw-bot: cr
cheers,
jamal
> --
>
> net/sched: sch_teql: unshare the header before writing and fix retry strip
>
> This patch calls skb_cow_head() in __teql_resolve() before
> dev_hard_header() writes the slave's link header, so that a header-cloned
> skb does not corrupt the other clone. It also records how many header bytes
> each slave added in teql_master_xmit() and pulls back only that many on
> retry. As a result, an AF_PACKET frame with no dst keeps its user-supplied
> header.
>
> 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..3f781a3ffb41a 100644
> > --- a/net/sched/sch_teql.c
> > +++ b/net/sched/sch_teql.c
>
> [ ... ]
>
> > @@ -293,15 +293,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;
> > }
>
> [Severity: Medium]
> The skb_cow_head() only runs when neigh_event_send() returns 0. What
> happens to a header-cloned skb that takes the else branch instead?
>
> Suppose every slave neighbour is unresolved on the first pass of
> teql_master_xmit(). Then neigh_event_send(n, NULL) fails, teql_resolve()
> returns -EAGAIN and nores is set, and no unshare has run. teql then
> restarts with the same skb as skb_res:
>
> teql_master_xmit() {
> ...
> if (nores && skb_res == NULL) {
> skb_res = skb;
> rcu_read_unlock();
> goto restart;
> }
> ...
> }
>
> On the restart, neigh_event_send(n, skb_res) parks the skb on the slave
> neighbour's arp_queue with its header still cloned:
>
> net/core/neighbour.c:__neigh_event_send() {
> ...
> skb_dst_force(skb);
> __skb_queue_tail(&neigh->arp_queue, skb);
> ...
> }
>
> The usual reinjection path is covered. The skb's dst resolves to teql0's
> own neighbour, whose output is neigh_direct_output(). That re-enters
> teql_master_xmit(), where the new skb_cow_head() runs.
>
> However, neigh_update_process_arp_queue() can fall back to a different
> neighbour:
>
> net/core/neighbour.c:neigh_update_process_arp_queue() {
> ...
> n2 = NULL;
> if (dst &&
> READ_ONCE(dst->obsolete) != DST_OBSOLETE_DEAD) {
> n2 = dst_neigh_lookup_skb(dst, skb);
> if (n2)
> n1 = n2;
> }
> READ_ONCE(n1->output)(n1, skb);
> ...
> }
>
> This happens in two cases:
>
> - The dst became DST_OBSOLETE_DEAD while the skb was parked (for example,
> a route delete that ends in dst_dev_put()), or dst_neigh_lookup_skb()
> fails. Then n1 stays the slave's neighbour.
>
> - In the tc-mirred setup from the commit message, the dst belongs to the
> physical device, so n1 is that device's neighbour.
>
> In both cases neigh_resolve_output() writes the link header without
> checking skb_header_cloned():
>
> net/core/neighbour.c:neigh_resolve_output() {
> ...
> __skb_pull(skb, skb_network_offset(skb));
> seq = read_seqbegin(&neigh->ha_lock);
> err = dev_hard_header(skb, dev, ntohs(skb->protocol),
> neigh->ha, NULL, skb->len);
> ...
> }
>
> Can this overwrite the link header of the other clone, such as the mirred
> original still pending on the physical device or a PF_PACKET tap clone? In
> the mirred case the bytes written are usually identical, but they differ if
> the lladdr changed in the meantime.
>
> The commit message says "a header-cloned skb is unshared before the write",
> but the arp_queue handoff does not seem to be covered.
>
> The later patches in the series don't add an unshare on this path either:
>
> - "net: neighbour: reinject a parked skb through a headerless output
> device" only rewrites skb->dev for a headerless n1.
>
> - "net/sched: sch_teql: keep skb->dev consistent on the arp-queue path"
> only moves the skb->dev = slave assignment.
>
> Would it work to call skb_cow_head() before neigh_event_send(n, skb_res),
> or once at the top of teql_master_xmit()?
>
> > +out:
> > neigh_release(n);
> > return err;
> > }
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-6HS9.v4.r0.20261111094338%40mojatatu.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads