mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Finn Thain <fthain@linux-m68k.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	 Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>,
	 linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org,
	 Kees Cook <kees@kernel.org>
Subject: Re: [PATCH] m68k: mm: Remove size argument when calling strscpy()
Date: Fri, 7 Mar 2025 19:58:39 +1100 (AEDT)	[thread overview]
Message-ID: <dd1425d0-6d46-86a7-b508-ff0a646d61c0@linux-m68k.org> (raw)
In-Reply-To: <CAMuHMdWjOkUXy+jf0yghs2_SQM3UWY3e8or3T11=fXYYD-VJEw@mail.gmail.com>


On Fri, 7 Mar 2025, Geert Uytterhoeven wrote:

> On Fri, 7 Mar 2025 at 00:24, Finn Thain <fthain@linux-m68k.org> wrote:
> > On Thu, 6 Mar 2025, Geert Uytterhoeven wrote:
> > > On Mon, 3 Mar 2025 at 00:07, Thorsten Blum <thorsten.blum@linux.dev> wrote:
> > > > The size parameter of strscpy() is optional and specifying the 
> > > > size of the destination buffer is unnecessary. Remove it to 
> > > > simplify the code.
> > > >
> > > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > >
> > > Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> i.e. will 
> > > queue in the m68k tree for v6.15.
> >
> > The commit message says "simplify the code" which is only true if you 
> > never scratch the surface (i.e. it's simple code if the reader is 
> > simple too...)
> 
> The code is simpler in the sense that the API is simpler to use, and 
> harder to abuse (i.e. to get it wrong).
> 
> > Commit 30035e45753b ("string: provide strscpy()") was a good idea. It 
> > was easily auditable. But that's not what we have now.
> >
> > Patches like this one (which appear across the whole tree) need 
> > reviewers (lots of them) that know what kind of a bounds check you end 
> > up with when you ask an arbitary compiler to evaluate this:
> >
> > sizeof(dst) + __must_be_array(dst) + __must_be_cstr(dst) + 
> > __must_be_cstr(src)
> >
> > Frankly, I can't be sure. But it's a serious question, and not what 
> > I'd call a "simple" one.
> 
> All the __must_be_*() macros evaluate to zero when true, and cause a 
> build failure when false.
> 

It seems to me that the code review problem could be solved either by not 
churning the whole tree, or if we must have the churn, by short-circuiting 
the recursive search by reviewers for macro definitions.

Can we do something like this?

sizeof(dst) * !!__must_be_array(dst) * !!__must_be_cstr(dst) * !!__must_be_cstr(src)

At first glance multiplication appears to be safe (unlike all the addition 
terms that we have) because the limit of the string copy is either 
unchanged or zeroed.

Yes, I know you said "zero when true". That looks like another design flaw 
to me. But maybe I'm missing something that's more important than 
readability and ease of review.

> BTW, Linux does not support being built by an "arbitrary compiler": only 
> gcc and clang are supported.
> 

So only gcc and clang must agree about all of the details...

  reply	other threads:[~2025-03-07  8:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-02 23:05 Thorsten Blum
2025-03-06 17:41 ` Jean-Michel Hautbois
2025-03-06 17:44 ` Geert Uytterhoeven
2025-03-06 23:24   ` Finn Thain
2025-03-07  8:28     ` Geert Uytterhoeven
2025-03-07  8:58       ` Finn Thain [this message]
2025-03-07  9:28         ` Geert Uytterhoeven
2025-03-07  9:15     ` Thorsten Blum
2025-03-07  9:59       ` Finn Thain

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=dd1425d0-6d46-86a7-b508-ff0a646d61c0@linux-m68k.org \
    --to=fthain@linux-m68k.org \
    --cc=geert@linux-m68k.org \
    --cc=jeanmichel.hautbois@yoseli.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=thorsten.blum@linux.dev \
    /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

all inboxes | Powered by JetHome®