mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe LEROY <christophe.leroy@c-s.fr>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	Geoff Levand <geoff@infradead.org>
Subject: Re: [PATCH v2] powerpc/64: Fix build failure with GCC 8.1
Date: Tue, 29 May 2018 10:56:31 +0200	[thread overview]
Message-ID: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> (raw)
In-Reply-To: <CAMuHMdVSKigQPUQH=BVc2fRSRmuEThLaf+V9ghMPDT9_m1C6BA@mail.gmail.com>



Le 29/05/2018 à 09:47, Geert Uytterhoeven a écrit :
> Hi Christophe,
> 
> CC Geoff
> 
> On Tue, May 29, 2018 at 8:03 AM, Christophe Leroy
> <christophe.leroy@c-s.fr> wrote:
>>    CC      arch/powerpc/kernel/nvram_64.o
>> arch/powerpc/kernel/nvram_64.c: In function 'nvram_create_partition':
>> arch/powerpc/kernel/nvram_64.c:1042:2: error: 'strncpy' specified bound 12 equals destination size [-Werror=stringop-truncation]
>>    strncpy(new_part->header.name, name, 12);
>>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>>    CC      arch/powerpc/kernel/trace/ftrace.o
>> In function 'make_field',
>>      inlined from 'ps3_repository_read_boot_dat_address' at arch/powerpc/platforms/ps3/repository.c:900:9:
>> arch/powerpc/platforms/ps3/repository.c:106:2: error: 'strncpy' output truncated before terminating nul copying 8 bytes from a string of the same length [-Werror=stringop-truncation]
>>    strncpy((char *)&n, text, 8);
>>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> 
> Thanks for your patch!
> 
>> --- a/arch/powerpc/kernel/nvram_64.c
>> +++ b/arch/powerpc/kernel/nvram_64.c
>> @@ -1039,7 +1039,7 @@ loff_t __init nvram_create_partition(const char *name, int sig,
>>          new_part->index = free_part->index;
>>          new_part->header.signature = sig;
>>          new_part->header.length = size;
>> -       strncpy(new_part->header.name, name, 12);
>> +       memcpy(new_part->header.name, name, strnlen(name, sizeof(new_part->header.name)));
> 
> The comment for nvram_header.lgnth says:
> 
>          /* Terminating null required only for names < 12 chars. */
> 
> This will not terminate the string with a zero (the struct is
> allocated with kmalloc).
> So the original code is correct, the new one isn't.

Right, then I have to first zeroize the destination.

> 
>>          new_part->header.checksum = nvram_checksum(&new_part->header);
>>
>>          rc = nvram_write_header(new_part);
>> diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c
>> index 50dbaf24b1ee..e49c887787c4 100644
>> --- a/arch/powerpc/platforms/ps3/repository.c
>> +++ b/arch/powerpc/platforms/ps3/repository.c
>> @@ -101,9 +101,9 @@ static u64 make_first_field(const char *text, u64 index)
>>
>>   static u64 make_field(const char *text, u64 index)
>>   {
>> -       u64 n;
>> +       u64 n = 0;
>>
>> -       strncpy((char *)&n, text, 8);
>> +       memcpy((char *)&n, text, strnlen(text, sizeof(n)));
> 
> This changes behavior: strncpy() fills the remainder of the buffer with
> zeroes.  I don't remember the details of the PS3 repository structure,
> but given this writes to a fixed size u64 buffer, I'd expect the PS3
> hypervisor code to (1) rely on the zero padding, and (2) not need a zero
> terminator if there are 8 characters in the buffer, so probably the
> original code is correct, and the "fixed" code isn't.

Here I have set n to 0 prior to the copy, so the buffer IS zero padded.

Christophe

> 
> Has this been tested on a PS3?
> 
>>          return n + index;
>>   }
> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

  reply	other threads:[~2018-05-29  8:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29  6:03 Christophe Leroy
2018-05-29  7:47 ` Geert Uytterhoeven
2018-05-29  8:56   ` Christophe LEROY [this message]
2018-05-29  9:05     ` Geert Uytterhoeven
2018-05-29  9:37       ` Christophe LEROY
2018-05-29 15:24         ` David Laight
2018-05-31  5:54         ` Michael Ellerman
2018-05-31  5:57           ` Christophe LEROY
2018-05-31 11:17             ` Michael Ellerman
2018-06-04 14:11 ` [v2] " Michael Ellerman

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=1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr \
    --to=christophe.leroy@c-s.fr \
    --cc=benh@kernel.crashing.org \
    --cc=geert@linux-m68k.org \
    --cc=geoff@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.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

all inboxes | Powered by JetHome®