linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc
@ 2022-08-31  6:53 Jiasheng Jiang
  2022-08-31  7:00 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2022-08-31  6:53 UTC (permalink / raw)
  To: keescook, arnd, gregkh; +Cc: linux-kernel, Jiasheng Jiang

As the potential failure of the memory allocation,
it should be better to check the return value after
calling kmalloc and vmalloc and skip the execute_location
if fails.

Fixes: cc33c537c12f ("lkdtm: add "EXEC_*" triggers")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/misc/lkdtm/perms.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index b93404d65650..9ba927d74973 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -180,14 +180,16 @@ static void lkdtm_EXEC_STACK(void)
 static void lkdtm_EXEC_KMALLOC(void)
 {
 	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
-	execute_location(kmalloc_area, CODE_WRITE);
+	if (kmalloc_area)
+		execute_location(kmalloc_area, CODE_WRITE);
 	kfree(kmalloc_area);
 }
 
 static void lkdtm_EXEC_VMALLOC(void)
 {
 	u32 *vmalloc_area = vmalloc(EXEC_SIZE);
-	execute_location(vmalloc_area, CODE_WRITE);
+	if (vmalloc_area)
+		execute_location(vmalloc_area, CODE_WRITE);
 	vfree(vmalloc_area);
 }
 
-- 
2.25.1


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

* Re: [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc
  2022-08-31  6:53 [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc Jiasheng Jiang
@ 2022-08-31  7:00 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-08-31  7:00 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: keescook, arnd, linux-kernel

On Wed, Aug 31, 2022 at 02:53:55PM +0800, Jiasheng Jiang wrote:
> As the potential failure of the memory allocation,
> it should be better to check the return value after
> calling kmalloc and vmalloc and skip the execute_location
> if fails.
> 
> Fixes: cc33c537c12f ("lkdtm: add "EXEC_*" triggers")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/misc/lkdtm/perms.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
> index b93404d65650..9ba927d74973 100644
> --- a/drivers/misc/lkdtm/perms.c
> +++ b/drivers/misc/lkdtm/perms.c
> @@ -180,14 +180,16 @@ static void lkdtm_EXEC_STACK(void)
>  static void lkdtm_EXEC_KMALLOC(void)
>  {
>  	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
> -	execute_location(kmalloc_area, CODE_WRITE);
> +	if (kmalloc_area)

How will this ever fail?  Have you seen that happen?

> +		execute_location(kmalloc_area, CODE_WRITE);
>  	kfree(kmalloc_area);
>  }
>  
>  static void lkdtm_EXEC_VMALLOC(void)
>  {
>  	u32 *vmalloc_area = vmalloc(EXEC_SIZE);
> -	execute_location(vmalloc_area, CODE_WRITE);
> +	if (vmalloc_area)

Same here, if the system really can not allocate 64 bytes, much worse
things will have happened already.

thanks,

greg k-h

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

end of thread, other threads:[~2022-08-31  7:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31  6:53 [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc Jiasheng Jiang
2022-08-31  7:00 ` Greg KH

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