You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
mm, treewide: rename kzfree() to kfree_sensitive()
As said by Linus: A symmetric naming is only helpful if it implies symmetries in use. Otherwise it's actively misleading. In "kzalloc()", the z is meaningful and an important part of what the caller wants. In "kzfree()", the z is actively detrimental, because maybe in the future we really _might_ want to use that "memfill(0xdeadbeef)" or something. The "zero" part of the interface isn't even _relevant_. The main reason that kzfree() exists is to clear sensitive information that should not be leaked to other future users of the same memory objects. Rename kzfree() to kfree_sensitive() to follow the example of the recently added kvfree_sensitive() and make the intention of the API more explicit. In addition, memzero_explicit() is used to clear the memory to make sure that it won't get optimized away by the compiler. The renaming is done by using the command sequence: git grep -w --name-only kzfree |\ xargs sed -i 's/kzfree/kfree_sensitive/' followed by some editing of the kfree_sensitive() kerneldoc and adding a kzfree backward compatibility macro in slab.h. [akpm@linux-foundation.org: fs/crypto/inline_crypt.c needs linux/slab.h] [akpm@linux-foundation.org: fix fs/crypto/inline_crypt.c some more] Suggested-by: Joe Perches <joe@perches.com> Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: David Howells <dhowells@redhat.com> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Cc: James Morris <jmorris@namei.org> Cc: "Serge E. Hallyn" <serge@hallyn.com> Cc: Joe Perches <joe@perches.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: David Rientjes <rientjes@google.com> Cc: Dan Carpenter <dan.carpenter@oracle.com> Cc: "Jason A . Donenfeld" <Jason@zx2c4.com> Link: http://lkml.kernel.org/r/20200616154311.12314-3-longman@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
57c720d414
commit
453431a549
@@ -249,7 +249,7 @@ static void prng_tdes_deinstantiate(void)
|
||||
{
|
||||
pr_debug("The prng module stopped "
|
||||
"after running in triple DES mode\n");
|
||||
kzfree(prng_data);
|
||||
kfree_sensitive(prng_data);
|
||||
}
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ outfree:
|
||||
static void prng_sha512_deinstantiate(void)
|
||||
{
|
||||
pr_debug("The prng module stopped after running in SHA-512 mode\n");
|
||||
kzfree(prng_data);
|
||||
kfree_sensitive(prng_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ static int get_e820_md5(struct e820_table *table, void *buf)
|
||||
if (crypto_shash_digest(desc, (u8 *)table, size, buf))
|
||||
ret = -EINVAL;
|
||||
|
||||
kzfree(desc);
|
||||
kfree_sensitive(desc);
|
||||
|
||||
free_tfm:
|
||||
crypto_free_shash(tfm);
|
||||
|
||||
@@ -177,7 +177,7 @@ static int adiantum_setkey(struct crypto_skcipher *tfm, const u8 *key,
|
||||
keyp += NHPOLY1305_KEY_SIZE;
|
||||
WARN_ON(keyp != &data->derived_keys[ARRAY_SIZE(data->derived_keys)]);
|
||||
out:
|
||||
kzfree(data);
|
||||
kfree_sensitive(data);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
|
||||
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
|
||||
memcpy(alignbuffer, key, keylen);
|
||||
ret = tfm->setkey(tfm, alignbuffer, keylen);
|
||||
kzfree(buffer);
|
||||
kfree_sensitive(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ static void ahash_restore_req(struct ahash_request *req, int err)
|
||||
req->priv = NULL;
|
||||
|
||||
/* Free the req->priv.priv from the ADJUSTED request. */
|
||||
kzfree(priv);
|
||||
kfree_sensitive(priv);
|
||||
}
|
||||
|
||||
static void ahash_notify_einprogress(struct ahash_request *req)
|
||||
|
||||
@@ -571,7 +571,7 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
|
||||
alg->cra_exit(tfm);
|
||||
crypto_exit_ops(tfm);
|
||||
crypto_mod_put(alg);
|
||||
kzfree(mem);
|
||||
kfree_sensitive(mem);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
|
||||
}
|
||||
|
||||
error:
|
||||
kzfree(desc);
|
||||
kfree_sensitive(desc);
|
||||
error_no_desc:
|
||||
crypto_free_shash(tfm);
|
||||
kleave(" = %d", ret);
|
||||
@@ -447,6 +447,6 @@ int verify_pefile_signature(const void *pebuf, unsigned pelen,
|
||||
ret = pefile_digest_pe(pebuf, pelen, &ctx);
|
||||
|
||||
error:
|
||||
kzfree(ctx.digest);
|
||||
kfree_sensitive(ctx.digest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ static void __deflate_exit(void *ctx)
|
||||
static void deflate_free_ctx(struct crypto_scomp *tfm, void *ctx)
|
||||
{
|
||||
__deflate_exit(ctx);
|
||||
kzfree(ctx);
|
||||
kfree_sensitive(ctx);
|
||||
}
|
||||
|
||||
static void deflate_exit(struct crypto_tfm *tfm)
|
||||
|
||||
@@ -1218,19 +1218,19 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg)
|
||||
{
|
||||
if (!drbg)
|
||||
return;
|
||||
kzfree(drbg->Vbuf);
|
||||
kfree_sensitive(drbg->Vbuf);
|
||||
drbg->Vbuf = NULL;
|
||||
drbg->V = NULL;
|
||||
kzfree(drbg->Cbuf);
|
||||
kfree_sensitive(drbg->Cbuf);
|
||||
drbg->Cbuf = NULL;
|
||||
drbg->C = NULL;
|
||||
kzfree(drbg->scratchpadbuf);
|
||||
kfree_sensitive(drbg->scratchpadbuf);
|
||||
drbg->scratchpadbuf = NULL;
|
||||
drbg->reseed_ctr = 0;
|
||||
drbg->d_ops = NULL;
|
||||
drbg->core = NULL;
|
||||
if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) {
|
||||
kzfree(drbg->prev);
|
||||
kfree_sensitive(drbg->prev);
|
||||
drbg->prev = NULL;
|
||||
drbg->fips_primed = false;
|
||||
}
|
||||
@@ -1701,7 +1701,7 @@ static int drbg_fini_hash_kernel(struct drbg_state *drbg)
|
||||
struct sdesc *sdesc = (struct sdesc *)drbg->priv_data;
|
||||
if (sdesc) {
|
||||
crypto_free_shash(sdesc->shash.tfm);
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
}
|
||||
drbg->priv_data = NULL;
|
||||
return 0;
|
||||
|
||||
@@ -67,7 +67,7 @@ static u64 *ecc_alloc_digits_space(unsigned int ndigits)
|
||||
|
||||
static void ecc_free_digits_space(u64 *space)
|
||||
{
|
||||
kzfree(space);
|
||||
kfree_sensitive(space);
|
||||
}
|
||||
|
||||
static struct ecc_point *ecc_alloc_point(unsigned int ndigits)
|
||||
@@ -101,9 +101,9 @@ static void ecc_free_point(struct ecc_point *p)
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
kzfree(p->x);
|
||||
kzfree(p->y);
|
||||
kzfree(p);
|
||||
kfree_sensitive(p->x);
|
||||
kfree_sensitive(p->y);
|
||||
kfree_sensitive(p);
|
||||
}
|
||||
|
||||
static void vli_clear(u64 *vli, unsigned int ndigits)
|
||||
|
||||
@@ -124,7 +124,7 @@ static int ecdh_compute_value(struct kpp_request *req)
|
||||
|
||||
/* fall through */
|
||||
free_all:
|
||||
kzfree(shared_secret);
|
||||
kfree_sensitive(shared_secret);
|
||||
free_pubkey:
|
||||
kfree(public_key);
|
||||
return ret;
|
||||
|
||||
@@ -139,7 +139,7 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
|
||||
CRYPTO_TFM_REQ_MASK);
|
||||
err = crypto_ahash_setkey(ghash, (u8 *)&data->hash, sizeof(be128));
|
||||
out:
|
||||
kzfree(data);
|
||||
kfree_sensitive(data);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,8 +304,8 @@ void gf128mul_free_64k(struct gf128mul_64k *t)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
kzfree(t->t[i]);
|
||||
kzfree(t);
|
||||
kfree_sensitive(t->t[i]);
|
||||
kfree_sensitive(t);
|
||||
}
|
||||
EXPORT_SYMBOL(gf128mul_free_64k);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ void *jent_zalloc(unsigned int len)
|
||||
|
||||
void jent_zfree(void *ptr)
|
||||
{
|
||||
kzfree(ptr);
|
||||
kfree_sensitive(ptr);
|
||||
}
|
||||
|
||||
int jent_fips_enabled(void)
|
||||
|
||||
@@ -53,7 +53,7 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
|
||||
err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
|
||||
crypto_stats_rng_seed(alg, err);
|
||||
out:
|
||||
kzfree(buf);
|
||||
kfree_sensitive(buf);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_rng_reset);
|
||||
|
||||
@@ -199,7 +199,7 @@ static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err)
|
||||
sg_copy_from_buffer(req->dst,
|
||||
sg_nents_for_len(req->dst, ctx->key_size),
|
||||
out_buf, ctx->key_size);
|
||||
kzfree(out_buf);
|
||||
kfree_sensitive(out_buf);
|
||||
|
||||
out:
|
||||
req->dst_len = ctx->key_size;
|
||||
@@ -322,7 +322,7 @@ static int pkcs1pad_decrypt_complete(struct akcipher_request *req, int err)
|
||||
out_buf + pos, req->dst_len);
|
||||
|
||||
done:
|
||||
kzfree(req_ctx->out_buf);
|
||||
kfree_sensitive(req_ctx->out_buf);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -500,7 +500,7 @@ static int pkcs1pad_verify_complete(struct akcipher_request *req, int err)
|
||||
req->dst_len) != 0)
|
||||
err = -EKEYREJECTED;
|
||||
done:
|
||||
kzfree(req_ctx->out_buf);
|
||||
kfree_sensitive(req_ctx->out_buf);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
|
||||
memcpy(req->iv, subreq->iv, crypto_aead_ivsize(geniv));
|
||||
|
||||
out:
|
||||
kzfree(subreq->iv);
|
||||
kfree_sensitive(subreq->iv);
|
||||
}
|
||||
|
||||
static void seqiv_aead_encrypt_complete(struct crypto_async_request *base,
|
||||
|
||||
@@ -44,7 +44,7 @@ static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
|
||||
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
|
||||
memcpy(alignbuffer, key, keylen);
|
||||
err = shash->setkey(tfm, alignbuffer, keylen);
|
||||
kzfree(buffer);
|
||||
kfree_sensitive(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -592,7 +592,7 @@ static int skcipher_setkey_unaligned(struct crypto_skcipher *tfm,
|
||||
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
|
||||
memcpy(alignbuffer, key, keylen);
|
||||
ret = cipher->setkey(tfm, alignbuffer, keylen);
|
||||
kzfree(buffer);
|
||||
kfree_sensitive(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1744,7 +1744,7 @@ out:
|
||||
kfree(vec.plaintext);
|
||||
kfree(vec.digest);
|
||||
crypto_free_shash(generic_tfm);
|
||||
kzfree(generic_desc);
|
||||
kfree_sensitive(generic_desc);
|
||||
return err;
|
||||
}
|
||||
#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
|
||||
@@ -3665,7 +3665,7 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
|
||||
if (IS_ERR(drng)) {
|
||||
printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
|
||||
"%s\n", driver);
|
||||
kzfree(buf);
|
||||
kfree_sensitive(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -3712,7 +3712,7 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
|
||||
|
||||
outbuf:
|
||||
crypto_free_rng(drng);
|
||||
kzfree(buf);
|
||||
kfree_sensitive(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ static void __zstd_exit(void *ctx)
|
||||
static void zstd_free_ctx(struct crypto_scomp *tfm, void *ctx)
|
||||
{
|
||||
__zstd_exit(ctx);
|
||||
kzfree(ctx);
|
||||
kfree_sensitive(ctx);
|
||||
}
|
||||
|
||||
static void zstd_exit(struct crypto_tfm *tfm)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user