Skip to contentSkip to conversation

ice: fix potential NULL pointer deref in error path of ice_set_ringparam()

PATCH In review Kohei Enju 5 participants 7 messages Feb 20 – Apr 9

Subsystems (3)
lore
Share & tools
lore

Kohei Enju

author
#0 lore raw

PATCH 1/1 ice: fix potential NULL pointer deref in error path of ice_set_ringparam()

ice_set_ringparam nullifies tstamp_ring of temporary tx_rings, without clearing ICE_TX_RING_FLAGS_TXTIME bit.
When ICE_TX_RING_FLAGS_TXTIME is set and the subsequent ice_setup_tx_ring() call fails, a NULL pointer dereference could happen in the unwinding sequence:

ice_clean_tx_ring()
-> ice_is_txtime_cfg() == true (ICE_TX_RING_FLAGS_TXTIME is set) -> ice_free_tx_tstamp_ring()
-> ice_free_tstamp_ring()

    -> tstamp_ring->desc (NULL deref)

Clear ICE_TX_RING_FLAGS_TXTIME bit to avoid the potential issue.

Note that this potential issue is found by manual code review. Compile test only since unfortunately I don't have E830 devices.

Fixes ccde82e90946 ("ice: add E830 Earliest TxTime First Offload support")
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -0
index 7f769a90dde1..5ed86648d0d6 100644
@@ -3290,6 +3290,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
 		tx_rings[i].desc = NULL;
 		tx_rings[i].tx_buf = NULL;
 		tx_rings[i].tstamp_ring = NULL;
+		clear_bit(ICE_TX_RING_FLAGS_TXTIME, tx_rings[i].flags);
 		tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
 		err = ice_setup_tx_ring(&tx_rings[i]);
 		if (err) {
Signature · 1 line
2.51.0
#1 lore raw
Quoted 30 lines

-----Original Message-----
From: Kohei Enju <[email protected]>
Sent: Friday, February 20, 2026 7:40 PM
To: [email protected]; [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Loktionov, Aleksandr <[email protected]>; Alice Michael <[email protected]>; Greenwalt, Paul <[email protected]>; Fijalkowski, Maciej <[email protected]>; [email protected]; Kohei Enju <[email protected]>
Subject: [PATCH v1 iwl-net] ice: fix potential NULL pointer deref in error path of ice_set_ringparam()

ice_set_ringparam nullifies tstamp_ring of temporary tx_rings, without clearing ICE_TX_RING_FLAGS_TXTIME bit.
When ICE_TX_RING_FLAGS_TXTIME is set and the subsequent ice_setup_tx_ring() call fails, a NULL pointer dereference could happen in the unwinding sequence:

ice_clean_tx_ring()
-> ice_is_txtime_cfg() == true (ICE_TX_RING_FLAGS_TXTIME is set) -> ice_free_tx_tstamp_ring()
-> ice_free_tstamp_ring()

    -> tstamp_ring->desc (NULL deref)
Quoted 7 lines

Clear ICE_TX_RING_FLAGS_TXTIME bit to avoid the potential issue.

Note that this potential issue is found by manual code review. Compile test only since unfortunately I don't have E830 devices.

Fixes ccde82e90946 ("ice: add E830 Earliest TxTime First Offload

support")

If it's a fix, shouldn't it go to net?

Quoted 11 lines
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_ethtool.c +0 -0
index 7f769a90dde1..5ed86648d0d6 100644

drivers/net/ethernet/intel/ice/ice_ethtool.c ice_set_ringparam(struct net_device *netdev, · line 3296

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -0
@@ -3290,6 +3290,7 @@ ice_set_ringparam(struct net_device *netdev,
 struct ethtool_ringparam *ring,
 		tx_rings[i].desc = NULL;
 		tx_rings[i].tx_buf = NULL;
 		tx_rings[i].tstamp_ring = NULL;
+		clear_bit(ICE_TX_RING_FLAGS_TXTIME, tx_rings[i].flags);
 		tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
 		err = ice_setup_tx_ring(&tx_rings[i]);

If ice_setup_tx_ring() internally reads ICE_TX_RING_FLAGS_TXTIME to decide whether to allocate the tstamp_ring, then clearing the bit first means ice_setup_tx_ring() skips TxTime setup even on success - leaving TxTime silently broken after ice_set_ringparam() completes normally. The crash is fixed on the error path, but I'm afraid a functional regression is introduced on the success path. Please correct me if I'm wrong.

Thank you
Alex

Quoted 3 lines

if (err) {
--
2.51.0

author
#2 lore raw
Quoted 35 lines · Aleksandr
Quoted 27 lines

-----Original Message-----
From: Kohei Enju <[email protected]>
Sent: Friday, February 20, 2026 7:40 PM
To: [email protected]; [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Loktionov, Aleksandr <[email protected]>; Alice Michael <[email protected]>; Greenwalt, Paul <[email protected]>; Fijalkowski, Maciej <[email protected]>; [email protected]; Kohei Enju <[email protected]>
Subject: [PATCH v1 iwl-net] ice: fix potential NULL pointer deref in error path of ice_set_ringparam()
=20
ice_set_ringparam nullifies tstamp_ring of temporary tx_rings, without clearing ICE_TX_RING_FLAGS_TXTIME bit.
When ICE_TX_RING_FLAGS_TXTIME is set and the subsequent ice_setup_tx_ring() call fails, a NULL pointer dereference could happen in the unwinding sequence:
=20
ice_clean_tx_ring()
-> ice_is_txtime_cfg() =3D=3D true (ICE_TX_RING_FLAGS_TXTIME is set) -> ice_free_tx_tstamp_ring()
-> ice_free_tstamp_ring()

    -> tstamp_ring->desc (NULL deref)
Quoted 8 lines

=20
Clear ICE_TX_RING_FLAGS_TXTIME bit to avoid the potential issue. =20
Note that this potential issue is found by manual code review. Compile test only since unfortunately I don't have E830 devices. =20

Fixes ccde82e90946 ("ice: add E830 Earliest TxTime First Offload

support")

Quoted 1 line

If it's a fix, shouldn't it go to net?

This fix relies on a commit 8a4e78094945 ("ice: fix race condition in TX timestamp ring cleanup"), which changed type of flags from u8 to BITMAP, as you advised in [1].
Since the commit only exists in Tony's tree, I chose iwl-net, not net.

[1] https://lore.kernel.org/intel-wired-lan/IA3PR11MB8986EB459D2FD1697644CF98E598A@IA3PR11MB8986.namprd11.prod.outlook.com/

Quoted 18 lines
Quoted 18 lines
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 1 +
 1 file changed, 1 insertion(+)

=20

drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -0
index 7f769a90dde1..5ed86648d0d6 100644
@@ -3290,6 +3290,7 @@ ice_set_ringparam(struct net_device *netdev,
 struct ethtool_ringparam *ring,
 		tx_rings[i].desc =3D NULL;
 		tx_rings[i].tx_buf =3D NULL;
 		tx_rings[i].tstamp_ring =3D NULL;
+		clear_bit(ICE_TX_RING_FLAGS_TXTIME, tx_rings[i].flags);
 		tx_rings[i].tx_tstamps =3D &pf->ptp.port.tx;
Quoted 8 lines

drivers/net/ethernet/intel/ice/ice_ethtool.c ice_set_ringparam(struct net_device *netdev, · line 3296

Quoted 1 line
drivers/net/ethernet/intel/ice/ice_ethtool.c +0 -0
 		err =3D ice_setup_tx_ring(&tx_rings[i]);

If ice_setup_tx_ring() internally reads ICE_TX_RING_FLAGS_TXTIME to decide = whether to allocate the tstamp_ring, then clearing the bit first means ice_= setup_tx_ring() skips TxTime setup even on success - leaving TxTime silentl= y broken after ice_set_ringparam() completes normally. The crash is fixed o= n the error path, but I'm afraid a functional regression is introduced on t= he success path.
Please correct me if I'm wrong.

I believe, in the successful path, tx_tstamps and the flag ICE_TX_RING_FLAGS_TXTIME are restored in ice_up().

ice_up()
ice_vsi_cfg_lan()
ice_vsi_cfg_lan_txqs()
ice_vsi_cfg_txqs()
ice_vsi_cfg_txq()
ice_is_txtime_ena() ( == test_bit(ring->q_index, pf->txtime_txqs)) ice_alloc_setup_tstamp_ring()
ice_alloc_tstamp_ring()
- allocate tx_tstamps
- set_bit(ICE_TX_RING_FLAGS_TXTIME, tx_ring->flags);

Enablement of TxTime feature is managed by pf->txtime_txqs, and ring->flags represents only a 'result' of the enablement.

Therefore I think it's not a problem, but please let me know if my understanding is wrong.
Thank you for reviewing, Alex!

Quoted 7 lines

Thank you
Alex

Quoted 3 lines

if (err) {
--
2.51.0

#3 lore raw
In reply to Loktionov, Aleksandr
Quoted 30 lines · Aleksandr
Quoted 30 lines

-----Original Message-----
From: Kohei Enju <[email protected]>
Sent: Friday, February 20, 2026 7:40 PM
To: [email protected]; [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Loktionov, Aleksandr <[email protected]>; Alice Michael <[email protected]>; Greenwalt, Paul <[email protected]>; Fijalkowski, Maciej <[email protected]>; [email protected]; Kohei Enju <[email protected]>
Subject: [PATCH v1 iwl-net] ice: fix potential NULL pointer deref in error path of ice_set_ringparam()

ice_set_ringparam nullifies tstamp_ring of temporary tx_rings, without clearing ICE_TX_RING_FLAGS_TXTIME bit.
When ICE_TX_RING_FLAGS_TXTIME is set and the subsequent ice_setup_tx_ring() call fails, a NULL pointer dereference could happen in the unwinding sequence:

ice_clean_tx_ring()
-> ice_is_txtime_cfg() == true (ICE_TX_RING_FLAGS_TXTIME is set) -> ice_free_tx_tstamp_ring()
-> ice_free_tstamp_ring()

    -> tstamp_ring->desc (NULL deref)
Quoted 9 lines
Quoted 7 lines

Clear ICE_TX_RING_FLAGS_TXTIME bit to avoid the potential issue.

Note that this potential issue is found by manual code review. Compile test only since unfortunately I don't have E830 devices.

Fixes ccde82e90946 ("ice: add E830 Earliest TxTime First Offload

support")

If it's a fix, shouldn't it go to net?

Thank you for identifying this bug. However, clearing ICE_TX_RING_FLAGS_TXTIME before ice_setup_tx_ring() will break TxTime offload on the success path.

ice_setup_tx_ring() doesn't read this flag, but ice_up() (called later) needs it set to reallocate the tstamp ring for the new ring size. Your change would silently disable TxTime after any successful ring parameter change.

The fix should clear the flag only in the error path:

if (err) {
	while (i--) {
		clear_bit(ICE_TX_RING_FLAGS_TXTIME, tx_rings[i].flags);
		ice_clean_tx_ring(&tx_rings[i]);
	}
	vfree(tx_rings);
	goto done;
}

Also, per Alex's comment, please target 'net'.

Thanks,
Paul

Quoted 28 lines
Quoted 11 lines
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_ethtool.c +0 -0
index 7f769a90dde1..5ed86648d0d6 100644

drivers/net/ethernet/intel/ice/ice_ethtool.c ice_set_ringparam(struct net_device *netdev, · line 3296

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -0
@@ -3290,6 +3290,7 @@ ice_set_ringparam(struct net_device *netdev,
 struct ethtool_ringparam *ring,
 		tx_rings[i].desc = NULL;
 		tx_rings[i].tx_buf = NULL;
 		tx_rings[i].tstamp_ring = NULL;
+		clear_bit(ICE_TX_RING_FLAGS_TXTIME, tx_rings[i].flags);
 		tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
 		err = ice_setup_tx_ring(&tx_rings[i]);

If ice_setup_tx_ring() internally reads ICE_TX_RING_FLAGS_TXTIME to decide whether to allocate the tstamp_ring, then clearing the bit first means ice_setup_tx_ring() skips TxTime setup even on success - leaving TxTime silently broken after ice_set_ringparam() completes normally. The crash is fixed on the error path, but I'm afraid a functional regression is introduced on the success path. Please correct me if I'm wrong.

Thank you
Alex

Quoted 3 lines

if (err) {
--
2.51.0

maintainer
#4 lore raw
Quoted 3 lines · Paul

On 2/20/2026 12:04 PM, Loktionov, Aleksandr wrote:

...

Quoted 1 line

Also, per Alex's comment, please target 'net'.

Since this is for an Intel driver, iwl-net is the correct target.

Also, as was responded, this works off changes that are only on net-queue at the moment.

https://lore.kernel.org/intel-wired-lan/[email protected]/

Thanks,
Tony

Reviewed-by
#5 lore raw
Quoted 11 lines · Tony Nguyen
Quoted 3 lines · Paul

On 2/20/2026 12:04 PM, Loktionov, Aleksandr wrote:

...

Quoted 1 line

Also, per Alex's comment, please target 'net'.

Quoted 8 lines

Since this is for an Intel driver, iwl-net is the correct target.

Also, as was responded, this works off changes that are only on net- queue at the moment.

https://lore.kernel.org/intel-wired-lan/20260220204526.7514-1-
[email protected]/

Thanks for the clarification Kohei and Tony.

Quoted 2 lines

Thanks,
Tony

Tested-by on v1 1/1
#6 lore raw
In reply to Kohei Enju
Quoted 19 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Kohei Enju
Sent: 21 February 2026 00:10
To: [email protected]; [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Loktionov, Aleksandr <[email protected]>; Alice Michael <[email protected]>; Greenwalt, Paul <[email protected]>; Fijalkowski, Maciej <[email protected]>; [email protected]; Kohei Enju <[email protected]>
Subject: [Intel-wired-lan] [PATCH v1 iwl-net] ice: fix potential NULL pointer deref in error path of ice_set_ringparam()

ice_set_ringparam nullifies tstamp_ring of temporary tx_rings, without clearing ICE_TX_RING_FLAGS_TXTIME bit. When ICE_TX_RING_FLAGS_TXTIME is set and the subsequent
ice_setup_tx_ring() call fails, a NULL pointer dereference could happen in the unwinding sequence:

ice_clean_tx_ring()
-> ice_is_txtime_cfg() == true (ICE_TX_RING_FLAGS_TXTIME is set) -> ice_free_tx_tstamp_ring()
-> ice_free_tstamp_ring()
-> tstamp_ring->desc (NULL deref)

Clear ICE_TX_RING_FLAGS_TXTIME bit to avoid the potential issue.

Quoted 9 lines

Note that this potential issue is found by manual code review. Compile test only since unfortunately I don't have E830 devices.

Fixes ccde82e90946 ("ice: add E830 Earliest TxTime First Offload support")

---
drivers/net/ethernet/intel/ice/ice_ethtool.c | 1 +

1 file changed, 1 insertion(+)