public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] string: use strnlen in strlcat
@ 2026-04-30 20:50 Thorsten Blum
  2026-05-01  8:55 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2026-04-30 20:50 UTC (permalink / raw)
  To: Andrew Morton, Kees Cook, Andy Shevchenko
  Cc: Thorsten Blum, linux-kernel, linux-hardening

Use strnlen() to limit the destination scan to the provided buffer size.
Remove the redundant comment.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 lib/string.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index b632c71df1a5..7b67e186d898 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -251,12 +251,11 @@ EXPORT_SYMBOL(strncat);
 #ifndef __HAVE_ARCH_STRLCAT
 size_t strlcat(char *dest, const char *src, size_t count)
 {
-	size_t dsize = strlen(dest);
+	size_t dsize = strnlen(dest, count);
 	size_t len = strlen(src);
 	size_t res = dsize + len;
 
-	/* This would be a bug */
-	BUG_ON(dsize >= count);
+	BUG_ON(dsize == count);
 
 	dest += dsize;
 	count -= dsize;

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

* Re: [PATCH] string: use strnlen in strlcat
  2026-04-30 20:50 [PATCH] string: use strnlen in strlcat Thorsten Blum
@ 2026-05-01  8:55 ` Andy Shevchenko
  2026-05-02  8:37   ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-05-01  8:55 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Andrew Morton, Kees Cook, Andy Shevchenko, linux-kernel,
	linux-hardening

On Thu, Apr 30, 2026 at 11:53 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Use strnlen() to limit the destination scan to the provided buffer size.
> Remove the redundant comment.

Please, do not spend time on amending strlcat(). This function must
die. Instead, convert current users to use alternative ways.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] string: use strnlen in strlcat
  2026-05-01  8:55 ` Andy Shevchenko
@ 2026-05-02  8:37   ` Andy Shevchenko
  2026-05-04 12:26     ` Manuel Ebner
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-05-02  8:37 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thorsten Blum, Andrew Morton, Kees Cook, Andy Shevchenko,
	linux-kernel, linux-hardening

On Fri, May 01, 2026 at 11:55:33AM +0300, Andy Shevchenko wrote:
> On Thu, Apr 30, 2026 at 11:53 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
> >
> > Use strnlen() to limit the destination scan to the provided buffer size.
> > Remove the redundant comment.
> 
> Please, do not spend time on amending strlcat(). This function must
> die. Instead, convert current users to use alternative ways.

Note, there is a patch by Kees to address this in partitions framework
(vast of the users of strlcat() in the kernel). Not sure if it's already
pending in Linux Next or not yet.

I have done a simple one in ACPI recently (in upstream already I believe).
So, you can use those two examples and continue killing strlcat().

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] string: use strnlen in strlcat
  2026-05-02  8:37   ` Andy Shevchenko
@ 2026-05-04 12:26     ` Manuel Ebner
  2026-05-04 12:52       ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel Ebner @ 2026-05-04 12:26 UTC (permalink / raw)
  To: Andy Shevchenko, Andy Shevchenko
  Cc: Thorsten Blum, Andrew Morton, Kees Cook, Andy Shevchenko,
	linux-kernel, linux-hardening

On Sat, 2026-05-02 at 11:37 +0300, Andy Shevchenko wrote:
> On Fri, May 01, 2026 at 11:55:33AM +0300, Andy Shevchenko wrote:
> > On Thu, Apr 30, 2026 at 11:53 PM Thorsten Blum <thorsten.blum@linux.dev>
> > wrote:
> > > 
> > > Use strnlen() to limit the destination scan to the provided buffer size.
> > > Remove the redundant comment.
> > 
> > Please, do not spend time on amending strlcat(). This function must
> > die. Instead, convert current users to use alternative ways.
> 
> Note, there is a patch by Kees to address this in partitions framework
> (vast of the users of strlcat() in the kernel). Not sure if it's already
> pending in Linux Next or not yet.
> 
> I have done a simple one in ACPI recently (in upstream already I believe).
> So, you can use those two examples and continue killing strlcat().

Hi,
i would like to add this to the file Documentation/process/deprecated.rst.
Does right after strlcpy() make sense?

Could you point me to the examples?

Thanks
 Manuel

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

* Re: [PATCH] string: use strnlen in strlcat
  2026-05-04 12:26     ` Manuel Ebner
@ 2026-05-04 12:52       ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-05-04 12:52 UTC (permalink / raw)
  To: Manuel Ebner
  Cc: Andy Shevchenko, Thorsten Blum, Andrew Morton, Kees Cook,
	Andy Shevchenko, linux-kernel, linux-hardening

On Mon, May 4, 2026 at 3:26 PM Manuel Ebner <manuelebner@mailbox.org> wrote:
> On Sat, 2026-05-02 at 11:37 +0300, Andy Shevchenko wrote:
> > On Fri, May 01, 2026 at 11:55:33AM +0300, Andy Shevchenko wrote:
> > > On Thu, Apr 30, 2026 at 11:53 PM Thorsten Blum <thorsten.blum@linux.dev>
> > > wrote:

> > > Please, do not spend time on amending strlcat(). This function must
> > > die. Instead, convert current users to use alternative ways.
> >
> > Note, there is a patch by Kees to address this in partitions framework
> > (vast of the users of strlcat() in the kernel). Not sure if it's already
> > pending in Linux Next or not yet.
> >
> > I have done a simple one in ACPI recently (in upstream already I believe).
> > So, you can use those two examples and continue killing strlcat().
>
> i would like to add this to the file Documentation/process/deprecated.rst.
> Does right after strlcpy() make sense?

Yes, please.

> Could you point me to the examples?

c2d466b9fe19 ("block: partitions: Replace pp_buf with struct seq_buf")
36cb728754ea ("ACPI: processor: idle: Replace strlcat() with better
alternative")


-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2026-05-04 12:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 20:50 [PATCH] string: use strnlen in strlcat Thorsten Blum
2026-05-01  8:55 ` Andy Shevchenko
2026-05-02  8:37   ` Andy Shevchenko
2026-05-04 12:26     ` Manuel Ebner
2026-05-04 12:52       ` Andy Shevchenko

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