From: Kees Cook <keescook@chromium.org>
To: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
linux-hardening@vger.kernel.org, linux-um@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] um: refactor deprecated strncpy to strtomem
Date: Mon, 7 Aug 2023 16:39:56 -0700 [thread overview]
Message-ID: <202308071636.AF290F0@keescook> (raw)
In-Reply-To: <CAGG=3QVUqVdkzBo-=vGWprPBUhuV8p3bRSx3Qsvtqx_LDct05w@mail.gmail.com>
On Mon, Aug 07, 2023 at 03:36:55PM -0700, Bill Wendling wrote:
> On Mon, Aug 7, 2023 at 2:18 PM Justin Stitt <justinstitt@google.com> wrote:
> >
> > Use `strtomem` here since `console_buf` is not expected to be
> > NUL-terminated. We should probably also just use `MCONSOLE_MAX_DATA`
How is it known that console_buf is not a C-string?
> > instead of using `ARRAY_SIZE()` for every iteration of the loop.
> >
> Is this change necessary? I have a general preference for ARRAY_SIZE,
> because a change in size is less likely to be overlooked (unless that
> goes against the coding standard).
I would prefer this stay either ARRAY_SIZE or sizeof, as it keeps it
tied to the variable in question.
>
> > Also mark char buffer as `__nonstring` as per Kees' suggestion here [1]
> >
> > Finally, follow checkpatch's recommendation of using `min_t` over `min`
> >
> > Link: https://github.com/KSPP/linux/issues/90 [1]
> > Cc: linux-hardening@vger.kernel.org
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > ---
> > Notes:
> > I only build tested this patch.
> > ---
> > arch/um/drivers/mconsole_kern.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
> > index 5026e7b9adfe..fd4c024202ae 100644
> > --- a/arch/um/drivers/mconsole_kern.c
> > +++ b/arch/um/drivers/mconsole_kern.c
> > @@ -4,6 +4,7 @@
> > * Copyright (C) 2001 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
> > */
> >
> > +#include "linux/compiler_attributes.h"
>
> nit: Should this include be in angle brackets?
>
> #include <linux/compiler_attributes.h>
True, though this shouldn't need to be included at all. What was
missing?
>
> > #include <linux/console.h>
> > #include <linux/ctype.h>
> > #include <linux/string.h>
> > @@ -554,7 +555,7 @@ struct mconsole_output {
> >
> > static DEFINE_SPINLOCK(client_lock);
> > static LIST_HEAD(clients);
> > -static char console_buf[MCONSOLE_MAX_DATA];
> > +static char console_buf[MCONSOLE_MAX_DATA] __nonstring;
> >
> > static void console_write(struct console *console, const char *string,
> > unsigned int len)
> > @@ -566,8 +567,8 @@ static void console_write(struct console *console, const char *string,
> > return;
> >
> > while (len > 0) {
> > - n = min((size_t) len, ARRAY_SIZE(console_buf));
> > - strncpy(console_buf, string, n);
> > + n = min_t(size_t, len, MCONSOLE_MAX_DATA);
> > + strtomem(console_buf, string);
> > string += n;
> > len -= n;
> >
> >
> > ---
> > base-commit: c1a515d3c0270628df8ae5f5118ba859b85464a2
> > change-id: 20230807-arch-um-3ef24413427e
> >
> > Best regards,
> > --
> > Justin Stitt <justinstitt@google.com>
> >
--
Kees Cook
next prev parent reply other threads:[~2023-08-07 23:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 21:17 [PATCH] um: refactor deprecated strncpy to strtomem Justin Stitt
2023-08-07 22:36 ` Bill Wendling
2023-08-07 23:39 ` Kees Cook [this message]
2023-08-08 17:28 ` Justin Stitt
2023-08-09 0:41 ` Kees Cook
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=202308071636.AF290F0@keescook \
--to=keescook@chromium.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=johannes@sipsolutions.net \
--cc=justinstitt@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=morbo@google.com \
--cc=richard@nod.at \
/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