* [PATCH] keys: Replace memcpy with strscpy in proc_keys_show
@ 2025-11-12 17:26 Thorsten Blum
2025-11-19 2:36 ` Jarkko Sakkinen
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-11-12 17:26 UTC (permalink / raw)
To: David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
Serge E. Hallyn
Cc: Thorsten Blum, keyrings, linux-security-module, linux-kernel
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@linux.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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] keys: Replace memcpy with strscpy in proc_keys_show
2025-11-12 17:26 [PATCH] keys: Replace memcpy with strscpy in proc_keys_show Thorsten Blum
@ 2025-11-19 2:36 ` Jarkko Sakkinen
0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2025-11-19 2:36 UTC (permalink / raw)
To: Thorsten Blum
Cc: David Howells, Paul Moore, James Morris, Serge E. Hallyn,
keyrings, linux-security-module, linux-kernel
On Wed, Nov 12, 2025 at 06:26:21PM +0100, Thorsten Blum wrote:
> 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.
> and ensures the buffer is always NUL-terminated.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.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
>
BR, Jarkko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-19 2:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 17:26 [PATCH] keys: Replace memcpy with strscpy in proc_keys_show Thorsten Blum
2025-11-19 2:36 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).