Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit453431a

Browse files
Waiman-Longtorvalds
authored andcommitted
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 informationthat should not be leaked to other future users of the same memoryobjects.Rename kzfree() to kfree_sensitive() to follow the example of the recentlyadded kvfree_sensitive() and make the intention of the API more explicit.In addition, memzero_explicit() is used to clear the memory to make surethat 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 addinga 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.comSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent57c720d commit453431a

File tree

114 files changed

+323
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+323
-320
lines changed

‎arch/s390/crypto/prng.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void prng_tdes_deinstantiate(void)
249249
{
250250
pr_debug("The prng module stopped "
251251
"after running in triple DES mode\n");
252-
kzfree(prng_data);
252+
kfree_sensitive(prng_data);
253253
}
254254

255255

@@ -442,7 +442,7 @@ static int __init prng_sha512_instantiate(void)
442442
staticvoidprng_sha512_deinstantiate(void)
443443
{
444444
pr_debug("The prng module stopped after running in SHA-512 mode\n");
445-
kzfree(prng_data);
445+
kfree_sensitive(prng_data);
446446
}
447447

448448

‎arch/x86/power/hibernate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int get_e820_md5(struct e820_table *table, void *buf)
9898
if (crypto_shash_digest(desc, (u8*)table,size,buf))
9999
ret=-EINVAL;
100100

101-
kzfree(desc);
101+
kfree_sensitive(desc);
102102

103103
free_tfm:
104104
crypto_free_shash(tfm);

‎crypto/adiantum.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int adiantum_setkey(struct crypto_skcipher *tfm, const u8 *key,
177177
keyp+=NHPOLY1305_KEY_SIZE;
178178
WARN_ON(keyp!=&data->derived_keys[ARRAY_SIZE(data->derived_keys)]);
179179
out:
180-
kzfree(data);
180+
kfree_sensitive(data);
181181
returnerr;
182182
}
183183

‎crypto/ahash.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
183183
alignbuffer= (u8*)ALIGN((unsigned long)buffer,alignmask+1);
184184
memcpy(alignbuffer,key,keylen);
185185
ret=tfm->setkey(tfm,alignbuffer,keylen);
186-
kzfree(buffer);
186+
kfree_sensitive(buffer);
187187
returnret;
188188
}
189189

@@ -302,7 +302,7 @@ static void ahash_restore_req(struct ahash_request *req, int err)
302302
req->priv=NULL;
303303

304304
/* Free the req->priv.priv from the ADJUSTED request. */
305-
kzfree(priv);
305+
kfree_sensitive(priv);
306306
}
307307

308308
staticvoidahash_notify_einprogress(structahash_request*req)

‎crypto/api.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
571571
alg->cra_exit(tfm);
572572
crypto_exit_ops(tfm);
573573
crypto_mod_put(alg);
574-
kzfree(mem);
574+
kfree_sensitive(mem);
575575
}
576576
EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
577577

‎crypto/asymmetric_keys/verify_pefile.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
376376
}
377377

378378
error:
379-
kzfree(desc);
379+
kfree_sensitive(desc);
380380
error_no_desc:
381381
crypto_free_shash(tfm);
382382
kleave(" = %d",ret);
@@ -447,6 +447,6 @@ int verify_pefile_signature(const void *pebuf, unsigned pelen,
447447
ret=pefile_digest_pe(pebuf,pelen,&ctx);
448448

449449
error:
450-
kzfree(ctx.digest);
450+
kfree_sensitive(ctx.digest);
451451
returnret;
452452
}

‎crypto/deflate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static void __deflate_exit(void *ctx)
163163
staticvoiddeflate_free_ctx(structcrypto_scomp*tfm,void*ctx)
164164
{
165165
__deflate_exit(ctx);
166-
kzfree(ctx);
166+
kfree_sensitive(ctx);
167167
}
168168

169169
staticvoiddeflate_exit(structcrypto_tfm*tfm)

‎crypto/drbg.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,19 +1218,19 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg)
12181218
{
12191219
if (!drbg)
12201220
return;
1221-
kzfree(drbg->Vbuf);
1221+
kfree_sensitive(drbg->Vbuf);
12221222
drbg->Vbuf=NULL;
12231223
drbg->V=NULL;
1224-
kzfree(drbg->Cbuf);
1224+
kfree_sensitive(drbg->Cbuf);
12251225
drbg->Cbuf=NULL;
12261226
drbg->C=NULL;
1227-
kzfree(drbg->scratchpadbuf);
1227+
kfree_sensitive(drbg->scratchpadbuf);
12281228
drbg->scratchpadbuf=NULL;
12291229
drbg->reseed_ctr=0;
12301230
drbg->d_ops=NULL;
12311231
drbg->core=NULL;
12321232
if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) {
1233-
kzfree(drbg->prev);
1233+
kfree_sensitive(drbg->prev);
12341234
drbg->prev=NULL;
12351235
drbg->fips_primed= false;
12361236
}
@@ -1701,7 +1701,7 @@ static int drbg_fini_hash_kernel(struct drbg_state *drbg)
17011701
structsdesc*sdesc= (structsdesc*)drbg->priv_data;
17021702
if (sdesc) {
17031703
crypto_free_shash(sdesc->shash.tfm);
1704-
kzfree(sdesc);
1704+
kfree_sensitive(sdesc);
17051705
}
17061706
drbg->priv_data=NULL;
17071707
return0;

‎crypto/ecc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static u64 *ecc_alloc_digits_space(unsigned int ndigits)
6767

6868
staticvoidecc_free_digits_space(u64*space)
6969
{
70-
kzfree(space);
70+
kfree_sensitive(space);
7171
}
7272

7373
staticstructecc_point*ecc_alloc_point(unsignedintndigits)
@@ -101,9 +101,9 @@ static void ecc_free_point(struct ecc_point *p)
101101
if (!p)
102102
return;
103103

104-
kzfree(p->x);
105-
kzfree(p->y);
106-
kzfree(p);
104+
kfree_sensitive(p->x);
105+
kfree_sensitive(p->y);
106+
kfree_sensitive(p);
107107
}
108108

109109
staticvoidvli_clear(u64*vli,unsignedintndigits)

‎crypto/ecdh.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int ecdh_compute_value(struct kpp_request *req)
124124

125125
/* fall through */
126126
free_all:
127-
kzfree(shared_secret);
127+
kfree_sensitive(shared_secret);
128128
free_pubkey:
129129
kfree(public_key);
130130
returnret;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp