af_key: Fix memory leak in key_notify_policy.
Subsystems (3)
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
@@ -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
Steffen Klassert
maintainerQuoted 13 lines · Young Xiao
We leak the allocated
out_skbin casepfkey_xfrm_policy2msg()fails. Fix this by freeing it on error.Signed-off-by Young Xiao <[email protected]>--- net/key/af_key.c | 2 ++ 1 file changed, 2 insertions(+)net/key/af_key.c +0
-0
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
-0out_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.
Quoted 28 lines · Steffen Klassert
Quoted 13 lines · Young Xiao
We leak the allocated
out_skbin casepfkey_xfrm_policy2msg()fails. Fix this by freeing it on error.Signed-off-by Young Xiao <[email protected]>--- net/key/af_key.c | 2 ++ 1 file changed, 2 insertions(+)net/key/af_key.c +0
-0net/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
-0out_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
-0err =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:
J.
Quoted 36 lines · Jeremy Sowden
Quoted 28 lines · Steffen Klassert
Quoted 13 lines · Young Xiao
We leak the allocated
out_skbin casepfkey_xfrm_policy2msg()fails. Fix this by freeing it on error.Signed-off-by Young Xiao <[email protected]>--- net/key/af_key.c | 2 ++ 1 file changed, 2 insertions(+)net/key/af_key.c +0
-0net/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
-0out_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
-0err =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:
That reminds me. Stephen Rothwell reported a problem with the "Fixes:" tag:
Quoted 6 lines · Stephen Rothwell
In commit
7c80eb1c7e2b("af_key: fix leaks inkey_pol_get_respanddump_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.
Steffen Klassert
maintainerQuoted 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 inkey_pol_get_respanddump_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.
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 inkey_pol_get_respanddump_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.