The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: Geoff Levand <geoff@infradead.org>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Justin Stitt <justinstitt@google.com>,
	Kees Cook <kees@kernel.org>,
	stable@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/ps3: Fix repository.c build failure
Date: Sun, 2 Aug 2026 00:06:50 +0200	[thread overview]
Message-ID: <am5t-ixyIp1IwdV5@linux.dev> (raw)
In-Reply-To: <6be33030-781f-4480-8ccd-81c5b1df220a@kernel.org>

On Fri, Jul 31, 2026 at 09:34:28AM +0200, Christophe Leroy (CS GROUP) wrote:
> Le 03/07/2026 à 18:58, Thorsten Blum a écrit :
> > GCC fails to build ps3_defconfig with the following errors:
> > 
> >    arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
> >    arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]
> >       78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
> >          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
> >    arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
> >       78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
> >          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread
> > when text is a short string literal that is smaller than sizeof(n), such
> > as "bi" or "bus". Use strlen(text) instead and clamp the copy length to
> > sizeof(n) before memcpy().
> > 
> > Drop the redundant char * cast while at it.
> > 
> > Fixes: f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> >   arch/powerpc/platforms/ps3/repository.c | 5 ++++-
> >   1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c
> > index b8c030eab138..0cc755ac3e7f 100644
> > --- a/arch/powerpc/platforms/ps3/repository.c
> > +++ b/arch/powerpc/platforms/ps3/repository.c
> > @@ -6,6 +6,8 @@
> >    *  Copyright 2006 Sony Corp.
> >    */
> > +#include <linux/minmax.h>
> > +
> >   #include <asm/lv1call.h>
> >   #include "platform.h"
> > @@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
> >   static u64 make_first_field(const char *text, u64 index)
> >   {
> >   	u64 n = 0;
> > +	size_t len = min(strlen(text), sizeof(n));
> > -	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
> > +	memcpy(&n, text, len);
> >   	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
> >   }
> 
> Maybe change to u32 and remove the n >> 32.
> 
> Shouldn't the same fix be done in make_field() ?

make_field() has two callers where the compiler can't infer the size
of the string at compile time, so it doesn't produce this error.

make_first_field() is called only with constant strings, which lets the
compiler infer that all string lengths are less than 8 bytes.

      reply	other threads:[~2026-08-01 22:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 16:58 [PATCH] powerpc/ps3: Fix repository.c build failure Thorsten Blum
2026-07-29 16:56 ` Thorsten Blum
2026-07-30 14:28   ` Thorsten Blum
2026-07-31  7:34 ` Christophe Leroy (CS GROUP)
2026-08-01 22:06   ` Thorsten Blum [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=am5t-ixyIp1IwdV5@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=chleroy@kernel.org \
    --cc=geoff@infradead.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=stable@vger.kernel.org \
    /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