Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3993059imm; Tue, 29 May 2018 19:04:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKiIEMdDQkUQbpsPCVw1N7TpvW3FpgsobaLGAPMartrS+DIuA8rT1cIugGFM1cOq3aNivZL X-Received: by 2002:a65:4502:: with SMTP id n2-v6mr639656pgq.95.1527645897209; Tue, 29 May 2018 19:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527645897; cv=none; d=google.com; s=arc-20160816; b=xWMGZ/3GZVQPxap1m+jWpaCZw3SkP4NwJv+rjmntfHsvnCC8tFAOUHZr6Cf3iuLAu1 5aAAVIDF5J6JF5/qOSxVhFnqKERqcnmIQBX2+RsRMK9g6rIDN0GCkLDL0gBWQUbem9EK ZMVV7Zwv8tJGfCBJNxO4ulsD5EVvPCoQtqyE9zfWWGNdS91XWBIqC1MbyvDWMmnqIIEg Si/HBn1xHgjyGObg2m9pXtH+UbyFQ78/8LgbaiktpCpRB048tAy+57Vsn4jvFGOJ4tl0 p/sGqo8FmetQR/y6Y+3OxecrsJG81gLZ/HvPOkhXAjzp974cySiir47Ip88AYbdn3CBB uNsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=eKZbI/TAUKXTRv07ZyZzyxMayhs/NGRSn7isC7jN9mk=; b=PvBHC9g1hRAf2YA++KGTPhKgjYNWervPOlKgmo6cBWHmQpp5llg2nf/ZV61QMh4peM wmveUUE7qWYDnuYagyyFekHEKSdEIoGg9Z4AdrAS/aN/KneGM84AEK3I0ZCIwNMZ4Dku w6d+NU6gTRzCPdYD6kdxywidCxX3EuS4ZAUShNvinSeGTWJCTh4hjtHfKdhbf2M8KOIR ohDyexqb3+jwCPK9ruyVdOY/9eEWyTskhQK+I3zlhN/169BOJ8m6+N8cO91siXnvIlm/ HeTokI/rhd0OzYe243TFV/pWTRGmTsjHmKRrGhJPJaZ7jZlk+ET3qC8TVLGYeZI+0u0U sNkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z/G516zM; 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 y17-v6si17602269plp.485.2018.05.29.19.04.43; Tue, 29 May 2018 19:04: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z/G516zM; 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 S935911AbeE3CDf (ORCPT + 99 others); Tue, 29 May 2018 22:03:35 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:45188 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935643AbeE3CDa (ORCPT ); Tue, 29 May 2018 22:03:30 -0400 Received: by mail-ot0-f193.google.com with SMTP id 15-v6so19316794otn.12; Tue, 29 May 2018 19:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=eKZbI/TAUKXTRv07ZyZzyxMayhs/NGRSn7isC7jN9mk=; b=Z/G516zMfCM8s+Q1J+r5ZvRD47CxeeyXlnTAWqcp/eXZBtMJTP1wn25S0UgboVwSeq mR05C4M9LSUsXSIm43QxJ1FVle8D1g4LP6pd6H3LCImwGldPdCOJnaaL2zEpDsxE5Vk/ g855arKvlkGrQL3Q3pdtIDtJ2qbBFxfHuRjwNdO9pC/VtxfX438N9uu1it274TFEDDjT uu3wZaS2LbudnnnzVz7WFKUNdwEZf8iGD1XKFYssCfWE8uTjXTo7LEXdp/Ehz4oQvPKz vB1SqzqVScO4/Ue4JkcE4tLv7f2Xj3MzlM9J9dnWEzGpSyysfXX5BKNwhV6uLQOTP3p1 6MrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=eKZbI/TAUKXTRv07ZyZzyxMayhs/NGRSn7isC7jN9mk=; b=Bum+L5zjzsJokwCCJVAJcOz0S6Vk2lhoCpEQOAjaPcfBx1xRtDoYfnHKbkd4esc8l8 HpaG+jnjcROZTyHNQgHV5jtNrylrUpyGT9h4GzL00o+JFgrea960P+uXyybup3fSXSJH bd1K3VM5Qw8ZPKgI8qz9yyrI2mxHwgxZvshJfMax5Gd1E9fC4iL5sz/XXEE8kietSv1F AQw6K00m1JvXpFt0affZ6Sa41rt3citcc40WJpS6EGlFEbe16GXtx8StEEIhxW0Bwy32 GqotzrsfJ5ph9pg9RNIDg5ro1V/kRzjxaavCnhshs0aO25zH9aijP96ML30Qx2H2+4pK jqcQ== X-Gm-Message-State: ALKqPwfPVOLNJCQtgS9vUiJ3f2ffvY0Hhllp9wtyc7myZO5h1ZSPFHTM DTvjutM/12VzjHaJr2wxHr1IKW9Dto0wCa+JchM= X-Received: by 2002:a9d:29b5:: with SMTP id n50-v6mr575553otb.136.1527645810163; Tue, 29 May 2018 19:03:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2451:0:0:0:0:0 with HTTP; Tue, 29 May 2018 19:03:29 -0700 (PDT) In-Reply-To: <20180529163400.GA166256@gmail.com> References: <1527572683-26098-1-git-send-email-nick.desaulniers@gmail.com> <20180529163400.GA166256@gmail.com> From: Nick Desaulniers Date: Tue, 29 May 2018 19:03:29 -0700 Message-ID: Subject: Re: [PATCH] crypto: blkcipher: prefer strlcpy to strncpy To: Eric Biggers Cc: Herbert Xu , davem@davemloft.net, linux-crypto@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 9:34 AM, Eric Biggers wrote: > On Mon, May 28, 2018 at 10:44:43PM -0700, Nick Desaulniers wrote: >> Fixes stringop-truncation warnings from gcc-8. >> >> Signed-off-by: Nick Desaulniers >> --- >> crypto/ablkcipher.c | 8 ++++---- >> crypto/blkcipher.c | 4 ++-- >> 2 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c >> index d880a48..e38867f 100644 >> --- a/crypto/ablkcipher.c >> +++ b/crypto/ablkcipher.c >> @@ -370,8 +370,8 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) >> { >> struct crypto_report_blkcipher rblkcipher; >> >> - strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type)); >> - strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", >> + strlcpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type)); >> + strlcpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", >> sizeof(rblkcipher.geniv)); >> >> rblkcipher.blocksize = alg->cra_blocksize; >> @@ -444,8 +444,8 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) >> { >> struct crypto_report_blkcipher rblkcipher; >> >> - strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type)); >> - strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", >> + strlcpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type)); >> + strlcpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "", >> sizeof(rblkcipher.geniv)); >> >> rblkcipher.blocksize = alg->cra_blocksize; >> diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c >> index 01c0d4a..ee88e48 100644 >> --- a/crypto/blkcipher.c >> +++ b/crypto/blkcipher.c >> @@ -509,8 +509,8 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) >> { >> struct crypto_report_blkcipher rblkcipher; >> >> - strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); >> - strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "", >> + strlcpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); >> + strlcpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "", >> sizeof(rblkcipher.geniv)); >> >> rblkcipher.blocksize = alg->cra_blocksize; >> -- >> 2.7.4 >> > > Hi Nick, this patch is wrong. The 'struct crypto_report_blkcipher' is being > copied to userspace via netlink, so all bytes of it must be initialized. > strncpy() does this but strlcpy() does not. > > I noticed that you're sending out some other patches replacing strncpy() with > strlcpy() too. Can you please double check them for this same bug? > > Thanks, > > - Eric Thanks for pointing out this subtlety, I've retracted the other patches.