From: Kees Cook <keescook@chromium.org>
To: "GONG, Ruiqi" <gongruiqi@huaweicloud.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, gongruiqi1@huawei.com
Subject: Re: [PATCH] lkdtm: use the return value of strim()
Date: Thu, 17 Aug 2023 09:55:22 -0700 [thread overview]
Message-ID: <202308170954.B18CCA9@keescook> (raw)
In-Reply-To: <20230817142117.972418-1-gongruiqi@huaweicloud.com>
On Thu, Aug 17, 2023 at 10:21:17PM +0800, GONG, Ruiqi wrote:
> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
>
> Make use of the return value of strim() to achieve left-trim as well as
> right-trim, which prevents the following unusual fail case:
>
> # echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
> sh: write error: Invalid argument
>
> Link: https://github.com/KSPP/linux/issues/337
> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
> ---
> drivers/misc/lkdtm/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
> index 0772e4a4757e..812c96461ab2 100644
> --- a/drivers/misc/lkdtm/core.c
> +++ b/drivers/misc/lkdtm/core.c
> @@ -242,7 +242,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
> }
> /* NULL-terminate and remove enter */
> buf[count] = '\0';
> - strim(buf);
> + buf = strim(buf);
>
> crashtype = find_crashtype(buf);
> free_page((unsigned long)buf);
Will free_page() still work in this case, though? The address won't
match the allocation any more...
-Kees
> @@ -318,7 +318,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
> }
> /* NULL-terminate and remove enter */
> buf[count] = '\0';
> - strim(buf);
> + buf = strim(buf);
>
> crashtype = find_crashtype(buf);
> free_page((unsigned long) buf);
> --
> 2.25.1
>
--
Kees Cook
next prev parent reply other threads:[~2023-08-17 16:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 14:21 [PATCH] lkdtm: use the return value of strim() GONG, Ruiqi
2023-08-17 16:55 ` Kees Cook [this message]
2023-08-18 2:39 ` GONG, Ruiqi
2023-08-18 10:44 ` Heiko Carstens
2023-08-22 12:03 ` Greg Kroah-Hartman
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=202308170954.B18CCA9@keescook \
--to=keescook@chromium.org \
--cc=arnd@arndb.de \
--cc=gongruiqi1@huawei.com \
--cc=gongruiqi@huaweicloud.com \
--cc=gregkh@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox