[PATCH] tsacct: Replace strncpy() with strscpy()

From: Kees Cook
Date: Thu Jul 11 2024 - 13:13:16 EST


Replace the deprecated[1] use of strncpy() in bacct_add_tsk(). Since this
is UAPI, include trailing padding in the copy.

Link: https://github.com/KSPP/linux/issues/90 [1]
Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
---
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
Cc: Peng Liu <liupeng256@xxxxxxxxxx>
Cc: "Dr. Thomas Orgis" <thomas.orgis@xxxxxxxxxxxxxx>
Cc: Ismael Luceno <ismael@xxxxxxxxxxx>
---
kernel/tsacct.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 4252f0645b9e..16b283f9d831 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -76,7 +76,7 @@ void bacct_add_tsk(struct user_namespace *user_ns,
stats->ac_minflt = tsk->min_flt;
stats->ac_majflt = tsk->maj_flt;

- strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm));
+ strscpy_pad(stats->ac_comm, tsk->comm);
}


--
2.34.1