Re: [PATCH] net: microchip: vcap api: Fix memory leaks in vcap_api_encode_rule_test()
From: Jens Emil Schulz Østergaard
Date: Fri Oct 11 2024 - 11:10:52 EST
On Fri Oct 11, 2024 at 12:24 PM CEST, Daniel Machon wrote:
> > Cc: stable@xxxxxxxxxxxxxxx
> > Fixes: a3c1e45156ad ("net: microchip: vcap: Fix use-after-free error in kunit test")
> > Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
> > ---
> > drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c b/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c
> > index f2a5a36fdacd..7251121ab196 100644
> > --- a/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c
> > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c
> > @@ -1444,6 +1444,8 @@ static void vcap_api_encode_rule_test(struct kunit *test)
> >
> > ret = vcap_del_rule(&test_vctrl, &test_netdev, id);
> > KUNIT_EXPECT_EQ(test, 0, ret);
> > +
> > + vcap_free_rule(rule);
> > }
>
> Wait, should vcap_del_rule not handle the freeing of the rule?
> Maybe Emil can shed some light on this..
>
> /Daniel
>
No, this is a bug. I made the mistake of thinking that vcap_del_rule freed the
rule.
However, it frees an internal copy of the rule, which is made in vcap_add_rule.
The local copy must still be freed. I reproduced the leak and the patch fixes
this.
/Emil