From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EC5BC2BB1D for ; Tue, 14 Apr 2020 19:38:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 738E12074D for ; Tue, 14 Apr 2020 19:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FZpZUQb8"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RUtwHLrS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 738E12074D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UUFP6wNajAiLMvK8BQZGO+UdC0976y8DrvBTRAbb558=; b=FZpZUQb8Hxle28 pugrfDO67uUBjcSJ+TlAvtTPl/xKHjLKZbZVdlPex1pU40gLOqIi1qTFnbPSIDR1I8/s0fQ6F/SWN vLqZTNwDMpoXC0GTha7+YZeJW1Q4TMO8s38GNxO/hS+X+vWKNh85G9fhLze4hJek9yR8pOKJubhs1 vSxFjR+xWglL0p6+GrSCV2TYdjZlYDHrGHxHB6vmc53oeEtL8UtblNwp+Etv6VH+ozghUVEMGLqcZ AIlFKGSCLK0MBI1lQltRZKwDvtcmxlIFIL5ubJ2hfAm1mQ+j6g9w1R5j63C9GwzduzGD2tRHPJ5BP YXUQMsa7wLw6/MQiBo3A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jORNv-00051I-BD; Tue, 14 Apr 2020 19:38:15 +0000 Received: from us-smtp-2.mimecast.com ([207.211.31.81] helo=us-smtp-delivery-1.mimecast.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jORNs-0004zc-7B for linux-amlogic@lists.infradead.org; Tue, 14 Apr 2020 19:38:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586893088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K7rEujuH9mCHHkQNQF3bIC7vs8ss/qE9yTiJvgoWENY=; b=RUtwHLrSbkaJMm0IrMRS9rm0IZmdDO3dP2/xxkZGnWHf/t7JN2MxaoW4q5N/mb6RPBFLLy P947ZeFYc1NGC7YZYlO7Mw3aqTJi1Hqp7+A3wGm8Zn3fqfDRZznd1zIsAv1KIqCY5KfpPZ cSeVgzUqVzTuzDNClrQrNJ8UGRg4zNQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-BEtuMjG3PL-f8LyKeyu6gQ-1; Tue, 14 Apr 2020 15:38:03 -0400 X-MC-Unique: BEtuMjG3PL-f8LyKeyu6gQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A5A58017F3; Tue, 14 Apr 2020 19:37:58 +0000 (UTC) Received: from llong.remote.csb (ovpn-118-173.rdu2.redhat.com [10.10.118.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0277F100E7E3; Tue, 14 Apr 2020 19:37:51 +0000 (UTC) Subject: Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit() To: =?UTF-8?Q?Michal_Such=c3=a1nek?= References: <20200413211550.8307-1-longman@redhat.com> <20200413222846.24240-1-longman@redhat.com> <20200414191601.GZ25468@kitsune.suse.cz> From: Waiman Long Organization: Red Hat Message-ID: <578fe9b6-1ccd-2698-60aa-96c3f2dd2c31@redhat.com> Date: Tue, 14 Apr 2020 15:37:51 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20200414191601.GZ25468@kitsune.suse.cz> Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200414_123812_356274_4A62794B X-CRM114-Status: GOOD ( 17.84 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-btrfs@vger.kernel.org, Jarkko Sakkinen , virtualization@lists.linux-foundation.org, David Howells , linux-mm@kvack.org, linux-sctp@vger.kernel.org, keyrings@vger.kernel.org, kasan-dev@googlegroups.com, samba-technical@lists.samba.org, linux-stm32@st-md-mailman.stormreply.com, devel@driverdev.osuosl.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, x86@kernel.org, James Morris , Matthew Wilcox , cocci@systeme.lip6.fr, linux-wpan@vger.kernel.org, intel-wired-lan@lists.osuosl.org, David Rientjes , "Serge E. Hallyn" , linux-pm@vger.kernel.org, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christophe Leroy , linux-cifs@vger.kernel.org, Linus Torvalds , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-security-module@vger.kernel.org, target-devel@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-crypto@vger.kernel.org, netdev@vger.kernel.org, Joe Perches , Andrew Morton , linuxppc-dev@lists.ozlabs.org, wireguard@lists.zx2c4.com, linux-ppp@vger.kernel.org Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org On 4/14/20 3:16 PM, Michal Such=E1nek wrote: > On Tue, Apr 14, 2020 at 12:24:36PM -0400, Waiman Long wrote: >> On 4/14/20 2:08 AM, Christophe Leroy wrote: >>> >>> Le 14/04/2020 =E0 00:28, Waiman Long a =E9crit=A0: >>>> Since kfree_sensitive() will do an implicit memzero_explicit(), there >>>> is no need to call memzero_explicit() before it. Eliminate those >>>> memzero_explicit() and simplify the call sites. For better correctness, >>>> the setting of keylen is also moved down after the key pointer check. >>>> >>>> Signed-off-by: Waiman Long >>>> --- >>>> =A0 .../allwinner/sun8i-ce/sun8i-ce-cipher.c=A0=A0=A0=A0=A0 | 19 +++++= ------------- >>>> =A0 .../allwinner/sun8i-ss/sun8i-ss-cipher.c=A0=A0=A0=A0=A0 | 20 +++++= -------------- >>>> =A0 drivers/crypto/amlogic/amlogic-gxl-cipher.c=A0=A0 | 12 +++-------- >>>> =A0 drivers/crypto/inside-secure/safexcel_hash.c=A0 |=A0 3 +-- >>>> =A0 4 files changed, 14 insertions(+), 40 deletions(-) >>>> >>>> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c >>>> b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c >>>> index aa4e8fdc2b32..8358fac98719 100644 >>>> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c >>>> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c >>>> @@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) >>>> =A0 { >>>> =A0=A0=A0=A0=A0 struct sun8i_cipher_tfm_ctx *op =3D crypto_tfm_ctx(tfm= ); >>>> =A0 -=A0=A0=A0 if (op->key) { >>>> -=A0=A0=A0=A0=A0=A0=A0 memzero_explicit(op->key, op->keylen); >>>> -=A0=A0=A0=A0=A0=A0=A0 kfree(op->key); >>>> -=A0=A0=A0 } >>>> +=A0=A0=A0 kfree_sensitive(op->key); >>>> =A0=A0=A0=A0=A0 crypto_free_sync_skcipher(op->fallback_tfm); >>>> =A0=A0=A0=A0=A0 pm_runtime_put_sync_suspend(op->ce->dev); >>>> =A0 } >>>> @@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher >>>> *tfm, const u8 *key, >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 dev_dbg(ce->dev, "ERROR: Invalid keylen %u= \n", keylen); >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 return -EINVAL; >>>> =A0=A0=A0=A0=A0 } >>>> -=A0=A0=A0 if (op->key) { >>>> -=A0=A0=A0=A0=A0=A0=A0 memzero_explicit(op->key, op->keylen); >>>> -=A0=A0=A0=A0=A0=A0=A0 kfree(op->key); >>>> -=A0=A0=A0 } >>>> -=A0=A0=A0 op->keylen =3D keylen; >>>> +=A0=A0=A0 kfree_sensitive(op->key); >>>> =A0=A0=A0=A0=A0 op->key =3D kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); >>>> =A0=A0=A0=A0=A0 if (!op->key) >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 return -ENOMEM; >>>> +=A0=A0=A0 op->keylen =3D keylen; >>> Does it matter at all to ensure op->keylen is not set when of->key is >>> NULL ? I'm not sure. >>> >>> But if it does, then op->keylen should be set to 0 when freeing op->key= . = >> My thinking is that if memory allocation fails, we just don't touch >> anything and return an error code. I will not explicitly set keylen to 0 >> in this case unless it is specified in the API documentation. > You already freed the key by now so not touching anything is not > possible. The key is set to NULL on allocation failure so setting keylen > to 0 should be redundant. However, setting keylen to 0 is consisent with > not having a key, and it avoids the possibility of leaking the length > later should that ever cause any problem. OK, I can change it to clear the key length when the allocation failed which isn't likely. Cheers, Longman _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic