Skip to contentSkip to conversation

net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()

PATCH Applied Abdun Nihaal 2 participants 2 messages Aug 1 – Aug 5

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

PATCH v3 1/1 net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()

The memory allocated for struct vcap_rule_internal, keyfields and actionfields inside vcap_dup_rule() are not freed in some of the error paths in vcap_decode_rule(). Fix that by calling vcap_free_rule().

Compile tested only. Issue found using a prototype static analysis tool built on top of the LLVM compiler infrastructure.

Fixes 610c32b2ce66 ("net: microchip: vcap: Add vcap_get_rule")

---

v2->v3:
- Rename the error label to "err_free_rule" to denote the first action being undone, as suggested by Jakub Kicinski
- Move the information about compile tested only, and how the issue was found to the commit message, as suggested by Jakub Kicinski.

v1->v2:
- Convert the error labels from "err" to "out_err" to avoid confusion with the err variable, as suggested by Joe Damato.

Link to v1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Link to v2: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

 drivers/net/ethernet/microchip/vcap/vcap_api.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/vcap/vcap_api.c +6 -3
index ff86cde11a32..788c0728d763 100644
@@ -2427,18 +2427,21 @@ struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem)
 
 	err = vcap_read_rule(ri);
 	if (err)
-		return ERR_PTR(err);
+		goto err_free_rule;
 
 	err = vcap_decode_keyset(ri);
 	if (err)
-		return ERR_PTR(err);
+		goto err_free_rule;
 
 	err = vcap_decode_actionset(ri);
 	if (err)
-		return ERR_PTR(err);
+		goto err_free_rule;
 
 out:
 	return &ri->data;
+err_free_rule:
+	vcap_free_rule(&ri->data);
+	return ERR_PTR(err);
 }
 
 struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id)
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Sat, 1 Aug 2026 11:25:05 +0530 you wrote:

The memory allocated for struct vcap_rule_internal, keyfields and actionfields inside vcap_dup_rule() are not freed in some of the error paths in vcap_decode_rule(). Fix that by calling vcap_free_rule().

Compile tested only. Issue found using a prototype static analysis tool built on top of the LLVM compiler infrastructure.

[...]

Here is the summary with links:
- [v3,net] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()

    https://git.kernel.org/netdev/net-next/c/30ce0cb576b6

You are awesome, thank you!

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