Re: [PATCH 1/3] kobject : kobject_set_name_vargs leak fix
From: Dave Young
Date: Thu May 14 2009 - 08:59:51 EST
On Thu, May 14, 2009 at 8:38 PM, Ming Lei <tom.leiming@xxxxxxxxx> wrote:
> 2009/5/14 Dave Young <hidave.darkstar@xxxxxxxxx>:
>> On Mon, May 11, 2009 at 2:16 PM, Dave Young <hidave.darkstar@xxxxxxxxx> wrote:
>>> kobject_set_name_vargs will leak the old_name when return -ENOMEM,
>>> move the kfree(old_name) before the return path.
>>
>> Hi, greg
>>
>> I rethought about this problem, does such issue exist really? I means
>> that kobject->name != NULL scenario.
>>
>> there's following comments of this function:
>>
>> Â* This sets the name of the kobject. ÂIf you have already added the
>> Â* kobject to the system, you must call kobject_rename() in order to
>> Â* change the name of the kobject
>>
>> So what if something like :
>>
>> if (kobject->name) {
>> ÂWARN(1, KERN_WARNING, "there's name for kobject already!");
>> Âreturn -EINVAL;
>> }
>>
>> if (!fmt)
>> Âreturn 0;
>>
>>>
>>> Signed-off-by: Dave Young <hidave.darkstar@xxxxxxxxx>
>>> ---
>>> lib/kobject.c | Â Â2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff -uprN linux.old/lib/kobject.c linux.new/lib/kobject.c
>>> --- linux.old/lib/kobject.c   2009-05-11 13:59:01.000000000 +0800
>>> +++ linux.new/lib/kobject.c   2009-05-11 13:59:34.000000000 +0800
>>> @@ -221,6 +221,7 @@ int kobject_set_name_vargs(struct kobjec
>>> Â Â Â Âif (kobj->name && !fmt)
>>> Â Â Â Â Â Â Â Âreturn 0;
>>>
>>> + Â Â Â kfree(old_name);
>>> Â Â Â Âkobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
>>> Â Â Â Âif (!kobj->name)
>>> Â Â Â Â Â Â Â Âreturn -ENOMEM;
>
> IMO, Greg means it is better that the fix should be :
> Â Â Â Âif (!kobj->name) {
> Â Â Â Â Â Â Â Âkobj->name = old_name;
> Â Â Â Â Â Â Â Âreturn -ENOMEM;
> Â Â Â Â}
>
> Right?
Hm, it's better against my original patch. I have gave up the approach.
It does not make sense for (!old_name) case , furthermore as my reply
kobject with name set before should not come into this function,
kobject_rename should be used instead.
>
>>> @@ -229,7 +230,6 @@ int kobject_set_name_vargs(struct kobjec
>>> Â Â Â Âwhile ((s = strchr(kobj->name, '/')))
>>> Â Â Â Â Â Â Â Âs[0] = '!';
>>>
>>> - Â Â Â kfree(old_name);
>>> Â Â Â Âreturn 0;
>>> Â}
>>>
>>
>>
>>
>> --
>> Regards
>> dave
>> --
>> 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/
>>
>
>
>
> --
> Lei Ming
>
--
Regards
dave
--
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/