From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v5 net-next 8/9] net: dsa: netc: add PTP two-step timestamping support
Date: Tue, 13 Oct 2026 09:59:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-169419@kernel.org> (raw)
In-Reply-To: <20261012095924.1129312-9-wei.fang@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: netc: uninitialized tstamp_queue causes NULL deref on port init failure
--
commit 14af7463afd31a995fbafa852be1eeb366978370
Author: Wei Fang <wei.fang@nxp.com>
net: dsa: netc: add PTP two-step timestamping support
This commit adds two-step TX and RX timestamping support for the NETC switch.
It implements hardware filters to redirect PTP frames to the CPU port and
handles hardware-generated timestamps via the tagger.
> diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
> index 1a7103fe1e343..cb262ae5ba796 100644
> --- a/drivers/net/dsa/netc/netc_main.c
> +++ b/drivers/net/dsa/netc/netc_main.c
[ ... ]
> @@ -277,6 +291,11 @@ static void netc_free_all_ports(struct netc_switch *priv)
> if (!np)
> continue;
>
> + if (np->dp && dsa_port_is_user(np->dp)) {
> + disable_delayed_work_sync(&np->tstamp_timeout_work);
> + netc_port_purge_tstamp_queue(np);
> + }
> +
[Severity: High]
If np->dp is set but netc_port_ptp_init() hasn't run yet, tstamp_timeout_work
and tstamp_queue will be completely zero-initialized since np is allocated
with kzalloc_obj. Is it safe to call disable_delayed_work_sync() and
netc_port_purge_tstamp_queue() on zero-initialized structures?
[ ... ]
> @@ -346,6 +365,15 @@ static int netc_init_all_ports(struct netc_switch *priv)
> dev_err(dev, "Failed to create MDIO bus\n");
> goto free_all_ports;
> }
> +
> + /* Only the user port needs to support PTP feature, so
> + * PTP-related resources, such as tstamp_queue,
> + * tstamp_lock, etc., are initialized only for the user
> + * port.
> + */
> + err = netc_port_ptp_init(np);
> + if (err)
> + return err;
> }
> }
[Severity: High]
In netc_init_all_ports(), np->dp is assigned early in the loop:
np->dp = dp;
...
err = netc_port_create_mdio_bus(np, dp->dn);
if (err) {
dev_err(dev, "Failed to create MDIO bus\n");
goto free_all_ports;
}
If netc_port_create_mdio_bus() or netc_port_get_info_from_dt() fails, it
jumps to free_all_ports before netc_port_ptp_init() is called. Could this
leave the zero-initialized PTP structures exposed to the cleanup path in
netc_free_all_ports() since np->dp was already set?
> diff --git a/drivers/net/dsa/netc/netc_ptp.c b/drivers/net/dsa/netc/netc_ptp.c
> new file mode 100644
> index 0000000000000..756c69a02064e
> --- /dev/null
> +++ b/drivers/net/dsa/netc/netc_ptp.c
[ ... ]
> +void netc_port_purge_tstamp_queue(struct netc_port *np)
> +{
> + struct sk_buff_head free_list;
> +
> + __skb_queue_head_init(&free_list);
> +
> + spin_lock_bh(&np->tstamp_lock);
> + skb_queue_splice_init(&np->tstamp_queue, &free_list);
> + spin_unlock_bh(&np->tstamp_lock);
> +
> + __skb_queue_purge(&free_list);
> +}
[Severity: High]
If np->tstamp_queue is uninitialized (all zeros), skb_queue_splice_init()
will find that list->next is NULL. When it calls __skb_queue_splice(), it
attempts to write to list->next->prev, which would cause a deterministic NULL
pointer dereference and a kernel panic. Additionally, locking the
uninitialized tstamp_lock would trigger lockdep splats.
Could np->dp be cleared on the error path to avoid this, or should we track
PTP initialization state separately?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012095924.1129312-1-wei.fang@oss.nxp.com?part=8
next prev parent reply other threads:[~2026-10-13 9:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 9:59 [PATCH v5 net-next 0/9] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-10-12 9:59 ` [PATCH v5 net-next 1/9] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-10-12 9:59 ` [PATCH v5 net-next 2/9] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-10-12 9:59 ` [PATCH v5 net-next 3/9] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-10-12 9:59 ` [PATCH v5 net-next 4/9] net: dsa: netc: tie setup resources and reset to DSA setup/teardown wei.fang
2026-10-13 9:59 ` sashiko-bot
2026-10-14 2:23 ` Wei Fang (OSS)
2026-10-13 10:57 ` netdev-bot+sashiko
2026-10-14 6:44 ` Wei Fang (OSS)
2026-10-12 9:59 ` [PATCH v5 net-next 5/9] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-10-13 9:59 ` sashiko-bot
2026-10-14 6:26 ` Wei Fang (OSS)
2026-10-12 9:59 ` [PATCH v5 net-next 6/9] net: dsa: netc: check return value of ntmp_ipft_delete_entry() wei.fang
2026-10-13 10:57 ` netdev-bot+sashiko
2026-10-12 9:59 ` [PATCH v5 net-next 7/9] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-10-12 9:59 ` [PATCH v5 net-next 8/9] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-10-13 9:59 ` sashiko-bot [this message]
2026-10-13 10:57 ` netdev-bot+sashiko
2026-10-12 9:59 ` [PATCH v5 net-next 9/9] net: dsa: netc: add PTP one-step " wei.fang
2026-10-13 9:59 ` sashiko-bot
2026-10-13 10:57 ` netdev-bot+sashiko
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=sashiko-outbox-169419@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wei.fang@oss.nxp.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