From: Greg KH <gregkh@linuxfoundation.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: keescook@chromium.org, arnd@arndb.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc
Date: Wed, 31 Aug 2022 09:00:20 +0200 [thread overview]
Message-ID: <Yw8HBKceRuLlZa0d@kroah.com> (raw)
In-Reply-To: <20220831065355.2125181-1-jiasheng@iscas.ac.cn>
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
prev parent reply other threads:[~2022-08-31 7:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 6:53 [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc Jiasheng Jiang
2022-08-31 7:00 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yw8HBKceRuLlZa0d@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=arnd@arndb.de \
--cc=jiasheng@iscas.ac.cn \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.