linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create()
@ 2019-05-30  3:39 Gen Zhang
  2019-06-11  9:37 ` Gen Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Gen Zhang @ 2019-05-30  3:39 UTC (permalink / raw)
  To: ssantosh; +Cc: linux-kernel, linux-arm-kernel

In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It
returns NULL when fails. So 'pool->name' should be checked. And free
'pool' when error.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
---
diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
index 8b41837..0f8cb28 100644
--- a/drivers/soc/ti/knav_qmss_queue.c
+++ b/drivers/soc/ti/knav_qmss_queue.c
@@ -814,6 +814,12 @@ void *knav_pool_create(const char *name,
 	}
 
 	pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
+	if (!pool->name) {
+		dev_err(kdev->dev, "failed to duplicate for pool(%s)\n",
+			name);
+		ret = -ENOMEM;
+		goto err_name;
+	}
 	pool->kdev = kdev;
 	pool->dev = kdev->dev;
 
@@ -864,6 +870,7 @@ void *knav_pool_create(const char *name,
 	mutex_unlock(&knav_dev_lock);
 err:
 	kfree(pool->name);
+err_name:
 	devm_kfree(kdev->dev, pool);
 	return ERR_PTR(ret);
 }

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create()
  2019-05-30  3:39 [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create() Gen Zhang
@ 2019-06-11  9:37 ` Gen Zhang
  2019-06-11  9:54   ` Marc Zyngier
  0 siblings, 1 reply; 5+ messages in thread
From: Gen Zhang @ 2019-06-11  9:37 UTC (permalink / raw)
  To: ssantosh, marc.zyngier, olof; +Cc: linux-kernel, linux-arm-kernel

On Thu, May 30, 2019 at 11:39:49AM +0800, Gen Zhang wrote:
> In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It
> returns NULL when fails. So 'pool->name' should be checked. And free
> 'pool' when error.
> 
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> ---
> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
> index 8b41837..0f8cb28 100644
> --- a/drivers/soc/ti/knav_qmss_queue.c
> +++ b/drivers/soc/ti/knav_qmss_queue.c
> @@ -814,6 +814,12 @@ void *knav_pool_create(const char *name,
>  	}
>  
>  	pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
> +	if (!pool->name) {
> +		dev_err(kdev->dev, "failed to duplicate for pool(%s)\n",
> +			name);
> +		ret = -ENOMEM;
> +		goto err_name;
> +	}
>  	pool->kdev = kdev;
>  	pool->dev = kdev->dev;
>  
> @@ -864,6 +870,7 @@ void *knav_pool_create(const char *name,
>  	mutex_unlock(&knav_dev_lock);
>  err:
>  	kfree(pool->name);
> +err_name:
>  	devm_kfree(kdev->dev, pool);
>  	return ERR_PTR(ret);
>  }
Can anyone look into this patch?

Thanks
Gen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create()
  2019-06-11  9:37 ` Gen Zhang
@ 2019-06-11  9:54   ` Marc Zyngier
  2019-06-11 10:08     ` Gen Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Zyngier @ 2019-06-11  9:54 UTC (permalink / raw)
  To: Gen Zhang, ssantosh, olof; +Cc: linux-kernel, linux-arm-kernel

Hi Gen,

No idea why I'm being cc'd on this but hey... ;-)

On 11/06/2019 10:37, Gen Zhang wrote:
> On Thu, May 30, 2019 at 11:39:49AM +0800, Gen Zhang wrote:
>> In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It
>> returns NULL when fails. So 'pool->name' should be checked. And free
>> 'pool' when error.
>>
>> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
>> ---
>> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
>> index 8b41837..0f8cb28 100644
>> --- a/drivers/soc/ti/knav_qmss_queue.c
>> +++ b/drivers/soc/ti/knav_qmss_queue.c
>> @@ -814,6 +814,12 @@ void *knav_pool_create(const char *name,
>>  	}
>>  
>>  	pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
>> +	if (!pool->name) {
>> +		dev_err(kdev->dev, "failed to duplicate for pool(%s)\n",
>> +			name);

There is no need to output anything, the kernel will be loud enough if
you run out of memory.

>> +		ret = -ENOMEM;
>> +		goto err_name;
>> +	}
>>  	pool->kdev = kdev;
>>  	pool->dev = kdev->dev;
>>  
>> @@ -864,6 +870,7 @@ void *knav_pool_create(const char *name,
>>  	mutex_unlock(&knav_dev_lock);
>>  err:
>>  	kfree(pool->name);
>> +err_name:

kfree(NULL) is perfectly valid, there is no need to create a second
label. Just branch to the existing error label.

>>  	devm_kfree(kdev->dev, pool);
>>  	return ERR_PTR(ret);
>>  }
> Can anyone look into this patch?
> 
> Thanks
> Gen
> 

The real question is whether this is actually an error at all.
pool->name doesn't seem to be used for anything but debug information,
and the printing code can perfectly accommodate a NULL pointer.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create()
  2019-06-11  9:54   ` Marc Zyngier
@ 2019-06-11 10:08     ` Gen Zhang
  2019-06-11 21:10       ` santosh.shilimkar
  0 siblings, 1 reply; 5+ messages in thread
From: Gen Zhang @ 2019-06-11 10:08 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: ssantosh, olof, linux-kernel, linux-arm-kernel

On Tue, Jun 11, 2019 at 10:54:15AM +0100, Marc Zyngier wrote:
> Hi Gen,
> 
> No idea why I'm being cc'd on this but hey... ;-)
I copied email address ftom thid commit:-)
https://github.com/torvalds/linux/commit/832ad0e3da4510fd17f98804abe512ea9a747035#diff-f2a24befc247191f4b81af93e9336785
> 
> On 11/06/2019 10:37, Gen Zhang wrote:
> > On Thu, May 30, 2019 at 11:39:49AM +0800, Gen Zhang wrote:
> >> In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It
> >> returns NULL when fails. So 'pool->name' should be checked. And free
> >> 'pool' when error.
> >>
> >> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> >> ---
> >> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
> >> index 8b41837..0f8cb28 100644
> >> --- a/drivers/soc/ti/knav_qmss_queue.c
> >> +++ b/drivers/soc/ti/knav_qmss_queue.c
> >> @@ -814,6 +814,12 @@ void *knav_pool_create(const char *name,
> >>  	}
> >>  
> >>  	pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
> >> +	if (!pool->name) {
> >> +		dev_err(kdev->dev, "failed to duplicate for pool(%s)\n",
> >> +			name);
> 
> There is no need to output anything, the kernel will be loud enough if
> you run out of memory.
Thanks for your comments.
> 
> >> +		ret = -ENOMEM;
> >> +		goto err_name;
> >> +	}
> >>  	pool->kdev = kdev;
> >>  	pool->dev = kdev->dev;
> >>  
> >> @@ -864,6 +870,7 @@ void *knav_pool_create(const char *name,
> >>  	mutex_unlock(&knav_dev_lock);
> >>  err:
> >>  	kfree(pool->name);
> >> +err_name:
> 
> kfree(NULL) is perfectly valid, there is no need to create a second
> label. Just branch to the existing error label.
Sure, better not to add redundant codes.
> 
> >>  	devm_kfree(kdev->dev, pool);
> >>  	return ERR_PTR(ret);
> >>  }
> > Can anyone look into this patch?
> > 
> > Thanks
> > Gen
> > 
> 
> The real question is whether this is actually an error at all.
> pool->name doesn't seem to be used for anything but debug information,
> and the printing code can perfectly accommodate a NULL pointer.
That sounds reasonable. This patch just fixes a *theoretical* bug.

Thanks
Gen
> 
> Thanks,
> 
> 	M.
> -- 
> Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create()
  2019-06-11 10:08     ` Gen Zhang
@ 2019-06-11 21:10       ` santosh.shilimkar
  0 siblings, 0 replies; 5+ messages in thread
From: santosh.shilimkar @ 2019-06-11 21:10 UTC (permalink / raw)
  To: Gen Zhang, Marc Zyngier; +Cc: ssantosh, olof, linux-kernel, linux-arm-kernel



On 6/11/19 3:08 AM, Gen Zhang wrote:
> On Tue, Jun 11, 2019 at 10:54:15AM +0100, Marc Zyngier wrote:
>> Hi Gen,
>>
>> No idea why I'm being cc'd on this but hey... ;-)
> I copied email address ftom thid commit:-)
> https://github.com/torvalds/linux/commit/832ad0e3da4510fd17f98804abe512ea9a747035#diff-f2a24befc247191f4b81af93e9336785
>>
>> On 11/06/2019 10:37, Gen Zhang wrote:
>>> On Thu, May 30, 2019 at 11:39:49AM +0800, Gen Zhang wrote:
>>>> In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It
>>>> returns NULL when fails. So 'pool->name' should be checked. And free
>>>> 'pool' when error.
>>>>
>>>> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
>>>> ---
>>>> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
>>>> index 8b41837..0f8cb28 100644
>>>> --- a/drivers/soc/ti/knav_qmss_queue.c
>>>> +++ b/drivers/soc/ti/knav_qmss_queue.c
>>>> @@ -814,6 +814,12 @@ void *knav_pool_create(const char *name,
>>>>   	}
>>>>   
>>>>   	pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
>>>> +	if (!pool->name) {
>>>> +		dev_err(kdev->dev, "failed to duplicate for pool(%s)\n",
>>>> +			name);
>>
>> There is no need to output anything, the kernel will be loud enough if
>> you run out of memory.
> Thanks for your comments.
>>
>>>> +		ret = -ENOMEM;
>>>> +		goto err_name;
>>>> +	}
>>>>   	pool->kdev = kdev;
>>>>   	pool->dev = kdev->dev;
>>>>   
>>>> @@ -864,6 +870,7 @@ void *knav_pool_create(const char *name,
>>>>   	mutex_unlock(&knav_dev_lock);
>>>>   err:
>>>>   	kfree(pool->name);
>>>> +err_name:
>>
>> kfree(NULL) is perfectly valid, there is no need to create a second
>> label. Just branch to the existing error label.
> Sure, better not to add redundant codes.
>>
>>>>   	devm_kfree(kdev->dev, pool);
>>>>   	return ERR_PTR(ret);
>>>>   }
>>> Can anyone look into this patch?
>>>
>>> Thanks
>>> Gen
>>>
>>
>> The real question is whether this is actually an error at all.
>> pool->name doesn't seem to be used for anything but debug information,
>> and the printing code can perfectly accommodate a NULL pointer.
> That sounds reasonable. This patch just fixes a *theoretical* bug.
> 
Not even theoretical bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-11 21:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-30  3:39 [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create() Gen Zhang
2019-06-11  9:37 ` Gen Zhang
2019-06-11  9:54   ` Marc Zyngier
2019-06-11 10:08     ` Gen Zhang
2019-06-11 21:10       ` santosh.shilimkar

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).