* [PATCH net] net: Fix one possible memleak in ip_setup_cork
@ 2018-04-16 2:16 gfree.wind
2018-04-16 2:16 ` gfree.wind
0 siblings, 1 reply; 7+ messages in thread
From: gfree.wind @ 2018-04-16 2:16 UTC (permalink / raw)
To: davem, kuznet, netdev; +Cc: Gao Feng
From: Gao Feng <gfree.wind@vip.163.com>
It would allocate memory in this function when the cork->opt is NULL. But
the memory isn't freed if failed in the latter rt check, and return error
directly. It causes the memleak if its caller is ip_make_skb which also
doesn't free the cork->opt when meet a error.
Now move the rt check ahead to avoid the memleak.
Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
---
net/ipv4/ip_output.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4c11b81..83c73ba 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1109,6 +1109,10 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
struct ip_options_rcu *opt;
struct rtable *rt;
+ rt = *rtp;
+ if (unlikely(!rt))
+ return -EFAULT;
+
/*
* setup for corking.
*/
@@ -1124,9 +1128,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
cork->flags |= IPCORK_OPT;
cork->addr = ipc->addr;
}
- rt = *rtp;
- if (unlikely(!rt))
- return -EFAULT;
+
/*
* We steal reference to this route, caller should not release it
*/
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 2:16 [PATCH net] net: Fix one possible memleak in ip_setup_cork gfree.wind
@ 2018-04-16 2:16 ` gfree.wind
2018-04-16 2:55 ` David Miller
2018-04-16 16:58 ` David Miller
0 siblings, 2 replies; 7+ messages in thread
From: gfree.wind @ 2018-04-16 2:16 UTC (permalink / raw)
To: davem, kuznet, netdev; +Cc: Gao Feng
From: Gao Feng <gfree.wind@vip.163.com>
It would allocate memory in this function when the cork->opt is NULL. But
the memory isn't freed if failed in the latter rt check, and return error
directly. It causes the memleak if its caller is ip_make_skb which also
doesn't free the cork->opt when meet a error.
Now move the rt check ahead to avoid the memleak.
Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
---
net/ipv4/ip_output.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4c11b81..83c73ba 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1109,6 +1109,10 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
struct ip_options_rcu *opt;
struct rtable *rt;
+ rt = *rtp;
+ if (unlikely(!rt))
+ return -EFAULT;
+
/*
* setup for corking.
*/
@@ -1124,9 +1128,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
cork->flags |= IPCORK_OPT;
cork->addr = ipc->addr;
}
- rt = *rtp;
- if (unlikely(!rt))
- return -EFAULT;
+
/*
* We steal reference to this route, caller should not release it
*/
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 2:16 ` gfree.wind
@ 2018-04-16 2:55 ` David Miller
2018-04-16 3:05 ` Gao Feng
2018-04-16 16:58 ` David Miller
1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2018-04-16 2:55 UTC (permalink / raw)
To: gfree.wind; +Cc: kuznet, netdev
From: gfree.wind@vip.163.com
Date: Mon, 16 Apr 2018 10:16:45 +0800
> From: Gao Feng <gfree.wind@vip.163.com>
>
> It would allocate memory in this function when the cork->opt is NULL. But
> the memory isn't freed if failed in the latter rt check, and return error
> directly. It causes the memleak if its caller is ip_make_skb which also
> doesn't free the cork->opt when meet a error.
>
> Now move the rt check ahead to avoid the memleak.
>
> Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
Why did you post this patch twice?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re:Re: [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 2:55 ` David Miller
@ 2018-04-16 3:05 ` Gao Feng
0 siblings, 0 replies; 7+ messages in thread
From: Gao Feng @ 2018-04-16 3:05 UTC (permalink / raw)
To: davem@davemloft.net; +Cc: kuznet, netdev@vger.kernel.org
At 2018-04-16 10:55:56, "David Miller" <davem@davemloft.net> wrote:
>From: gfree.wind@vip.163.com
>Date: Mon, 16 Apr 2018 10:16:45 +0800
>
>> From: Gao Feng <gfree.wind@vip.163.com>
>>
>> It would allocate memory in this function when the cork->opt is NULL. But
>> the memory isn't freed if failed in the latter rt check, and return error
>> directly. It causes the memleak if its caller is ip_make_skb which also
>> doesn't free the cork->opt when meet a error.
>>
>> Now move the rt check ahead to avoid the memleak.
>>
>> Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
>
>Why did you post this patch twice?
Sorry, it is my input error. I typed "yes" not "all" at the first time when execute git-send-email.
Then I corrected it as the second time.
Best Regards
Feng
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 2:16 ` gfree.wind
2018-04-16 2:55 ` David Miller
@ 2018-04-16 16:58 ` David Miller
2018-04-16 21:18 ` Eric Dumazet
1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2018-04-16 16:58 UTC (permalink / raw)
To: gfree.wind; +Cc: kuznet, netdev
From: gfree.wind@vip.163.com
Date: Mon, 16 Apr 2018 10:16:45 +0800
> From: Gao Feng <gfree.wind@vip.163.com>
>
> It would allocate memory in this function when the cork->opt is NULL. But
> the memory isn't freed if failed in the latter rt check, and return error
> directly. It causes the memleak if its caller is ip_make_skb which also
> doesn't free the cork->opt when meet a error.
>
> Now move the rt check ahead to avoid the memleak.
>
> Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
Looks good, applied and queued up for -stable.
I guess in the other code paths, ip_flush_pending_frames() or similar
would clean up the in-sock cork information.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 16:58 ` David Miller
@ 2018-04-16 21:18 ` Eric Dumazet
2018-04-18 1:33 ` Gao Feng
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2018-04-16 21:18 UTC (permalink / raw)
To: David Miller, gfree.wind; +Cc: kuznet, netdev
On 04/16/2018 09:58 AM, David Miller wrote:
> From: gfree.wind@vip.163.com
> Date: Mon, 16 Apr 2018 10:16:45 +0800
>
>> From: Gao Feng <gfree.wind@vip.163.com>
>>
>> It would allocate memory in this function when the cork->opt is NULL. But
>> the memory isn't freed if failed in the latter rt check, and return error
>> directly. It causes the memleak if its caller is ip_make_skb which also
>> doesn't free the cork->opt when meet a error.
>>
>> Now move the rt check ahead to avoid the memleak.
>>
>> Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
>
> Looks good, applied and queued up for -stable.
>
> I guess in the other code paths, ip_flush_pending_frames() or similar
> would clean up the in-sock cork information.
>
I am not sure ip_make_skb() can be called with a NULL rt.
Patch makes no harm, but does not seem to fix a bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re:Re: [PATCH net] net: Fix one possible memleak in ip_setup_cork
2018-04-16 21:18 ` Eric Dumazet
@ 2018-04-18 1:33 ` Gao Feng
0 siblings, 0 replies; 7+ messages in thread
From: Gao Feng @ 2018-04-18 1:33 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem@davemloft.net, kuznet@ms2.inr.ac.ru, netdev@vger.kernel.org
At 2018-04-17 05:18:25, "Eric Dumazet" <eric.dumazet@gmail.com> wrote:
>
>
>On 04/16/2018 09:58 AM, David Miller wrote:
>> From: gfree.wind@vip.163.com
>> Date: Mon, 16 Apr 2018 10:16:45 +0800
>>
>>> From: Gao Feng <gfree.wind@vip.163.com>
>>>
>>> It would allocate memory in this function when the cork->opt is NULL. But
>>> the memory isn't freed if failed in the latter rt check, and return error
>>> directly. It causes the memleak if its caller is ip_make_skb which also
>>> doesn't free the cork->opt when meet a error.
>>>
>>> Now move the rt check ahead to avoid the memleak.
>>>
>>> Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
>>
>> Looks good, applied and queued up for -stable.
>>
>> I guess in the other code paths, ip_flush_pending_frames() or similar
>> would clean up the in-sock cork information.
>>
>
>I am not sure ip_make_skb() can be called with a NULL rt.
>
>Patch makes no harm, but does not seem to fix a bug.
>
Thanks Eric.
I just look up current all callers of ip_make_skb and ip_append_data, they check
if the rt is valid ahead. So current codes won't pass one NULL rt to ip_setup_cork indeed.
Then this patch is just as an enhancement, not a fix.
As the programming rule, the function should free the mem which is allocated by itself when
it failed.
Best Regards
Feng
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-04-18 1:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-16 2:16 [PATCH net] net: Fix one possible memleak in ip_setup_cork gfree.wind
2018-04-16 2:16 ` gfree.wind
2018-04-16 2:55 ` David Miller
2018-04-16 3:05 ` Gao Feng
2018-04-16 16:58 ` David Miller
2018-04-16 21:18 ` Eric Dumazet
2018-04-18 1:33 ` Gao Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).