Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp486447imm; Thu, 31 May 2018 04:18:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKQuvJnCt2urF68XwzrtsIpOU6i81JkqG06mCnv2bnWZwgi+C5QaczNmszyXfmIaB9mxajX X-Received: by 2002:a17:902:bb0b:: with SMTP id l11-v6mr6745072pls.190.1527765498382; Thu, 31 May 2018 04:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527765498; cv=none; d=google.com; s=arc-20160816; b=BVrvEHuIyT7XCvEhcSjyoCO8Rl4o39a9JC5t33n6y4wygPYMi4bslG10JDPBMAaXSo 6lbjw/Mv8hgFEWFl0vlUwWqKx1fm6o9KeC8Efk4pQ59kldrZlNTOcTBy/kGulxW6Q7HJ NI+nHheGGgV62joJzkH4s95sdUmjfM3H7d3Zk1qBUTtEsnXq5y/jvtEajySprod67ZWL PTbMSnyHaLxYKshLcxzMXKxeYJmJP1bomVbFuLsx/rksiyc2cTO8pKE78ywPdIYZ1DIP NaYd8IfhHkf1vc0AoTrpBdfi42GcbEgR56o3Ri3HjBcoBpoN9F7L/03i6btCGFeIEm8A rnqA== 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:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :arc-authentication-results; bh=w7kEKrWLKKQnAKyBuFN4nGt1B/M+SIP/hlasD4YamM8=; b=YyVS/CrOp2VDWLGAMY6tDvofRZJpqRbFFp2+D0hpqJNMPNcxa2pDc/xmDJ5TbnC1uu YwVpS0cLP0LQCWv4aIzNgJA/fUIm+T1PT1RbssJlZCK/ho+SZtsY7DnWnUKLdswROFws Cgqn7qTlmev1aEaJhGoTv7YEwyrZq9xdcZun8SM+twFQmoe7iVreIFcp7u+uY24NhM30 puYwXm7bs6eujNP4O8WaBrbVQhSKkp7V/FtN7ObynB4uprkv1QYrJNGAFWCtM5kOge6P OkbNqyWSRsSvdKFs3evzDatHQQ3yitEJFuXNGp/kdSIyGSzaqqvltaoWhjEKKi+7vXdY mVOA== 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 q4-v6si36280129plb.312.2018.05.31.04.18.04; Thu, 31 May 2018 04:18:18 -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 S1754691AbeEaLR1 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 31 May 2018 07:17:27 -0400 Received: from ozlabs.org ([203.11.71.1]:40849 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754598AbeEaLRY (ORCPT ); Thu, 31 May 2018 07:17:24 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 40xQ0d6skHz9rxs; Thu, 31 May 2018 21:17:21 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: Christophe LEROY , Geert Uytterhoeven Cc: Benjamin Herrenschmidt , Paul Mackerras , Linux Kernel Mailing List , linuxppc-dev , Geoff Levand Subject: Re: [PATCH v2] powerpc/64: Fix build failure with GCC 8.1 In-Reply-To: References: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> <3a438dd8-49c3-ad39-e2a1-040e0ce67279@c-s.fr> <87efhsz7xz.fsf@concordia.ellerman.id.au> Date: Thu, 31 May 2018 21:17:20 +1000 Message-ID: <878t80yszj.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe LEROY writes: > 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() Sorry that wasn't clear was it. I'll add the kzalloc(). cheers