]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfrm: fix memory leak in xfrm_add_acquire()
authorZilin Guan <zilin@seu.edu.cn>
Mon, 10 Nov 2025 06:41:25 +0000 (06:41 +0000)
committerSteffen Klassert <steffen.klassert@secunet.com>
Fri, 14 Nov 2025 09:12:36 +0000 (10:12 +0100)
The xfrm_add_acquire() function constructs an xfrm policy by calling
xfrm_policy_construct(). This allocates the policy structure and
potentially associates a security context and a device policy with it.

However, at the end of the function, the policy object is freed using
only kfree() . This skips the necessary cleanup for the security context
and device policy, leading to a memory leak.

To fix this, invoke the proper cleanup functions xfrm_dev_policy_delete(),
xfrm_dev_policy_free(), and security_xfrm_policy_free() before freeing the
policy object. This approach mirrors the error handling path in
xfrm_add_policy(), ensuring that all associated resources are correctly
released.

Fixes: 980ebd25794f ("[IPSEC]: Sync series - acquire insert")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_user.c

index 9d98cc9daa37c5aadb960228a8e741415165aee6..403b5ecac2c544111b0c2b3268d288c76d7aea81 100644 (file)
@@ -3038,6 +3038,9 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
        }
 
        xfrm_state_free(x);
+       xfrm_dev_policy_delete(xp);
+       xfrm_dev_policy_free(xp);
+       security_xfrm_policy_free(xp->security);
        kfree(xp);
 
        return 0;