Commit a55ef3bf authored by Zilin Guan's avatar Zilin Guan Committed by Steffen Klassert
Browse files

xfrm: fix memory leak in xfrm_add_acquire()



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: 980ebd25 ("[IPSEC]: Sync series - acquire insert")
Signed-off-by: default avatarZilin Guan <zilin@seu.edu.cn>
Reviewed-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent 59630e2c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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;