Linux Sound subsystem development
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>,
	Mahad Ibrahim <mahad.ibrahim.dev@gmail.com>,
	Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/7] ALSA: remove remaining strlcat() users under sound/
Date: Sat, 8 Aug 2026 14:04:01 +0100	[thread overview]
Message-ID: <20260808140401.485a84de@pumpkin> (raw)
In-Reply-To: <202608071442.37E40CEFC@keescook>

On Fri, 7 Aug 2026 14:46:44 -0700
Kees Cook <kees@kernel.org> wrote:

> On Fri, Aug 07, 2026 at 06:03:58PM +0200, Takashi Iwai wrote:
> > If strlcat() were super-dangerous, it's understandable to drop.  But,
> > it's not, and issues discussed in the github are minor and something
> > that can be addressed in strlcat() implementation; that is, can't we
> > rather re-implement strlcat() in a safer way, instead of killing it?
> > 
> > Sure, there are code calling strlcat() that could be optimized better.
> > They can be cleaned up.  But it alone can't be a reason that strlcat()
> > must die without mercy.  
> 
> The risk comes from the compiler having no way to know what the size of
> the destination buffer is, as the "char *" argument has no length
> associated with it. One thing we can do is change the argument
> requirements for strlcat (like we did when designing memtostr, etc),
> that requires that the argument explicitly be an array (not a string
> pointer), at which point bounds checking can be done.
> 
> Usually this requires changing the plumbing of arguments, as a lot of C
> code is used to just passing around a bare "char *", etc. And if that
> re-plumbing is going to happen, it might as well be seq_buf.
> 
> But yes, just replacing it with strlen/strscpy isn't very ergonomic.
> Adding the length explicitly with strscpy certainly gets us the bounds
> again, but it's _separate_ from the string still, and that will lead to
> mistakes too. Better to have it be part of the type (i.e. either an
> array or seq_buf).

And, if the destination is an array (where the compiler knows the size)
there is nothing wrong with a 2 argument function.

Like strscpy() you want any result to be the new length of the destination
string.

Embedding a fixed length char[] in a struct can be a simple better option
and lets the compiler do a lot of the checks for you.

	David

> 
> -Kees
> 


      reply	other threads:[~2026-08-08 13:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 11:41 [PATCH 0/7] ALSA: remove remaining strlcat() users under sound/ Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 1/7] ALSA: ump: replace strlcat() with strscpy() Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 2/7] ALSA: ac97: replace strlcat() with scnprintf() Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 3/7] ALSA: cmipci: replace strlcat() with strscpy() Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 4/7] ALSA: caiaq: " Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 5/7] ALSA: usb-audio: replace strlcat() with append_ctl_name() Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 6/7] ALSA: hiface: replace strlcat() with scnprintf() Mahad Ibrahim
2026-08-07 11:41 ` [PATCH 7/7] ALSA: usb-audio: replace strlcat() in longname construction Mahad Ibrahim
2026-08-07 12:15 ` [PATCH 0/7] ALSA: remove remaining strlcat() users under sound/ Takashi Iwai
2026-08-07 13:04   ` David Laight
2026-08-07 15:41   ` Mahad Ibrahim
2026-08-07 16:03     ` Takashi Iwai
2026-08-07 21:46       ` Kees Cook
2026-08-08 13:04         ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260808140401.485a84de@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mahad.ibrahim.dev@gmail.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox