Subject: [AF_KEY]: Fix skb leak on pfkey_send_migrate() error

From: Patrick McHardy <[email-masked]>
Date: Sun, 20 Jan 2008 16:12:28 +0100

commit 4dd3440faa345731c27337ee041c0e9abf2b70dc
Author: Patrick McHardy <[email-masked]>
Date:   Sun Jan 20 16:10:04 2008 +0100

    [AF_KEY]: Fix skb leak on pfkey_send_migrate() error
    
    Signed-off-by: Patrick McHardy <[email-masked]>

diff --git a/net/key/af_key.c b/net/key/af_key.c
index 3667f44..16b72b5 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3591,27 +3591,29 @@ static int pfkey_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
 		/* old ipsecrequest */
 		int mode = pfkey_mode_from_xfrm(mp->mode);
 		if (mode < 0)
-			return -EINVAL;
+			goto err;
 		if (set_ipsecrequest(skb, mp->proto, mode,
 				     (mp->reqid ?  IPSEC_LEVEL_UNIQUE : IPSEC_LEVEL_REQUIRE),
 				     mp->reqid, mp->old_family,
-				     &mp->old_saddr, &mp->old_daddr) < 0) {
-			return -EINVAL;
-		}
+				     &mp->old_saddr, &mp->old_daddr) < 0)
+			goto err;
 
 		/* new ipsecrequest */
 		if (set_ipsecrequest(skb, mp->proto, mode,
 				     (mp->reqid ? IPSEC_LEVEL_UNIQUE : IPSEC_LEVEL_REQUIRE),
 				     mp->reqid, mp->new_family,
-				     &mp->new_saddr, &mp->new_daddr) < 0) {
-			return -EINVAL;
-		}
+				     &mp->new_saddr, &mp->new_daddr) < 0)
+			goto err;
 	}
 
 	/* broadcast migrate message to sockets */
 	pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL);
 
 	return 0;
+
+err:
+	kfree_skb(skb);
+	return -EINVAL;
 }
 #else
 static int pfkey_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,