All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Birger Koblitz" <mail@birger-koblitz.de>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH net-next 3/3] net: usb: ax88179: Enable PTP
Date: Mon, 30 Nov 2026 09:30:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-240777@kernel.org> (raw)
In-Reply-To: <20261129-ptp-v1-3-8148c402beaf@birger-koblitz.de>

Thank you for your contribution! Sashiko AI review found 18 potential
issues to consider:
- [High] net: usb: ax88179: NULL deref on skb_clone() failure in
  ax88179a_tx_fixup()
- [High] net: usb: ax88179: unlocked tx_skbs access and leak in
  ax88279_process_tx_ts()
- [High] net: usb: ax88179: uninitialized ptp_hdr deref on non-PTP TX
  timestamp SKBs
- [High] net: usb: ax88179: out-of-bounds PTP timestamp read in
  ax88179a_rx_fixup()
- [High] net: usb: ax88179: dropped PTP packet desynchronizes
  ax88179a_rx_fixup()
- [High] net: usb: ax88179: 32-bit shift overflow in AX179A_RX_PD_PTP
  macro
- [High] net: usb: ax88179: UAF and NULL ptp_config() deref in
  ax88179a_bind()
- [High] net: usb: ax88179: active PTP URB double submission on resume
  and link up
- [High] net: usb: ax88179: urb leak and UAF race in ax88179a_unbind()
- [High] net: usb: ax88179: uncanceled PTP work and phylink race in
  ax88179a_suspend()
- [High] net: usb: ax88179: data races on ep4_buf and ptp_info_buf in
  ax88179a_ptp_read_ts()
- [High] net: usb: ax88179: wrong array index in ax88179a_ptp_read_ts()
  and ax88279_read_ts_complete()
- [High] net: usb: ax88179: misplaced PTP_1588_CLOCK_OPTIONAL dependency
  in Kconfig
- [Medium] net: usb: ax88179: skb_copy_expand() drops TX timestamp in
  ax88179a_tx_fixup()
- [Medium] net: usb: ax88179: wrong speed constants passed in
  ax88179a_mac_link_up()
- [Medium] net: usb: ax88179: capability mismatch in
  ax88179a_get_ts_info()
- [Medium] net: usb: ax88179: resource leaks and dangling ptp in
  ax88179a_ptp_register()
- [Medium] net: usb: ax88179: missing cpu_to_le32 conversion on 32-bit
  PTP register writes
--

commit 43874aad48bf8ec849f6baccb1d0f436a2536594
Author: Birger Koblitz <mail@birger-koblitz.de>

net: usb: ax88179: Enable PTP

This commit adds a ptp_enable module parameter and hooks up PTP hardware
timestamping support across bind, unbind, suspend, resume, link changes,
ethtool, and the RX/TX paths for AX88179A and AX88279 devices.

> diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
> index 69095110e7043..994e749ffaa2b 100644
> --- a/drivers/net/usb/ax88179a_devices.c
> +++ b/drivers/net/usb/ax88179a_devices.c
[ ... ]
> @@ -137,6 +142,9 @@ static int ax88179a_suspend(struct usb_interface *intf, pm_message_t message)
>  	int ret;
>  
>  	priv = dev->driver_priv;
> +	if (netif_running(dev->net))
> +		ax88179a_ptp_kill_urbs(dev);
> +
>  	ax88179_set_pm_mode(dev, true);
>  
>  	if (netif_running(dev->net)) {

[Severity: High]
Can pending phylink or PTP work run during and after ax88179a_suspend()?

ax88179a_ptp_kill_urbs() runs before phylink_suspend() and
usbnet_suspend(), so phylink resolve work can call ax88179a_mac_link_up()
and resubmit ptp->urb in between.

On AX88179A, ax88179a_ptp_kill_urbs() is a no-op, and when priv->wolopts
is set phylink_suspend() does not call ax88179a_mac_link_down().  Because
ax88179a_suspend() never cancels ptp->req_tx_timestamp or
ptp->process_ptp_info_buf, ax88179a_ptp_read_ts_work() can run after
ax88179a_suspend() clears in_pm, issuing non-PM USB control reads on the
suspended device and calling netif_device_detach() on failure.

[ ... ]

> @@ -232,6 +242,11 @@ static int ax88179a_resume(struct usb_interface *intf)
>  
>  	ax88179_set_pm_mode(dev, false);
>  
> +	if (netif_running(dev->net) &&
> +	    ax179_data->chip_version == AX_VERSION_AX88279 && ax179_data->ptp) {
> +		ax179_data->ptp->ptp_read_ts(dev);
> +	}
> +
>  	return usbnet_resume(intf);
>  }

[Severity: High]
Does calling ptp_read_ts() in both ax88179a_resume() and
ax88179a_mac_link_up() submit ptp->urb twice on AX88279?

ax88279_ptp_read_ts() reinitializes and submits the single pre-allocated
ptp->urb.  When ax88179a_resume() calls ptp_read_ts() and phylink also
calls ax88179a_mac_link_up() (either synchronously inside
phylink_resume() when WoL was active, or when link negotiation completes),
ptp->urb is reinitialized and submitted while already active, triggering
WARN_ONCE() in usb_submit_urb().

Also, ax88279_read_ts_complete() calls ptp->ptp_read_ts(dev) from URB
completion context, which passes GFP_KERNEL to usb_submit_urb() in atomic
context.  And if ptp->urb is submitted here while the link is down and the
interface is then stopped before link-up, ax88179a_stop() never calls
ax88179a_ptp_kill_urbs(dev), leaving ptp->urb active after ndo_stop.

> @@ -353,6 +368,42 @@ static int ax88179a_set_eee(struct net_device *net, struct ethtool_keee *edata)
>  	return phylink_ethtool_set_eee(ax179_data->phylink, edata);
>  }
>  
> +static int ax88179a_get_ts_info(struct net_device *net,
> +				struct kernel_ethtool_ts_info *info)
> +{
> +	struct ax88179_data *ax179_data = netdev2data(net);
> +
> +	if (!ax179_data->ptp)
> +		return ethtool_op_get_ts_info(net, info);
> +
> +	info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
> +				SOF_TIMESTAMPING_RX_SOFTWARE |
> +				SOF_TIMESTAMPING_SOFTWARE |
> +				SOF_TIMESTAMPING_TX_HARDWARE |
> +				SOF_TIMESTAMPING_RX_HARDWARE |
> +				SOF_TIMESTAMPING_RAW_HARDWARE;
> +
> +	info->phc_index = ax179_data->ptp->phc_index;
> +
> +	info->tx_types = BIT(HWTSTAMP_TX_OFF) |
> +			 BIT(HWTSTAMP_TX_ON) |
> +			 BIT(HWTSTAMP_TX_ONESTEP_SYNC) |
> +			 BIT(HWTSTAMP_TX_ONESTEP_P2P);
> +
> +	info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
> +			   BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
> +
> +	return 0;
> +}

[Severity: Medium]
Do info->tx_types and info->rx_filters match what ax88179a_hwtstamp_set()
actually supports?

ax88179a_hwtstamp_set() only accepts HWTSTAMP_TX_OFF and HWTSTAMP_TX_ON
and returns -ERANGE for HWTSTAMP_TX_ONESTEP_SYNC and
HWTSTAMP_TX_ONESTEP_P2P.  It also forces any non-NONE filter to
HWTSTAMP_FILTER_ALL, which is missing from info->rx_filters.

[ ... ]

> @@ -606,6 +672,11 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
>  
>  	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
>  			 AX_MAC_RX_PATH_READY | AX_MAC_TX_PATH_READY);
> +
> +	if (ax179_data->ptp) {
> +		ax179_data->ptp->ptp_config(dev, speed);
> +		ax179_data->ptp->ptp_read_ts(dev);
> +	}
>  }

[Severity: Medium]
Does ax88179a_ptp_config() expect SPEED_* values here instead of
ETHER_LINK_*?

ax88179a_mac_link_up() passes phylink's speed (SPEED_10, SPEED_100,
SPEED_1000), which matches ax88279_ptp_config(), but
ax88179a_ptp_config() switches on ETHER_LINK_10 (1), ETHER_LINK_100 (2),
and ETHER_LINK_1000 (3):

drivers/net/usb/ax88179a_ptp.c:ax88179a_ptp_config() {
    ...
	switch (speed) {
	case ETHER_LINK_10:
    ...
	case ETHER_LINK_100:
    ...
}

As a result, 10M and 100M links on AX88179A always fall through to the
default 1000M TX/RX PHY delay calibration values.

[Severity: High]
Can ptp_read_ts() in ax88179a_mac_link_up() race with
ax88179a_ptp_read_ts_work() and ax88279_process_tx_ts()?

On AX88179A, phylink resolve work calls ax88179a_ptp_read_ts(dev) here
while ptp->req_tx_timestamp work also calls ax88179a_ptp_read_ts(dev)
concurrently, writing into the shared ptp->ep4_buf and updating
ptp->ptp_info_buf and ptp->ptp_info_buf_head without any lock:

CPU0 (phylink resolve)            CPU1 (req_tx_timestamp / process_ptp)
ax88179a_mac_link_up()
  ax88179a_ptp_read_ts()
    ax88179_read_cmd(..., ep4_buf)
                                  ax88179a_ptp_read_ts_work()
                                    ax88179a_ptp_read_ts()
                                      ax88179_read_cmd(..., ep4_buf)
    ptp->ptp_info_buf_head++
                                  ax88279_process_tx_ts()
                                    match_ptp_ts()
                                      ptp_info_buf[ptp_info_buf_tail]
                                      <-- data race / out-of-bounds head
    ptp->ptp_info_buf_head %= ...

On both AX88179A and AX88279, the producer updates ptp_info_buf_head with
non-atomic ++ followed by %= AX88179A_PTP_QUEUE_SIZE without locking or
barriers against match_ptp_ts() running in ptp->process_ptp_info_buf work.

[Severity: High]
Do ax88179a_ptp_read_ts() and ax88279_read_ts_complete() read from
ptp_info[0] instead of ptp_info[i]?

Both functions loop over i = 0..AX88179A_PTP_QUEUE_SIZE - 1 and check
if (ptp_info[i].status), but copy the fields from ptp_info->... instead
of ptp_info[i]:

drivers/net/usb/ax88179a_ptp.c:ax88179a_ptp_read_ts() {
    ...
		if (ptp_info[i].status) {
			int j;

			j = ptp->ptp_info_buf_head;
			ptp->ptp_info_buf[j].msg_type = ptp_info->msg_type;
			ptp->ptp_info_buf[j].sequence_id = ptp_info->sequence_id;
			ptp->ptp_info_buf[j].nsec = le32_to_cpu(ptp_info->nsec);
			ptp->ptp_info_buf[j].sec = le16_to_cpu(ptp_info->sec_h);
			ptp->ptp_info_buf[j].sec <<= 32;
			ptp->ptp_info_buf[j].sec |= le32_to_cpu(ptp_info->sec_l);
    ...
}

Any TX timestamp delivered in queue slots 1..4 is lost and replaced with
slot 0.

[ ... ]

> @@ -927,6 +1003,30 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
>  	 */
>  	pm_runtime_get_noresume(&intf->dev);
>  
> +	if (!ptp_enable)
> +		return 0;
> +
> +	ret = ax88179a_ptp_register(dev);
> +	if (ret < 0) {
> +		netdev_warn(dev->net, "Failed to register PHC device. (%d)\n", ret);
> +		netdev_warn(dev->net, "PTP disabled\n");
> +		/* Disable PTP functionality again and cycle PHY to take effect */
> +		ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
> +		ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
> +		msleep(50);
> +		return 0;
> +	}
> +
> +	if (ax179_data->ptp && ax179_data->chip_version == AX_VERSION_AX88179A) {
> +		ax179_data->ptp->ptp_config(dev, SPEED_UNKNOWN);
> +
> +		/* Power cycle PHY to make PTP settings take effect,
> +		 * reset() will power on the PHY again
> +		 */
> +		ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
> +		msleep(50);
> +	}
> +
>  	return 0;

[Severity: High]
Can ax88179a_ptp_register() leave ax179_data->ptp dangling or with NULL
callbacks when registration fails or the hardware is unsupported?

In ax88179a_ptp_register(), ax179_data->ptp = ax88179a_ptp is assigned on
entry:

drivers/net/usb/ax88179a_ptp.c:ax88179a_ptp_register() {
    ...
	ax179_data->ptp = ax88179a_ptp;
    ...
	case AX_VERSION_AX88179A:
    ...
		if (ax88179_read_cmd(dev, AX88179A_ACCESS_BL,
				     AX88179A_HW_EC_VERSION, 1, 1, &ptp_ver) < 0)
			return 0;

		if (ptp_ver < 3) {
			netdev_warn(dev->net, "PTP on AX88179A version %d < 3 unsupported\n",
				    ptp_ver);
			return 0;
		}
    ...
no_ctrlreq:
	kfree(ax88179a_ptp->urb);
err:
	kfree(ax88179a_ptp);
	return ret;
}

On AX88179A with ptp_ver < 3 (including AX88772D) or an EC version read
failure, ax88179a_ptp_register() returns 0 before setting ptp_config,
pps_ctrl, and ptp_read_ts, so ax179_data->ptp->ptp_config() in
ax88179a_bind() immediately dereferences a NULL function pointer.

When ax88179a_ptp_register() returns a negative error, it frees
ax88179a_ptp without clearing ax179_data->ptp, and ax88179a_bind() returns
0, causing a use-after-free in every later if (ax179_data->ptp) check and
a double free in ax88179a_ptp_unregister().

[Severity: Medium]
Does ax88179a_ptp_register() also leak urb and ctrlreq and call kfree() on
a struct urb in its error paths?

In the snippet above, jumping to err after ptp_clock_register() fails (or
returning early on ptp_ver < 3) leaks ax88179a_ptp->urb and
ax88179a_ptp->ctrlreq, and the no_ctrlreq label frees ax88179a_ptp->urb
with kfree() instead of usb_free_urb().

[Severity: High]
Does linking ax88179a_ptp_register() into CONFIG_USB_NET_AX88179 fail when
CONFIG_USB_NET_AX88179=y and CONFIG_PTP_1588_CLOCK=m?

In commit "net: usb: ax88179: Add PTP support", depends on
PTP_1588_CLOCK_OPTIONAL was added to config USB_NET_AX8817X instead of
config USB_NET_AX88179 in drivers/net/usb/Kconfig, so a built-in ax88179
driver fails to link against modular ptp_clock_register(),
ptp_clock_index(), and ptp_clock_unregister().

[Severity: Medium]
Do the 32-bit register writes in ax88179a_ptp_config(),
ax88179a_ptp_pps_ctrl(), ax88279_ptp_pps_ctrl(), and
ax88279_ptp_pbus_write_u32() miss cpu_to_le32() conversion on big-endian
hosts?

ax88179_write_cmd() only byte-swaps 2-byte values (size == 2), unlike
ax88179_read_cmd() and ax88179_write_u32().  Passing a CPU-endian u32
with size 4 to ax88179_write_cmd() in those helpers sends big-endian
register values over USB on big-endian systems.

> @@ -946,6 +1046,8 @@ static void ax88179a_unbind(struct usbnet *dev, struct usb_interface *intf)
>  
>  	/* Configure RX control register => stop operation */
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
> +	ax88179a_ptp_kill_urbs(dev);
> +	ax88179a_ptp_unregister(dev);
>  
>  	rtnl_lock();
>  	phylink_disconnect_phy(ax179_data->phylink);

[Severity: High]
Can freeing ax179_data->ptp before phylink_disconnect_phy() cause a
use-after-free in ax88179a_unbind(), and does ax88179a_ptp_unregister()
leak urb on AX88179A?

ax88179a_ptp_unregister() frees ax179_data->ptp without clearing
ax179_data->ptp = NULL or cancelling ax88179a_ptp->req_tx_timestamp, and
it runs before phylink_disconnect_phy() flushes phylink resolve work:

CPU0                              CPU1 (phylink resolve / req_tx_timestamp)
ax88179a_unbind()
  ax88179a_ptp_unregister()
    kfree(ax179_data->ptp)
                                  ax88179a_mac_link_down()
                                    if (ax179_data->ptp)
                                      ax179_data->ptp->pps_ctrl(...)
                                      <-- use-after-free
  phylink_disconnect_phy()
    flush_work(&pl->resolve)

In addition, ax88179a_ptp_register() allocates ax88179a_ptp->urb on both
AX88279 and AX88179A, but ax88179a_ptp_unregister() only calls
usb_free_urb(ax88179a_ptp->urb) on AX88279, leaking the URB on every
AX88179A unbind.

> @@ -1017,8 +1119,10 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  	hdr_off = FIELD_GET(AX179A_RX_DH_DESC_OFFSET, rx_hdr);
>  	pkt_cnt = rx_hdr & AX179A_RX_DH_PKT_CNT_MASK;
>  
> -	/* Consistency check header position */
> -	if (hdr_off != skb->len - (pkt_cnt * sizeof(rx_hdr)))
> +	/* Consistency check header position, frames with PTP timestamps
> +	 * have longer headers than normal frames, so check for minimum size
> +	 */
> +	if (hdr_off > skb->len - (pkt_cnt * sizeof(rx_hdr)))
>  		goto err;

[Severity: High]
Can AX179A_RX_PD_PTP descriptors causepkt_desc_ptr to read past the end of
the SKB in ax88179a_rx_fixup()?

The pre-loop check only validates 8 bytes per packet (pkt_cnt * 8 +
hdr_off <= skb->len), and skb_trim(skb, hdr_off) then discards the original
metadata end offset.  When AX179A_RX_PD_PTP is set on a descriptor, the
loop consumes two additional 64-bit words (++pkt_desc_ptr twice) without
checking that 16 extra bytes remain in the metadata area before rx_hdr.
(Also, skb->len - (pkt_cnt * sizeof(rx_hdr)) can wrap around as an
unsigned subtraction when pkt_cnt * 8 > skb->len.)

> @@ -1075,6 +1179,13 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  			__vlan_hwaccel_put_tag(ax_skb, htons(ETH_P_8021Q), vlan_tag);
>  		}
>  
> +		if (pkt_desc & AX179A_RX_PD_PTP) {
> +			u64 ts_l = get_unaligned_le64(++pkt_desc_ptr);
> +			u64 ts_h = get_unaligned_le64(++pkt_desc_ptr);
> +
> +			ax88179a_process_rx_ts(ax_skb, ts_l, ts_h);
> +		}
> +
>  		usbnet_skb_return(dev, ax_skb);
>  		skb_pull(skb, pkt_len_plus_padd);

[Severity: High]
What happens if a packet with AX179A_RX_PD_PTP set hits the drop/error
check earlier in the ax88179a_rx_fixup() loop?

When a frame has AX179A_RX_PD_DROP set, lacks AX179A_RX_PD_RX_OK, or has an
invalid length, the continue branch only increments pkt_desc_ptr by one
u64 instead of skipping the two 64-bit timestamp words as well, so the
next iteration misinterprets ts_l as the next packet's RX descriptor.

[Severity: High]
Does AX179A_RX_PD_PTP overflow on 32-bit architectures?

In commit "net: usb: ax88179: Add PTP support", drivers/net/usb/ax88179_lib.h
defines AX179A_RX_PD_PTP as BIT(56) instead of BIT_ULL(56).  On 32-bit
builds, 1UL << 56 triggers -Wshift-count-overflow (breaking the build with
CONFIG_WERROR=y) and evaluates to 0.

> @@ -1090,6 +1201,7 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  
>  static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
>  {
> +	struct ax88179_data *ax179_data = dev->driver_priv;
>  	u64 tx_desc = skb->len & AX179A_TX_DESC_LEN_MASK;
>  	int frame_size = dev->maxpacket;
>  	struct sk_buff *ax_skb;
> @@ -1132,6 +1244,24 @@ static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb
>  	}
>  	if (padding_size != 0)
>  		skb_put_zero(skb, padding_size);
> +
> +	if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && ax179_data->ptp) {
> +		struct sk_buff *ptp_skb;
> +
> +		/* Keep the original SKB owned by the socket in our
> +		 * queue with PTP SKBs, while continuing TX with a
> +		 * clone, so that skb_tstamp_tx() can later return
> +		 * the TX timestamp via the socket's error channel.
> +		 */
> +		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
> +		ptp_skb = skb_clone(skb, GFP_ATOMIC);
> +		skb_queue_tail(&ax179_data->ptp->tx_skbs, skb);
> +		skb = ptp_skb;
> +		// Get the TX timestamp
> +		if (ax179_data->chip_version == AX_VERSION_AX88179A)
> +			schedule_work(&ax179_data->ptp->req_tx_timestamp);
> +	}
> +
>  	/* Copy TX header */
>  	tx_desc_ptr = skb_push(skb, sizeof(tx_desc));

[Severity: High]
If skb_clone() fails in ax88179a_tx_fixup(), won't skb_push() immediately
dereference a NULL skb pointer?

ptp_skb is not checked for NULL, so on allocation failure the original skb
is queued onto ax179_data->ptp->tx_skbs, skb becomes NULL, and skb_push()
crashes.

[Severity: Medium]
Does skb_copy_expand() earlier in ax88179a_tx_fixup() drop the socket and
SKBTX_HW_TSTAMP flag before this check runs?

When the outgoing skb is cloned or needs headroom or tailroom (for
example, when padding_size is 8..15 bytes and exceeds needed_tailroom of
8), ax88179a_tx_fixup() replaces skb with skb_copy_expand() and frees the
original socket-owned skb.  Because skb_copy_expand() does not copy
skb->sk or skb_shinfo(skb)->tx_flags, SKBTX_HW_TSTAMP is already cleared
by the time execution reaches this check and the TX timestamp is silently
lost.

Even when skb_copy_expand() is not taken, skb_put_zero() mutates the
length of the original skb before skb_clone(), skb_push() writes the TX
descriptor into the shared head buffer of a cloned skb, and on AX88179A
schedule_work(&ax179_data->ptp->req_tx_timestamp) runs before
usbnet_start_xmit() has submitted the TX URB.

[Severity: High]
Can queuing non-PTP packets with SKBTX_HW_TSTAMP here dereference an
uninitialized ptp_hdr pointer in ax88279_process_tx_ts()?

ax88179a_tx_fixup() queues any SKB with SKBTX_HW_TSTAMP onto
ptp->tx_skbs without checking ax179_data->ptp->tx_tstamp or classifying
the packet.  In ax88279_process_tx_ts(), ptp_hdr is uninitialized on the
stack and is only assigned when type != PTP_CLASS_NONE:

drivers/net/usb/ax88179a_ptp.c:ax88279_process_tx_ts() {
	struct ptp_header *ptp_hdr;
    ...
	skb_queue_walk_safe(&ptp->tx_skbs, skb, tmp) {
		type = ptp_classify_raw(skb);
		if (type != PTP_CLASS_NONE) {
			ptp_hdr = ptp_parse_header(skb, type);
			if (!ptp_hdr)
				goto frame_err;
		}
		match_ptp_ts(ptp, ptp_hdr, skb, type);
}

When a user sends a non-PTP packet on a socket with
SOF_TIMESTAMPING_TX_HARDWARE, type is PTP_CLASS_NONE and match_ptp_ts()
immediately dereferences the uninitialized (or stale) ptp_hdr pointer at
ntohs(ptp_hdr->sequence_id).

[Severity: High]
Does ax88279_process_tx_ts() walk and unlink from ptp->tx_skbs without
holding ptp->tx_skbs.lock?

ax88179a_tx_fixup() enqueues with skb_queue_tail(), which takes
tx_skbs.lock, while ax88279_process_tx_ts() walks ptp->tx_skbs with
skb_queue_walk_safe() and unlinks entries with unlocked __skb_unlink():

CPU0 (TX path)                    CPU1 (process_ptp_info_buf work)
ax88179a_tx_fixup()               ax88279_process_tx_ts()
  skb_queue_tail(&ptp->tx_skbs)     skb_queue_walk_safe(&ptp->tx_skbs, ...)
    spin_lock_irqsave(&lock)
    __skb_queue_tail(...)           __skb_unlink(skb, &ptp->tx_skbs)
                                    <-- list corruption
    spin_unlock_irqrestore(&lock)

Also, neither ax88179a_mac_link_down() nor ax88179a_stop() cancels
ptp->process_ptp_info_buf or purges ptp->tx_skbs, leaving any queued SKBs
pinned until unbind.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-ptp-v1-0-8148c402beaf@birger-koblitz.de?part=3

      parent reply	other threads:[~2026-11-30  9:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:29 [PATCH net-next 0/3] net: usb: ax88179: Add support for PTP Birger Koblitz
2026-11-29  9:29 ` [PATCH net-next 1/3] net: usb: ax88179: Add PTP data structures and definitions Birger Koblitz
2026-11-30  9:30   ` sashiko-bot
2026-11-29  9:29 ` [PATCH net-next 2/3] net: usb: ax88179: Add PTP Implementation Birger Koblitz
2026-11-29 18:31   ` Manuel Ebner
2026-11-30  5:18     ` Birger Koblitz
2026-11-30  9:30   ` sashiko-bot
2026-11-29  9:29 ` [PATCH net-next 3/3] net: usb: ax88179: Enable PTP Birger Koblitz
2026-11-29 15:48   ` Andrew Lunn
2026-11-29 17:24     ` Birger Koblitz
2026-11-29 21:09       ` Andrew Lunn
2026-11-29 21:18   ` kernel test robot
2026-11-30  9:30   ` sashiko-bot [this message]

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-240777@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.