Skip to contentSkip to conversation

net: openvswitch: fix possible kfree_skb of ERR_PTR

PATCH Applied Adrian Moreno 5 participants 5 messages Jun 4 – Jun 9 1 message not in the archive

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

PATCH 1/1 net: openvswitch: fix possible kfree_skb of ERR_PTR

After the patch in the "Fixes" tag, the allocation of the "reply" skb can happen either before or after locking the ovs_mutex.

However, error cleanups still follow the classical reversed order, assuming "reply" is allocated before locking: it is freed after unlocking.

If "reply" allocation happens after locking the mutex and it fails, "reply" is left with an ERR_PTR, and execution jumps to the correspondent cleanup stage which will try to free an invalid pointer.

Fix this by setting the pointer to NULL after having saved its error value.

Fixes 893f139b9a6c ("openvswitch: Minimize ovs_flow_cmd_new|set critical sections.")
---
 net/openvswitch/datapath.c | 1 +
 1 file changed, 1 insertion(+)
net/openvswitch/datapath.c +1 -0
index bbbde50fc649..f0164817d9b7 100644
@@ -1316,6 +1316,7 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
 
 		if (IS_ERR(reply)) {
 			error = PTR_ERR(reply);
+			reply = NULL;
 			goto err_unlock_ovs;
 		}
 	}
Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Adrian,

Quoted 10 lines · Adrian Moreno via dev

After the patch in the "Fixes" tag, the allocation of the "reply" skb can happen either before or after locking the ovs_mutex.

However, error cleanups still follow the classical reversed order, assuming "reply" is allocated before locking: it is freed after unlocking.

If "reply" allocation happens after locking the mutex and it fails, "reply" is left with an ERR_PTR, and execution jumps to the correspondent cleanup stage which will try to free an invalid pointer.

Quoted 8 lines

Fix this by setting the pointer to NULL after having saved its error value.

Fixes 893f139b9a6c ("openvswitch: Minimize ovs_flow_cmd_new|set

critical sections.")

---

Good catch - I guess this should only happen when modifying an existing flow without putting any actions (and that would be only from an implicit drop case since the actions list would be empty). CC'ing Minxi, since he's recently had interest in the selftests area and may be able to help with writing a test case for the scenario.

A message that is not in the archive (sent off-list or not yet received): CAJ0BgHcpo68Cx0tL_rRFFzZm8vNpDagF-hfy9KgUhPh4maGfFQ@mail.gmail.com

maintainer
#3 lore raw
Quoted 1 line · On Fri, 5 Jun 2026 01:10:16 +0800 侯敏熙 wrote:

Should I target net or net-next for the test patch?

net-next, we _allow_ posting tests with the fixes for ease of testing and review. But if the test comes later, anyway, it should just go to net-next.

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Adrian Moreno
Quoted 10 lines · Adrian Moreno

After the patch in the "Fixes" tag, the allocation of the "reply" skb can happen either before or after locking the ovs_mutex.

However, error cleanups still follow the classical reversed order, assuming "reply" is allocated before locking: it is freed after unlocking.

If "reply" allocation happens after locking the mutex and it fails, "reply" is left with an ERR_PTR, and execution jumps to the correspondent cleanup stage which will try to free an invalid pointer.

Quoted 6 lines

Fix this by setting the pointer to NULL after having saved its error value.

Fixes 893f139b9a6c ("openvswitch: Minimize ovs_flow_cmd_new|set critical sections.")

Thanks Adrian for finding and fixing this! The change looks good to me.

#5 lore raw
In reply to Adrian Moreno
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 4 Jun 2026 14:19:46 +0200 you wrote:

After the patch in the "Fixes" tag, the allocation of the "reply" skb can happen either before or after locking the ovs_mutex.

However, error cleanups still follow the classical reversed order, assuming "reply" is allocated before locking: it is freed after unlocking.

If "reply" allocation happens after locking the mutex and it fails, "reply" is left with an ERR_PTR, and execution jumps to the correspondent cleanup stage which will try to free an invalid pointer.

[...]

Here is the summary with links:
- [net] net: openvswitch: fix possible kfree_skb of ERR_PTR

    https://git.kernel.org/netdev/net/c/ee30dd2909d8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html