Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp248686imm; Wed, 30 May 2018 22:55:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJok9sg6sPSdUjo7Jo14ImP5FGYFjAa66cuKmqTF9y2sisV9meeY7y3QkGN+KrwcC+Yq+Os X-Received: by 2002:a17:902:301:: with SMTP id 1-v6mr5676601pld.127.1527746154274; Wed, 30 May 2018 22:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527746154; cv=none; d=google.com; s=arc-20160816; b=hZcLcvzLhooTHmO00bPZdmkOUtp5YiZzuu6VOT0GtC5a5ZjhO5vtgrKH4CPKnkkc7R 9IIArPbiHIB1UuvUbEAKaGaFhwP6+kaQVoO2aanWPtUuQTZ/wHL8Pz3Y7KCniDA7JMpu lNWUSo7sM5LmTW9xuvuUqdX68tQoIDTV1uh6/aOisfeul+XJXt2yC7wFjFiUiNlVqnKz mu6DFifmqYVHmvMkkzHcpO8tpcqNqPHlAzMQGgSraB+h8HtvLUG+7Ct5DzQEh9kfQW35 Nb8w/mH6MmdVI3P+n6L7uFexsyFQ0zea/2Ev8TjiSO8wI+MxVhIE1v8wAuR5mT460Gcn myqA== 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=15IKedIs9HYU4kz87TcnBrUSUXBYeBZtOp9C8Na/grw=; b=zj0FUuMWyWOVn6FFjHW9mBqi4BMYoquCwZ1WZBpVuhwCS3eKJ53IhIfUHS2o9XmICT FTeVcfDqfDb/yZxUmr+Cgq6NT8WKhV3PCGCDubBdzfzWo0pYI/EjLbsoGXBvwsbqe7zU seKSg/UhfWQ6r0VEJatKEOF9b+TGuEMZMS7lYE5EphYk50hcqSOOi8CQuG9iq+GEw2ul 3je8aGm24jntuZFcTVxHbkSLuMdv7KzxmCqeZvG4kPrlzijUcuxT9OthXzS5aBzrp1gU x60NbOKKsuh24yBVuSLgrrhZpsQ0sT0PsQbbKwQ9W2Tq0tKsDSF2pJHq1uSQeiNGIjGn YXhw== 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 y34-v6si36562780plb.17.2018.05.30.22.55.40; Wed, 30 May 2018 22:55:54 -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 S1753909AbeEaFyT convert rfc822-to-8bit (ORCPT + 99 others); Thu, 31 May 2018 01:54:19 -0400 Received: from ozlabs.org ([203.11.71.1]:36829 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753772AbeEaFyS (ORCPT ); Thu, 31 May 2018 01:54:18 -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 40xGqs2QsVz9s01; Thu, 31 May 2018 15:54:17 +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: <3a438dd8-49c3-ad39-e2a1-040e0ce67279@c-s.fr> References: <1fa5b220-4d21-b4cd-33bf-8a3ce3178063@c-s.fr> <3a438dd8-49c3-ad39-e2a1-040e0ce67279@c-s.fr> Date: Thu, 31 May 2018 15:54:16 +1000 Message-ID: <87efhsz7xz.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 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(). cheers