Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] NFS: nfsroot: replace strlcat() with snprintf()
@ 2026-08-14  7:28 Mariia Nikitash
  2026-08-17 20:33 ` Justin Stitt
  2026-08-18  8:55 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: Mariia Nikitash @ 2026-08-14  7:28 UTC (permalink / raw)
  To: trondmy, anna
  Cc: keescook, justinstitt, linux-hardening, linux-nfs, linux-kernel,
	nikitash.mariiaw, Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace its
uses in root_nfs_cat() with snprintf().

Build the separator and source string in a single call using the
remaining space in the destination buffer. snprintf() returns the length
it would have written excluding the terminating NUL, so comparing the
return value against the remaining buffer space preserves the existing
truncation check.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Mariia Nikitash <mariianikitash@google.com>
---
 fs/nfs/nfsroot.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index 432612d22437..e951fe731679 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -173,12 +173,12 @@ static int __init root_nfs_cat(char *dest, const char *src,
 			       const size_t destlen)
 {
 	size_t len = strlen(dest);
+	size_t remaining = destlen - len;
+	const char *sep = "";
 
 	if (len && dest[len - 1] != ',')
-		if (strlcat(dest, ",", destlen) >= destlen)
-			return -1;
-
-	if (strlcat(dest, src, destlen) >= destlen)
+		sep = ",";
+	if (snprintf(dest + len, remaining, "%s%s", sep, src) >= remaining)
 		return -1;
 	return 0;
 }
-- 
2.55.0.679.g6767b8d81c-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-18  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14  7:28 [PATCH] NFS: nfsroot: replace strlcat() with snprintf() Mariia Nikitash
2026-08-17 20:33 ` Justin Stitt
2026-08-17 20:51   ` Bill Wendling
2026-08-18  8:55 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox