Skip to contentSkip to conversation

ice: Fix use-after-scope in ice_sched_add_nodes_to_layer()

PATCH Superseded NeKon69 3 participants 3 messages Jun 13 – Jun 16

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

NeKon69

author
#0 lore raw

PATCH 1/1 ice: Fix use-after-scope in ice_sched_add_nodes_to_layer()

Commit 7fb09a737536 ("ice: Modify recursive way of adding nodes") changed ice_sched_add_nodes_to_layer() from recursive control flow to an iterative loop.

Inside the loop, first_teid_ptr may be set to the address of a block-local variable:

	u32 temp;
	...
	if (num_added)
		first_teid_ptr = &temp;

On the next loop iteration, first_teid_ptr may be passed to ice_sched_add_nodes_to_hw_layer(), after temp from the previous iteration has gone out of scope.

Move temp outside the loop so the pointer remains valid for the lifetime of ice_sched_add_nodes_to_layer().

This was found by Clang with LifetimeSafety enabled while testing C language support on a Linux allmodconfig build.

Fixes 7fb09a737536 ("ice: Modify recursive way of adding nodes")
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_sched.c +1 -1
index fff0c1afdb41..089ad3967be5 100644
@@ -1074,11 +1074,11 @@ ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
 	u32 *first_teid_ptr = first_node_teid;
 	u16 new_num_nodes = num_nodes;
 	int status = 0;
+	u32 temp;
 
 	*num_nodes_added = 0;
 	while (*num_nodes_added < num_nodes) {
 		u16 max_child_nodes, num_added = 0;
-		u32 temp;
 
 		status = ice_sched_add_nodes_to_hw_layer(pi, tc_node, parent,
 							 layer,	new_num_nodes,
Signature · 1 line
2.54.0
reviewer
#1 lore raw
Quoted 19 lines · On Sat, Jun 13, 2026 at 01:14:40PM +0300, NeKon69 wrote:

Commit 7fb09a737536 ("ice: Modify recursive way of adding nodes") changed ice_sched_add_nodes_to_layer() from recursive control flow to an iterative loop.

Inside the loop, first_teid_ptr may be set to the address of a block-local variable:

	u32 temp;
	...
	if (num_added)
		first_teid_ptr = &temp;

On the next loop iteration, first_teid_ptr may be passed to ice_sched_add_nodes_to_hw_layer(), after temp from the previous iteration has gone out of scope.

Move temp outside the loop so the pointer remains valid for the lifetime of ice_sched_add_nodes_to_layer().

Quoted 6 lines

This was found by Clang with LifetimeSafety enabled while testing C language support on a Linux allmodconfig build.

Fixes 7fb09a737536 ("ice: Modify recursive way of adding nodes")

I agree that this patch is correct.

However, I do wonder if it would be cleaner to allow passing NULL as the first_node_teid argument of ice_sched_add_nodes_to_hw_layer()

...

Reviewed-by on v1 1/1
#2 lore raw
In reply to NeKon69
Quoted 47 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of NeKon69
Sent: Saturday, June 13, 2026 12:15 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; NeKon69 <[email protected]>
Subject: [Intel-wired-lan] [PATCH net] ice: Fix use-after-scope in ice_sched_add_nodes_to_layer()

Commit 7fb09a737536 ("ice: Modify recursive way of adding nodes") changed ice_sched_add_nodes_to_layer() from recursive control flow to an iterative loop.

Inside the loop, first_teid_ptr may be set to the address of a block-local variable:

	u32 temp;
	...
	if (num_added)
		first_teid_ptr = &temp;

On the next loop iteration, first_teid_ptr may be passed to ice_sched_add_nodes_to_hw_layer(), after temp from the previous iteration has gone out of scope.

Move temp outside the loop so the pointer remains valid for the lifetime of ice_sched_add_nodes_to_layer().

This was found by Clang with LifetimeSafety enabled while testing C language support on a Linux allmodconfig build.

Fixes 7fb09a737536 ("ice: Modify recursive way of adding nodes")

---
drivers/net/ethernet/intel/ice/ice_sched.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_sched.c +1 -2
index fff0c1afdb41..089ad3967be5 100644
@@ -1074,11 +1074,11 @@ ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
 	u32 *first_teid_ptr = first_node_teid;
 	u16 new_num_nodes = num_nodes;
 	int status = 0;
+	u32 temp;
 
 	*num_nodes_added = 0;
 	while (*num_nodes_added < num_nodes) {
 		u16 max_child_nodes, num_added = 0;
-		u32 temp;
 
 		status = ice_sched_add_nodes_to_hw_layer(pi, tc_node, parent,
 							 layer,	new_num_nodes,
--
Quoted 2 lines

2.54.0