* Re: [PATCH] netlink: Fix kfree NULL pointer
[not found] <AANLkTikp0m8cQYfEBHP_E8XpGZqdMj6Cr4M=aWCnei=X@mail.gmail.com>
@ 2010-09-08 5:19 ` Eric Dumazet
2010-09-08 5:33 ` jovi zhang
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2010-09-08 5:19 UTC (permalink / raw)
To: jovi zhang
Cc: David S. Miller, Johannes Berg, Eric W. Biederman,
Alexey Dobriyan, linux-kernel, netdev
Le mercredi 08 septembre 2010 à 13:13 +0800, jovi zhang a écrit :
> It will kfree NULL pointer if listeners is NULL. fix it.
>
> Signed-off-by: bookjovi@gmail.com
> net/netlink/af_netlink.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 980fe4a..1c7bf48 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -1532,8 +1532,10 @@ netlink_kernel_create(struct net *net, int
> unit, unsigned int groups,
> if (input)
> nlk_sk(sk)->netlink_rcv = input;
>
> - if (netlink_insert(sk, net, 0))
> + if (netlink_insert(sk, net, 0)) {
> + kfree(listeners);
> goto out_sock_release;
> + }
>
> nlk = nlk_sk(sk);
> nlk->flags |= NETLINK_KERNEL_SOCKET;
> @@ -1553,7 +1555,6 @@ netlink_kernel_create(struct net *net, int unit,
> unsigned int groups,
> return sk;
>
> out_sock_release:
> - kfree(listeners);
> netlink_kernel_release(sk);
> return NULL;
This patch is not needed
kfree(NULL) is legal
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] netlink: Fix kfree NULL pointer
2010-09-08 5:19 ` [PATCH] netlink: Fix kfree NULL pointer Eric Dumazet
@ 2010-09-08 5:33 ` jovi zhang
2010-09-08 5:53 ` David Miller
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: jovi zhang @ 2010-09-08 5:33 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Johannes Berg, Eric W. Biederman,
Alexey Dobriyan, linux-kernel, netdev
On Wed, Sep 8, 2010 at 1:19 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le mercredi 08 septembre 2010 à 13:13 +0800, jovi zhang a écrit :
>> It will kfree NULL pointer if listeners is NULL. fix it.
>>
>> Signed-off-by: bookjovi@gmail.com
>> net/netlink/af_netlink.c | 5 +++--
>> 1 files changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
>> index 980fe4a..1c7bf48 100644
>> --- a/net/netlink/af_netlink.c
>> +++ b/net/netlink/af_netlink.c
>> @@ -1532,8 +1532,10 @@ netlink_kernel_create(struct net *net, int
>> unit, unsigned int groups,
>> if (input)
>> nlk_sk(sk)->netlink_rcv = input;
>>
>> - if (netlink_insert(sk, net, 0))
>> + if (netlink_insert(sk, net, 0)) {
>> + kfree(listeners);
>> goto out_sock_release;
>> + }
>>
>> nlk = nlk_sk(sk);
>> nlk->flags |= NETLINK_KERNEL_SOCKET;
>> @@ -1553,7 +1555,6 @@ netlink_kernel_create(struct net *net, int unit,
>> unsigned int groups,
>> return sk;
>>
>> out_sock_release:
>> - kfree(listeners);
>> netlink_kernel_release(sk);
>> return NULL;
>
>
> This patch is not needed
>
> kfree(NULL) is legal
>
>
>
>
YES, maybe kfree(NULL) is legal, but I cannot see there have any need
to invoke kfree(NULL) in this function.
Also I check kfree usage in other code, I havn't find any kfree(NULL) usage.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] netlink: Fix kfree NULL pointer
2010-09-08 5:33 ` jovi zhang
@ 2010-09-08 5:53 ` David Miller
2010-09-08 5:54 ` Eric W. Biederman
2010-09-08 5:55 ` Eric Dumazet
2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2010-09-08 5:53 UTC (permalink / raw)
To: bookjovi
Cc: eric.dumazet, johannes.berg, ebiederm, adobriyan, linux-kernel,
netdev
From: jovi zhang <bookjovi@gmail.com>
Date: Wed, 8 Sep 2010 13:33:28 +0800
> Also I check kfree usage in other code, I havn't find any kfree(NULL) usage.
You aren't looking hard enough.
Please leave this code alone, it's functionally correct and fine.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] netlink: Fix kfree NULL pointer
2010-09-08 5:33 ` jovi zhang
2010-09-08 5:53 ` David Miller
@ 2010-09-08 5:54 ` Eric W. Biederman
2010-09-08 5:55 ` Eric Dumazet
2 siblings, 0 replies; 7+ messages in thread
From: Eric W. Biederman @ 2010-09-08 5:54 UTC (permalink / raw)
To: jovi zhang
Cc: Eric Dumazet, David S. Miller, Johannes Berg, Alexey Dobriyan,
linux-kernel, netdev
jovi zhang <bookjovi@gmail.com> writes:
> On Wed, Sep 8, 2010 at 1:19 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>
>>
>> This patch is not needed
>>
>> kfree(NULL) is legal
>>
>>
>>
>>
>
> YES, maybe kfree(NULL) is legal, but I cannot see there have any need
> to invoke kfree(NULL) in this function.
> Also I check kfree usage in other code, I havn't find any kfree(NULL)
> usage.
Usually kfree(NULL) is not explicit, but "var = NULL; kfree(var)" is
common in error handling paths to reduce the complexity of error
handling, making bugs less likely.
Eric
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] netlink: Fix kfree NULL pointer
2010-09-08 5:33 ` jovi zhang
2010-09-08 5:53 ` David Miller
2010-09-08 5:54 ` Eric W. Biederman
@ 2010-09-08 5:55 ` Eric Dumazet
2010-09-08 6:14 ` jovi zhang
2 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2010-09-08 5:55 UTC (permalink / raw)
To: jovi zhang
Cc: David S. Miller, Johannes Berg, Eric W. Biederman,
Alexey Dobriyan, linux-kernel, netdev
Le mercredi 08 septembre 2010 à 13:33 +0800, jovi zhang a écrit :
> YES, maybe kfree(NULL) is legal, but I cannot see there have any need
> to invoke kfree(NULL) in this function.
> Also I check kfree usage in other code, I havn't find any kfree(NULL) usage.
We have hundred call sites doing kfree(NULL), if it makes code shorter.
Its usually code path handling exceptions (errors if you prefer), and we
prefer to use ugly gotos, and even kfree(NULL), to make it as short as
possible.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] netlink: Fix kfree NULL pointer
2010-09-08 5:55 ` Eric Dumazet
@ 2010-09-08 6:14 ` jovi zhang
0 siblings, 0 replies; 7+ messages in thread
From: jovi zhang @ 2010-09-08 6:14 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Johannes Berg, Eric W. Biederman,
Alexey Dobriyan, linux-kernel, netdev
On Wed, Sep 8, 2010 at 1:55 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le mercredi 08 septembre 2010 à 13:33 +0800, jovi zhang a écrit :
>
>> YES, maybe kfree(NULL) is legal, but I cannot see there have any need
>> to invoke kfree(NULL) in this function.
>> Also I check kfree usage in other code, I havn't find any kfree(NULL) usage.
>
> We have hundred call sites doing kfree(NULL), if it makes code shorter.
>
> Its usually code path handling exceptions (errors if you prefer), and we
> prefer to use ugly gotos, and even kfree(NULL), to make it as short as
> possible.
OK, I understand.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] netlink: Fix kfree NULL pointer
@ 2010-09-08 5:13 jovi zhang
0 siblings, 0 replies; 7+ messages in thread
From: jovi zhang @ 2010-09-08 5:13 UTC (permalink / raw)
To: David S. Miller, Johannes Berg, Eric Dumazet, Eric W. Biederman,
Alexey
It will kfree NULL pointer if listeners is NULL. fix it.
Signed-off-by: bookjovi@gmail.com
net/netlink/af_netlink.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 980fe4a..1c7bf48 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1532,8 +1532,10 @@ netlink_kernel_create(struct net *net, int
unit, unsigned int groups,
if (input)
nlk_sk(sk)->netlink_rcv = input;
- if (netlink_insert(sk, net, 0))
+ if (netlink_insert(sk, net, 0)) {
+ kfree(listeners);
goto out_sock_release;
+ }
nlk = nlk_sk(sk);
nlk->flags |= NETLINK_KERNEL_SOCKET;
@@ -1553,7 +1555,6 @@ netlink_kernel_create(struct net *net, int unit,
unsigned int groups,
return sk;
out_sock_release:
- kfree(listeners);
netlink_kernel_release(sk);
return NULL;
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-09-08 6:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <AANLkTikp0m8cQYfEBHP_E8XpGZqdMj6Cr4M=aWCnei=X@mail.gmail.com>
2010-09-08 5:19 ` [PATCH] netlink: Fix kfree NULL pointer Eric Dumazet
2010-09-08 5:33 ` jovi zhang
2010-09-08 5:53 ` David Miller
2010-09-08 5:54 ` Eric W. Biederman
2010-09-08 5:55 ` Eric Dumazet
2010-09-08 6:14 ` jovi zhang
2010-09-08 5:13 jovi zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox