octeontx2-pf: Fix potential use after free in otx2_tc_add_flow()
PATCH 1/1 octeontx2-pf: Fix potential use after free in otx2_tc_add_flow()
This code calls kfree_rcu(new_node, rcu) and then dereferences "new_node" and then dereferences it on the next line. Two lines later, we take a mutex so I don't think this is an RCU safe region. Re-order it to do the dereferences before queuing up the free.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +1 -1
@@ -1326,7 +1326,6 @@ static int otx2_tc_add_flow(struct otx2_nic *nic, free_leaf:otx2_tc_del_from_flow_list (flow_cfg, new_node); -kfree_rcu (new_node, rcu);if (new_node->is_act_police) {mutex_lock (&nic->mbox.lock);
@@ -1346,6 +1345,7 @@ static int otx2_tc_add_flow(struct otx2_nic *nic,mutex_unlock (&nic->mbox.lock); } +kfree_rcu (new_node, rcu);return rc; }
Signature · 1 line
2.51.0
Quoted 7 lines · Dan Carpenter
This code calls
kfree_rcu(new_node, rcu)and then dereferences "new_node" and then dereferences it on the next line. Two lines later, we take a mutex so I don't think this is an RCU safe region. Re-order it to do the dereferences before queuing up the free.Fixes 68fbff68dbea ("octeontx2-pf: Add police action for TC flower")Signed-off-by Dan Carpenter <[email protected]>
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Tue, 23 Sep 2025 14:19:11 +0300 you wrote:
This code calls
kfree_rcu(new_node, rcu)and then dereferences "new_node" and then dereferences it on the next line. Two lines later, we take a mutex so I don't think this is an RCU safe region. Re-order it to do the dereferences before queuing up the free.Fixes 68fbff68dbea ("octeontx2-pf: Add police action for TC flower")Signed-off-by Dan Carpenter <[email protected]>[...]
Here is the summary with links:
- [net] octeontx2-pf: Fix potential use after free in otx2_tc_add_flow()
https://git.kernel.org/netdev/net/c/d9c70e93ec59
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html