]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfrm: cleanup error path in xfrm_add_policy()
authorDeepanshu Kartikey <kartikey406@gmail.com>
Tue, 14 Apr 2026 02:09:47 +0000 (07:39 +0530)
committerSteffen Klassert <steffen.klassert@secunet.com>
Wed, 29 Apr 2026 07:36:05 +0000 (09:36 +0200)
Replace the open-coded manual cleanup in the error path of
xfrm_add_policy() with xfrm_policy_destroy(), which already
handles all the necessary cleanup internally. This is consistent
with how xfrm_policy_construct() handles its own error paths.

The walk.dead flag must be set before calling xfrm_policy_destroy()
as required by BUG_ON(!policy->walk.dead).

Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_user.c

index d56450f61669127e2a9c3d064870c29a540d8949..ae144d1e4a65cd72455a58170c9bcfd7f327b367 100644 (file)
@@ -2267,9 +2267,8 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
 
        if (err) {
                xfrm_dev_policy_delete(xp);
-               xfrm_dev_policy_free(xp);
-               security_xfrm_policy_free(xp->security);
-               kfree(xp);
+               xp->walk.dead = 1;
+               xfrm_policy_destroy(xp);
                return err;
        }