Doc, scripts: facilitate phaseout of strlcat
Subsystems (6)
v2 cover Doc, scripts: facilitate phaseout of strlcat
Thanks for all the feedback. I tried to incorporate it in this version.
The goal of this series is to facilitate the transition away from strlcat()
[v2]
add recipants
add remarks to strlcat definition in
lib/string.c
tools/include/nolibc/string.h
-> [3/3]
PATCH v2 1/3 Doc: deprecated.rst: add strlcat()
add strlcat and alternatives
--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/process/deprecated.rst +7 -0
@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. + strlcpy() --------- strlcpy() reads the entire source buffer first (since the return value
Signature · 1 line
2.54.0
Kees Cook
maintainerRe: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
Quoted 12 lines · Manuel Ebner
add strlcat and alternatives
Signed-off-by Manuel Ebner <[email protected]>--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/process/deprecated.rst +0
-0
Documentation/process/deprecated.rst used, and the destinations should be marked with the `__nonstring · line 162
Quoted 10 lines
Documentation/process/deprecated.rst +7
-0@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. +
How about just:
strlcat() must re-scan the destination string from the beginning on each call (O(n^2) behavior). Use the seq_buf API or similar instead.
Quoted 6 lines
Documentation/process/deprecated.rst +0
-0strlcpy() --------- strlcpy() reads the entire source buffer first (since the return valueSignature · 1 line
2.54.0
Signature · 1 line
Kees Cook
Randy Dunlap
reviewerRe: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
Quoted 26 lines · Kees Cook
Quoted 12 lines · Manuel Ebner
add strlcat and alternatives
Signed-off-by Manuel Ebner <[email protected]>--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/process/deprecated.rst +0
-0Documentation/process/deprecated.rst used, and the destinations should be marked with the `__nonstring · line 162
Quoted 10 lines
Documentation/process/deprecated.rst +7
-0@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. +How about just:
Quoted 3 lines
strlcat()must re-scan the destination string from the beginning on each call (O(n^2) behavior). Use theseq_bufAPI or similar instead.
Yeah, that avoids the "aswell" (should be "as well").
Quoted 8 lines
Quoted 7 lines
Documentation/process/deprecated.rst +0
-0strlcpy() --------- strlcpy() reads the entire source buffer first (since the return valueSignature · 1 line
2.54.0
Signature · 1 line
~Randy
Re: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
In reply to Kees CookQuoted 26 lines · Kees Cook
Quoted 12 lines · Manuel Ebner
add strlcat and alternatives
Signed-off-by Manuel Ebner <[email protected]>--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/process/deprecated.rst +0
-0Documentation/process/deprecated.rst used, and the destinations should be marked with the `__nonstring · line 162
Quoted 10 lines
Documentation/process/deprecated.rst +7
-0@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. +How about just:
Quoted 2 lines
strlcat()must re-scan the destination string from the beginning on each call (O(n^2) behavior). Use theseq_bufAPI or similar instead.
seq_buf API for appending something to e.g. boot_command_line seems to be odd, since boot_command_line is usually "just there" (depending on architecture and boot loader).
So if I would remove strlcat() from appending something to boot_command_line I would end up open-coding strlcat(), including the chance for the usual off-by-one bugs. Looks like this would be true for nearly all architectures.
Is performance really the only reason to deprecate strlcat()? This seems to be a bit questionable to me.
Re: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
Quoted 27 lines · On Sat, 16 May 2026 17:28:19 +0200 Heiko Carstens <[email protected]> wrote:
Quoted 26 lines · Kees Cook
Quoted 12 lines · Manuel Ebner
add strlcat and alternatives
Signed-off-by Manuel Ebner <[email protected]>--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/process/deprecated.rst +0
-0Documentation/process/deprecated.rst used, and the destinations should be marked with the `__nonstring · line 162
Quoted 10 lines
Documentation/process/deprecated.rst +7
-0@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. +How about just:
Quoted 6 lines
Quoted 2 lines
strlcat()must re-scan the destination string from the beginning on each call (O(n^2) behavior). Use theseq_bufAPI or similar instead.
seq_bufAPI for appending something to e.g.boot_command_lineseems to be odd, sinceboot_command_lineis usually "just there" (depending on architecture and boot loader).
Indeed, but ISTR that code uses strcat() a lot of the time. The lengths are all known, so memcpy() can be used.
I don't really see why strlcat() should be deprecated.
Clearly there are many cases where there are better ways to do things.
The only problem with strlcat() is that it returns the 'required length'.
So there are some broken uses.
- fs/nfs/flexfilelayout/flexfilelayout.c
- lib/kunit/string-stream.c (although the preceding vsnprintf() looks like the actual bug). There is also some very strange code in security/selinus/ima.c - but it may be ok.
In reality the return value of strlcat() isn't really much worse that that of snprintf().
-- David
Quoted 7 lines
So if I would remove
strlcat()from appending something toboot_command_lineI would end up open-codingstrlcat(), including the chance for the usual off-by-one bugs. Looks like this would be true for nearly all architectures.Is performance really the only reason to deprecate
strlcat()? This seems to be a bit questionable to me.
Re: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
Hi David,
Quoted 37 lines · David Laight
Quoted 27 lines · On Sat, 16 May 2026 17:28:19 +0200 Heiko Carstens <[email protected]> wrote:
Quoted 26 lines · Kees Cook
Quoted 12 lines · Manuel Ebner
add strlcat and alternatives
Signed-off-by Manuel Ebner <[email protected]>--- Documentation/process/deprecated.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/process/deprecated.rst +0
-0Documentation/process/deprecated.rst used, and the destinations should be marked with the `__nonstring · line 162
Quoted 10 lines
Documentation/process/deprecated.rst +7
-0@@ -153,6 +153,13 @@ used, and the destinations should be marked with the `__nonstring attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used. +strlcat() +--------- +strlcat() must re-scan the destination string from the beginning on each +call (O(n^2) behavior). Alternatives are seq_buf_puts() and seq_buf_printf(). +snprintf(), scnprintf() and sysfs_emit() are possible aswell, but the adoption +of the arguments needs to be taken care off. +How about just:
Quoted 6 lines
Quoted 2 lines
strlcat()must re-scan the destination string from the beginning on each call (O(n^2) behavior). Use theseq_bufAPI or similar instead.
seq_bufAPI for appending something to e.g.boot_command_lineseems to be odd, sinceboot_command_lineis usually "just there" (depending on architecture and boot loader).
Quoted 5 lines
Indeed, but ISTR that code uses
strcat()a lot of the time. The lengths are all known, somemcpy()can be used.I don't really see why
strlcat()should be deprecated. Clearly there are many cases where there are better ways to do things.
https://elixir.bootlin.com/linux/v7.0.8/source/include/linux/fortify-string.h#L346
already says "Do not use this function. [...] Prefer building the
* string with formatting, via scnprintf(), seq_buf, or similar.".
Quoted 8 lines
The only problem with
strlcat()is that it returns the 'required length'.
So there are some broken uses.
-fs/nfs/flexfilelayout/flexfilelayout.c
-lib/kunit/string-stream.c(although the precedingvsnprintf()looks like the actual bug). There is also some very strange code insecurity/selinus/ima.c- but it may be ok.In reality the return value of
strlcat()isn't really much worse that that ofsnprintf().
So we need strscat()? ;-)
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v2 1/3] Doc: deprecated.rst: add strlcat()
Quoted 1 line · On Mon, 18 May 2026 09:11:04 +0200 Geert Uytterhoeven <[email protected]>…
Hi David,
...
Quoted 6 lines
Quoted 2 lines
I don't really see why
strlcat()should be deprecated. Clearly there are many cases where there are better ways to do things.https://elixir.bootlin.com/linux/v7.0.8/source/include/linux/fortify-string.h#L346
already says "Do not use this function. [...] Prefer building the
* string with formatting, viascnprintf(),seq_buf, or similar.".
Trouble is that all requires a lot more rework.
I might try changing the type of the 'buffer' to sysfs_emit() from 'char *' to 'sysfs_buf *'.
Initially the types will have to be the same, but propagating it through will show where it can be used.
But last I looked I failed to even find the associated kmalloc(). Eventually it could be changed to a different type.
Quoted 10 lines
Quoted 8 lines
The only problem with
strlcat()is that it returns the 'required length'.
So there are some broken uses.
-fs/nfs/flexfilelayout/flexfilelayout.c
-lib/kunit/string-stream.c(although the precedingvsnprintf()looks like the actual bug). There is also some very strange code insecurity/selinus/ima.c- but it may be ok.In reality the return value of
strlcat()isn't really much worse that that ofsnprintf().So we need
strscat()? ;-)
Indeed...
-- David
Quoted 5 lines
Gr{oetje,eeting}s,
Geert
PATCH v2 2/3 scripts: checkpatch.pl: add warning for strlcat()
In reply to Manuel Ebneradd a warning for strlcat()
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
@@ -7085,6 +7085,12 @@ sub process { "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr); } +# strlcat uses that should be a more supported function + if ($line =~ /\bstrlcat\s*\(/ && !is_userspace($realfile)) { + WARN("STRLCAT", + "Prefer a more supported function over strlcat - see: https://github.com/KSPP/linux/issues/370\n" . $herecurr); + } + # strncpy uses that should likely be strscpy or strscpy_pad if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) { WARN("STRNCPY",
Signature · 1 line
2.54.0
Re: [PATCH v2 2/3] scripts: checkpatch.pl: add warning for strlcat()
Quoted 3 lines · Manuel Ebner
add a warning for
strlcat()Signed-off-by Manuel Ebner <[email protected]>
Signature · 1 line
Kees Cook
PATCH v2 3/3 drivers: add deprecated remarks to strlcat()
In reply to Manuel Ebneradd kernel-doc comment to strlcat() function definitions
--- lib/string.c | 11 +++++++++++ tools/include/nolibc/string.h | 11 +++++++++++ 2 files changed, 22 insertions(+)
lib/string.c +11 -0
@@ -249,6 +249,17 @@ EXPORT_SYMBOL(strncat);#endif #ifndef __HAVE_ARCH_STRLCAT +/** +* strlcat - Append a string to an existing string +* +* @dest: pointer to %NUL-terminated string to append to +* @src: pointer to %NUL-terminated string to append from +* @count: Maximum bytes available in @dest +* +* Do not use this function. Prefer building the string with +* formatting, via scnprintf(), seq_buf, or similar. +* +*/ size_t strlcat (char *dest,const char *src,size_t count) {size_t dsize =strlen (dest);
tools/include/nolibc/string.h +11 -0
@@ -208,6 +208,17 @@ char *strndup(const char *str, size_t maxlen) }static __attribute__((unused)) +/** +* strlcat - Append a string to an existing string +* +* @dst: pointer to %NUL-terminated string to append to +* @src: pointer to %NUL-terminated string to append from +* @size: Maximum bytes available in @dst +* +* Do not use this function. Prefer building the string with +* formatting, via scnprintf(), seq_buf, or similar. +* +*/ size_t strlcat (char *dst,const char *src,size_t size) {size_t len =strnlen (dst, size);
Signature · 1 line
2.54.0
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
Quoted 2 lines · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions
Add
definitions.
...
tools/include/nolibc/string.h
Quoted 2 lines
tools/include/nolibc/string.h +0
-0
I probably missed a discussion, but nolibc is not a kernel binary, they can choose themselves what to use, no?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
In reply to Manuel EbnerHi Manuel,
Quoted 3 lines · Manuel Ebner
add kernel-doc comment to
strlcat()function definitionsSigned-off-by Manuel Ebner <[email protected]>
Thanks for your patch!
lib/string.c EXPORT_SYMBOL(strncat); · line 258
Quoted 13 lines
lib/string.c +7
-0@@ -249,6 +249,17 @@ EXPORT_SYMBOL(strncat);#endif #ifndef __HAVE_ARCH_STRLCAT +/** +* strlcat - Append a string to an existing string +* +* @dest: pointer to %NUL-terminated string to append to +* @src: pointer to %NUL-terminated string to append from +* @count: Maximum bytes available in @dest +*
Missing "Returns ...".
lib/string.c EXPORT_SYMBOL(strncat); · line 265
Quoted 7 lines
lib/string.c +4
-0+* Do not use this function. Prefer building the string with +* formatting, via scnprintf(), seq_buf, or similar. +* +*/ size_t strlcat (char *dest,const char *src,size_t count) {size_t dsize =strlen (dest);
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
Quoted 2 lines · Geert Uytterhoeven
Quoted 1 line · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions
...
Quoted 9 lines
Quoted 7 lines
+/**
+ * strlcat - Append a string to an existing string
+ *
+ * @dest: pointer to %NUL-terminated string to append to
+ * @src: pointer to %NUL-terminated string to append from
+ * @count: Maximum bytes available in @dest
+ *Missing "Returns ...".
Documentation says "Return:" as
- the section (note important colon)
- the singular (however plural is undocumented and supported)
Quoted 4 lines
Quoted 4 lines
+ * Do not use this function. Prefer building the string with
+ * formatting, viascnprintf(),seq_buf, or similar.
+ *
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven
Quoted 1 line · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions
...
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
+/**
+ * strlcat - Append a string to an existing string
+ *
+ * @dest: pointer to %NUL-terminated string to append to
+ * @src: pointer to %NUL-terminated string to append from
+ * @count: Maximum bytes available in @dest
+ *Missing "Returns ...".
Documentation says "Return:" as
I mean the kernel-doc documentation. Here the section is missed and needs to be added, indeed.
Quoted 7 lines
- the section (note important colon)
- the singular (however plural is undocumented and supported)Quoted 4 lines
Quoted 4 lines
+ * Do not use this function. Prefer building the string with
+ * formatting, viascnprintf(),seq_buf, or similar.
+ *
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
In reply to Andy ShevchenkoHi Andy,
Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven
Quoted 1 line · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions...
Quoted 8 lines
Quoted 7 lines
+/**
+ * strlcat - Append a string to an existing string
+ *
+ * @dest: pointer to %NUL-terminated string to append to
+ * @src: pointer to %NUL-terminated string to append from
+ * @count: Maximum bytes available in @dest
+ *
Quoted 5 lines
Quoted 1 line
Missing "Returns ...".
Documentation says "Return:" as
- the section (note important colon)
- the singular (however plural is undocumented and supported)
Trailing "s" is not always plural in English ;-)
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
Quoted 18 lines · On Fri, 15 May 2026 09:32:06 +0200 Geert Uytterhoeven <[email protected]>…
Hi Andy,
Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven
Quoted 1 line · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions...
Quoted 8 lines
Quoted 7 lines
+/**
+ * strlcat - Append a string to an existing string
+ *
+ * @dest: pointer to %NUL-terminated string to append to
+ * @src: pointer to %NUL-terminated string to append from
+ * @count: Maximum bytes available in @dest
+ *
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Missing "Returns ...".
Documentation says "Return:" as
- the section (note important colon)
- the singular (however plural is undocumented and supported)Trailing "s" is not always plural in English ;-)
It is for 'Return' :-)
Most of the exceptions are words taken directly from Latin, where something that might be a Latin plural is used (who knows what the Romans actually used).
It many cases the 's' plural is also valid.
-- David
Quoted 5 lines
Gr{oetje,eeting}s,
Geert
Re: [PATCH v2 3/3] drivers: add deprecated remarks to strlcat()
Hi David,
Quoted 20 lines · David Laight
Quoted 18 lines · On Fri, 15 May 2026 09:32:06 +0200 Geert Uytterhoeven <[email protected]>…
Quoted 17 lines · Andy Shevchenko
Quoted 2 lines · Geert Uytterhoeven
Quoted 1 line · Manuel Ebner
add kernel-doc comment to
strlcat()function definitions...
Quoted 9 lines
Quoted 7 lines
+/**
+ * strlcat - Append a string to an existing string
+ *
+ * @dest: pointer to %NUL-terminated string to append to
+ * @src: pointer to %NUL-terminated string to append from
+ * @count: Maximum bytes available in @dest
+ *Missing "Returns ...".
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Documentation says "Return:" as
- the section (note important colon)
- the singular (however plural is undocumented and supported)Trailing "s" is not always plural in English ;-)
It is for 'Return' :-)
In case "returns" is a shorthand for "return values", it indeed is ;-) I meant a conjugation of the verb "to return".
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hello
i'll ditch this series - it's just not the time yet.
Manuel
Quoted 11 lines · Manuel Ebner
Thanks for all the feedback. I tried to incorporate it in this version.
The goal of this series is to facilitate the transition away from
strlcat()[v2]
add recipants
add remarks to strlcat definition in
lib/string.c
tools/include/nolibc/string.h
-> [3/3]