Skip to contentSkip to conversation

keys: Replace memcpy with strscpy in proc_keys_show

PATCH In review Thorsten Blum 2 participants 2 messages Nov 12, 2025 – Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 security/keys/proc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/keys/proc.c +3 -2
index 4f4e2c1824f1..1d380766f45d 100644
@@ -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;
 
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 2 lines · Thorsten Blum

Use strscpy() to copy strings into the fixed-size buffer 'xbuf' instead of hardcoding the number of bytes to copy. This improves maintainability

I don't consider maintainaibility as a stimulus of applying change given that as a word it means me absolutely nothing.

Quoted 34 lines

and ensures the buffer is always NUL-terminated.

---
 security/keys/proc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/keys/proc.c +3 -2
index 4f4e2c1824f1..1d380766f45d 100644
@@ -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;
 
Signature · 1 line
2.51.0

BR, Jarkko