Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1671517imm; Fri, 22 Jun 2018 23:47:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJevLRcBlP6qOHeF+7x6SeZrWkl6DgKaLtzVo7aiKReHBDvxNCqn7Ax2xa5b6iNOPkCLJ5I X-Received: by 2002:a63:6e8f:: with SMTP id j137-v6mr3960337pgc.453.1529736471897; Fri, 22 Jun 2018 23:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529736471; cv=none; d=google.com; s=arc-20160816; b=bwhoENXgY9Xpn0NQCrW8ibN3e9YobxRHbHMp49agGEwwlZ0IHkBr3iYWi+DPB2R8Mn iMGmNrrWlR150WV0KFF7EB4dIQRDlvP8JOobocev/l1lDMo+1n1+Qjz9LsGkGZlKYt8R 4Y5m/ioYqQQgi03WJv/43IYztMtb4KqZIYy3LCNlOoec3zcSd0F0UNWIaTNrde8Jrkbq 7F8dna4Jrij2Xd7s1ehFL2qG8nF1FT+OQlcstKgAtOZm/iAmefBeAiv+yYI6nKPmoJIV YDyVvpk0eIivQn75v1j66pk3rchLibgxoliTCEMr7KD/GNMWvyP36vJgGbpuDEBuv333 F9Bg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ErCszpsvfyCg67s0VV5WFnPK1kQktA5tdKlJyHtUUnc=; b=qMY5FvTsbDfBf2iiKm0Ddr5Kv4cF1hRLxA9BgX+9F+r0EwhJGwbaTYnyohXpD8IFMx tV+hkGJT0lYwCE5i5wHV349dVDP7K88ld5+tIm7XZZNOISCb4Wfm9TTPcVxCzNiaod3f H3HdoRMZ3kdVekRCJEJxutzSxX/pIWNeR1PHkjhDda+9opYXggC8HtrWz99WvIKJHH6C g+gDo/aR6ymOhsp2reMWmO2y6KIoBtHUEQI+iBORs883CkaUzQUSIrVIUpjjZ7M5On3t mzWHnxFosQi2ExMkPc8eq6HvS0BM3EDk+VzaBNAhKwLB0RxHYXCnzLG3adOE5+WVd9uR FmiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="U/zPpqPQ"; 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 63-v6si8948935pfx.61.2018.06.22.23.47.37; Fri, 22 Jun 2018 23:47:51 -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="U/zPpqPQ"; 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 S1751502AbeFWGqw (ORCPT + 99 others); Sat, 23 Jun 2018 02:46:52 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40177 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbeFWGqu (ORCPT ); Sat, 23 Jun 2018 02:46:50 -0400 Received: by mail-pl0-f65.google.com with SMTP id t12-v6so4464188plo.7; Fri, 22 Jun 2018 23:46:50 -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:in-reply-to:user-agent; bh=ErCszpsvfyCg67s0VV5WFnPK1kQktA5tdKlJyHtUUnc=; b=U/zPpqPQ7rArvMt2HO9nALSBvIBkE5peSiYydYk5ElHRK3oQrJuu7bz73EajtvM3rM DIqWXGjuk2XR2hNJyFRs69yZTwJRBAWTqF+QQDEx4+nkB4RpAw2pI2O62sFdEG5QxSLQ RUDgsshVtxM/ylhgUScKbiRyg6sVMgtVx4rfj9jPXNrrGvhupjcFIX/wTb6C6S55RWkF xmcurIEUbC5c6nbjrmqUY+Z61mssZU7lvYBj53NLdHhNFRtfPRYuajKsgQlqe3doK2Cj WeCnm8aHWV7Fyz4pnBO8IWtaif/FAIR94HigZWDQVMXcNLoX/t7OozT0pfPMGs9UNc3z BTeA== 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:in-reply-to:user-agent; bh=ErCszpsvfyCg67s0VV5WFnPK1kQktA5tdKlJyHtUUnc=; b=WE8oVvsVgX/wdWPbgcmL0Y4YHmb93eoie0KQ4GA2vl7vXVLbAkPfUdYA/osIIJtzMJ 11LJRrn+cuzucfRq0xL1GLjWr1XBXADIWwIeRxdO1S8+GTV0yr7Gobo6ZA5Kmgi6Suzz ObBzKPCP2nqW7Vn5Dfd0ewJKPdLj4/+Roe2CS6vFvmjZq1zKMVqm4SGDXaliI/tRG3bc jvL3kB0M4X230ZjIr7T+ALX2IrdSaq6Xd4GEQD9slpcY8P/JBZaK39WgRH2MLkt4ChBJ ZmdbbPe83BUpbQQAJMwqReyeRiOC6vPCjU7roGrT8OOYmsLdBCcKzl9nCWRtBWDXDypJ f0/Q== X-Gm-Message-State: APt69E0VYsIfE93ld39NlgCOtV51SyS9GWp2usC2VpwF2GmPjUtGow19 b9QGg5fjZD5ixU3iYB8Simg= X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr4549754plc.248.1529736410243; Fri, 22 Jun 2018 23:46:50 -0700 (PDT) Received: from localhost (g134.124-44-9.ppp.wakwak.ne.jp. [124.44.9.134]) by smtp.gmail.com with ESMTPSA id e68-v6sm17163793pfl.65.2018.06.22.23.46.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 23:46:49 -0700 (PDT) Date: Sat, 23 Jun 2018 15:46:48 +0900 From: Stafford Horne To: Eric Biggers Cc: LKML , Greg KH , arnd@arndb.de, linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" , Nick Desaulniers Subject: Re: [RFC PATCH 1/2] crypto: Fix -Wstringop-truncation warnings Message-ID: <20180623064648.GH24595@lianli.shorne-pla.net> References: <20180623020753.27266-1-shorne@gmail.com> <20180623020753.27266-2-shorne@gmail.com> <20180623024149.GB880@sol.localdomain> <20180623025256.GG24595@lianli.shorne-pla.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180623025256.GG24595@lianli.shorne-pla.net> 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 Sat, Jun 23, 2018 at 11:52:56AM +0900, Stafford Horne wrote: > On Fri, Jun 22, 2018 at 07:41:49PM -0700, Eric Biggers wrote: > > On Sat, Jun 23, 2018 at 11:07:52AM +0900, Stafford Horne wrote: > > > As of GCC 9.0.0 the build is reporting warnings like: > > > [...] > > > strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); > > > strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "", > > > - sizeof(rblkcipher.geniv)); > > > + sizeof(rblkcipher.geniv) - 1); > > > > > > rblkcipher.blocksize = alg->cra_blocksize; > > > rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize; > > > > Your "fix" introduces an information disclosure bug, as it results in > > uninitialized memory being copied to userspace. This same broken patch was sent > > by someone else too. > > > > Maybe it would be best to just memset() the crypto_report_* structs to 0 after > > declaration and then replace the strncpy()'s with strscpy()'s, even if just to > > stop people from sending broken "fixes". Do you want to do that? > > Right, I didnt realize that we were using strncpy to also init the whole buffer. > > I will do as suggest, and respin. Hi Eric, I thought about this a bit, doing memset() and strscpy() seemed fine, but the below also would work, be a bit faster and stop gcc form complaining. What do you think? @@ -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; Let me know what you think. -Stafford