mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: m-malladi@ti.com
Cc: diogo.ivo@siemens.com, haokexin@gmail.com,
	philippe.schenker@impulsing.ch, devnexen@gmail.com,
	horms@kernel.org, jacob.e.keller@intel.com, pabeni@redhat.com,
	kuba@kernel.org, edumazet@kernel.org, davem@davemloft.net,
	andrew+netdev@lunn.ch, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	vigneshr@ti.com, danishanwar@ti.com
Subject: Re: [PATCH net v3 RESEND 1/3] net: ti: icssg-prueth: Fix TX timestamp cleanup crash
Date: Mon, 16 Nov 2026 13:54:51 +0000	[thread overview]
Message-ID: <179483729133.3136.8884772760823152816@kernel.org> (raw)
In-Reply-To: <20261112102140.2744508-2-m-malladi@ti.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 2 (2) · Medium: 3 · 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).

- [High] The patch only makes prueth_cleanup_tx_ts() aware of the
  ERR_PTR(-EBUSY) sentinel.
- [High] The ERR_PTR(-EBUSY) state exists only between
  prueth_tx_ts_cookie_get() (icssg_common.c:1184) and the store…
- [Medium] The Fixes: tag names the wrong commit.
- [Medium] The commit message and the new comment misdescribe both the
  trigger and the effect.
- [Medium] The new check in prueth_cleanup_tx_ts() loads
  emac->tx_ts_skb[i] twice with plain, non-READ_ONCE loads: once in…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  prueth_cleanup_tx_ts() (phylib work context) and the TX timestamp…
- [High] This problem wasn't introduced by this patch, but
  prueth_tx_ts_cookie_get() (icssg_common.c:1177-1190) reserves a slot…

--

net: ti: icssg-prueth: Fix TX timestamp cleanup crash

This patch changes prueth_cleanup_tx_ts() to skip slots that hold NULL or
the ERR_PTR(-EBUSY) reservation sentinel. It still clears every slot to
NULL. The goal is to stop dev_kfree_skb_any() from being called on a slot
that the TX path has reserved but not yet filled.

> Fixes: e2dc7bfd677fc ("net: ti: icssg-prueth: Move common functions into a separate file")

[Severity: Medium]
Is this the right commit for the Fixes: tag?

e2dc7bfd677fc is a code move, and its message says it introduces no
functional changes. Before that commit, icssg_prueth.c already had
prueth_tx_ts_cookie_get() storing ERR_PTR(-EBUSY), and a static
prueth_cleanup_tx_ts() with the same check:

    if (emac->tx_ts_skb[i]) {
        dev_kfree_skb_any(emac->tx_ts_skb[i]);

Both came from 186734c15886 ("net: ti: icssg-prueth: add packet
timestamping and ptp support"), which landed in v6.6. e2dc7bfd677fc
landed in v6.10. Stable tooling that follows the current tag would skip
6.6.y, which has the same cleanup code.

Should this be:

Fixes: 186734c15886 ("net: ti: icssg-prueth: add packet timestamping and ptp support")

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c
> index 4a7d1a6f470b1..8cb2ad2ebece5 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_common.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c
> @@ -1426,10 +1426,13 @@ void prueth_cleanup_tx_ts(struct prueth_emac *emac)
>  	int i;
>  
>  	for (i = 0; i < PRUETH_MAX_TX_TS_REQUESTS; i++) {
> -		if (emac->tx_ts_skb[i]) {
> +		/* Slot may hold ERR_PTR(-EBUSY) if the TX path reserved it
> +		 * but has not yet stored the real skb pointer.  Skip the free
> +		 * but still clear the slot so it can be reused.
> +		 */

[Severity: Medium]
Do this comment and the commit message accurately describe when the slot
holds ERR_PTR(-EBUSY)?

Only prueth_tx_ts_cookie_get() writes the sentinel. A few instructions
later, icssg_ndo_start_xmit() overwrites it, with no return or goto in
between:

    tx_ts_cookie = prueth_tx_ts_cookie_get(emac);
    if (tx_ts_cookie >= 0) {
        skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
        ...
        emac->tx_ts_skb[tx_ts_cookie] = skb_get(skb);

So prueth_cleanup_tx_ts() can only see the sentinel while an xmit is
running at the same time. The commit message doesn't describe this as a
race.

The commit message also says "preventing NULL pointer dereference".
Wouldn't the original failure be a dereference of the ERR_PTR value inside
kfree_skb(), not a NULL dereference?

The comment says the slot is cleared "so it can be reused". The xmit that
reserved the slot is still running, though, and will store skb_get(skb)
into it anyway.

Could the commit message and the comment describe the actual race?

> +		if (!IS_ERR_OR_NULL(emac->tx_ts_skb[i]))
>  			dev_kfree_skb_any(emac->tx_ts_skb[i]);

[Severity: Medium]
Can these two plain loads of emac->tx_ts_skb[i] return different values?

Three things change the slot with no common lock: icssg_ndo_start_xmit()
on any TX queue, tx_ts_work(), and the xmit error paths. Consider this
sequence:

- The load in IS_ERR_OR_NULL() sees a valid skb.
- tx_ts_work() takes that skb and writes NULL.
- Another xmit reserves the slot before the second load.

The result is dev_kfree_skb_any(ERR_PTR(-EBUSY)), which is the crash this
patch is meant to prevent.

This only happens if the compiler emits two separate loads, which C allows
for plain accesses.

Would it be safer to read the slot once into a local with READ_ONCE() or
xchg()? The underlying fix still needs a lock.

[Severity: High]
This isn't a bug introduced by this patch, but what stops this free from
racing with the TX timestamp consumers?

prueth_cleanup_tx_ts() runs from the phylib link change path. Meanwhile,
tx_ts_work() (threaded tx_ts_irq) and prueth_tx_ts_sr1() (threaded mgm
IRQ) read and then clear the same slot without a lock:

    skb = emac->tx_ts_skb[tsr.cookie];
    emac->tx_ts_skb[tsr.cookie] = NULL;	/* free slot */
    ...
    skb_tstamp_tx(skb, &ssh);
    dev_consume_skb_any(skb);

Suppose tx_ts_work() reads skb S, and prueth_cleanup_tx_ts() also reads S
and calls dev_kfree_skb_any(S) before tx_ts_work() writes NULL.
tx_ts_work() then calls skb_tstamp_tx() and dev_consume_skb_any() on a
reference that has already been dropped.

If TX completion has already released the base reference, isn't that a
use-after-free followed by a double free?

The error paths in icssg_ndo_start_xmit() race with cleanup the same way:

    cleanup_tx_ts:
        if (in_tx_ts) {
            dev_kfree_skb_any(emac->tx_ts_skb[tx_ts_cookie]);
            emac->tx_ts_skb[tx_ts_cookie] = NULL;
        }

Both sides can drop the skb_get() reference, and then drop_free_skb frees
the base reference.

prueth_cleanup_tx_ts() also still doesn't adjust tx_ts_pending.

> -			emac->tx_ts_skb[i] = NULL;
> -		}
> +		emac->tx_ts_skb[i] = NULL;

[Severity: High]
The ERR_PTR(-EBUSY) case only happens while icssg_ndo_start_xmit() is
running. Can this unlocked NULL write then overwrite the skb that the
xmit is about to store?

emac_adjust_link() does:

    netif_tx_stop_all_queues(ndev);
    prueth_cleanup_tx_ts(emac);

emac_adjust_link_sr1() does the same. netif_tx_stop_all_queues() only sets
the XOFF bits and doesn't wait for an xmit that is already running:

CPU0 (emac_adjust_link)            CPU1 (icssg_ndo_start_xmit)
                                   prueth_tx_ts_cookie_get()
                                     tx_ts_skb[k] = ERR_PTR(-EBUSY)
prueth_cleanup_tx_ts()
  IS_ERR_OR_NULL(tx_ts_skb[k])
    -> true, skip free
                                   tx_ts_skb[k] = skb_get(skb)
  tx_ts_skb[k] = NULL

Does this leak the skb_get() reference on the skb, along with its socket's
sk_wmem_alloc charge?

When the timestamp response for k arrives, tx_ts_work() sees NULL, logs
"Invalid TX TS cookie" and breaks without decrementing tx_ts_pending.

Once the slot is NULL, an xmit on another TX queue can also reserve the
same index through prueth_tx_ts_cookie_get(), while the original xmit
still owns it. Two in-flight packets then share one cookie. The original
xmit's error paths (cleanup_tx_ts and free_desc_stop_q_busy_cleanup_tx_ts)
would call:

    dev_kfree_skb_any(emac->tx_ts_skb[tx_ts_cookie]);

on whatever the slot holds at that point. That may be the other packet's
skb or ERR_PTR(-EBUSY).

Cleanup and the xmit error path can also still both free the same valid
skb pointer.

Instead of another value check, would this need netif_tx_disable() before
the cleanup? It would also need a lock shared by prueth_tx_ts_cookie_get(),
the xmit error paths, tx_ts_work() and prueth_cleanup_tx_ts().

[Severity: High]
This makes prueth_cleanup_tx_ts() aware of the sentinel. Don't the
timestamp completion handlers still treat any non-NULL slot as a valid
skb?

tx_ts_work() in icssg_prueth.c only rejects NULL:

    if (tsr.cookie >= PRUETH_MAX_TX_TS_REQUESTS ||
        !emac->tx_ts_skb[tsr.cookie]) {

An ERR_PTR(-EBUSY) slot passes this check, and the later if (!skb) check
can't catch it. The value then goes to skb_tstamp_tx() and
dev_consume_skb_any().

prueth_tx_ts_sr1() in icssg_prueth_sr1.c only checks the cookie range:

    skb = emac->tx_ts_skb[cookie];
    emac->tx_ts_skb[cookie] = NULL;	/* free slot */
    ...
    skb_tstamp_tx(skb, &ssh);

skb_tstamp_tx() dereferences orig_skb->sk, so an empty slot causes a NULL
dereference.

prueth_cleanup_tx_ts() sets every slot to NULL on link-down. It doesn't
reset tx_ts_pending, and it doesn't synchronize with firmware timestamp
responses already queued for those cookies.

On SR1, consider this sequence:

- A timestamped frame is sent.
- The firmware posts the response.
- The link goes down.

emac_adjust_link_sr1()->prueth_cleanup_tx_ts() can then NULL the slot
before prueth_rx_mgm_ts_thread_sr1()->prueth_tx_ts_sr1() runs, which
leads to skb_tstamp_tx(NULL, ...).

On SR2, a stale response for cookie k could be handled while a new xmit
holds k reserved. That would pass ERR_PTR(-EBUSY) to skb_tstamp_tx(). If
the stale response is handled after the new skb_get() store, the old
timestamp is attached to an unrelated packet.

The missing NULL check in prueth_tx_ts_sr1() predates this patch. This
commit is fixing the case where a reserved or cleared slot is used as an
skb, so should tx_ts_work() and prueth_tx_ts_sr1() be covered as well?

[Severity: High]
This is a pre-existing issue, but is the slot reservation in
prueth_tx_ts_cookie_get() safe across TX queues?

    for (i = 0; i < PRUETH_MAX_TX_TS_REQUESTS; i++) {
        if (!emac->tx_ts_skb[i]) {
            emac->tx_ts_skb[i] = ERR_PTR(-EBUSY); /* reserve slot */
            return i;
        }
    }

All TX queues of the netdev share emac->tx_ts_skb[] (up to
PRUETH_MAX_TX_QUEUES on SR2). icssg_ndo_start_xmit(), however, is only
serialized by each queue's own lock. Two CPUs sending HW-timestamped skbs
on different queues could both see slot i as NULL and both reserve it.

Both packets would then carry cookie i in epib[0]:

- The second skb_get(skb) store overwrites the first, which leaks the
  first skb and its socket's wmem charge.
- tx_ts_pending is incremented twice for one slot.
- The first response could attach one packet's timestamp to the other.
- The second response would hit "Invalid TX TS cookie".

Suppose xmit B's ERR_PTR(-EBUSY) write lands after xmit A has stored its
skb. A's error path would then call dev_kfree_skb_any(ERR_PTR(-EBUSY)).

SR1 uses a single TX queue and doesn't appear to be affected.

Would a spinlock around tx_ts_skb[], or cmpxchg() for the reservation, be
needed here? This also looks like the root cause of the reservation
window races above.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112102140.2744508-1-m-malladi%40ti.com

  reply	other threads:[~2026-11-16 13:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 10:21 [PATCH net v3 RESEND 0/3] Fix switch mode for offload and non-offload cases Meghana Malladi
2026-11-12 10:21 ` [PATCH net v3 RESEND 1/3] net: ti: icssg-prueth: Fix TX timestamp cleanup crash Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko [this message]
2026-11-12 10:21 ` [PATCH net v3 RESEND 2/3] net: ti: icssg-prueth: Fix phylib stop/start in emac_restart Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko
2026-11-12 10:21 ` [PATCH net v3 RESEND 3/3] net: ti: icssg-prueth: Fix bridge port_vlan and flooding state Meghana Malladi
2026-11-16 13:54   ` netdev-bot+sashiko
2026-11-12 10:26 ` [PATCH net v3 RESEND 0/3] Fix switch mode for offload and non-offload cases netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179483729133.3136.8884772760823152816@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=devnexen@gmail.com \
    --cc=diogo.ivo@siemens.com \
    --cc=edumazet@kernel.org \
    --cc=haokexin@gmail.com \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m-malladi@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=philippe.schenker@impulsing.ch \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®