Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2410006pxy; Tue, 3 Aug 2021 05:59:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySWfJ4u2e3ugdM2rKa09g9IfcJGkwUwqoqkM4yhihle5nzaJIs6bh0vgYlVckvI5WRbTHk X-Received: by 2002:a17:906:2bc9:: with SMTP id n9mr20226965ejg.23.1627995579397; Tue, 03 Aug 2021 05:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627995579; cv=none; d=google.com; s=arc-20160816; b=Z8ghiyT5a6GxKsz4CtFlkOlA2yzW4ZgIJruiCxZ2n/EP7rVLqj1N6wEfsQl+Y1dArY p/c/vjmBpXpPVdo9+iCMrD7v9gGPuMCwbmnIyFhEzTUUPu0nZ4TQug1YUsOWWAtQWH8x F+jGIBCG4JLjuBBfnH45Eyzunyt8iEvvGP56MWajCbKnavf8b+RN7wcEaXhvUdG6IzEu h2qXXfpo3D2l8A6isYS6kh9cwP311XZ/S+Zz7/0ZcFwxowi+IhPb0MMJcGNM1JTkFEYk 6NP4qnmg3EMPUNRbXv9rUEAy4dhlclmbdm4xqRaP88QoJhpGorpgqvXpYILQRuW73Vie bqYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=EV8WINAfsJBLmArG+ToeQdghBTgrWjDQNf6ygENcFFw=; b=Egk2JWOGWTnSOCtWTzT3fBueLbHpOziI1ZQ9o9W/l8c8a0YMX++q6RfKxejMte2tzy FDoqWIT0RMR3JKfZOwO4XhLh0O+0D9ZZoUmB0q4a45kbnN/wftU2t+Dy7j61N18Ygrnu qup2iviX47QiiJvRLFXmbsH+/VQLs7goLt++40xU7cMmvznmu1xVJ1xqssQ4xmXzwL3Z JPqZMUuSEa8kfcqyZUZ6Wpaoo/iNltQgXREd18cjug3yrKMagjR2E6ovEhWJC1lqu+Bh WPl89LXBq3AVvsmyIBqXKG6MdWlYhIkBcGpIqxvhiaCfYrxmSHNkGpfovuADJByRNDKD Ym6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp42si13573353ejc.261.2021.08.03.05.59.15; Tue, 03 Aug 2021 05:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235944AbhHCM6D (ORCPT + 99 others); Tue, 3 Aug 2021 08:58:03 -0400 Received: from smtpbg587.qq.com ([113.96.223.105]:38622 "EHLO smtpbg587.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235895AbhHCM6C (ORCPT ); Tue, 3 Aug 2021 08:58:02 -0400 X-QQ-mid: bizesmtp37t1627995332t0z35aya Received: from localhost.localdomain (unknown [125.69.40.136]) by esmtp6.qq.com (ESMTP) with id ; Tue, 03 Aug 2021 20:55:30 +0800 (CST) X-QQ-SSF: 01000000002000B0C000B00A0000000 X-QQ-FEAT: FsG0r2mBeltZwXHsnSFyQIVXmyMoeC5BD2c5iGCpiLDw2FB21T+BluHr2+WdJ oph6RdKQTsSFUCzmZUnpNtkvp7eRJJ7u4igpOBS3y1HdKXXsaVO7JQf5TGooeEoSctgHhA8 OXl9EoQ04EBtRvwL3HqP+UCbpDMWLeVkuWP3fiXqES3NnB44Hyo5mQ1OoJemMhdsRwVPFxE Qn3LIQsc1dHzAB5VHQ7o+h4EE1wdh7/PGW+rcJmy8JOO3AagTdn8xhSW26L620rIClOA0LB JmUxJ0S/Cx2RsqipiQbq1yD67gbfWKBZTBJy0J4LL1wFz+stATLDWWpOxFfU/SGyz+ZJYmL k/6kLXzErmCrW71M+Y= X-QQ-GoodBg: 0 From: Jason Wang To: herbert@gondor.apana.org.au Cc: clabbe.montjoie@gmail.com, davem@davemloft.net, mripard@kernel.org, wens@csie.org, jernej.skrabec@gmail.com, wangborong@cdjrlc.com, mchehab+huawei@kernel.org, corbet@lwn.net, baijiaju1990@gmail.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data Date: Tue, 3 Aug 2021 20:55:25 +0800 Message-Id: <20210803125525.72603-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kfree_sensitive is a kernel API to clear sensitive information that should not be leaked to other future users of the same memory objects and free the memory. Its function is the same as the combination of memzero_explicit and kfree. Thus, we can replace the combination APIs with the single kfree_sensitive API. Signed-off-by: Jason Wang --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 9 +++------ drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c index cd1baee424a1..b3a9bbfb8831 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c @@ -26,8 +26,7 @@ void sun8i_ce_prng_exit(struct crypto_tfm *tfm) { struct sun8i_ce_rng_tfm_ctx *ctx = crypto_tfm_ctx(tfm); - memzero_explicit(ctx->seed, ctx->slen); - kfree(ctx->seed); + kfree_sensitive(ctx->seed); ctx->seed = NULL; ctx->slen = 0; } @@ -38,8 +37,7 @@ int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, struct sun8i_ce_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm); if (ctx->seed && ctx->slen != slen) { - memzero_explicit(ctx->seed, ctx->slen); - kfree(ctx->seed); + kfree_sensitive(ctx->seed); ctx->slen = 0; ctx->seed = NULL; } @@ -157,9 +155,8 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src, memcpy(dst, d, dlen); memcpy(ctx->seed, d + dlen, ctx->slen); } - memzero_explicit(d, todo); err_iv: - kfree(d); + kfree_sensitive(d); err_mem: return err; } diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c index 5b7af4498bd5..19cd2e52f89d 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c @@ -95,9 +95,8 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa memcpy(data, d, max); err = max; } - memzero_explicit(d, todo); err_dst: - kfree(d); + kfree_sensitive(d); return err; } -- 2.32.0