[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251112172620.4254-2-thorsten.blum@linux.dev>
Date: Wed, 12 Nov 2025 18:26:21 +0100
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: David Howells <dhowells@...hat.com>,
Jarkko Sakkinen <jarkko@...nel.org>,
Paul Moore <paul@...l-moore.com>,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
keyrings@...r.kernel.org,
linux-security-module@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] keys: Replace memcpy with strscpy in proc_keys_show
Use strscpy() to copy strings into the fixed-size buffer 'xbuf' instead
of hardcoding the number of bytes to copy. This improves maintainability
and ensures the buffer is always NUL-terminated.
Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
---
security/keys/proc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/security/keys/proc.c b/security/keys/proc.c
index 4f4e2c1824f1..1d380766f45d 100644
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -10,6 +10,7 @@
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/string.h>
#include <asm/errno.h>
#include "internal.h"
@@ -199,9 +200,9 @@ static int proc_keys_show(struct seq_file *m, void *v)
/* come up with a suitable timeout value */
expiry = READ_ONCE(key->expiry);
if (expiry == TIME64_MAX) {
- memcpy(xbuf, "perm", 5);
+ strscpy(xbuf, "perm");
} else if (now >= expiry) {
- memcpy(xbuf, "expd", 5);
+ strscpy(xbuf, "expd");
} else {
timo = expiry - now;
--
2.51.0
Powered by blists - more mailing lists