[PATCH net 2/2] rtnetlink: Release nets when leaving rtnl_setlink()

Bastien Curutchet (eBPF Foundation) posted 2 patches 10 months, 1 week ago
[PATCH net 2/2] rtnetlink: Release nets when leaving rtnl_setlink()
Posted by Bastien Curutchet (eBPF Foundation) 10 months, 1 week ago
rtnl_setlink() uses the rtnl_nets_* helpers but never calls the
rtnl_nets_destroy(). It leads to small memory leaks.

Call rtnl_nets_destroy() before exiting to properly decrement the nets'
reference counters.

Fixes: 636af13f213b ("rtnetlink: Register rtnl_dellink() and rtnl_setlink() with RTNL_FLAG_DOIT_PERNET_WIP.")
Cc: stable@vger.kernel.org
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
---
 net/core/rtnetlink.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 94111d3383788566f2296039e68549e2b40d5a4a..e4ac14c081a48e36f5381e025a3991c90827c2bf 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3441,6 +3441,7 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 
 	rtnl_nets_unlock(&rtnl_nets);
 errout:
+	rtnl_nets_destroy(&rtnl_nets);
 	return err;
 }
 

-- 
2.48.1
Re: [PATCH net 2/2] rtnetlink: Release nets when leaving rtnl_setlink()
Posted by Kuniyuki Iwashima 10 months, 1 week ago
From: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@bootlin.com>
Date: Wed, 12 Feb 2025 09:23:48 +0100
> rtnl_setlink() uses the rtnl_nets_* helpers but never calls the
> rtnl_nets_destroy(). It leads to small memory leaks.
> 
> Call rtnl_nets_destroy() before exiting to properly decrement the nets'
> reference counters.
> 
> Fixes: 636af13f213b ("rtnetlink: Register rtnl_dellink() and rtnl_setlink() with RTNL_FLAG_DOIT_PERNET_WIP.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>

It's fixed in 1438f5d07b9a ("rtnetlink: fix netns leak with
rtnl_setlink()").

Thanks!
Re: [PATCH net 2/2] rtnetlink: Release nets when leaving rtnl_setlink()
Posted by Bastien Curutchet 10 months, 1 week ago
On 2/12/25 9:31 AM, Kuniyuki Iwashima wrote:
> From: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@bootlin.com>
> Date: Wed, 12 Feb 2025 09:23:48 +0100
>> rtnl_setlink() uses the rtnl_nets_* helpers but never calls the
>> rtnl_nets_destroy(). It leads to small memory leaks.
>>
>> Call rtnl_nets_destroy() before exiting to properly decrement the nets'
>> reference counters.
>>
>> Fixes: 636af13f213b ("rtnetlink: Register rtnl_dellink() and rtnl_setlink() with RTNL_FLAG_DOIT_PERNET_WIP.")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
> 
> It's fixed in 1438f5d07b9a ("rtnetlink: fix netns leak with
> rtnl_setlink()").
> 

Oops, I missed it, sorry about that.

Best regards,
Bastien