Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3912943imm; Mon, 25 Jun 2018 06:45:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKG7FI8uaWq+A+XlINer5Fgq5zCeBD4xPwwGxRK2ca7eNUy3LgC8QWNxmkYxujz41nOVzOu X-Received: by 2002:a17:902:b48f:: with SMTP id y15-v6mr12657581plr.261.1529934335822; Mon, 25 Jun 2018 06:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529934335; cv=none; d=google.com; s=arc-20160816; b=XNhUCeC9wC00kssqxt7vee02YjvU76eaIno0cU8S5K7KQUEOus4ZzMe4OK382or8NM /O1GeJEfxg7ztQma1QpuP3W5kuOtCIneIlR8RZ+Rv4sKrL/44S9SCY6zGEhM1JbR+Hlm rY/Ij1hW/39kzkGPaHHao5AAKCIXQ6Zlz7Tyw+NGmiFTd9MqTbYfc2k83Zwakoi1upAf 3/cRY6p1mo00nUXyy8UxRMGxZr9MYhoVil83IUSy9am45v0DicZpyuUyx+G7FKOyU0U4 eIn1VDytKeZ1XfSXo1FFC1Ec1zdMOzR3XZcBdxd/hyqRtCy4v0/Pm/WW07DYWcKlFr2H HfCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=ebccYx03yS2XKmIL6Fqtm0lEKpMG2UJfyXAeajlli9c=; b=Pwl1RNRuF0JAv6eHFZERN1e8vpg1vM82n7cS10l78ATgOXmErRpJEsRzZcIZ5TmuN8 PzUsYgPiXgqLkDFChLeQLHgbQVyMUMrp6XdBgqU72HYNajW+P6NcXlXZ0Kx2ZTj3WKsN SFy8552MT7WPj7dloZROBeA5SnjJzR7NtoxGpH2i/CNMh/n4YI2TQXhmU/TAeADvtadW WZTJPQHkyMNrCWPcfBfV5NvGZp0dSOJCEpKen2LOd3u5cwV4t74bjZ2twel4T9byF4Z7 HYOWAJ+xEsN13xEB70M1cqV9M09KNpWAQsIDNHWEYVaRO2XbjmFPcRcc0fz1yVbeQQTy ygJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L74402jp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z185-v6si15297272pfb.257.2018.06.25.06.45.21; Mon, 25 Jun 2018 06:45:35 -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=pass header.i=@gmail.com header.s=20161025 header.b=L74402jp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933803AbeFYNkZ (ORCPT + 99 others); Mon, 25 Jun 2018 09:40:25 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40080 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755345AbeFYNkY (ORCPT ); Mon, 25 Jun 2018 09:40:24 -0400 Received: by mail-pf0-f193.google.com with SMTP id z24-v6so6465428pfe.7; Mon, 25 Jun 2018 06:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=ebccYx03yS2XKmIL6Fqtm0lEKpMG2UJfyXAeajlli9c=; b=L74402jpSY8Jr7JzfgUL4Hx2fByoK5dZ3xxcmCNtM7XTmrZe06ZvurOU6WozOYFvuk fzXI6cvBQ3pDe7K4rIZpbWq0svkiJlPIXy+Lq9OH+oMXcvoD5TQJsIK90IgzkHamFD6o n5KgijnTfn9WCHmGRaSMqS6Xq6UWSyUwwVs0OmNmFhlWN0k26rdr/Lf6MVQObY9XBDe7 JRx+7E+zdVJR1COLSsV7om9Qk255DiqxLjef2bAEF6hklV2/qBUvEUOgr4sLGy5mxCzs q6uS5Eso2azjYC7hX/IMrD1FmAIY3qx7cn4ZQ2sLxNUo23R0Kyy+XXVtphUuSU/KouWx UnHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=ebccYx03yS2XKmIL6Fqtm0lEKpMG2UJfyXAeajlli9c=; b=HA9He9odAGGXJ/zJvuxgILX3dzJf6RGNvcPkuK539pOhd06B4td/qChnN3XrRW67Q0 ps/ICWqRyXnucBBJcXtcEhglUDMLLftg0/vEgOCdVfvJaMYbVbth9V9fbGYMV+c9wkEu BaLl/wVHV2RbV2+4S3S2aNz0xiebNCfTMBNJvPGfp9N5oe7xnsDvJkelgLOyhwCPCCb4 xJJIxiQpUvHbkP0v2QDD9oxbNkvDLZi9OZymOKJy7d+Z841E/jGVIxHw7gVfz7eO2J2N nxQiJ+8pk3cQp9FtL9n338KjwJVNp3QAzsM7mpwiOFMZ0NQoLk04VRh2kRXZDwBfJkVz gbrQ== X-Gm-Message-State: APt69E18io83+UZNseMI8KkuQkRVB0SAB2rErZKpqfyh+W1qYnXkWH4G Af0Zl96uPLzH/mYiDGZaV5c= X-Received: by 2002:a63:7e1a:: with SMTP id z26-v6mr10800562pgc.278.1529934023759; Mon, 25 Jun 2018 06:40:23 -0700 (PDT) Received: from localhost (g134.124-44-9.ppp.wakwak.ne.jp. [124.44.9.134]) by smtp.gmail.com with ESMTPSA id x2-v6sm21380170pfn.11.2018.06.25.06.40.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 06:40:23 -0700 (PDT) Date: Mon, 25 Jun 2018 22:40:21 +0900 From: Stafford Horne To: Christophe LEROY Cc: LKML , Greg KH , arnd@arndb.de, Eric Biggers , linux-crypto@vger.kernel.org, Max Filippov , Nick Desaulniers , Herbert Xu , "David S. Miller" Subject: Re: [PATCH v2 1/2] crypto: Fix -Wstringop-truncation warnings Message-ID: <20180625134021.GJ24595@lianli.shorne-pla.net> References: <20180625124538.21051-1-shorne@gmail.com> <20180625124538.21051-2-shorne@gmail.com> <2588342c-50da-a75b-3e51-32e3d931644c@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2588342c-50da-a75b-3e51-32e3d931644c@c-s.fr> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 25, 2018 at 02:59:58PM +0200, Christophe LEROY wrote: > > > Le 25/06/2018 à 14:45, Stafford Horne a écrit : > > As of GCC 9.0.0 the build is reporting warnings like: > > > > crypto/ablkcipher.c: In function ‘crypto_ablkcipher_report’: > > crypto/ablkcipher.c:374:2: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation] > > strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > sizeof(rblkcipher.geniv)); > > ~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > This means the strnycpy might create a non null terminated string. Fix this by > > explicitly performing '\0' termination. > > > > Cc: Greg Kroah-Hartman > > Cc: Arnd Bergmann > > Cc: Max Filippov > > Cc: Eric Biggers > > Cc: Nick Desaulniers > > Signed-off-by: Stafford Horne > > --- > > crypto/ablkcipher.c | 2 ++ > > crypto/blkcipher.c | 1 + > > 2 files changed, 3 insertions(+) > > > > diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c > > index d880a4897159..1edb5000d783 100644 > > --- a/crypto/ablkcipher.c > > +++ b/crypto/ablkcipher.c > > @@ -373,6 +373,7 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) > > strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type)); > > strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", > > sizeof(rblkcipher.geniv)); > > Is it worth copying something we are going to discard at the following line > ? Shouldn't you limit the copy to sizeof(rblkcipher.geniv) - 1 ? Hi, I thought about that, I just did it like this as I thought it might be easier to read and I noticed a few other areas in the kernel that did this way. After a closer look I can see we have both patterns, perhaps we need a mcro/helper. I don't mind either way, I can fix, if the crypto maintainers want to adjust the patch that would work too. -Stafford > > + rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0'; > > rblkcipher.blocksize = alg->cra_blocksize; > > rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; > > @@ -447,6 +448,7 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) > > strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type)); > > strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", > > sizeof(rblkcipher.geniv)); > > Same comment here. > > Christophe > > > + rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0'; > > rblkcipher.blocksize = alg->cra_blocksize; > > rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; > > diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c > > index 01c0d4aa2563..dd4dcab3766a 100644 > > --- a/crypto/blkcipher.c > > +++ b/crypto/blkcipher.c > > @@ -512,6 +512,7 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) > > strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); > > strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "", > > sizeof(rblkcipher.geniv)); > > + rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0'; > > rblkcipher.blocksize = alg->cra_blocksize; > > rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize; > >