Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp251406imm; Wed, 30 May 2018 22:59:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLBI337H9rVb/pjbYCp2r9l5ClQHo2Gt3JCRn+xeobMl1BIAAMw/IGEZetWM8CgxTv3nZz5 X-Received: by 2002:a62:249b:: with SMTP id k27-v6mr5560711pfk.143.1527746396888; Wed, 30 May 2018 22:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527746396; cv=none; d=google.com; s=arc-20160816; b=jnKa+JpWfQ7Uglck+fjrPa054gREyFwrP4YsyC+GUae07kX9D69Sdlf1V6aYUzDDGE KmBy/jULY5/sYBFz0qeG079eXsJ78lD1X9U0h4tc4ikPOOiDtysOa4ayXpBI6SJaETQ1 sR6F5zgOhmPQH+jeJnUfvF+QCrd+yq113R1gTGyvbYzPriSJX16CuRRxtmNzJBdP3uDr tJb2G9ZQN+dSw2TNO/JJviOZ3uOndhXQVZC0Kp+tLGp0UBjaQazA2SdfNETpHYbbTaat EEuJIBWoDA8GDWVWv4l3HUIq8pO56z1wY/Tw5ayuA5GLyZXyizQ82LgUGQg3U7YbNB42 Ny8g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=VoFQEoKNMhy26Z+jw0eZMntg8GKVIYtu49Q35lgjemY=; b=0LgcBsE/5RinaU1YgcZuaOLAQXO+2vHbIO8dHDyrClNhv6znfjHoTGs2mQacNmLIwT yESKah6u9/lFz9+Uy1BOCE/g8YLQA6+k6v73Dp7NVWXN7qWe7TGzQ1D4bNeCA17O2NYw PEKs3AahBD6YVWbNpi2wh5PgjPJzhkrMb/nFFXZlYiDwbSSG43nVDQN2sg5VchE9QSwr E3svd2XTMeFCAwlZWMZQPJIMmId2djue6aqNEbadTEVrlGr00aUUsesr7l56EasHu/t/ rKDvwAzw91K4kWT00wNbWafANHqK14/2numR+DK4P7d+uXQiQSlu2XuAiAMcYjARFttt 6iqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t23-v6si38211958plo.508.2018.05.30.22.59.43; Wed, 30 May 2018 22:59:56 -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; 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 S1754004AbeEaF5z (ORCPT + 99 others); Thu, 31 May 2018 01:57:55 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:52114 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753790AbeEaF5u (ORCPT ); Thu, 31 May 2018 01:57:50 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40xGvs60x7z9ttKk; Thu, 31 May 2018 07:57:45 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id KpxwvJRGxj2I; Thu, 31 May 2018 07:57:45 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40xGvs5Tb5z9ttKh; Thu, 31 May 2018 07:57:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 71ECD8B7D4; Thu, 31 May 2018 07:57:48 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id oD62HuY3CBKA; Thu, 31 May 2018 07:57:48 +0200 (CEST) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 284378B74F; Thu, 31 May 2018 07:57:48 +0200 (CEST) Subject: Re: [PATCH v2] powerpc/64: Fix build failure with GCC 8.1 To: Michael Ellerman , Geert Uytterhoeven Cc: Benjamin Herrenschmidt , Paul Mackerras , Linux Kernel Mailing List , linuxppc-dev , Geoff Levand References: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> <3a438dd8-49c3-ad39-e2a1-040e0ce67279@c-s.fr> <87efhsz7xz.fsf@concordia.ellerman.id.au> From: Christophe LEROY Message-ID: Date: Thu, 31 May 2018 07:57:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <87efhsz7xz.fsf@concordia.ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 31/05/2018 à 07:54, Michael Ellerman a écrit : > Christophe LEROY writes: >> Le 29/05/2018 à 11:05, Geert Uytterhoeven a écrit : >>> Hi Christophe, >>> On Tue, May 29, 2018 at 10:56 AM, Christophe LEROY >>> wrote: >>>> Le 29/05/2018 à 09:47, Geert Uytterhoeven a écrit : >>>>> On Tue, May 29, 2018 at 8:03 AM, Christophe Leroy >>>>>> --- 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. >>> >>> 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(). > > > The right fix is to not try and mirror the on-device structure in the > kernel struct. We should just use a proper NULL terminated string, which > would avoid the need to explicitly do strncmp(.., .., 12) in the code > and be less bug prone in general. > > The only place where we should need to worry about the 12 byte buffer is > in nvram_write_header(). > > Anyway that's a bigger change, so I'll take this for now with kzalloc(). Thanks. You take it as is and add the kzalloc() or you expect a v3 from me with the kzalloc() Christophe