Subject: Re: dev_get_valid_name buggy with hash collision

From: Daniel Lezcano <[email-masked]>
Date: Wed, 19 May 2010 21:39:56 +0200

On 05/19/2010 07:05 PM, Octavian Purdila wrote:
> On Tuesday 18 May 2010 17:55:36 you wrote:
>
>    
>>>>          if (!dev_valid_name(name))
>>>>                  return -EINVAL;
>>>>
>>>>          if (fmt&&   strchr(name, '%'))
>>>> -               return __dev_alloc_name(net, name, buf);
>>>> +               return dev_alloc_name(dev, name);
>>>>          else if (__dev_get_by_name(net, name))
>>>>                  return -EEXIST;
>>>> -       else if (buf != name)
>>>> -               strlcpy(buf, name, IFNAMSIZ);
>>>> +       else if (strncmp(dev->name, name, IFNAMSIZ))
>>>> +                strlcpy(dev->name, name, IFNAMSIZ);
>>>>          
>>> Why do the strncmp, can't we preserve the (buf != name) condition
>>>        
>> The 'buf' parameter is no longer passed to the function. We have the
>> 'dev'  and the 'newname' parameters.
>> The pointer test was just to check 'dev_get_valid_name' was called from
>> the 'register_netdevice' function context with 'dev_get_valid_name(net,
>> dev->name, dev->name, 0)'. Comparing the strings is valid in this case.
>>
>> Otherwise dev_get_valid_name is called from:
>>
>>    *  "dev_change_net_namespace" with "dev%d" or "ifname" specified
>> within the netlink message. Both are different pointers, the first will
>> fall in the "if (fmt&&  strchr(name, '%'))".
>>
>>    * "dev_change_name", where the pointers are different and the strings
>> are different.
>>
>>      
> True, but we why not use "if (dev->name !=name)" instead of strncmp? It should
> yield the same results and it is lighter then full strncmp.
>    

Yes, I agree. In the context of the different callers, that's correct.
Will resend it with the pointer comparison.

Thanks
   -- Daniel