Skip to contentSkip to conversation

ice: fix stats array overflow when VF requests more queues

PATCH In review Michal Schmidt 6 participants 10 messages Apr 27 – Jun 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: fix stats array overflow when VF requests more queues

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

KASAN detects the bug:
==================================================================

 BUG: KASAN: slab-out-of-bounds in ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]
 Read of size 8 at addr ffff88810affea60 by task kworker/u131:7/221

 CPU: 24 UID: 0 PID: 221 Comm: kworker/u131:7 Not tainted 7.1.0-rc1+ #1 PREEMPT(lazy)
 ...
 Workqueue: ice ice_service_task [ice]
 Call Trace:
  <TASK>
  ...
  kasan_report+0xd7/0x120
  ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]
  ice_vsi_cfg_def+0x12e2/0x2060 [ice]
  ice_vsi_cfg+0xb5/0x3c0 [ice]
  ice_reset_vf+0x858/0xf80 [ice]
  ice_vc_request_qs_msg+0x1da/0x290 [ice]
  ice_vc_process_vf_msg+0xb15/0x1430 [ice]
  __ice_clean_ctrlq+0x70d/0x9d0 [ice]
  ice_service_task+0x840/0xf20 [ice]
  process_one_work+0x690/0xff0
  worker_thread+0x4d9/0xd20
  kthread+0x322/0x410
  ret_from_fork+0x332/0x660
  ret_from_fork_asm+0x1a/0x30
  </TASK>

 Allocated by task 2439:
  kasan_save_stack+0x1c/0x40
  kasan_save_track+0x10/0x30
  __kasan_kmalloc+0x96/0xb0
  __kmalloc_noprof+0x1d8/0x580
  ice_vsi_cfg_def+0x115c/0x2060 [ice]
  ice_vsi_cfg+0xb5/0x3c0 [ice]
  ice_vsi_setup+0x180/0x320 [ice]
  ice_start_vfs+0x1f3/0x590 [ice]
  ice_ena_vfs+0x66d/0x798 [ice]
  ice_sriov_configure.cold+0xe4/0x121 [ice]
  sriov_numvfs_store+0x279/0x480
  kernfs_fop_write_iter+0x331/0x4f0
  vfs_write+0x4c4/0xe40
  ksys_write+0x10c/0x240
  do_syscall_64+0xd9/0x650
  entry_SYSCALL_64_after_hwframe+0x76/0x7e

 The buggy address belongs to the object at ffff88810affea40
                which belongs to the cache kmalloc-32 of size 32
 The buggy address is located 0 bytes to the right of
                allocated 32-byte region [ffff88810affea40, ffff88810affea60)
 ...
 ==================================================================

ice_vsi_rebuild() handles this correctly by calling ice_vsi_realloc_stat_arrays() before reconfiguration, but ice_vf_reconfig_vsi() was missing this call.

Fix by calling ice_vsi_realloc_stat_arrays() in ice_vf_reconfig_vsi() before ice_vsi_decfg(), mirroring the ice_vsi_rebuild() pattern. Set vsi->req_txq/req_rxq from vf->num_req_qs so the realloc function knows the target array size.

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with ice_vf_reconfig_vsi()")
Assisted-by Claude:claude-opus-4-6 semcode
---
 drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
 drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
 drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -1
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
  * ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones
  * @vsi: VSI pointer
  */
-static int
+int
 ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)
 {
 	u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
drivers/net/ethernet/intel/ice/ice_lib.h +1 -0
index 49454d98dcfe..6f7da84384e5 100644
@@ -66,6 +66,7 @@ int ice_ena_vsi(struct ice_vsi *vsi, bool locked);
 void ice_vsi_decfg(struct ice_vsi *vsi);
 void ice_dis_vsi(struct ice_vsi *vsi, bool locked);
 
+int ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi);
 int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags);
 int ice_vsi_cfg(struct ice_vsi *vsi);
 struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf);
drivers/net/ethernet/intel/ice/ice_vf_lib.c +7 -0
index 772f6b07340d..9edb2c14f553 100644
@@ -268,6 +268,13 @@ static int ice_vf_reconfig_vsi(struct ice_vf *vf)
 
 	vsi->flags = ICE_VSI_FLAG_NO_INIT;
 
+	vsi->req_txq = vf->num_req_qs;
+	vsi->req_rxq = vf->num_req_qs;
+
+	err = ice_vsi_realloc_stat_arrays(vsi);
+	if (err)
+		return err;
+
 	ice_vsi_decfg(vsi);
 	ice_fltr_remove_all(vsi);
 
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 91 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Michal Schmidt
Sent: Monday, April 27, 2026 5:18 PM
To: 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]>; Keller, Jacob E <[email protected]>; Oros, Petr <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: [Intel-wired-lan] [PATCH net] ice: fix stats array overflow when VF requests more queues

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

KASAN detects the bug:
==================================================================

 BUG: KASAN: slab-out-of-bounds in
ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]  Read of size 8 at addr

ffff88810affea60 by task kworker/u131:7/221

 CPU: 24 UID: 0 PID: 221 Comm: kworker/u131:7 Not tainted 7.1.0-rc1+
#1 PREEMPT(lazy)  ...
 Workqueue: ice ice_service_task [ice]
 Call Trace:
  <TASK>
  ...
  kasan_report+0xd7/0x120
  ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]
  ice_vsi_cfg_def+0x12e2/0x2060 [ice]
  ice_vsi_cfg+0xb5/0x3c0 [ice]
  ice_reset_vf+0x858/0xf80 [ice]
  ice_vc_request_qs_msg+0x1da/0x290 [ice]
  ice_vc_process_vf_msg+0xb15/0x1430 [ice]
  __ice_clean_ctrlq+0x70d/0x9d0 [ice]
  ice_service_task+0x840/0xf20 [ice]
  process_one_work+0x690/0xff0
  worker_thread+0x4d9/0xd20
  kthread+0x322/0x410
  ret_from_fork+0x332/0x660
  ret_from_fork_asm+0x1a/0x30
  </TASK>

 Allocated by task 2439:
  kasan_save_stack+0x1c/0x40
  kasan_save_track+0x10/0x30
  __kasan_kmalloc+0x96/0xb0
  __kmalloc_noprof+0x1d8/0x580
  ice_vsi_cfg_def+0x115c/0x2060 [ice]
  ice_vsi_cfg+0xb5/0x3c0 [ice]
  ice_vsi_setup+0x180/0x320 [ice]
  ice_start_vfs+0x1f3/0x590 [ice]
  ice_ena_vfs+0x66d/0x798 [ice]
  ice_sriov_configure.cold+0xe4/0x121 [ice]
  sriov_numvfs_store+0x279/0x480
  kernfs_fop_write_iter+0x331/0x4f0
  vfs_write+0x4c4/0xe40
  ksys_write+0x10c/0x240
  do_syscall_64+0xd9/0x650
  entry_SYSCALL_64_after_hwframe+0x76/0x7e

 The buggy address belongs to the object at ffff88810affea40
                which belongs to the cache kmalloc-32 of size 32  The
buggy address is located 0 bytes to the right of
                allocated 32-byte region [ffff88810affea40,

ffff88810affea60) ...
==================================================================

ice_vsi_rebuild() handles this correctly by calling ice_vsi_realloc_stat_arrays() before reconfiguration, but ice_vf_reconfig_vsi() was missing this call.

Fix by calling ice_vsi_realloc_stat_arrays() in ice_vf_reconfig_vsi() before ice_vsi_decfg(), mirroring the ice_vsi_rebuild() pattern. Set vsi->req_txq/req_rxq from vf->num_req_qs so the realloc function knows the target array size.

Quoted 5 lines

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with

ice_vf_reconfig_vsi()")

Not sure are links to local JIRAs are acceptable in kernel?

Why no Cc: [email protected]?

Quoted 57 lines
Assisted-by Claude:claude-opus-4-6 semcode
---
 drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
 drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
 drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -0
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi
 *vsi,
  * ice_vsi_realloc_stat_arrays - Frees unused stat structures or

alloc new ones
* @vsi: VSI pointer
*/

drivers/net/ethernet/intel/ice/ice_lib.c +1 -1
-static int
+int
 ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)  {
 	u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
drivers/net/ethernet/intel/ice/ice_lib.h +0 -0
index 49454d98dcfe..6f7da84384e5 100644
@@ -66,6 +66,7 @@ int ice_ena_vsi(struct ice_vsi *vsi, bool locked);

void ice_vsi_decfg(struct ice_vsi *vsi); void ice_dis_vsi(struct ice_vsi *vsi, bool locked);

+int ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi);
int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags); int
ice_vsi_cfg(struct ice_vsi *vsi); struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf); diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.c b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
index 772f6b07340d..9edb2c14f553 100644

drivers/net/ethernet/intel/ice/ice_vf_lib.c +7 -1
@@ -268,6 +268,13 @@ static int ice_vf_reconfig_vsi(struct ice_vf *vf)
 
 	vsi->flags = ICE_VSI_FLAG_NO_INIT;
 
+	vsi->req_txq = vf->num_req_qs;
+	vsi->req_rxq = vf->num_req_qs;
+
+	err = ice_vsi_realloc_stat_arrays(vsi);
+	if (err)
+		return err;
+
 	ice_vsi_decfg(vsi);
 	ice_fltr_remove_all(vsi);
 
--

2.54.0

#2 lore raw
Quoted 3 lines · Aleksandr
Quoted 3 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Michal Schmidt

...

Quoted 6 lines
Quoted 5 lines

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with

ice_vf_reconfig_vsi()")

Not sure are links to local JIRAs are acceptable in kernel?

The ticket is publicly visible and does not require a login.

Quoted 1 line

Why no Cc: [email protected]?

Apparently I still have not internalized the removal of the netdev special stable handling from 5 years ago. Sorry!

Michal

Quoted 60 lines
Quoted 57 lines
Assisted-by Claude:claude-opus-4-6 semcode
---
 drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
 drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
 drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -0
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi
 *vsi,
  * ice_vsi_realloc_stat_arrays - Frees unused stat structures or

alloc new ones
* @vsi: VSI pointer
*/

drivers/net/ethernet/intel/ice/ice_lib.c +1 -1
-static int
+int
 ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)  {
      u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
drivers/net/ethernet/intel/ice/ice_lib.h +0 -0
index 49454d98dcfe..6f7da84384e5 100644
@@ -66,6 +66,7 @@ int ice_ena_vsi(struct ice_vsi *vsi, bool locked);

void ice_vsi_decfg(struct ice_vsi *vsi); void ice_dis_vsi(struct ice_vsi *vsi, bool locked);

+int ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi);
int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags); int
ice_vsi_cfg(struct ice_vsi *vsi); struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf); diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.c b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
index 772f6b07340d..9edb2c14f553 100644

drivers/net/ethernet/intel/ice/ice_vf_lib.c +7 -1
@@ -268,6 +268,13 @@ static int ice_vf_reconfig_vsi(struct ice_vf *vf)
 
      vsi->flags = ICE_VSI_FLAG_NO_INIT;
 
+     vsi->req_txq = vf->num_req_qs;
+     vsi->req_rxq = vf->num_req_qs;
+
+     err = ice_vsi_realloc_stat_arrays(vsi);
+     if (err)
+             return err;
+
      ice_vsi_decfg(vsi);
      ice_fltr_remove_all(vsi);
 
--

2.54.0

#3 lore raw
Quoted 9 lines · Michal Schmidt
Quoted 1 line · Aleksandr

Why no Cc: [email protected]?

Apparently I still have not internalized the removal of the netdev special stable handling from 5 years ago. Sorry!

Michal

Old habbits take a while to change :D

maintainer
#4 lore raw
In reply to Michal Schmidt
Quoted 12 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

thank you for reproducing the bug, it is exactly the situation that I was facing
have you tried with my proposed (unfortunately not public yet) fix to just combine ice_vsi_alloc_stat_arrays() and ice_vsi_realloc_stat_arrays() into one function?

I will check yours too, but need to rebuild.

Quoted 116 lines

KASAN detects the bug:
==================================================================

  BUG: KASAN: slab-out-of-bounds in ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]
  Read of size 8 at addr ffff88810affea60 by task kworker/u131:7/221

  CPU: 24 UID: 0 PID: 221 Comm: kworker/u131:7 Not tainted 7.1.0-rc1+ #1 PREEMPT(lazy)
  ...
  Workqueue: ice ice_service_task [ice]
  Call Trace:
   <TASK>
   ...
   kasan_report+0xd7/0x120
   ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice]
   ice_vsi_cfg_def+0x12e2/0x2060 [ice]
   ice_vsi_cfg+0xb5/0x3c0 [ice]
   ice_reset_vf+0x858/0xf80 [ice]
   ice_vc_request_qs_msg+0x1da/0x290 [ice]
   ice_vc_process_vf_msg+0xb15/0x1430 [ice]
   __ice_clean_ctrlq+0x70d/0x9d0 [ice]
   ice_service_task+0x840/0xf20 [ice]
   process_one_work+0x690/0xff0
   worker_thread+0x4d9/0xd20
   kthread+0x322/0x410
   ret_from_fork+0x332/0x660
   ret_from_fork_asm+0x1a/0x30
   </TASK>

  Allocated by task 2439:
   kasan_save_stack+0x1c/0x40
   kasan_save_track+0x10/0x30
   __kasan_kmalloc+0x96/0xb0
   __kmalloc_noprof+0x1d8/0x580
   ice_vsi_cfg_def+0x115c/0x2060 [ice]
   ice_vsi_cfg+0xb5/0x3c0 [ice]
   ice_vsi_setup+0x180/0x320 [ice]
   ice_start_vfs+0x1f3/0x590 [ice]
   ice_ena_vfs+0x66d/0x798 [ice]
   ice_sriov_configure.cold+0xe4/0x121 [ice]
   sriov_numvfs_store+0x279/0x480
   kernfs_fop_write_iter+0x331/0x4f0
   vfs_write+0x4c4/0xe40
   ksys_write+0x10c/0x240
   do_syscall_64+0xd9/0x650
   entry_SYSCALL_64_after_hwframe+0x76/0x7e

  The buggy address belongs to the object at ffff88810affea40
                 which belongs to the cache kmalloc-32 of size 32
  The buggy address is located 0 bytes to the right of
                 allocated 32-byte region [ffff88810affea40, ffff88810affea60)
  ...
  ==================================================================

ice_vsi_rebuild() handles this correctly by calling ice_vsi_realloc_stat_arrays() before reconfiguration, but ice_vf_reconfig_vsi() was missing this call.

Fix by calling ice_vsi_realloc_stat_arrays() in ice_vf_reconfig_vsi() before ice_vsi_decfg(), mirroring the ice_vsi_rebuild() pattern. Set vsi->req_txq/req_rxq from vf->num_req_qs so the realloc function knows the target array size.

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with ice_vf_reconfig_vsi()")
Assisted-by Claude:claude-opus-4-6 semcode
---
  drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
  drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
  drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
  3 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -1
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
   * ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones
   * @vsi: VSI pointer
   */
-static int
+int
  ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)
  {
  	u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
drivers/net/ethernet/intel/ice/ice_lib.h +1 -0
index 49454d98dcfe..6f7da84384e5 100644
@@ -66,6 +66,7 @@ int ice_ena_vsi(struct ice_vsi *vsi, bool locked);
  void ice_vsi_decfg(struct ice_vsi *vsi);
  void ice_dis_vsi(struct ice_vsi *vsi, bool locked);
 
+int ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi);
  int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags);
  int ice_vsi_cfg(struct ice_vsi *vsi);
  struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf);
drivers/net/ethernet/intel/ice/ice_vf_lib.c +7 -0
index 772f6b07340d..9edb2c14f553 100644
@@ -268,6 +268,13 @@ static int ice_vf_reconfig_vsi(struct ice_vf *vf)
 
  	vsi->flags = ICE_VSI_FLAG_NO_INIT;
 
+	vsi->req_txq = vf->num_req_qs;
+	vsi->req_rxq = vf->num_req_qs;
+
+	err = ice_vsi_realloc_stat_arrays(vsi);
+	if (err)
+		return err;
+
  	ice_vsi_decfg(vsi);
  	ice_fltr_remove_all(vsi);
 
reviewer Reviewed-by on v1 1/1
#7 lore raw
In reply to Michal Schmidt
Quoted 11 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

...

Quoted 6 lines

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with ice_vf_reconfig_vsi()")
Assisted-by Claude:claude-opus-4-6 semcode

FTR: There is an AI generated review of this patch available on sashiko.dev. I believe the issues flagged there pre-date this patch and do not impact this patch. So while I do not think they should block progress of this patch I suggest looking over them to see if any follow-up is warranted.

#5 lore raw
In reply to Przemek Kitszel
Quoted 14 lines · Przemek Kitszel
Quoted 12 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

Quoted 5 lines

thank you for reproducing the bug, it is exactly the situation that I was facing
have you tried with my proposed (unfortunately not public yet) fix to just combine ice_vsi_alloc_stat_arrays() and ice_vsi_realloc_stat_arrays() into one function?

I tried that now and the result is: yes, your patch fixes the bug too. Michal

maintainer Reviewed-by on v1 1/1
#8 lore raw
In reply to Michal Schmidt
Quoted 13 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

KASAN detects the bug:

[...]

Quoted 10 lines

ice_vsi_rebuild() handles this correctly by calling ice_vsi_realloc_stat_arrays() before reconfiguration, but ice_vf_reconfig_vsi() was missing this call.

Fix by calling ice_vsi_realloc_stat_arrays() in ice_vf_reconfig_vsi() before ice_vsi_decfg(), mirroring the ice_vsi_rebuild() pattern. Set vsi->req_txq/req_rxq from vf->num_req_qs so the realloc function knows the target array size.

Quoted 5 lines

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with ice_vf_reconfig_vsi()")

I have an unpublished fix for the same issue,
but your patch is smaller, and thus more suitable for net-

thank you

Quoted 50 lines
Assisted-by Claude:claude-opus-4-6 semcode
---
  drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
  drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
  drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
  3 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -1
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
   * ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones
   * @vsi: VSI pointer
   */
-static int
+int
  ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)
  {
  	u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
drivers/net/ethernet/intel/ice/ice_lib.h +1 -0
index 49454d98dcfe..6f7da84384e5 100644
@@ -66,6 +66,7 @@ int ice_ena_vsi(struct ice_vsi *vsi, bool locked);
  void ice_vsi_decfg(struct ice_vsi *vsi);
  void ice_dis_vsi(struct ice_vsi *vsi, bool locked);
 
+int ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi);
  int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags);
  int ice_vsi_cfg(struct ice_vsi *vsi);
  struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf);
drivers/net/ethernet/intel/ice/ice_vf_lib.c +7 -0
index 772f6b07340d..9edb2c14f553 100644
@@ -268,6 +268,13 @@ static int ice_vf_reconfig_vsi(struct ice_vf *vf)
 
  	vsi->flags = ICE_VSI_FLAG_NO_INIT;
 
+	vsi->req_txq = vf->num_req_qs;
+	vsi->req_rxq = vf->num_req_qs;
+
+	err = ice_vsi_realloc_stat_arrays(vsi);
+	if (err)
+		return err;
+
  	ice_vsi_decfg(vsi);
  	ice_fltr_remove_all(vsi);
 
#9 lore raw
Quoted 61 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Przemek Kitszel
Sent: Monday, May 4, 2026 3:09 PM
To: Schmidt, Michal <[email protected]>
Cc: [email protected]; [email protected]; Andrew Lunn <[email protected]>; Eric Dumazet <[email protected]>; Nguyen, Anthony L <[email protected]>; [email protected]; Keller, Jacob E <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; David S. Miller <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net] ice: fix stats array overflow when VF requests more queues

Quoted 13 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

KASAN detects the bug:

[...]

Quoted 10 lines

ice_vsi_rebuild() handles this correctly by calling ice_vsi_realloc_stat_arrays() before reconfiguration, but ice_vf_reconfig_vsi() was missing this call.

Fix by calling ice_vsi_realloc_stat_arrays() in ice_vf_reconfig_vsi() before ice_vsi_decfg(), mirroring the ice_vsi_rebuild() pattern. Set vsi->req_txq/req_rxq from vf->num_req_qs so the realloc function knows the target array size.

Quoted 6 lines

See the linked RHEL Jira item for a reproducer.

Fixes 2a2cb4c6c181 ("ice: replace ice_vf_recreate_vsi() with

ice_vf_reconfig_vsi()")

I have an unpublished fix for the same issue, but your patch is smaller, and thus more suitable for net-

thank you

Quoted 7 lines
Assisted-by Claude:claude-opus-4-6 semcode
---
  drivers/net/ethernet/intel/ice/ice_lib.c    | 2 +-
  drivers/net/ethernet/intel/ice/ice_lib.h    | 1 +
  drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 +++++++
  3 files changed, 9 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/net/ethernet/intel/ice/ice_lib.c ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_lib.c +0 -0
index 837b71b7b2b7..fc78176a2a8d 100644
@@ -3015,7 +3015,7 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
maintainer
#6 lore raw
In reply to Michal Schmidt
Quoted 16 lines · Michal Schmidt
Quoted 14 lines · Przemek Kitszel
Quoted 12 lines · Michal Schmidt

When a VF increases its queue count via VIRTCHNL_OP_REQUEST_QUEUES, ice_vc_request_qs_msg() sets vf->num_req_qs and triggers a VF reset. The reset calls ice_vf_reconfig_vsi(), which does ice_vsi_decfg() followed by ice_vsi_cfg(). ice_vsi_decfg() does not free the per-ring stats arrays. Inside ice_vsi_cfg_def(), ice_vsi_set_num_qs() updates alloc_txq/alloc_rxq to the new larger value, but ice_vsi_alloc_stat_arrays() returns early because the stats already exist. ice_vsi_alloc_ring_stats() then iterates using the new larger alloc_txq and writes beyond the bounds of the old, smaller tx_ring_stats/rx_ring_stats pointer arrays, corrupting adjacent SLUB metadata.

Quoted 9 lines
Quoted 5 lines

thank you for reproducing the bug, it is exactly the situation that I was facing
have you tried with my proposed (unfortunately not public yet) fix to just combine ice_vsi_alloc_stat_arrays() and ice_vsi_realloc_stat_arrays() into one function?

I tried that now and the result is: yes, your patch fixes the bug too. Michal

Hi,
are you going to make your patch more robust against on CHNL VSIs?
https://lore.kernel.org/netdev/[email protected]

alternatively I could sent my "alternative fix" which covers that case