* [PATCH net v2] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()
@ 2026-07-28 11:42 Abdun Nihaal
2026-07-30 22:50 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Abdun Nihaal @ 2026-07-28 11:42 UTC (permalink / raw)
To: Steen.Hegelund
Cc: Abdun Nihaal, daniel.machon, UNGLinuxDriver, andrew+netdev, davem,
edumazet, kuba, pabeni, netdev, linux-kernel, joe,
linux-arm-kernel, horatiu.vultur, stable
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().
Fixes: 610c32b2ce66 ("net: microchip: vcap: Add vcap_get_rule")
Cc: stable@vger.kernel.org
Reviewed-by: Joe Damato <joe@dama.to>
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Issue found using static analysis.
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/20260727125757.134611-1-nihaal@cse.iitm.ac.in/
drivers/net/ethernet/microchip/vcap/vcap_api.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index ff86cde11a32..376be059d662 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -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 out_err;
err = vcap_decode_keyset(ri);
if (err)
- return ERR_PTR(err);
+ goto out_err;
err = vcap_decode_actionset(ri);
if (err)
- return ERR_PTR(err);
+ goto out_err;
out:
return &ri->data;
+out_err:
+ vcap_free_rule(&ri->data);
+ return ERR_PTR(err);
}
struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()
2026-07-28 11:42 [PATCH net v2] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule() Abdun Nihaal
@ 2026-07-30 22:50 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-07-30 22:50 UTC (permalink / raw)
To: Abdun Nihaal
Cc: Steen.Hegelund, daniel.machon, UNGLinuxDriver, andrew+netdev,
davem, edumazet, pabeni, netdev, linux-kernel, joe,
linux-arm-kernel, horatiu.vultur, stable
On Tue, 28 Jul 2026 17:12:51 +0530 Abdun Nihaal 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().
>
> Fixes: 610c32b2ce66 ("net: microchip: vcap: Add vcap_get_rule")
> Cc: stable@vger.kernel.org
> Reviewed-by: Joe Damato <joe@dama.to>
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
> ---
> Compile tested only. Issue found using static analysis.
This is important information please add it to the main commit message
body.
> 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/20260727125757.134611-1-nihaal@cse.iitm.ac.in/
>
> drivers/net/ethernet/microchip/vcap/vcap_api.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> index ff86cde11a32..376be059d662 100644
> --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> @@ -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 out_err;
>
> err = vcap_decode_keyset(ri);
> if (err)
> - return ERR_PTR(err);
> + goto out_err;
>
> err = vcap_decode_actionset(ri);
> if (err)
> - return ERR_PTR(err);
> + goto out_err;
>
> out:
> return &ri->data;
> +out_err:
Please name the label after the first action being undone
err_free_rule:
> + vcap_free_rule(&ri->data);
> + return ERR_PTR(err);
--
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-30 22:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 11:42 [PATCH net v2] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule() Abdun Nihaal
2026-07-30 22:50 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox