Skip to content

Commit a55ef3b

Browse files
GoodLuck612klassert
authored andcommitted
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: 980ebd2 ("[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>
1 parent 59630e2 commit a55ef3b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/xfrm/xfrm_user.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,9 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
30383038
}
30393039

30403040
xfrm_state_free(x);
3041+
xfrm_dev_policy_delete(xp);
3042+
xfrm_dev_policy_free(xp);
3043+
security_xfrm_policy_free(xp->security);
30413044
kfree(xp);
30423045

30433046
return 0;

0 commit comments

Comments
 (0)