Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3162455imm; Tue, 29 May 2018 02:06:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrAAilyEDzjl8fqhvhHEi0pB48cgnvHy+5QxJWxFFW8kZ7ccbfLO+y5VAhCVz4ANeBqxBOl X-Received: by 2002:aa7:81cc:: with SMTP id c12-v6mr16739979pfn.169.1527584792193; Tue, 29 May 2018 02:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527584792; cv=none; d=google.com; s=arc-20160816; b=GbTKj3g640Qe1J1XC7VlCRErdxRJpIp4SW38BdBLN52qpmlEb7COhxCepRohhWfiPf lr03ytrvVU3uEaAaHdfpE/Pk1uHjZ+CQLwF9Q4BmrL7lUgJGXFHl5pNpbQFbSkkdphCY 5uMROkYZ/umT3rDg7vY/ejOzAEQMRZ7uQK83xlfc3fXYouEP05OQSM8W8JurkI+q1aza ZQQjgrIz4aITYl3N4grSz6jGhI7Vjw2BecOBy/oPwFtKg4gof30DmkmMgts25Ld5jl9z G2WoeMn9vQvNiYz3d1r0YmlsGXDrB6bYGKItwk0wLVzI6g+y1C5VobeyZ45LcfVE0K1x SIiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=Gss26E/Wn6ZkvQSChImYU9eLKhLQ2Flq59TIyhjpZ/4=; b=vKn4cICQyyAMigY2R7lurA1GgL6+EfPlcIJflLsgmbqw7JIlkmy5TABOUA3ThSBHV2 7NkJ/tTZGrfEOBW50SljHuj3vzX5+P4Svj8ZJrE71ZdLQd9pCOLzeovmr2ZDclGzjAo/ D4YwjWAAONJDB0fuCM8oNYoPwt3dnsFotUPiGHJ2PzNmHq0v8a7IwxUJY7vGidm8M18n QFiUSHmbLxdmWwspUe6J0exIntR1zMXhOvZjllHP6TuZOVv+YdTTeC3BOgd5aefTR2ez Zc3G06E0fKuOeMpC4emqe0rVqRv2FD6nfG2Alp2qQfQGJiYtu/O7E0rvAAZytLZYsA95 0Pmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=G/HgtqpS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x15-v6si26103157pgq.442.2018.05.29.02.06.17; Tue, 29 May 2018 02:06:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=G/HgtqpS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932600AbeE2JFv (ORCPT + 99 others); Tue, 29 May 2018 05:05:51 -0400 Received: from mail-ua0-f196.google.com ([209.85.217.196]:33567 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932288AbeE2JFs (ORCPT ); Tue, 29 May 2018 05:05:48 -0400 Received: by mail-ua0-f196.google.com with SMTP id i2-v6so9475266uah.0 for ; Tue, 29 May 2018 02:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=Gss26E/Wn6ZkvQSChImYU9eLKhLQ2Flq59TIyhjpZ/4=; b=G/HgtqpSiiioJHiPruf6SBsWq1URNCFVZYEf6Yu4lnRNVLdYylazg1mey2uoynNXSj vejxl4lm80Ep9cwbygdlVneQ8hF802Z8eps8q2Vv8RGtHMNqTKKak5267umYAcs+L7OB x6fsAN8Nak5OakHJ/1p1T+BE1xy3zwiYKMnwBBkmAx9CxZW8lYgsX4zJ/EhXszfOLdLs NK2gyDVYVJde8unHKlG4vd7mS73NiLmXQvwRv/HBM3v9qye8mppYQzkXMgqodiB4j+vN XuMsN5Qc41OxZb7GChm310YTdage0rxomZrwLOUhl4ox4kNCJrwQfo5V84X3kWLuwE7k 85PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=Gss26E/Wn6ZkvQSChImYU9eLKhLQ2Flq59TIyhjpZ/4=; b=fKxlhTkvBs6YD8FI+ar8xrBqAEzwQP8aeHJTc4gqM7I+24SP03y1U9nuc/4ZfMIEn2 yqcsmY5d37NofRoOD7Pcmtz/PEjWPBJAvz4/4BXPWZOKBMbwrjd2uiILastzNc8MZtqY 1TN0/IiPzI/4viDvT96p2d2TonZxT8iyj/ZD2tTp9tyz65MEWkmy7B5wGlD0rtRIPKcB lsYf5ehUybMawWSnlnGbFzRX8s4C5UFTNjUUXUWcvYaRHq3d9EhNmOVeheuWKJoit53q nQ0TkRn3wFCBHDcJJZTxRmxei3h6Ba+gJR4dEczhQ6mPrzzMMAWE2gv+11+wfI9WmAO3 7JNQ== X-Gm-Message-State: ALKqPwfnP8Fewh1Ym61hJB0xc8LFyQ9gU7SMCmeIp8B4/kscFT2HvFby nJyx1CHs5tGfSAx+LU/OxtVWYidjrM1fBEMUJkc= X-Received: by 2002:ab0:96:: with SMTP id 22-v6mr7093887uaj.4.1527584747822; Tue, 29 May 2018 02:05:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:7a0a:0:0:0:0:0 with HTTP; Tue, 29 May 2018 02:05:47 -0700 (PDT) In-Reply-To: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> References: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> From: Geert Uytterhoeven Date: Tue, 29 May 2018 11:05:47 +0200 X-Google-Sender-Auth: gbmV-9g6R5xjBsuVlzQ9mAWA7Vg Message-ID: Subject: Re: [PATCH v2] powerpc/64: Fix build failure with GCC 8.1 To: Christophe LEROY Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Linux Kernel Mailing List , linuxppc-dev , Geoff Levand Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, On Tue, May 29, 2018 at 10:56 AM, Christophe LEROY wrote: > Le 29/05/2018 =C3=A0 09:47, Geert Uytterhoeven a =C3=A9crit : >> On Tue, May 29, 2018 at 8:03 AM, Christophe Leroy >> 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=3Dstringop-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 s= ame >>> length [-Werror=3Dstringop-truncation] >>> strncpy((char *)&n, text, 8); >>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> >>> Signed-off-by: Christophe Leroy >> >> >> 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 =3D free_part->index; >>> new_part->header.signature =3D sig; >>> new_part->header.length =3D 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. Using kzalloc() instead of kmalloc() will do. Still, papering around these warnings seems to obscure things, IMHO. And it increases code size, as you had to add a call to strnlen(). >>> new_part->header.checksum =3D nvram_checksum(&new_part->header= ); >>> >>> rc =3D 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 =3D 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. Sorry, I missed that part. Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds