summaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
authorJustin Stitt <justinstitt@google.com>2023-08-09 18:19:32 +0000
committerRichard Weinberger <richard@nod.at>2023-08-26 22:48:38 +0200
commit32280e83b555d692e8c7b96563b0ee2037585712 (patch)
treee1523b18bad4a62b1e12157e6391ac0911e25f8c /arch/um
parentab7ca2eb63a2168619f7595622fe29967ed0959b (diff)
downloadlinux-32280e83b555d692e8c7b96563b0ee2037585712.tar.gz
linux-32280e83b555d692e8c7b96563b0ee2037585712.tar.bz2
linux-32280e83b555d692e8c7b96563b0ee2037585712.zip
um: Refactor deprecated strncpy to memcpy
Use `memcpy` since `console_buf` is not expected to be NUL-terminated and it more accurately describes what is happening with the buffers `console_buf` and `string` as per Kees' analysis [1]. Also mark char buffer as `__nonstring` as per Kees' suggestion [2]. This change now makes it more clear what this code does and that `console_buf` is not expected to be NUL-terminated. Link: https://lore.kernel.org/all/202308081708.D5ADC80F@keescook/ [1] Link: https://github.com/KSPP/linux/issues/90 [2] Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings Cc: linux-hardening@vger.kernel.org Suggested-by: Kees Cook <keescook@chromium.org> Signed-off-by: Justin Stitt <justinstitt@google.com> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'arch/um')
-rw-r--r--arch/um/drivers/mconsole_kern.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 5026e7b9adfe..ff4bda95b9c7 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -554,7 +554,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)
@@ -567,7 +567,7 @@ static void console_write(struct console *console, const char *string,
while (len > 0) {
n = min((size_t) len, ARRAY_SIZE(console_buf));
- strncpy(console_buf, string, n);
+ memcpy(console_buf, string, n);
string += n;
len -= n;