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>
这个提交包含在:
@@ -138,7 +138,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
|
||||
err_fput:
|
||||
fput(file);
|
||||
err_enckey:
|
||||
kzfree(enckey);
|
||||
kfree_sensitive(enckey);
|
||||
error:
|
||||
memzero_explicit(buf, enclen);
|
||||
kvfree(buf);
|
||||
@@ -155,7 +155,7 @@ void big_key_free_preparse(struct key_preparsed_payload *prep)
|
||||
|
||||
path_put(path);
|
||||
}
|
||||
kzfree(prep->payload.data[big_key_data]);
|
||||
kfree_sensitive(prep->payload.data[big_key_data]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,7 +187,7 @@ void big_key_destroy(struct key *key)
|
||||
path->mnt = NULL;
|
||||
path->dentry = NULL;
|
||||
}
|
||||
kzfree(key->payload.data[big_key_data]);
|
||||
kfree_sensitive(key->payload.data[big_key_data]);
|
||||
key->payload.data[big_key_data] = NULL;
|
||||
}
|
||||
|
||||
|
@@ -58,9 +58,9 @@ error:
|
||||
|
||||
static void dh_free_data(struct dh *dh)
|
||||
{
|
||||
kzfree(dh->key);
|
||||
kzfree(dh->p);
|
||||
kzfree(dh->g);
|
||||
kfree_sensitive(dh->key);
|
||||
kfree_sensitive(dh->p);
|
||||
kfree_sensitive(dh->g);
|
||||
}
|
||||
|
||||
struct dh_completion {
|
||||
@@ -126,7 +126,7 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc)
|
||||
if (sdesc->shash.tfm)
|
||||
crypto_free_shash(sdesc->shash.tfm);
|
||||
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -220,7 +220,7 @@ static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc,
|
||||
ret = -EFAULT;
|
||||
|
||||
err:
|
||||
kzfree(outbuf);
|
||||
kfree_sensitive(outbuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -395,11 +395,11 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
|
||||
out6:
|
||||
kpp_request_free(req);
|
||||
out5:
|
||||
kzfree(outbuf);
|
||||
kfree_sensitive(outbuf);
|
||||
out4:
|
||||
crypto_free_kpp(tfm);
|
||||
out3:
|
||||
kzfree(secret);
|
||||
kfree_sensitive(secret);
|
||||
out2:
|
||||
dh_free_data(&dh_inputs);
|
||||
out1:
|
||||
|
@@ -370,7 +370,7 @@ static int get_derived_key(u8 *derived_key, enum derived_key_type key_type,
|
||||
master_keylen);
|
||||
ret = crypto_shash_tfm_digest(hash_tfm, derived_buf, derived_buf_len,
|
||||
derived_key);
|
||||
kzfree(derived_buf);
|
||||
kfree_sensitive(derived_buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -812,13 +812,13 @@ static int encrypted_instantiate(struct key *key,
|
||||
ret = encrypted_init(epayload, key->description, format, master_desc,
|
||||
decrypted_datalen, hex_encoded_iv);
|
||||
if (ret < 0) {
|
||||
kzfree(epayload);
|
||||
kfree_sensitive(epayload);
|
||||
goto out;
|
||||
}
|
||||
|
||||
rcu_assign_keypointer(key, epayload);
|
||||
out:
|
||||
kzfree(datablob);
|
||||
kfree_sensitive(datablob);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -827,7 +827,7 @@ static void encrypted_rcu_free(struct rcu_head *rcu)
|
||||
struct encrypted_key_payload *epayload;
|
||||
|
||||
epayload = container_of(rcu, struct encrypted_key_payload, rcu);
|
||||
kzfree(epayload);
|
||||
kfree_sensitive(epayload);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -885,7 +885,7 @@ static int encrypted_update(struct key *key, struct key_preparsed_payload *prep)
|
||||
rcu_assign_keypointer(key, new_epayload);
|
||||
call_rcu(&epayload->rcu, encrypted_rcu_free);
|
||||
out:
|
||||
kzfree(buf);
|
||||
kfree_sensitive(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -946,7 +946,7 @@ static long encrypted_read(const struct key *key, char *buffer,
|
||||
memzero_explicit(derived_key, sizeof(derived_key));
|
||||
|
||||
memcpy(buffer, ascii_buf, asciiblob_len);
|
||||
kzfree(ascii_buf);
|
||||
kfree_sensitive(ascii_buf);
|
||||
|
||||
return asciiblob_len;
|
||||
out:
|
||||
@@ -961,7 +961,7 @@ out:
|
||||
*/
|
||||
static void encrypted_destroy(struct key *key)
|
||||
{
|
||||
kzfree(key->payload.data[0]);
|
||||
kfree_sensitive(key->payload.data[0]);
|
||||
}
|
||||
|
||||
struct key_type key_type_encrypted = {
|
||||
|
@@ -68,7 +68,7 @@ static int TSS_sha1(const unsigned char *data, unsigned int datalen,
|
||||
}
|
||||
|
||||
ret = crypto_shash_digest(&sdesc->shash, data, datalen, digest);
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
|
||||
if (!ret)
|
||||
ret = crypto_shash_final(&sdesc->shash, digest);
|
||||
out:
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ int TSS_authhmac(unsigned char *digest, const unsigned char *key,
|
||||
paramdigest, TPM_NONCE_SIZE, h1,
|
||||
TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
|
||||
out:
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(TSS_authhmac);
|
||||
@@ -251,7 +251,7 @@ int TSS_checkhmac1(unsigned char *buffer,
|
||||
if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE))
|
||||
ret = -EINVAL;
|
||||
out:
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(TSS_checkhmac1);
|
||||
@@ -353,7 +353,7 @@ static int TSS_checkhmac2(unsigned char *buffer,
|
||||
if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE))
|
||||
ret = -EINVAL;
|
||||
out:
|
||||
kzfree(sdesc);
|
||||
kfree_sensitive(sdesc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
|
||||
*bloblen = storedsize;
|
||||
}
|
||||
out:
|
||||
kzfree(td);
|
||||
kfree_sensitive(td);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1031,12 +1031,12 @@ static int trusted_instantiate(struct key *key,
|
||||
if (!ret && options->pcrlock)
|
||||
ret = pcrlock(options->pcrlock);
|
||||
out:
|
||||
kzfree(datablob);
|
||||
kzfree(options);
|
||||
kfree_sensitive(datablob);
|
||||
kfree_sensitive(options);
|
||||
if (!ret)
|
||||
rcu_assign_keypointer(key, payload);
|
||||
else
|
||||
kzfree(payload);
|
||||
kfree_sensitive(payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1045,7 +1045,7 @@ static void trusted_rcu_free(struct rcu_head *rcu)
|
||||
struct trusted_key_payload *p;
|
||||
|
||||
p = container_of(rcu, struct trusted_key_payload, rcu);
|
||||
kzfree(p);
|
||||
kfree_sensitive(p);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1087,13 +1087,13 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
|
||||
ret = datablob_parse(datablob, new_p, new_o);
|
||||
if (ret != Opt_update) {
|
||||
ret = -EINVAL;
|
||||
kzfree(new_p);
|
||||
kfree_sensitive(new_p);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!new_o->keyhandle) {
|
||||
ret = -EINVAL;
|
||||
kzfree(new_p);
|
||||
kfree_sensitive(new_p);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1107,22 +1107,22 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
|
||||
ret = key_seal(new_p, new_o);
|
||||
if (ret < 0) {
|
||||
pr_info("trusted_key: key_seal failed (%d)\n", ret);
|
||||
kzfree(new_p);
|
||||
kfree_sensitive(new_p);
|
||||
goto out;
|
||||
}
|
||||
if (new_o->pcrlock) {
|
||||
ret = pcrlock(new_o->pcrlock);
|
||||
if (ret < 0) {
|
||||
pr_info("trusted_key: pcrlock failed (%d)\n", ret);
|
||||
kzfree(new_p);
|
||||
kfree_sensitive(new_p);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
rcu_assign_keypointer(key, new_p);
|
||||
call_rcu(&p->rcu, trusted_rcu_free);
|
||||
out:
|
||||
kzfree(datablob);
|
||||
kzfree(new_o);
|
||||
kfree_sensitive(datablob);
|
||||
kfree_sensitive(new_o);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1154,7 +1154,7 @@ static long trusted_read(const struct key *key, char *buffer,
|
||||
*/
|
||||
static void trusted_destroy(struct key *key)
|
||||
{
|
||||
kzfree(key->payload.data[0]);
|
||||
kfree_sensitive(key->payload.data[0]);
|
||||
}
|
||||
|
||||
struct key_type key_type_trusted = {
|
||||
|
@@ -82,7 +82,7 @@ EXPORT_SYMBOL_GPL(user_preparse);
|
||||
*/
|
||||
void user_free_preparse(struct key_preparsed_payload *prep)
|
||||
{
|
||||
kzfree(prep->payload.data[0]);
|
||||
kfree_sensitive(prep->payload.data[0]);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(user_free_preparse);
|
||||
|
||||
@@ -91,7 +91,7 @@ static void user_free_payload_rcu(struct rcu_head *head)
|
||||
struct user_key_payload *payload;
|
||||
|
||||
payload = container_of(head, struct user_key_payload, rcu);
|
||||
kzfree(payload);
|
||||
kfree_sensitive(payload);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -147,7 +147,7 @@ void user_destroy(struct key *key)
|
||||
{
|
||||
struct user_key_payload *upayload = key->payload.data[0];
|
||||
|
||||
kzfree(upayload);
|
||||
kfree_sensitive(upayload);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(user_destroy);
|
||||
|
在新工单中引用
屏蔽一个用户