All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
@ 2022-07-25  8:11 Ren Yu
  2022-07-25  8:42 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Ren Yu @ 2022-07-25  8:11 UTC (permalink / raw)
  To: keescook, arnd, gregkh, linux-kernel; +Cc: liqiong, yuzhe, Ren Yu

As the possible alloc failure of the kmalloc() and vmalloc(),the
return pointer could be NULL.therefore it should be better to check it.

Signed-off-by: Ren Yu <renyu@nfschina.com>
---
 drivers/misc/lkdtm/perms.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index b93404d65650..34b43b9ea1f1 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -180,6 +180,9 @@ static void lkdtm_EXEC_STACK(void)
 static void lkdtm_EXEC_KMALLOC(void)
 {
 	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
+	if (!kmalloc_area)
+		return;
+
 	execute_location(kmalloc_area, CODE_WRITE);
 	kfree(kmalloc_area);
 }
@@ -187,6 +190,9 @@ static void lkdtm_EXEC_KMALLOC(void)
 static void lkdtm_EXEC_VMALLOC(void)
 {
 	u32 *vmalloc_area = vmalloc(EXEC_SIZE);
+	if (!vmalloc_area)
+		return;
+
 	execute_location(vmalloc_area, CODE_WRITE);
 	vfree(vmalloc_area);
 }
-- 
2.11.0


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

* Re: [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
  2022-07-25  8:11 [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc() Ren Yu
@ 2022-07-25  8:42 ` Greg KH
  2022-07-25  9:54   ` tury
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2022-07-25  8:42 UTC (permalink / raw)
  To: Ren Yu; +Cc: keescook, arnd, linux-kernel, liqiong, yuzhe

On Mon, Jul 25, 2022 at 04:11:53PM +0800, Ren Yu wrote:
> As the possible alloc failure of the kmalloc() and vmalloc(),the
> return pointer could be NULL.therefore it should be better to check it.
> 
> Signed-off-by: Ren Yu <renyu@nfschina.com>
> ---
>  drivers/misc/lkdtm/perms.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
> index b93404d65650..34b43b9ea1f1 100644
> --- a/drivers/misc/lkdtm/perms.c
> +++ b/drivers/misc/lkdtm/perms.c
> @@ -180,6 +180,9 @@ static void lkdtm_EXEC_STACK(void)
>  static void lkdtm_EXEC_KMALLOC(void)
>  {
>  	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
> +	if (!kmalloc_area)
> +		return;
> +

Always run checkpatch on your patches so that grumpy maintainers do not
have to tell you to run checkpatch on your patches...

Also, shouldn't this return an error?

But most importantly, how can this ever fail?

thanks,

greg k-h

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

* Re: [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
  2022-07-25  8:42 ` Greg KH
@ 2022-07-25  9:54   ` tury
  2022-07-25 12:37     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: tury @ 2022-07-25  9:54 UTC (permalink / raw)
  To: Greg KH; +Cc: keescook, arnd, linux-kernel, liqiong, yuzhe

When there is insufficient memory, the allocation will fail.

the return value is void,so i think it is ok .

should i have changed comment to something like this ?

As the possible alloc failure of the kmalloc() and vmalloc(),
the return pointer could be NULL.therefore it should be better to check it.


在 2022年07月25日 16:42, Greg KH 写道:
> On Mon, Jul 25, 2022 at 04:11:53PM +0800, Ren Yu wrote:
>> As the possible alloc failure of the kmalloc() and vmalloc(),the
>> return pointer could be NULL.therefore it should be better to check it.
>>
>> Signed-off-by: Ren Yu <renyu@nfschina.com>
>> ---
>>   drivers/misc/lkdtm/perms.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
>> index b93404d65650..34b43b9ea1f1 100644
>> --- a/drivers/misc/lkdtm/perms.c
>> +++ b/drivers/misc/lkdtm/perms.c
>> @@ -180,6 +180,9 @@ static void lkdtm_EXEC_STACK(void)
>>   static void lkdtm_EXEC_KMALLOC(void)
>>   {
>>   	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
>> +	if (!kmalloc_area)
>> +		return;
>> +
> Always run checkpatch on your patches so that grumpy maintainers do not
> have to tell you to run checkpatch on your patches...
>
> Also, shouldn't this return an error?
>
> But most importantly, how can this ever fail?
>
> thanks,
>
> greg k-h
>

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

* Re: [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
  2022-07-25  9:54   ` tury
@ 2022-07-25 12:37     ` Greg KH
  2022-07-26  5:43       ` tury
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2022-07-25 12:37 UTC (permalink / raw)
  To: tury; +Cc: keescook, arnd, linux-kernel, liqiong, yuzhe

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Mon, Jul 25, 2022 at 05:54:15PM +0800, tury wrote:
> When there is insufficient memory, the allocation will fail.

And have you ever seen that happen here?  The issue is for small
allocations, they never will fail.

> the return value is void,so i think it is ok .

Why?

> should i have changed comment to something like this ?
> 
> As the possible alloc failure of the kmalloc() and vmalloc(),
> the return pointer could be NULL.therefore it should be better to check it.

Please wrap your lines properly, and use '.' correctly.

thanks,

greg k-h

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

* Re: [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
  2022-07-25 12:37     ` Greg KH
@ 2022-07-26  5:43       ` tury
  2022-07-27 21:00         ` Kees Cook
  0 siblings, 1 reply; 6+ messages in thread
From: tury @ 2022-07-26  5:43 UTC (permalink / raw)
  To: Greg KH; +Cc: keescook, arnd, linux-kernel, liqiong, yuzhe

在 2022年07月25日 20:37, Greg KH 写道:
> A: http://en.wikipedia.org/wiki/Top_post
> Q: Were do I find info about this thing called top-posting?
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?
>
> A: No.
> Q: Should I include quotations after my reply?
>
> http://daringfireball.net/2007/07/on_top
>
> On Mon, Jul 25, 2022 at 05:54:15PM +0800, tury wrote:
>> When there is insufficient memory, the allocation will fail.
> And have you ever seen that happen here?  The issue is for small
> allocations, they never will fail.
>
>> the return value is void,so i think it is ok .
> Why?
Because the function lkdtm_EXEC_KMALLOC()   declaration is void,and The 
return value is not checked elsewhere.
Should I add some warning messages?
>
>> should i have changed comment to something like this ?
>>
>> As the possible alloc failure of the kmalloc() and vmalloc(),
>> the return pointer could be NULL.therefore it should be better to check it.
> Please wrap your lines properly, and use '.' correctly.
>
> thanks,
>
> greg k-h
Thank you for your help and patience,
>


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

* Re: [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
  2022-07-26  5:43       ` tury
@ 2022-07-27 21:00         ` Kees Cook
  0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2022-07-27 21:00 UTC (permalink / raw)
  To: tury; +Cc: Greg KH, arnd, linux-kernel, liqiong, yuzhe

On Tue, Jul 26, 2022 at 01:43:41PM +0800, tury wrote:
> 在 2022年07月25日 20:37, Greg KH 写道:
> > A: http://en.wikipedia.org/wiki/Top_post
> > Q: Were do I find info about this thing called top-posting?
> > A: Because it messes up the order in which people normally read text.
> > Q: Why is top-posting such a bad thing?
> > A: Top-posting.
> > Q: What is the most annoying thing in e-mail?
> > 
> > A: No.
> > Q: Should I include quotations after my reply?
> > 
> > http://daringfireball.net/2007/07/on_top
> > 
> > On Mon, Jul 25, 2022 at 05:54:15PM +0800, tury wrote:
> > > When there is insufficient memory, the allocation will fail.
> > And have you ever seen that happen here?  The issue is for small
> > allocations, they never will fail.
> > 
> > > the return value is void,so i think it is ok .
> > Why?
> Because the function lkdtm_EXEC_KMALLOC()   declaration is void,and The
> return value is not checked elsewhere.
> Should I add some warning messages?

Memory allocation failures will already be reported by the allocator, so
there is normally no need for an additional message.

-- 
Kees Cook

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

end of thread, other threads:[~2022-07-27 21:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25  8:11 [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc() Ren Yu
2022-07-25  8:42 ` Greg KH
2022-07-25  9:54   ` tury
2022-07-25 12:37     ` Greg KH
2022-07-26  5:43       ` tury
2022-07-27 21:00         ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.