Re: [PATCH] xfrm: fix memory leak in xfrm_add_policy()
From: Sabrina Dubroca
Date: Mon Apr 13 2026 - 09:33:54 EST
2026-04-12, 07:38:09 +0530, Deepanshu Kartikey wrote:
> When xfrm_policy_insert() fails, the error path performs manual
> cleanup by calling xfrm_dev_policy_free(), security_xfrm_policy_free()
> and kfree() directly. This is incorrect because xfrm_policy_destroy()
> already handles all of these, causing a memory leak detected by
> kmemleak.
What is missing in the current code? "we have a better way to do this"
is not a bugfix, it's a clean up. The kmemleak report says that we're
leaking the xfrm_policy struct on this codepath, which doesn't make
sense, that's covered by the existing kfree(xp).
Also, please use "PATCH ipsec" for fixes to net/xfrm and the rest of
the IPsec implementation.
--
Sabrina