Skip to contentSkip to conversation

af_key: Fix memory leak in key_notify_policy.

PATCH In review Young Xiao 3 participants 6 messages Jun 14, 2019

Subsystems (3)
lore
Share & tools
lore

Young Xiao

author
#0 lore raw

PATCH 1/1 af_key: Fix memory leak in key_notify_policy.

We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails. Fix this by freeing it on error.

---
 net/key/af_key.c | 2 ++
 1 file changed, 2 insertions(+)
net/key/af_key.c +2 -0
index 4af1e1d..ec414f6 100644
@@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
 	}
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		goto out;
 
 	out_hdr = (struct sadb_msg *) out_skb->data;
@@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
 
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		return err;
 
 	out_hdr = (struct sadb_msg *) out_skb->data;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 13 lines · Young Xiao

We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails. Fix this by freeing it on error.

---
 net/key/af_key.c | 2 ++
 1 file changed, 2 insertions(+)
net/key/af_key.c +0 -0
index 4af1e1d..ec414f6 100644

net/key/af_key.c static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc · line 2447

Quoted 5 lines
net/key/af_key.c +1 -0
@@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
 	}
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		goto out;

Did you test this?

You need to add braces, otherwise 'goto out' will happen unconditionally.

net/key/af_key.c static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr) · line 2700

Quoted 8 lines
net/key/af_key.c +1 -0
 	out_hdr = (struct sadb_msg *) out_skb->data;
@@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
 
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		return err;

Same here.

#2 lore raw
Quoted 28 lines · Steffen Klassert
Quoted 13 lines · Young Xiao

We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails. Fix this by freeing it on error.

---
 net/key/af_key.c | 2 ++
 1 file changed, 2 insertions(+)
net/key/af_key.c +0 -0
index 4af1e1d..ec414f6 100644

net/key/af_key.c static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc · line 2447

Quoted 5 lines
net/key/af_key.c +1 -0
@@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
 	}
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		goto out;

Did you test this?

You need to add braces, otherwise 'goto out' will happen unconditionally.

Quoted 4 lines
net/key/af_key.c +0 -0
 	out_hdr = (struct sadb_msg *) out_skb->data;
@@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
 
Quoted 6 lines

net/key/af_key.c static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr) · line 2700

Quoted 4 lines
net/key/af_key.c +1 -0
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		return err;

Same here.

There's already a patch for this:

https://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git/commit/?id=7c80eb1c7e2b8420477fbc998971d62a648035d9

J.

#3 lore raw
Quoted 36 lines · Jeremy Sowden
Quoted 28 lines · Steffen Klassert
Quoted 13 lines · Young Xiao

We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails. Fix this by freeing it on error.

---
 net/key/af_key.c | 2 ++
 1 file changed, 2 insertions(+)
net/key/af_key.c +0 -0
index 4af1e1d..ec414f6 100644

net/key/af_key.c static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc · line 2447

Quoted 5 lines
net/key/af_key.c +1 -0
@@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
 	}
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		goto out;

Did you test this?

You need to add braces, otherwise 'goto out' will happen unconditionally.

Quoted 4 lines
net/key/af_key.c +0 -0
 	out_hdr = (struct sadb_msg *) out_skb->data;
@@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
 
Quoted 6 lines

net/key/af_key.c static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr) · line 2700

Quoted 4 lines
net/key/af_key.c +1 -0
 	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
 	if (err < 0)
+		kfree_skb(out_skb);
 		return err;

Same here.

Quoted 3 lines

There's already a patch for this:

https://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git/commit/?id=7c80eb1c7e2b8420477fbc998971d62a648035d9

That reminds me. Stephen Rothwell reported a problem with the "Fixes:" tag:

Quoted 6 lines · Stephen Rothwell

In commit

7c80eb1c7e2b ("af_key: fix leaks in key_pol_get_resp and dump_sp.")

Fixes tag

Quoted 7 lines
Fixes 55569ce256ce ("Fix conversion between IPSEC_MODE_xxx and XFRM_MODE_xxx.")

has these problem(s):

- Subject does not match target commit subject

    Just use
	git log -1 --format='Fixes: %h ("%s")'

What's the procedure for fixing this sort of thing? Do you need me to do anything?

J.

maintainer
#4 lore raw
Quoted 13 lines · Jeremy Sowden

That reminds me. Stephen Rothwell reported a problem with the "Fixes:" tag:

Quoted 8 lines · Stephen Rothwell

In commit

7c80eb1c7e2b ("af_key: fix leaks in key_pol_get_resp and dump_sp.")

Fixes tag

Fixes 55569ce256ce ("Fix conversion between IPSEC_MODE_xxx and XFRM_MODE_xxx.")
Quoted 8 lines
Quoted 5 lines

has these problem(s):

- Subject does not match target commit subject

    Just use
	git log -1 --format='Fixes: %h ("%s")'

What's the procedure for fixing this sort of thing? Do you need me to do anything?

No, that patch is already commited. We can't change the commit message anymore. Just keep it in mind for next time.

#5 lore raw
Quoted 19 lines · Steffen Klassert
Quoted 18 lines · Jeremy Sowden

That reminds me. Stephen Rothwell reported a problem with the "Fixes:" tag:

Quoted 13 lines · Stephen Rothwell

In commit

7c80eb1c7e2b ("af_key: fix leaks in key_pol_get_resp and dump_sp.")

Fixes tag

Fixes 55569ce256ce ("Fix conversion between IPSEC_MODE_xxx and XFRM_MODE_xxx.")

has these problem(s):

- Subject does not match target commit subject

    Just use
	git log -1 --format='Fixes: %h ("%s")'
Quoted 5 lines
Quoted 2 lines

What's the procedure for fixing this sort of thing? Do you need me to do anything?

No, that patch is already commited. We can't change the commit message anymore. Just keep it in mind for next time.

Will do. I've already made a note of that git-log invocation. Useful to know.

J.