Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3106908imm; Tue, 29 May 2018 00:48:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqfDj0C0nYrAMFWrAUl4gS67X3e4iQ3ks/lWmteh/ow8TTawadL0yBYnp8aazzzsyZfxCaP X-Received: by 2002:a17:902:988b:: with SMTP id s11-v6mr16520096plp.304.1527580103556; Tue, 29 May 2018 00:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527580103; cv=none; d=google.com; s=arc-20160816; b=fyy9EhFew7HLzOQQ2mEbhHvopaRelM7iiEAimkkc0TH6iGez0rnQuvQziAaAEnApEt OJ6QCY0QN8mOiLvxAwvSyWgNZzfSWtvlsAtPoFmSwNwpAfr6awgdJ+0SNbdIhy3h1L97 WHuPUz3vheRnCgrMsVxSP9PIUMpFrmIray2B7WfpcmVtyD7iuHtctdUt7BYBFKm5ZJE/ MCf/ps1MgjiC01TtsAPow8ecJWlUZ36Jz51dwU0jOgGuM4JjC1HbEdHqjLA0EPAaCBna 0Pz7HRMqU5pK/7tyF1Yd0+Pefg6sWo58sVCBKJLM0scp3nEdOJDO5Pvr95E1NaVn6k+A A9LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=lEPr9c05eKVZXnjB/qB7nAMgpkzv/brhjhX5H8zBog8=; b=vxRsEPJ0eI9XPJ2HLLd/XUHBq86qD/SuGFHdriyEOxxMBZgDfCb3ylE1lh1V1Ag2IG puglzogBYnPJQRJl7u47pHOYfYpv5GLHeZLsqNsPA8Tn82ofaySd2odNDCMYi14ynrMX Mye31kJ23vva8NQ0PEwDybu7BG7VYAEJ/rXMyqLiAd/+yY3HplUmxCk+EI15g0Lo9i4/ EYD+00M3mFG+PO/ssjdBa3rsYcQKkwllR8wuOJgt0VHWfIwdsGxS0kFNtwaI29lyiyJu cWBS9jVguS41ZkqgUTNRsf7kZzHRxAyClxWWqUdtdcx/YpyeEAi6Rq5J96LQvcIDFNE4 Incw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WmxosS2o; 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 t19-v6si31073721plo.287.2018.05.29.00.48.09; Tue, 29 May 2018 00:48:23 -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=WmxosS2o; 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 S1755282AbeE2HrY (ORCPT + 99 others); Tue, 29 May 2018 03:47:24 -0400 Received: from mail-ua0-f193.google.com ([209.85.217.193]:45170 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754813AbeE2HrT (ORCPT ); Tue, 29 May 2018 03:47:19 -0400 Received: by mail-ua0-f193.google.com with SMTP id j5-v6so9345581uak.12 for ; Tue, 29 May 2018 00:47:19 -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; bh=lEPr9c05eKVZXnjB/qB7nAMgpkzv/brhjhX5H8zBog8=; b=WmxosS2o+3DKAMSBXQ8/7Y3rfmz5zBSaQwuvT9c/7VqFWQLnpVdl0Q9R47gtc61Cs6 0NY4db55ipa4I6KMN7e8rxieH6jgk3qSSNDkFgNW44csFAwsCWIMM4IofMY8sA2V8v8w yr+xAZjrUmA/WN+aZdRwqq6Igd0RhjJHdPbs8U6tdND5OrPmhNeGJspHvPNMxju1AUq6 1K/HA+cD4RE1Zi86dQtKPVpZ+kkoftQdcnho1ojJ8iNZGcpiJbK/bG0hcYYwAMY9Se3O kcyKhOkxJ1SA5zk1i7tyMg7VisCqp9DUL2+dEFw2y6LQDhvo5oEQ4uJ4sgxmS/cY0Yi6 kLsA== 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; bh=lEPr9c05eKVZXnjB/qB7nAMgpkzv/brhjhX5H8zBog8=; b=pGNYQADgVWXdgN/Yk6lfU/DF6HHl5PbCvB5a9IA4r8ESmZRNUJi9dMcdt/vuTDvhbi JCO1qFO4IiA8FCb0y6rONKV5tGGQPu0GwKU8ZkWiA9eLUeikVRevFsyMtDXPCB5/Emr2 OProAcyJfy5YP8gXW546x3ogTf9+xaio2/3DOP35181d69Dda5pNZmrS0qhaKq9jjvGd 4DE0Gr8B/BwZk0NepIo7Sr5BUhtKptWhR2lfdyV1P4+zfT1PLlNZ0rkvG4fLm4xnLAp3 LXk+XF+An/W6JO6daxxu8WqJDd+363iRzUPiF0mLu0A3nVCFktipZY3YtntvVTXb6ops +jhA== X-Gm-Message-State: ALKqPwdajtzfL7bpZ7hFDXrc+AYJ4+/Fkm81pW+J6cN8/zOyjZrWZN0d PVgNx1UxwMHerHCcLtaoCCtW3/ZqPamlDzGQVN4xXYf7 X-Received: by 2002:a9f:2e0f:: with SMTP id t15-v6mr11177301uaj.114.1527580038149; Tue, 29 May 2018 00:47:18 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:7a0a:0:0:0:0:0 with HTTP; Tue, 29 May 2018 00:47:17 -0700 (PDT) In-Reply-To: References: From: Geert Uytterhoeven Date: Tue, 29 May 2018 09:47:17 +0200 X-Google-Sender-Auth: usaSpzXySNZ-xnenqaEnNT4-6Ic 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, CC Geoff 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=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 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. > 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. Has this been tested on a PS3? > return n + index; > } Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds