af_key: Fix memory leak in key_notify_policy.
authorSteffen Klassert <steffen.klassert@secunet.com>
Wed, 10 Jan 2018 08:33:26 +0000 (09:33 +0100)
committerSteffen Klassert <steffen.klassert@secunet.com>
Wed, 10 Jan 2018 08:45:11 +0000 (09:45 +0100)
We leak the allocated out_skb in case
pfkey_xfrm_policy2msg() fails. Fix this
by freeing it on error.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/key/af_key.c

index d40861a048fe0e7c0088c7b05594c891dac3941e..7e2e7188e7f4a28aa45c26848364ab0c297161a2 100644 (file)
@@ -2202,8 +2202,10 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, const struct km_ev
                return PTR_ERR(out_skb);
 
        err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
-       if (err < 0)
+       if (err < 0) {
+               kfree_skb(out_skb);
                return err;
+       }
 
        out_hdr = (struct sadb_msg *) out_skb->data;
        out_hdr->sadb_msg_version = PF_KEY_V2;