Re: [PATCH] netlink: Fix kfree NULL pointer

From: jovi zhang
Date: Wed Sep 08 2010 - 01:33:55 EST


On Wed, Sep 8, 2010 at 1:19 PM, Eric Dumazet <eric.dumazet@xxxxxxxxx> 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@xxxxxxxxx
>> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/