Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3864346imm; Mon, 25 Jun 2018 06:00:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ/IJik46uojUJt6Lr7hIdGYoJAg+2mvfuGTmlCfnoHVg9m8ADUCweENNxa5Is6kaKcVsiy X-Received: by 2002:a17:902:b494:: with SMTP id y20-v6mr12201025plr.136.1529931657587; Mon, 25 Jun 2018 06:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529931657; cv=none; d=google.com; s=arc-20160816; b=Af0GtkiwEGBJGE3ye5/wjmHQ5UeGW5kQDEIe4wnfXNMky1riX8M3hLCj3U9ItHtAK3 uQpyXHucQl58Od7AJKEcULR1kLFQ6TWmC6t/KVzBCI1iBqlm3MYgy/SfGNgHi/BygNbz 7BjXmkQbF85tLJ9QekJQrAH7TUa+4yBTnMTjBkInqolhrbkKP05DJTP5P9gArzQvq38N NRVtLLR3DW+R0d/KX/Y39Wgz99lKjPkcrfoi9i1El3lhZBKjDqK1kfD636oC5vx/zP9l 5r5cb43zU/YZ9s6Cz5Ip9hYjZjYqiYAQIUhm7zsbuUNu3y90JpLpmJBg40ARkzDzlFLH XcMA== 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=wVrRpfzr2/6xjPpXOHCifiARgJtRGPDmK2ufSEbFWNw=; b=IKoaGBBtf3wE9kDxaIM5CEP3LFJccL64C6JQjl5WptAHluV+T+urpsCfUJ9I39CwuB tG3u9fYcjYilJAF02ANhN4kilbBEBfMYADogmbskAirgxaiGU1DS5HoeuOox1LPCYDaL bSk1pnE54VRoJKCsHwyWDUvN1iqgyusg8Eyk89Qf5K7ZIdDYjX3eH/hklNsffelrLiaJ l+hXXzYy2mNf4xPldQZtbAFlDhXqi6roe3oan3XUmiGUVGiUj9iTR1otwz7wxwFFEd/S sm8jaVrp09ELUYbJgacO3hVK4IjfMPgzUYKOvnE3B5bn/ayun0feWKJ0AOn2K6OJdEEN KoGg== 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 x1-v6si3855579pga.289.2018.06.25.06.00.42; Mon, 25 Jun 2018 06:00:57 -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 S1755500AbeFYNAC (ORCPT + 99 others); Mon, 25 Jun 2018 09:00:02 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:62739 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752462AbeFYNAA (ORCPT ); Mon, 25 Jun 2018 09:00:00 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 41Dq5N0Kszz9tvV8; Mon, 25 Jun 2018 14:59:52 +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 fJUnT0KEzHqN; Mon, 25 Jun 2018 14:59:51 +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 41Dq5M6ZL8z9tvTy; Mon, 25 Jun 2018 14:59:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5880F8B7C4; Mon, 25 Jun 2018 14:59:59 +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 yQ-P65uSUlrL; Mon, 25 Jun 2018 14:59:59 +0200 (CEST) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.35]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1AB178B7A0; Mon, 25 Jun 2018 14:59:59 +0200 (CEST) Subject: Re: [PATCH v2 1/2] crypto: Fix -Wstringop-truncation warnings To: Stafford Horne , LKML Cc: Greg KH , arnd@arndb.de, Eric Biggers , linux-crypto@vger.kernel.org, Max Filippov , Nick Desaulniers , Herbert Xu , "David S. Miller" References: <20180625124538.21051-1-shorne@gmail.com> <20180625124538.21051-2-shorne@gmail.com> From: Christophe LEROY Message-ID: <2588342c-50da-a75b-3e51-32e3d931644c@c-s.fr> Date: Mon, 25 Jun 2018 14:59:58 +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: <20180625124538.21051-2-shorne@gmail.com> 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 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 ? > + 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; >