mm, treewide: Rename kzfree() to kfree_sensitive()
Subsystems (69)
cover mm, treewide: Rename kzfree() to kfree_sensitive()
This patchset makes a global rename of the kzfree() to kfree_sensitive() to highlight the fact buffer clearing is only needed if the data objects contain sensitive information like encrpytion key. The fact that kzfree() uses memset() to do the clearing isn't totally safe either as compiler may compile out the clearing in their optimizer. Instead, the new kfree_sensitive() uses memzero_explicit() which won't get compiled out.
Waiman Long (2):
mm, treewide: Rename kzfree() to kfree_sensitive()
crypto: Remove unnecessary memzero_explicit()
arch/s390/crypto/prng.c | 4 +-- arch/x86/power/hibernate.c | 2 +- crypto/adiantum.c | 2 +- crypto/ahash.c | 4 +-- crypto/api.c | 2 +- crypto/asymmetric_keys/verify_pefile.c | 4 +-- crypto/deflate.c | 2 +- crypto/drbg.c | 10 +++--- crypto/ecc.c | 8 ++--- crypto/ecdh.c | 2 +- crypto/gcm.c | 2 +- crypto/gf128mul.c | 4 +-- crypto/jitterentropy-kcapi.c | 2 +- crypto/rng.c | 2 +- crypto/rsa-pkcs1pad.c | 6 ++-- crypto/seqiv.c | 2 +- crypto/shash.c | 2 +- crypto/skcipher.c | 2 +- crypto/testmgr.c | 6 ++-- crypto/zstd.c | 2 +- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 17 +++------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 18 +++------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 14 +++----- drivers/crypto/atmel-ecc.c | 2 +- drivers/crypto/caam/caampkc.c | 28 +++++++-------- drivers/crypto/cavium/cpt/cptvf_main.c | 6 ++-- drivers/crypto/cavium/cpt/cptvf_reqmanager.c | 12 +++---- drivers/crypto/cavium/nitrox/nitrox_lib.c | 4 +-- drivers/crypto/cavium/zip/zip_crypto.c | 6 ++-- drivers/crypto/ccp/ccp-crypto-rsa.c | 6 ++-- drivers/crypto/ccree/cc_aead.c | 4 +-- drivers/crypto/ccree/cc_buffer_mgr.c | 4 +-- drivers/crypto/ccree/cc_cipher.c | 6 ++-- drivers/crypto/ccree/cc_hash.c | 8 ++--- drivers/crypto/ccree/cc_request_mgr.c | 2 +- drivers/crypto/inside-secure/safexcel_hash.c | 3 +- drivers/crypto/marvell/cesa/hash.c | 2 +- .../crypto/marvell/octeontx/otx_cptvf_main.c | 6 ++-- .../marvell/octeontx/otx_cptvf_reqmgr.h | 2 +- drivers/crypto/mediatek/mtk-aes.c | 2 +- drivers/crypto/nx/nx.c | 4 +-- drivers/crypto/virtio/virtio_crypto_algs.c | 12 +++---- drivers/crypto/virtio/virtio_crypto_core.c | 2 +- drivers/md/dm-crypt.c | 34 +++++++++---------- drivers/md/dm-integrity.c | 6 ++-- drivers/misc/ibmvmc.c | 6 ++-- .../hisilicon/hns3/hns3pf/hclge_mbx.c | 2 +- .../net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 6 ++-- drivers/net/ppp/ppp_mppe.c | 6 ++-- drivers/net/wireguard/noise.c | 4 +-- drivers/net/wireguard/peer.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 6 ++-- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 6 ++-- drivers/net/wireless/intersil/orinoco/wext.c | 4 +-- drivers/s390/crypto/ap_bus.h | 4 +-- drivers/staging/ks7010/ks_hostif.c | 2 +- drivers/staging/rtl8723bs/core/rtw_security.c | 2 +- drivers/staging/wlan-ng/p80211netdev.c | 2 +- drivers/target/iscsi/iscsi_target_auth.c | 2 +- fs/btrfs/ioctl.c | 2 +- fs/cifs/cifsencrypt.c | 2 +- fs/cifs/connect.c | 10 +++--- fs/cifs/dfs_cache.c | 2 +- fs/cifs/misc.c | 8 ++--- fs/crypto/keyring.c | 6 ++-- fs/crypto/keysetup_v1.c | 4 +-- fs/ecryptfs/keystore.c | 4 +-- fs/ecryptfs/messaging.c | 2 +- include/crypto/aead.h | 2 +- include/crypto/akcipher.h | 2 +- include/crypto/gf128mul.h | 2 +- include/crypto/hash.h | 2 +- include/crypto/internal/acompress.h | 2 +- include/crypto/kpp.h | 2 +- include/crypto/skcipher.h | 2 +- include/linux/slab.h | 2 +- lib/mpi/mpiutil.c | 6 ++-- lib/test_kasan.c | 6 ++-- mm/slab_common.c | 10 +++--- net/atm/mpoa_caches.c | 4 +-- net/bluetooth/ecdh_helper.c | 6 ++-- net/bluetooth/smp.c | 24 ++++++------- net/core/sock.c | 2 +- net/ipv4/tcp_fastopen.c | 2 +- net/mac80211/aead_api.c | 4 +-- net/mac80211/aes_gmac.c | 2 +- net/mac80211/key.c | 2 +- net/mac802154/llsec.c | 20 +++++------ net/sctp/auth.c | 2 +- net/sctp/socket.c | 2 +- net/sunrpc/auth_gss/gss_krb5_crypto.c | 4 +-- net/sunrpc/auth_gss/gss_krb5_keys.c | 6 ++-- net/sunrpc/auth_gss/gss_krb5_mech.c | 2 +- net/tipc/crypto.c | 10 +++--- net/wireless/core.c | 2 +- net/wireless/ibss.c | 4 +-- net/wireless/lib80211_crypt_tkip.c | 2 +- net/wireless/lib80211_crypt_wep.c | 2 +- net/wireless/nl80211.c | 24 ++++++------- net/wireless/sme.c | 6 ++-- net/wireless/util.c | 2 +- net/wireless/wext-sme.c | 2 +- scripts/coccinelle/free/devm_free.cocci | 4 +-- scripts/coccinelle/free/ifnullfree.cocci | 4 +-- scripts/coccinelle/free/kfree.cocci | 6 ++-- scripts/coccinelle/free/kfreeaddr.cocci | 2 +- security/apparmor/domain.c | 4 +-- security/apparmor/include/file.h | 2 +- security/apparmor/policy.c | 24 ++++++------- security/apparmor/policy_ns.c | 6 ++-- security/apparmor/policy_unpack.c | 14 ++++---- security/keys/big_key.c | 6 ++-- security/keys/dh.c | 14 ++++---- security/keys/encrypted-keys/encrypted.c | 14 ++++---- security/keys/trusted-keys/trusted_tpm1.c | 34 +++++++++---------- security/keys/user_defined.c | 6 ++-- 117 files changed, 332 insertions(+), 358 deletions(-)
Signature · 1 line
2.18.1
PATCH 1/2 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/\bkzfree\b/kfree_sensitive/'
followed by some editing of the kfree_sensitive() kerneldoc and the use of memzero_explicit() instead of memset().
--- arch/s390/crypto/prng.c | 4 +-- arch/x86/power/hibernate.c | 2 +- crypto/adiantum.c | 2 +- crypto/ahash.c | 4 +-- crypto/api.c | 2 +- crypto/asymmetric_keys/verify_pefile.c | 4 +-- crypto/deflate.c | 2 +- crypto/drbg.c | 10 +++--- crypto/ecc.c | 8 ++--- crypto/ecdh.c | 2 +- crypto/gcm.c | 2 +- crypto/gf128mul.c | 4 +-- crypto/jitterentropy-kcapi.c | 2 +- crypto/rng.c | 2 +- crypto/rsa-pkcs1pad.c | 6 ++-- crypto/seqiv.c | 2 +- crypto/shash.c | 2 +- crypto/skcipher.c | 2 +- crypto/testmgr.c | 6 ++-- crypto/zstd.c | 2 +- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 2 +- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 4 +-- drivers/crypto/atmel-ecc.c | 2 +- drivers/crypto/caam/caampkc.c | 28 +++++++-------- drivers/crypto/cavium/cpt/cptvf_main.c | 6 ++-- drivers/crypto/cavium/cpt/cptvf_reqmanager.c | 12 +++---- drivers/crypto/cavium/nitrox/nitrox_lib.c | 4 +-- drivers/crypto/cavium/zip/zip_crypto.c | 6 ++-- drivers/crypto/ccp/ccp-crypto-rsa.c | 6 ++-- drivers/crypto/ccree/cc_aead.c | 4 +-- drivers/crypto/ccree/cc_buffer_mgr.c | 4 +-- drivers/crypto/ccree/cc_cipher.c | 6 ++-- drivers/crypto/ccree/cc_hash.c | 8 ++--- drivers/crypto/ccree/cc_request_mgr.c | 2 +- drivers/crypto/marvell/cesa/hash.c | 2 +- .../crypto/marvell/octeontx/otx_cptvf_main.c | 6 ++-- .../marvell/octeontx/otx_cptvf_reqmgr.h | 2 +- drivers/crypto/mediatek/mtk-aes.c | 2 +- drivers/crypto/nx/nx.c | 4 +-- drivers/crypto/virtio/virtio_crypto_algs.c | 12 +++---- drivers/crypto/virtio/virtio_crypto_core.c | 2 +- drivers/md/dm-crypt.c | 34 +++++++++---------- drivers/md/dm-integrity.c | 6 ++-- drivers/misc/ibmvmc.c | 6 ++-- .../hisilicon/hns3/hns3pf/hclge_mbx.c | 2 +- .../net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 6 ++-- drivers/net/ppp/ppp_mppe.c | 6 ++-- drivers/net/wireguard/noise.c | 4 +-- drivers/net/wireguard/peer.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 6 ++-- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 6 ++-- drivers/net/wireless/intersil/orinoco/wext.c | 4 +-- drivers/s390/crypto/ap_bus.h | 4 +-- drivers/staging/ks7010/ks_hostif.c | 2 +- drivers/staging/rtl8723bs/core/rtw_security.c | 2 +- drivers/staging/wlan-ng/p80211netdev.c | 2 +- drivers/target/iscsi/iscsi_target_auth.c | 2 +- fs/btrfs/ioctl.c | 2 +- fs/cifs/cifsencrypt.c | 2 +- fs/cifs/connect.c | 10 +++--- fs/cifs/dfs_cache.c | 2 +- fs/cifs/misc.c | 8 ++--- fs/crypto/keyring.c | 6 ++-- fs/crypto/keysetup_v1.c | 4 +-- fs/ecryptfs/keystore.c | 4 +-- fs/ecryptfs/messaging.c | 2 +- include/crypto/aead.h | 2 +- include/crypto/akcipher.h | 2 +- include/crypto/gf128mul.h | 2 +- include/crypto/hash.h | 2 +- include/crypto/internal/acompress.h | 2 +- include/crypto/kpp.h | 2 +- include/crypto/skcipher.h | 2 +- include/linux/slab.h | 2 +- lib/mpi/mpiutil.c | 6 ++-- lib/test_kasan.c | 6 ++-- mm/slab_common.c | 10 +++--- net/atm/mpoa_caches.c | 4 +-- net/bluetooth/ecdh_helper.c | 6 ++-- net/bluetooth/smp.c | 24 ++++++------- net/core/sock.c | 2 +- net/ipv4/tcp_fastopen.c | 2 +- net/mac80211/aead_api.c | 4 +-- net/mac80211/aes_gmac.c | 2 +- net/mac80211/key.c | 2 +- net/mac802154/llsec.c | 20 +++++------ net/sctp/auth.c | 2 +- net/sctp/socket.c | 2 +- net/sunrpc/auth_gss/gss_krb5_crypto.c | 4 +-- net/sunrpc/auth_gss/gss_krb5_keys.c | 6 ++-- net/sunrpc/auth_gss/gss_krb5_mech.c | 2 +- net/tipc/crypto.c | 10 +++--- net/wireless/core.c | 2 +- net/wireless/ibss.c | 4 +-- net/wireless/lib80211_crypt_tkip.c | 2 +- net/wireless/lib80211_crypt_wep.c | 2 +- net/wireless/nl80211.c | 24 ++++++------- net/wireless/sme.c | 6 ++-- net/wireless/util.c | 2 +- net/wireless/wext-sme.c | 2 +- scripts/coccinelle/free/devm_free.cocci | 4 +-- scripts/coccinelle/free/ifnullfree.cocci | 4 +-- scripts/coccinelle/free/kfree.cocci | 6 ++-- scripts/coccinelle/free/kfreeaddr.cocci | 2 +- security/apparmor/domain.c | 4 +-- security/apparmor/include/file.h | 2 +- security/apparmor/policy.c | 24 ++++++------- security/apparmor/policy_ns.c | 6 ++-- security/apparmor/policy_unpack.c | 14 ++++---- security/keys/big_key.c | 6 ++-- security/keys/dh.c | 14 ++++---- security/keys/encrypted-keys/encrypted.c | 14 ++++---- security/keys/trusted-keys/trusted_tpm1.c | 34 +++++++++---------- security/keys/user_defined.c | 6 ++-- 116 files changed, 323 insertions(+), 323 deletions(-)
arch/s390/crypto/prng.c +2 -2
@@ -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 @@ static int __init prng_sha512_instantiate(void)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); }
arch/x86/power/hibernate.c +1 -1
@@ -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);
crypto/adiantum.c +1 -1
@@ -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; }
crypto/ahash.c +2 -2
@@ -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)
crypto/api.c +1 -1
@@ -564,7 +564,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);
crypto/asymmetric_keys/verify_pefile.c +2 -2
@@ -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; }
crypto/deflate.c +1 -1
@@ -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)
crypto/drbg.c +5 -5
@@ -1206,19 +1206,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; }
@@ -1685,7 +1685,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 ;
crypto/ecc.c +4 -4
@@ -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)
crypto/ecdh.c +1 -1
@@ -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;
crypto/gcm.c +1 -1
@@ -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; }
crypto/gf128mul.c +2 -2
@@ -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);
crypto/jitterentropy-kcapi.c +1 -1
@@ -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 )
crypto/rng.c +1 -1
@@ -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);
crypto/rsa-pkcs1pad.c +3 -3
@@ -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; }
crypto/seqiv.c +1 -1
@@ -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,
crypto/shash.c +1 -1
@@ -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; }
crypto/skcipher.c +1 -1
@@ -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; }
crypto/testmgr.c +3 -3
@@ -1744,7 +1744,7 @@ static int test_hash_vs_generic_impl(const char *driver,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; }
crypto/zstd.c +1 -1
@@ -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)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1 -1
@@ -257,7 +257,7 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &CE_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -kzfree (backup_iv); +kfree_sensitive (backup_iv); }else {scatterwalk_map_and_copy (areq->iv, areq->dst, offset, ivsize,0 );
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +1 -1
@@ -250,7 +250,7 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize);memzero_explicit (backup_iv, ivsize); -kzfree (backup_iv); +kfree_sensitive (backup_iv); }else {scatterwalk_map_and_copy (areq->iv, areq->dst, offset, ivsize,0 );
drivers/crypto/amlogic/amlogic-gxl-cipher.c +2 -2
@@ -254,8 +254,8 @@ static int meson_cipher(struct skcipher_request *areq) } } theend: -kzfree (bkeyiv); -kzfree (backup_iv); +kfree_sensitive (bkeyiv); +kfree_sensitive (backup_iv);return err; }
drivers/crypto/atmel-ecc.c +1 -1
@@ -69,7 +69,7 @@ static void atmel_ecdh_done(struct atmel_i2c_work_data *work_data, void *areq,/* fall through */ free_work_data: -kzfree (work_data); +kfree_sensitive (work_data);kpp_request_complete (req, status); }
drivers/crypto/caam/caampkc.c +14 -14
@@ -850,14 +850,14 @@ static int caam_rsa_dec(struct akcipher_request *req)static void caam_rsa_free_key (struct caam_rsa_key *key) { -kzfree (key->d); -kzfree (key->p); -kzfree (key->q); -kzfree (key->dp); -kzfree (key->dq); -kzfree (key->qinv); -kzfree (key->tmp1); -kzfree (key->tmp2); +kfree_sensitive (key->d); +kfree_sensitive (key->p); +kfree_sensitive (key->q); +kfree_sensitive (key->dp); +kfree_sensitive (key->dq); +kfree_sensitive (key->qinv); +kfree_sensitive (key->tmp1); +kfree_sensitive (key->tmp2);kfree (key->e);kfree (key->n);memset (key,0 ,sizeof (*key));
@@ -1014,17 +1014,17 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,return ; free_dq: -kzfree (rsa_key->dq); +kfree_sensitive (rsa_key->dq); free_dp: -kzfree (rsa_key->dp); +kfree_sensitive (rsa_key->dp); free_tmp2: -kzfree (rsa_key->tmp2); +kfree_sensitive (rsa_key->tmp2); free_tmp1: -kzfree (rsa_key->tmp1); +kfree_sensitive (rsa_key->tmp1); free_q: -kzfree (rsa_key->q); +kfree_sensitive (rsa_key->q); free_p: -kzfree (rsa_key->p); +kfree_sensitive (rsa_key->p); } static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
drivers/crypto/cavium/cpt/cptvf_main.c +3 -3
@@ -74,7 +74,7 @@ static void cleanup_worker_threads(struct cpt_vf *cptvf)for (i =0 ; i < cptvf->nr_queues; i++)tasklet_kill (&cwqe_info->vq_wqe[i].twork); -kzfree (cwqe_info); +kfree_sensitive (cwqe_info); cptvf->wqe_info =NULL ; }
@@ -88,7 +88,7 @@ static void free_pending_queues(struct pending_qinfo *pqinfo)continue ;/* free single queue */ -kzfree ((queue->head)); +kfree_sensitive ((queue->head)); queue->front =0 ; queue->rear =0 ;
@@ -189,7 +189,7 @@ static void free_command_queues(struct cpt_vf *cptvf, chunk->head =NULL ; chunk->dma_addr =0 ;hlist_del (&chunk->nextchunk); -kzfree (chunk); +kfree_sensitive (chunk); } queue->nchunks =0 ;
drivers/crypto/cavium/cpt/cptvf_reqmanager.c +6 -6
@@ -305,12 +305,12 @@ static void do_request_cleanup(struct cpt_vf *cptvf, } } -kzfree (info->scatter_components); -kzfree (info->gather_components); -kzfree (info->out_buffer); -kzfree (info->in_buffer); -kzfree ((void *)info->completion_addr); -kzfree (info); +kfree_sensitive (info->scatter_components); +kfree_sensitive (info->gather_components); +kfree_sensitive (info->out_buffer); +kfree_sensitive (info->in_buffer); +kfree_sensitive ((void *)info->completion_addr); +kfree_sensitive (info); }static void do_post_process (struct cpt_vf *cptvf,struct cpt_info_buffer *info)
drivers/crypto/cavium/nitrox/nitrox_lib.c +2 -2
@@ -90,7 +90,7 @@ static void nitrox_free_aqm_queues(struct nitrox_device *ndev)for (i =0 ; i < ndev->nr_queues; i++) {nitrox_cmdq_cleanup (ndev->aqmq[i]); -kzfree (ndev->aqmq[i]); +kfree_sensitive (ndev->aqmq[i]); ndev->aqmq[i] =NULL ; } }
@@ -122,7 +122,7 @@ static int nitrox_alloc_aqm_queues(struct nitrox_device *ndev) err =nitrox_cmdq_init (cmdq,AQM_Q_ALIGN_BYTES );if (err) { -kzfree (cmdq); +kfree_sensitive (cmdq); goto aqmq_fail; } ndev->aqmq[i] = cmdq;
drivers/crypto/cavium/zip/zip_crypto.c +3 -3
@@ -260,7 +260,7 @@ void *zip_alloc_scomp_ctx_deflate(struct crypto_scomp *tfm) ret =zip_ctx_init (zip_ctx,0 );if (ret) { -kzfree (zip_ctx); +kfree_sensitive (zip_ctx);return ERR_PTR (ret); }
@@ -279,7 +279,7 @@ void *zip_alloc_scomp_ctx_lzs(struct crypto_scomp *tfm) ret =zip_ctx_init (zip_ctx,1 );if (ret) { -kzfree (zip_ctx); +kfree_sensitive (zip_ctx);return ERR_PTR (ret); }
@@ -291,7 +291,7 @@ void zip_free_scomp_ctx(struct crypto_scomp *tfm, void *ctx)struct zip_kernel_ctx *zip_ctx = ctx;zip_ctx_exit (zip_ctx); -kzfree (zip_ctx); +kfree_sensitive (zip_ctx); } int zip_scomp_compress(struct crypto_scomp *tfm,
drivers/crypto/ccp/ccp-crypto-rsa.c +3 -3
@@ -112,13 +112,13 @@ static int ccp_check_key_length(unsigned int len)static void ccp_rsa_free_key_bufs (struct ccp_ctx *ctx) {/* Clean up old key data */ -kzfree (ctx->u.rsa.e_buf); +kfree_sensitive (ctx->u.rsa.e_buf); ctx->u.rsa.e_buf =NULL ; ctx->u.rsa.e_len =0 ; -kzfree (ctx->u.rsa.n_buf); +kfree_sensitive (ctx->u.rsa.n_buf); ctx->u.rsa.n_buf =NULL ; ctx->u.rsa.n_len =0 ; -kzfree (ctx->u.rsa.d_buf); +kfree_sensitive (ctx->u.rsa.d_buf); ctx->u.rsa.d_buf =NULL ; ctx->u.rsa.d_len =0 ; }
drivers/crypto/ccree/cc_aead.c +2 -2
@@ -448,7 +448,7 @@ static int cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *authkey,if (dma_mapping_error (dev, key_dma_addr)) {dev_err (dev,"Mapping key va=0x%p len=%u for DMA failed\n" , key, keylen); -kzfree (key); +kfree_sensitive (key);return -ENOMEM ; }if (keylen > blocksize) {
@@ -533,7 +533,7 @@ static int cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *authkey,if (key_dma_addr)dma_unmap_single (dev, key_dma_addr, keylen,DMA_TO_DEVICE ); -kzfree (key); +kfree_sensitive (key);return rc; }
drivers/crypto/ccree/cc_buffer_mgr.c +2 -2
@@ -488,7 +488,7 @@ void cc_unmap_aead_request(struct device *dev, struct aead_request *req)if (areq_ctx->gen_ctx.iv_dma_addr) {dma_unmap_single (dev, areq_ctx->gen_ctx.iv_dma_addr, hw_iv_size,DMA_BIDIRECTIONAL ); -kzfree (areq_ctx->gen_ctx.iv); +kfree_sensitive (areq_ctx->gen_ctx.iv); }/* Release pool */
@@ -559,7 +559,7 @@ static int cc_aead_chain_iv(struct cc_drvdata *drvdata,if (dma_mapping_error (dev, areq_ctx->gen_ctx.iv_dma_addr)) {dev_err (dev,"Mapping iv %u B at va=%pK for DMA failed\n" , hw_iv_size, req->iv); -kzfree (areq_ctx->gen_ctx.iv); +kfree_sensitive (areq_ctx->gen_ctx.iv); areq_ctx->gen_ctx.iv =NULL ; rc = -ENOMEM ; goto chain_iv_exit;
drivers/crypto/ccree/cc_cipher.c +3 -3
@@ -229,7 +229,7 @@ static void cc_cipher_exit(struct crypto_tfm *tfm) &ctx_p->user.key_dma_addr);/* Free key buffer in context */ -kzfree (ctx_p->user.key); +kfree_sensitive (ctx_p->user.key);dev_dbg (dev,"Free key buffer in context. key=@%p\n" , ctx_p->user.key); }
@@ -828,7 +828,7 @@ static void cc_cipher_complete(struct device *dev, void *cc_req, int err)/* Not a BACKLOG notification */ cc_unmap_cipher_request (dev, req_ctx, ivsize, src, dst);memcpy (req->iv, req_ctx->iv, ivsize); -kzfree (req_ctx->iv); +kfree_sensitive (req_ctx->iv); }skcipher_request_complete (req, err);
@@ -930,7 +930,7 @@ static int cc_cipher_process(struct skcipher_request *req, exit_process:if (rc != -EINPROGRESS && rc != -EBUSY ) { -kzfree (req_ctx->iv); +kfree_sensitive (req_ctx->iv); }return rc;
drivers/crypto/ccree/cc_hash.c +4 -4
@@ -764,7 +764,7 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key,if (dma_mapping_error (dev, ctx->key_params.key_dma_addr)) {dev_err (dev,"Mapping key va=0x%p len=%u for DMA failed\n" , ctx->key_params.key, keylen); -kzfree (ctx->key_params.key); +kfree_sensitive (ctx->key_params.key);return -ENOMEM ; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
@@ -913,7 +913,7 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key, &ctx->key_params.key_dma_addr, ctx->key_params.keylen); } -kzfree (ctx->key_params.key); +kfree_sensitive (ctx->key_params.key);return rc; }
@@ -950,7 +950,7 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash,if (dma_mapping_error (dev, ctx->key_params.key_dma_addr)) {dev_err (dev,"Mapping key va=0x%p len=%u for DMA failed\n" , key, keylen); -kzfree (ctx->key_params.key); +kfree_sensitive (ctx->key_params.key);return -ENOMEM ; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
@@ -999,7 +999,7 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash,dev_dbg (dev,"Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n" , &ctx->key_params.key_dma_addr, ctx->key_params.keylen); -kzfree (ctx->key_params.key); +kfree_sensitive (ctx->key_params.key);return rc; }
drivers/crypto/ccree/cc_request_mgr.c +1 -1
@@ -107,7 +107,7 @@ void cc_req_mgr_fini(struct cc_drvdata *drvdata)/* Kill tasklet */ tasklet_kill (&req_mgr_h->comptask);#endif -kzfree (req_mgr_h); +kfree_sensitive (req_mgr_h); drvdata->request_mgr_handle =NULL ; }
drivers/crypto/marvell/cesa/hash.c +1 -1
@@ -1154,7 +1154,7 @@ static int mv_cesa_ahmac_pad_init(struct ahash_request *req, }/* Set the memory region to 0 to avoid any leak. */ -kzfree (keydup); +kfree_sensitive (keydup);if (ret)return ret;
drivers/crypto/marvell/octeontx/otx_cptvf_main.c +3 -3
@@ -68,7 +68,7 @@ static void cleanup_worker_threads(struct otx_cptvf *cptvf)for (i =0 ; i < cptvf->num_queues; i++)tasklet_kill (&cwqe_info->vq_wqe[i].twork); -kzfree (cwqe_info); +kfree_sensitive (cwqe_info); cptvf->wqe_info =NULL ; }
@@ -82,7 +82,7 @@ static void free_pending_queues(struct otx_cpt_pending_qinfo *pqinfo)continue ;/* free single queue */ -kzfree ((queue->head)); +kfree_sensitive ((queue->head)); queue->front =0 ; queue->rear =0 ; queue->qlen =0 ;
@@ -176,7 +176,7 @@ static void free_command_queues(struct otx_cptvf *cptvf, chunk->head =NULL ; chunk->dma_addr =0 ;list_del (&chunk->nextchunk); -kzfree (chunk); +kfree_sensitive (chunk); } queue->num_chunks =0 ; queue->idx =0 ;
drivers/crypto/marvell/octeontx/otx_cptvf_reqmgr.h +1 -1
@@ -215,7 +215,7 @@ static inline void do_request_cleanup(struct pci_dev *pdev, DMA_BIDIRECTIONAL); } } -kzfree (info); +kfree_sensitive (info); }struct otx_cptvf_wqe ;
drivers/crypto/mediatek/mtk-aes.c +1 -1
@@ -1057,7 +1057,7 @@ static int mtk_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key,mtk_aes_write_state_be (ctx->key + ctx->keylen, data->hash,AES_BLOCK_SIZE ); out: -kzfree (data); +kfree_sensitive (data);return err; }
drivers/crypto/nx/nx.c +2 -2
@@ -746,7 +746,7 @@ void nx_crypto_ctx_exit(struct crypto_tfm *tfm) {struct nx_crypto_ctx *nx_ctx =crypto_tfm_ctx (tfm); -kzfree (nx_ctx->kmem); +kfree_sensitive (nx_ctx->kmem); nx_ctx->csbcpb =NULL ; nx_ctx->csbcpb_aead =NULL ; nx_ctx->in_sg =NULL ;
@@ -762,7 +762,7 @@ void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm) {struct nx_crypto_ctx *nx_ctx =crypto_aead_ctx (tfm); -kzfree (nx_ctx->kmem); +kfree_sensitive (nx_ctx->kmem); }static int nx_probe (struct vio_dev *viodev,const struct vio_device_id *id)
drivers/crypto/virtio/virtio_crypto_algs.c +6 -6
@@ -167,7 +167,7 @@ static int virtio_crypto_alg_skcipher_init_session( num_in, vcrypto, GFP_ATOMIC);if (err <0 ) {spin_unlock (&vcrypto->ctrl_lock); -kzfree (cipher_key); +kfree_sensitive (cipher_key);return err; }virtqueue_kick (vcrypto->ctrl_vq);
@@ -184,7 +184,7 @@ static int virtio_crypto_alg_skcipher_init_session(spin_unlock (&vcrypto->ctrl_lock);pr_err ("virtio_crypto: Create session failed status: %u\n" ,le32_to_cpu (vcrypto->input.status)); -kzfree (cipher_key); +kfree_sensitive (cipher_key);return -EINVAL ; }
@@ -197,7 +197,7 @@ static int virtio_crypto_alg_skcipher_init_session(spin_unlock (&vcrypto->ctrl_lock); -kzfree (cipher_key); +kfree_sensitive (cipher_key);return 0 ; }
@@ -466,9 +466,9 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req,return 0 ; free_iv: -kzfree (iv); +kfree_sensitive (iv); free: -kzfree (req_data); +kfree_sensitive (req_data);kfree (sgs);return err; }
@@ -579,7 +579,7 @@ static void virtio_crypto_skcipher_finalize_req( AES_BLOCK_SIZE, 0);crypto_finalize_skcipher_request (vc_sym_req->base.dataq->engine, req, err); -kzfree (vc_sym_req->iv); +kfree_sensitive (vc_sym_req->iv);virtcrypto_clear_request (&vc_sym_req->base); }
drivers/crypto/virtio/virtio_crypto_core.c +1 -1
@@ -17,7 +17,7 @@ void virtcrypto_clear_request(struct virtio_crypto_request *vc_req) {if (vc_req) { -kzfree (vc_req->req_data); +kfree_sensitive (vc_req->req_data);kfree (vc_req->sgs); } }
drivers/md/dm-crypt.c +17 -17
@@ -405,7 +405,7 @@ static void crypt_iv_lmk_dtr(struct crypt_config *cc)crypto_free_shash (lmk->hash_tfm); lmk->hash_tfm =NULL ; -kzfree (lmk->seed); +kfree_sensitive (lmk->seed); lmk->seed =NULL ; }
@@ -556,9 +556,9 @@ static void crypt_iv_tcw_dtr(struct crypt_config *cc) {struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; -kzfree (tcw->iv_seed); +kfree_sensitive (tcw->iv_seed); tcw->iv_seed =NULL ; -kzfree (tcw->whitening); +kfree_sensitive (tcw->whitening); tcw->whitening =NULL ;if (tcw->crc32_tfm && !IS_ERR (tcw->crc32_tfm))
@@ -992,8 +992,8 @@ static int crypt_iv_elephant(struct crypt_config *cc, struct dm_crypt_request *dkunmap_atomic (data); out: -kzfree (ks); -kzfree (es); +kfree_sensitive (ks); +kfree_sensitive (es);skcipher_request_free (req);return r; }
@@ -2247,7 +2247,7 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string key =request_key (key_string[0 ] =='l' ? &key_type_logon : &key_type_user, key_desc +1 ,NULL );if (IS_ERR (key)) { -kzfree (new_key_string); +kfree_sensitive (new_key_string);return PTR_ERR (key); }
@@ -2257,14 +2257,14 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringif (!ukp) {up_read (&key->sem);key_put (key); -kzfree (new_key_string); +kfree_sensitive (new_key_string);return -EKEYREVOKED ; }if (cc->key_size != ukp->datalen) {up_read (&key->sem);key_put (key); -kzfree (new_key_string); +kfree_sensitive (new_key_string);return -EINVAL ; }
@@ -2280,10 +2280,10 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringif (!ret) {set_bit (DM_CRYPT_KEY_VALID , &cc->flags); -kzfree (cc->key_string); +kfree_sensitive (cc->key_string); cc->key_string = new_key_string; }else -kzfree (new_key_string); +kfree_sensitive (new_key_string);return ret; }
@@ -2344,7 +2344,7 @@ static int crypt_set_key(struct crypt_config *cc, char *key)clear_bit (DM_CRYPT_KEY_VALID , &cc->flags);/* wipe references to any kernel keyring key */ -kzfree (cc->key_string); +kfree_sensitive (cc->key_string); cc->key_string =NULL ;/* Decode key from its hex representation. */
@@ -2376,7 +2376,7 @@ static int crypt_wipe_key(struct crypt_config *cc)return r; } -kzfree (cc->key_string); +kfree_sensitive (cc->key_string); cc->key_string =NULL ; r =crypt_setkey (cc);memset (&cc->key,0 , cc->key_size *sizeof (u8));
@@ -2455,15 +2455,15 @@ static void crypt_dtr(struct dm_target *ti)if (cc->dev)dm_put_device (ti, cc->dev); -kzfree (cc->cipher_string); -kzfree (cc->key_string); -kzfree (cc->cipher_auth); -kzfree (cc->authenc_key); +kfree_sensitive (cc->cipher_string); +kfree_sensitive (cc->key_string); +kfree_sensitive (cc->cipher_auth); +kfree_sensitive (cc->authenc_key);mutex_destroy (&cc->bio_alloc_lock);/* Must zero key material before freeing */ -kzfree (cc); +kfree_sensitive (cc);spin_lock (&dm_crypt_clients_lock);WARN_ON (!dm_crypt_clients_n);
drivers/md/dm-integrity.c +3 -3
@@ -3409,8 +3409,8 @@ static struct scatterlist **dm_integrity_alloc_journal_scatterlist(struct dm_intstatic void free_alg (struct alg_spec *a) { -kzfree (a->alg_string); -kzfree (a->key); +kfree_sensitive (a->alg_string); +kfree_sensitive (a->key);memset (a,0 ,sizeof *a); }
@@ -4341,7 +4341,7 @@ static void dm_integrity_dtr(struct dm_target *ti)for (i =0 ; i < ic->journal_sections; i++) {struct skcipher_request *req = ic->sk_requests[i];if (req) { -kzfree (req->iv); +kfree_sensitive (req->iv);skcipher_request_free (req); } }
drivers/misc/ibmvmc.c +3 -3
@@ -286,7 +286,7 @@ static void *alloc_dma_buffer(struct vio_dev *vdev, size_t size,if (dma_mapping_error (&vdev->dev, *dma_handle)) { *dma_handle =0 ; -kzfree (buffer); +kfree_sensitive (buffer);return NULL ; }
@@ -310,7 +310,7 @@ static void free_dma_buffer(struct vio_dev *vdev, size_t size, void *vaddr,dma_unmap_single (&vdev->dev, dma_handle, size,DMA_BIDIRECTIONAL );/* deallocate memory */ -kzfree (vaddr); +kfree_sensitive (vaddr); }/**
@@ -883,7 +883,7 @@ static int ibmvmc_close(struct inode *inode, struct file *file)spin_unlock_irqrestore (&hmc->lock, flags); } -kzfree (session); +kfree_sensitive (session);return rc; }
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +1 -1
@@ -132,7 +132,7 @@ static void hclge_free_vector_ring_chain(struct hnae3_ring_chain_node *head)while (chain) { chain_tmp = chain->next; -kzfree (chain); +kfree_sensitive (chain); chain = chain_tmp; } }
drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c +3 -3
@@ -960,9 +960,9 @@ int ixgbe_ipsec_vf_add_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)return 0 ; err_aead: -kzfree (xs->aead); +kfree_sensitive (xs->aead); err_xs: -kzfree (xs); +kfree_sensitive (xs); err_out: msgbuf[1 ] = err;return err;
@@ -1047,7 +1047,7 @@ int ixgbe_ipsec_vf_del_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)ixgbe_ipsec_del_sa (xs);/* remove the xs that was made-up in the add request */ -kzfree (xs); +kfree_sensitive (xs);return 0 ; }
drivers/net/ppp/ppp_mppe.c +3 -3
@@ -222,7 +222,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)kfree (state->sha1_digest);if (state->sha1) {crypto_free_shash (state->sha1->tfm); -kzfree (state->sha1); +kfree_sensitive (state->sha1); }kfree (state); out:
@@ -238,8 +238,8 @@ static void mppe_free(void *arg)if (state) {kfree (state->sha1_digest);crypto_free_shash (state->sha1->tfm); -kzfree (state->sha1); -kzfree (state); +kfree_sensitive (state->sha1); +kfree_sensitive (state); } }
drivers/net/wireguard/noise.c +2 -2
@@ -113,7 +113,7 @@ static struct noise_keypair *keypair_create(struct wg_peer *peer)static void keypair_free_rcu (struct rcu_head *rcu) { -kzfree (container_of(rcu ,struct noise_keypair ,rcu )); +kfree_sensitive (container_of(rcu ,struct noise_keypair ,rcu )); }static void keypair_free_kref (struct kref *kref)
@@ -825,7 +825,7 @@ bool wg_noise_handshake_begin_session(struct noise_handshake *handshake, handshake->entry.peer->device->index_hashtable, &handshake->entry, &new_keypair->entry); }else { -kzfree (new_keypair); +kfree_sensitive (new_keypair); }rcu_read_unlock_bh ();
drivers/net/wireguard/peer.c +1 -1
@@ -203,7 +203,7 @@ static void rcu_release(struct rcu_head *rcu)/* The final zeroing takes care of clearing any remaining handshake key * material and other potentially sensitive information. */ -kzfree (peer); +kfree_sensitive (peer); }static void kref_release (struct kref *refcount)
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +1 -1
@@ -1369,7 +1369,7 @@ static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans, &rxcb, rxq->id);if (reclaim) { -kzfree (txq->entries[cmd_index].free_buf); +kfree_sensitive (txq->entries[cmd_index].free_buf); txq->entries[cmd_index].free_buf =NULL ; }
drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c +3 -3
@@ -1024,7 +1024,7 @@ static int iwl_pcie_gen2_enqueue_hcmd(struct iwl_trans *trans,BUILD_BUG_ON (IWL_TFH_NUM_TBS >sizeof (out_meta->tbs) *BITS_PER_BYTE ); out_meta->flags = cmd->flags;if (WARN_ON_ONCE (txq->entries[idx].free_buf)) -kzfree (txq->entries[idx].free_buf); +kfree_sensitive (txq->entries[idx].free_buf); txq->entries[idx].free_buf = dup_buf;trace_iwlwifi_dev_hcmd (trans->dev, cmd, cmd_size, &out_cmd->hdr_wide);
@@ -1254,8 +1254,8 @@ static void iwl_pcie_gen2_txq_free(struct iwl_trans *trans, int txq_id)/* De-alloc array of command/tx buffers */ if (txq_id == trans_pcie->cmd_queue)for (i =0 ; i < txq->n_window; i++) { -kzfree (txq->entries[i].cmd); -kzfree (txq->entries[i].free_buf); +kfree_sensitive (txq->entries[i].cmd); +kfree_sensitive (txq->entries[i].free_buf); }del_timer_sync (&txq->stuck_timer);
drivers/net/wireless/intel/iwlwifi/pcie/tx.c +3 -3
@@ -724,8 +724,8 @@ static void iwl_pcie_txq_free(struct iwl_trans *trans, int txq_id)/* De-alloc array of command/tx buffers */ if (txq_id == trans_pcie->cmd_queue)for (i =0 ; i < txq->n_window; i++) { -kzfree (txq->entries[i].cmd); -kzfree (txq->entries[i].free_buf); +kfree_sensitive (txq->entries[i].cmd); +kfree_sensitive (txq->entries[i].free_buf); }/* De-alloc circular buffer of TFDs */
@@ -1768,7 +1768,7 @@ static int iwl_pcie_enqueue_hcmd(struct iwl_trans *trans,BUILD_BUG_ON (IWL_TFH_NUM_TBS >sizeof (out_meta->tbs) *BITS_PER_BYTE ); out_meta->flags = cmd->flags;if (WARN_ON_ONCE (txq->entries[idx].free_buf)) -kzfree (txq->entries[idx].free_buf); +kfree_sensitive (txq->entries[idx].free_buf); txq->entries[idx].free_buf = dup_buf;trace_iwlwifi_dev_hcmd (trans->dev, cmd, cmd_size, &out_cmd->hdr_wide);
drivers/net/wireless/intersil/orinoco/wext.c +2 -2
@@ -31,8 +31,8 @@ static int orinoco_set_key(struct orinoco_private *priv, int index, enum orinoco_alg alg, const u8 *key, int key_len, const u8 *seq, int seq_len) { - kzfree(priv->keys[index].key); -kzfree (priv->keys[index].seq); + kfree_sensitive(priv->keys[index].key); +kfree_sensitive (priv->keys[index].seq);if (key_len) { priv->keys[index].key =kzalloc (key_len,GFP_ATOMIC );
drivers/s390/crypto/ap_bus.h +2 -2
@@ -219,8 +219,8 @@ static inline void ap_init_message(struct ap_message *ap_msg)*/ static inline void ap_release_message (struct ap_message *ap_msg) { -kzfree (ap_msg->message); -kzfree (ap_msg->private); +kfree_sensitive (ap_msg->message); +kfree_sensitive (ap_msg->private); }#define for_each_ap_card (_ac) \
drivers/staging/ks7010/ks_hostif.c +1 -1
@@ -246,7 +246,7 @@ michael_mic(u8 *key, u8 *data, unsigned int len, u8 priority, u8 *result) ret =crypto_shash_finup (desc, data +12 , len -12 , result); err_free_desc: -kzfree (desc); +kfree_sensitive (desc); err_free_tfm:crypto_free_shash (tfm);
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
@@ -2251,7 +2251,7 @@ static void gf_mulx(u8 *pad)static void aes_encrypt_deinit (void *ctx) { -kzfree (ctx); +kfree_sensitive (ctx); }
drivers/staging/wlan-ng/p80211netdev.c +1 -1
@@ -429,7 +429,7 @@ static netdev_tx_t p80211knetdev_hard_start_xmit(struct sk_buff *skb, failed:/* Free up the WEP buffer if it's not the same as the skb */ if ((p80211_wep.data) && (p80211_wep.data != skb->data)) -kzfree (p80211_wep.data); +kfree_sensitive (p80211_wep.data);/* we always free the skb here, never in a lower level. */ if (!result)
drivers/target/iscsi/iscsi_target_auth.c +1 -1
@@ -484,7 +484,7 @@ static int chap_server_compute_hash(pr_debug ("[server] Sending CHAP_R=0x%s\n" , response); auth_ret =0 ; out: -kzfree (desc); +kfree_sensitive (desc);if (tfm)crypto_free_shash (tfm);kfree (initiatorchg);
fs/btrfs/ioctl.c +1 -1
@@ -2691,7 +2691,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)btrfs_put_root (root); out_free:btrfs_free_path (path); -kzfree (subvol_info); +kfree_sensitive (subvol_info);return ret; }
fs/cifs/cifsencrypt.c +1 -1
@@ -797,7 +797,7 @@ calc_seckey(struct cifs_ses *ses) ses->auth_key.len =CIFS_SESS_KEY_SIZE ;memzero_explicit (sec_key,CIFS_SESS_KEY_SIZE ); -kzfree (ctx_arc4); +kfree_sensitive (ctx_arc4);return 0 ; }
fs/cifs/connect.c +5 -5
@@ -2177,7 +2177,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, tmp_end++;if (!(tmp_end < end && tmp_end[1 ] == delim)) {/* No it is not. Set the password to NULL */ -kzfree (vol->password); +kfree_sensitive (vol->password); vol->password =NULL ;break ; }
@@ -2215,7 +2215,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, options = end; } -kzfree (vol->password); +kfree_sensitive (vol->password);/* Now build new password string */ temp_len =strlen (value); vol->password =kzalloc (temp_len+1 ,GFP_KERNEL );
@@ -3200,7 +3200,7 @@ cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses) rc = -ENOMEM ;kfree (vol->username); vol->username =NULL ; -kzfree (vol->password); +kfree_sensitive (vol->password); vol->password =NULL ; goto out_key_put; }
@@ -4212,7 +4212,7 @@ void cifs_cleanup_volume_info_contents(struct smb_vol *volume_info) {kfree (volume_info->username); -kzfree (volume_info->password); +kfree_sensitive (volume_info->password);kfree (volume_info->UNC);kfree (volume_info->domainname);kfree (volume_info->iocharset);
@@ -5337,7 +5337,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) out:kfree (vol_info->username); -kzfree (vol_info->password); +kfree_sensitive (vol_info->password);kfree (vol_info);return tcon;
fs/cifs/dfs_cache.c +1 -1
@@ -1131,7 +1131,7 @@ static int dup_vol(struct smb_vol *vol, struct smb_vol *new) err_free_unc:kfree (new->UNC); err_free_password: -kzfree (new->password); +kfree_sensitive (new->password); err_free_username:kfree (new->username);kfree (new);
fs/cifs/misc.c +4 -4
@@ -100,12 +100,12 @@ sesInfoFree(struct cifs_ses *buf_to_free)kfree (buf_to_free->serverOS);kfree (buf_to_free->serverDomain);kfree (buf_to_free->serverNOS); -kzfree (buf_to_free->password); +kfree_sensitive (buf_to_free->password);kfree (buf_to_free->user_name);kfree (buf_to_free->domainName); -kzfree (buf_to_free->auth_key.response); +kfree_sensitive (buf_to_free->auth_key.response);kfree (buf_to_free->iface_list); -kzfree (buf_to_free); +kfree_sensitive (buf_to_free); } struct cifs_tcon *
@@ -145,7 +145,7 @@ tconInfoFree(struct cifs_tcon *buf_to_free) }atomic_dec (&tconInfoAllocCount);kfree (buf_to_free->nativeFileSystem); -kzfree (buf_to_free->password); +kfree_sensitive (buf_to_free->password);kfree (buf_to_free->crfid.fid);#ifdef CONFIG_CIFS_DFS_UPCALL kfree (buf_to_free->dfs_path);
fs/crypto/keyring.c +3 -3
@@ -49,7 +49,7 @@ static void free_master_key(struct fscrypt_master_key *mk) }key_put (mk->mk_users); -kzfree (mk); +kfree_sensitive (mk); }static inline bool valid_key_spec (const struct fscrypt_key_specifier *spec)
@@ -491,7 +491,7 @@ static int fscrypt_provisioning_key_preparse(struct key_preparsed_payload *prep)static void fscrypt_provisioning_key_free_preparse (struct key_preparsed_payload *prep) { -kzfree (prep->payload.data[0 ]); +kfree_sensitive (prep->payload.data[0 ]); } static void fscrypt_provisioning_key_describe(const struct key *key,
@@ -508,7 +508,7 @@ static void fscrypt_provisioning_key_describe(const struct key *key,static void fscrypt_provisioning_key_destroy (struct key *key) { -kzfree (key->payload.data[0 ]); +kfree_sensitive (key->payload.data[0 ]); }static struct key_type key_type_fscrypt_provisioning = {
fs/crypto/keysetup_v1.c +2 -2
@@ -155,7 +155,7 @@ static void free_direct_key(struct fscrypt_direct_key *dk) {if (dk) {crypto_free_skcipher (dk->dk_ctfm); -kzfree (dk); +kfree_sensitive (dk); } }
@@ -285,7 +285,7 @@ static int setup_v1_file_key_derived(struct fscrypt_info *ci, err =fscrypt_set_per_file_enc_key (ci, derived_key); out: -kzfree (derived_key); +kfree_sensitive (derived_key);return err; }
fs/ecryptfs/keystore.c +2 -2
@@ -838,7 +838,7 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes, out_release_free_unlock:crypto_free_shash (s->hash_tfm); out_free_unlock: -kzfree (s->block_aligned_filename); +kfree_sensitive (s->block_aligned_filename); out_unlock:mutex_unlock (s->tfm_mutex); out:
@@ -847,7 +847,7 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,key_put (auth_tok_key); }skcipher_request_free (s->skcipher_req); -kzfree (s->hash_desc); +kfree_sensitive (s->hash_desc);kfree (s);return rc; }
fs/ecryptfs/messaging.c +1 -1
@@ -175,7 +175,7 @@ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon) }hlist_del (&daemon->euid_chain);mutex_unlock (&daemon->mux); -kzfree (daemon); +kfree_sensitive (daemon); out:return rc; }
include/crypto/aead.h +1 -1
@@ -425,7 +425,7 @@ static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,*/ static inline void aead_request_free (struct aead_request *req) { -kzfree (req); +kfree_sensitive (req); }/**
include/crypto/akcipher.h +1 -1
@@ -207,7 +207,7 @@ static inline struct akcipher_request *akcipher_request_alloc(*/ static inline void akcipher_request_free (struct akcipher_request *req) { -kzfree (req); +kfree_sensitive (req); }/**
include/crypto/gf128mul.h +1 -1
@@ -230,7 +230,7 @@ void gf128mul_4k_bbe(be128 *a, const struct gf128mul_4k *t);void gf128mul_x8_ble (le128 *r,const le128 *x);static inline void gf128mul_free_4k (struct gf128mul_4k *t) { -kzfree (t); +kfree_sensitive (t); }
include/crypto/hash.h +1 -1
@@ -606,7 +606,7 @@ static inline struct ahash_request *ahash_request_alloc(*/ static inline void ahash_request_free (struct ahash_request *req) { -kzfree (req); +kfree_sensitive (req); }static inline void ahash_request_zero (struct ahash_request *req)
include/crypto/internal/acompress.h +1 -1
@@ -46,7 +46,7 @@ static inline struct acomp_req *__acomp_request_alloc(struct crypto_acomp *tfm)static inline void __acomp_request_free (struct acomp_req *req) { -kzfree (req); +kfree_sensitive (req); }/**
include/crypto/kpp.h +1 -1
@@ -187,7 +187,7 @@ static inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm,*/ static inline void kpp_request_free (struct kpp_request *req) { -kzfree (req); +kfree_sensitive (req); }/**
include/crypto/skcipher.h +1 -1
@@ -508,7 +508,7 @@ static inline struct skcipher_request *skcipher_request_alloc(*/ static inline void skcipher_request_free (struct skcipher_request *req) { -kzfree (req); +kfree_sensitive (req); }static inline void skcipher_request_zero (struct skcipher_request *req)
include/linux/slab.h +1 -1
@@ -186,7 +186,7 @@ void memcg_deactivate_kmem_caches(struct mem_cgroup *, struct mem_cgroup *);*/ void *__must_check krealloc (const void *,size_t ,gfp_t );void kfree (const void *); -void kzfree (const void *); +void kfree_sensitive (const void *);size_t __ksize (const void *);size_t ksize (const void *);
lib/mpi/mpiutil.c +3 -3
@@ -69,7 +69,7 @@ void mpi_free_limb_space(mpi_ptr_t a)if (!a)return ; -kzfree (a); +kfree_sensitive (a); }void mpi_assign_limb_space (MPI a,mpi_ptr_t ap,unsigned nlimbs)
@@ -95,7 +95,7 @@ int mpi_resize(MPI a, unsigned nlimbs)if (!p)return -ENOMEM ;memcpy (p, a->d, a->alloced *sizeof (mpi_limb_t)); -kzfree (a->d); +kfree_sensitive (a->d); a->d = p; }else { a->d =kcalloc (nlimbs,sizeof (mpi_limb_t),GFP_KERNEL );
@@ -112,7 +112,7 @@ void mpi_free(MPI a)return ;if (a->flags &4 ) -kzfree (a->d); +kfree_sensitive (a->d);else mpi_free_limb_space (a->d);
lib/test_kasan.c +3 -3
@@ -757,15 +757,15 @@ static noinline void __init kmalloc_double_kzfree(void)char *ptr;size_t size =16 ; -pr_info ("double-free (kzfree)\n" ); +pr_info ("double-free (kfree_sensitive)\n" ); ptr =kmalloc (size,GFP_KERNEL );if (!ptr) {pr_err ("Allocation failed\n" );return ; } -kzfree (ptr); -kzfree (ptr); +kfree_sensitive (ptr); +kfree_sensitive (ptr); }#ifdef CONFIG_KASAN_VMALLOC
mm/slab_common.c +5 -5
@@ -1707,17 +1707,17 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)EXPORT_SYMBOL (krealloc);/** -* kzfree - like kfree but zero memory +* kfree_sensitive - Clear sensitive information in memory before freeing * @p: object to free memory of * * The memory of the object @p points to is zeroed before freed. -* If @p is %NULL, kzfree() does nothing. +* If @p is %NULL, kfree_sensitive() does nothing. * * Note: this function zeroes the whole allocated buffer which can be a good * deal bigger than the requested buffer size passed to kmalloc(). So be * careful when using this function in performance sensitive code. */ -void kzfree (const void *p) +void kfree_sensitive (const void *p) {size_t ks;void *mem = (void *)p;
@@ -1725,10 +1725,10 @@ void kzfree(const void *p)if (unlikely (ZERO_OR_NULL_PTR (mem)))return ; ks =ksize (mem); -memset (mem,0 , ks); +memzero_explicit (mem, ks);kfree (mem); } -EXPORT_SYMBOL (kzfree); +EXPORT_SYMBOL (kfree_sensitive);/** * ksize - get the actual amount of memory allocated for a given object
net/atm/mpoa_caches.c +2 -2
@@ -180,7 +180,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)static void in_cache_put (in_cache_entry *entry) {if (refcount_dec_and_test (&entry->use)) { -kzfree (entry); +kfree_sensitive (entry); } }
@@ -415,7 +415,7 @@ static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,static void eg_cache_put (eg_cache_entry *entry) {if (refcount_dec_and_test (&entry->use)) { -kzfree (entry); +kfree_sensitive (entry); } }
net/bluetooth/ecdh_helper.c +3 -3
@@ -104,7 +104,7 @@ int compute_ecdh_secret(struct crypto_kpp *tfm, const u8 public_key[64], free_all:kpp_request_free (req); free_tmp: -kzfree (tmp); +kfree_sensitive (tmp);return err; }
@@ -151,9 +151,9 @@ int set_ecdh_privkey(struct crypto_kpp *tfm, const u8 private_key[32]) err =crypto_kpp_set_secret (tfm, buf, buf_len);/* fall through */ free_all: -kzfree (buf); +kfree_sensitive (buf); free_tmp: -kzfree (tmp); +kfree_sensitive (tmp);return err; }
net/bluetooth/smp.c +12 -12
@@ -753,9 +753,9 @@ static void smp_chan_destroy(struct l2cap_conn *conn) complete =test_bit (SMP_FLAG_COMPLETE , &smp->flags);mgmt_smp_complete (hcon, complete); -kzfree (smp->csrk); -kzfree (smp->slave_csrk); -kzfree (smp->link_key); +kfree_sensitive (smp->csrk); +kfree_sensitive (smp->slave_csrk); +kfree_sensitive (smp->link_key);crypto_free_shash (smp->tfm_cmac);crypto_free_kpp (smp->tfm_ecdh);
@@ -789,7 +789,7 @@ static void smp_chan_destroy(struct l2cap_conn *conn) } chan->data =NULL ; -kzfree (smp); +kfree_sensitive (smp);hci_conn_drop (hcon); }
@@ -1149,7 +1149,7 @@ static void sc_generate_link_key(struct smp_chan *smp)const u8 salt[16 ] = {0x31 ,0x70 ,0x6d ,0x74 };if (smp_h7 (smp->tfm_cmac, smp->tk, salt, smp->link_key)) { -kzfree (smp->link_key); +kfree_sensitive (smp->link_key); smp->link_key =NULL ;return ; }
@@ -1158,14 +1158,14 @@ static void sc_generate_link_key(struct smp_chan *smp)const u8 tmp1[4 ] = {0x31 ,0x70 ,0x6d ,0x74 };if (smp_h6 (smp->tfm_cmac, smp->tk, tmp1, smp->link_key)) { -kzfree (smp->link_key); +kfree_sensitive (smp->link_key); smp->link_key =NULL ;return ; } }if (smp_h6 (smp->tfm_cmac, smp->link_key, lebr, smp->link_key)) { -kzfree (smp->link_key); +kfree_sensitive (smp->link_key); smp->link_key =NULL ;return ; }
@@ -1400,7 +1400,7 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) free_shash:crypto_free_shash (smp->tfm_cmac); zfree_smp: -kzfree (smp); +kfree_sensitive (smp);return NULL ; }
@@ -3263,7 +3263,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid) tfm_cmac =crypto_alloc_shash ("cmac(aes)" ,0 ,0 );if (IS_ERR (tfm_cmac)) {BT_ERR ("Unable to create CMAC crypto context" ); -kzfree (smp); +kfree_sensitive (smp);return ERR_CAST (tfm_cmac); }
@@ -3271,7 +3271,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)if (IS_ERR (tfm_ecdh)) {BT_ERR ("Unable to create ECDH crypto context" );crypto_free_shash (tfm_cmac); -kzfree (smp); +kfree_sensitive (smp);return ERR_CAST (tfm_ecdh); }
@@ -3285,7 +3285,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)if (smp) {crypto_free_shash (smp->tfm_cmac);crypto_free_kpp (smp->tfm_ecdh); -kzfree (smp); +kfree_sensitive (smp); }return ERR_PTR (-ENOMEM ); }
@@ -3332,7 +3332,7 @@ static void smp_del_chan(struct l2cap_chan *chan) chan->data =NULL ;crypto_free_shash (smp->tfm_cmac);crypto_free_kpp (smp->tfm_ecdh); -kzfree (smp); +kfree_sensitive (smp); }l2cap_chan_put (chan);
net/core/sock.c +1 -1
@@ -2182,7 +2182,7 @@ static inline void __sock_kfree_s(struct sock *sk, void *mem, int size,if (WARN_ON_ONCE (!mem))return ;if (nullify) -kzfree (mem); +kfree_sensitive (mem);else kfree (mem);atomic_sub (size, &sk->sk_omem_alloc);
net/ipv4/tcp_fastopen.c +1 -1
@@ -38,7 +38,7 @@ static void tcp_fastopen_ctx_free(struct rcu_head *head)struct tcp_fastopen_context *ctx = container_of(head, struct tcp_fastopen_context, rcu); -kzfree (ctx); +kfree_sensitive (ctx); }void tcp_fastopen_destroy_cipher (struct sock *sk)
net/mac80211/aead_api.c +2 -2
@@ -41,7 +41,7 @@ int aead_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,aead_request_set_ad (aead_req, sg[0 ].length);crypto_aead_encrypt (aead_req); -kzfree (aead_req); +kfree_sensitive (aead_req);return 0 ; }
@@ -76,7 +76,7 @@ int aead_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,aead_request_set_ad (aead_req, sg[0 ].length); err =crypto_aead_decrypt (aead_req); -kzfree (aead_req); +kfree_sensitive (aead_req);return err; }
net/mac80211/aes_gmac.c +1 -1
@@ -60,7 +60,7 @@ int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,aead_request_set_ad (aead_req,GMAC_AAD_LEN + data_len);crypto_aead_encrypt (aead_req); -kzfree (aead_req); +kfree_sensitive (aead_req);return 0 ; }
net/mac80211/key.c +1 -1
@@ -732,7 +732,7 @@ static void ieee80211_key_free_common(struct ieee80211_key *key)ieee80211_aes_gcm_key_free (key->u.gcmp.tfm);break ; } -kzfree (key); +kfree_sensitive (key); } static void __ieee80211_key_destroy(struct ieee80211_key *key,
net/mac802154/llsec.c +10 -10
@@ -49,7 +49,7 @@ void mac802154_llsec_destroy(struct mac802154_llsec *sec) msl = container_of(sl, struct mac802154_llsec_seclevel, level);list_del (&sl->list); -kzfree (msl); +kfree_sensitive (msl); }list_for_each_entry_safe (dev, dn, &sec->table.devices, list) {
@@ -66,7 +66,7 @@ void mac802154_llsec_destroy(struct mac802154_llsec *sec) mkey = container_of(key->key, struct mac802154_llsec_key, key);list_del (&key->list);llsec_key_put (mkey); -kzfree (key); +kfree_sensitive (key); } }
@@ -155,7 +155,7 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template)if (key->tfm[i])crypto_free_aead (key->tfm[i]); -kzfree (key); +kfree_sensitive (key);return NULL ; }
@@ -170,7 +170,7 @@ static void llsec_key_release(struct kref *ref)crypto_free_aead (key->tfm[i]);crypto_free_sync_skcipher (key->tfm0); -kzfree (key); +kfree_sensitive (key); } static struct mac802154_llsec_key*
@@ -261,7 +261,7 @@ int mac802154_llsec_key_add(struct mac802154_llsec *sec,return 0 ; fail: -kzfree (new); +kfree_sensitive (new);return -ENOMEM ; }
@@ -341,10 +341,10 @@ static void llsec_dev_free(struct mac802154_llsec_device *dev) devkey);list_del (&pos->list); -kzfree (devkey); +kfree_sensitive (devkey); } -kzfree (dev); +kfree_sensitive (dev); } int mac802154_llsec_dev_add(struct mac802154_llsec *sec,
@@ -682,7 +682,7 @@ llsec_do_encrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, rc =crypto_aead_encrypt (req); -kzfree (req); +kfree_sensitive (req);return rc; }
@@ -886,7 +886,7 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, rc =crypto_aead_decrypt (req); -kzfree (req); +kfree_sensitive (req);skb_trim (skb, skb->len - authlen);return rc;
@@ -926,7 +926,7 @@ llsec_update_devkey_record(struct mac802154_llsec_device *dev,if (!devkey)list_add_rcu (&next->devkey.list, &dev->dev.keys);else -kzfree (next); +kfree_sensitive (next);spin_unlock_bh (&dev->lock); }
net/sctp/auth.c +1 -1
@@ -49,7 +49,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)return ;if (refcount_dec_and_test (&key->refcnt)) { -kzfree (key); +kfree_sensitive (key);SCTP_DBG_OBJCNT_DEC (keys); } }
net/sctp/socket.c +1 -1
@@ -3748,7 +3748,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk, } out: -kzfree (authkey); +kfree_sensitive (authkey);return ret; }
net/sunrpc/auth_gss/gss_krb5_crypto.c +2 -2
@@ -1003,7 +1003,7 @@ krb5_rc4_setup_seq_key(struct krb5_ctx *kctx, err =0 ; out_err: -kzfree (desc); +kfree_sensitive (desc);crypto_free_shash (hmac);dprintk ("%s: returning %d\n" , __func__, err);return err;
@@ -1079,7 +1079,7 @@ krb5_rc4_setup_enc_key(struct krb5_ctx *kctx, err =0 ; out_err: -kzfree (desc); +kfree_sensitive (desc);crypto_free_shash (hmac);dprintk ("%s: returning %d\n" , __func__, err);return err;
net/sunrpc/auth_gss/gss_krb5_keys.c +3 -3
@@ -228,11 +228,11 @@ u32 krb5_derive_key(const struct gss_krb5_enctype *gk5e, ret =0 ; err_free_raw: -kzfree (rawkey); +kfree_sensitive (rawkey); err_free_out: -kzfree (outblockdata); +kfree_sensitive (outblockdata); err_free_in: -kzfree (inblockdata); +kfree_sensitive (inblockdata); err_free_cipher:crypto_free_sync_skcipher (cipher); err_return:
net/sunrpc/auth_gss/gss_krb5_mech.c +1 -1
@@ -443,7 +443,7 @@ context_derive_keys_rc4(struct krb5_ctx *ctx) desc->tfm = hmac; err =crypto_shash_digest (desc, sigkeyconstant, slen, ctx->cksum); -kzfree (desc); +kfree_sensitive (desc);if (err) goto out_err_free_hmac;/*
net/tipc/crypto.c +5 -5
@@ -441,7 +441,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,/* Allocate per-cpu TFM entry pointer */ tmp->tfm_entry = alloc_percpu(struct tipc_tfm *);if (!tmp->tfm_entry) { -kzfree (tmp); +kfree_sensitive (tmp);return -ENOMEM ; }
@@ -491,7 +491,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,/* Not any TFM is allocated? */ if (!tfm_cnt) {free_percpu (tmp->tfm_entry); -kzfree (tmp); +kfree_sensitive (tmp);return err; }
@@ -545,7 +545,7 @@ static int tipc_aead_clone(struct tipc_aead **dst, struct tipc_aead *src) aead->tfm_entry = alloc_percpu_gfp(struct tipc_tfm *, GFP_ATOMIC);if (unlikely (!aead->tfm_entry)) { -kzfree (aead); +kfree_sensitive (aead);return -ENOMEM ; }
@@ -1352,7 +1352,7 @@ int tipc_crypto_start(struct tipc_crypto **crypto, struct net *net,/* Allocate statistic structure */ c->stats = alloc_percpu_gfp(struct tipc_crypto_stats, GFP_ATOMIC);if (!c->stats) { -kzfree (c); +kfree_sensitive (c);return -ENOMEM ; }
@@ -1408,7 +1408,7 @@ void tipc_crypto_stop(struct tipc_crypto **crypto)free_percpu (c->stats); *crypto =NULL ; -kzfree (c); +kfree_sensitive (c); }void tipc_crypto_timeout (struct tipc_crypto *rx)
net/wireless/core.c +1 -1
@@ -1107,7 +1107,7 @@ static void __cfg80211_unregister_wdev(struct wireless_dev *wdev, bool sync) }#ifdef CONFIG_CFG80211_WEXT -kzfree (wdev->wext.keys); +kfree_sensitive (wdev->wext.keys); wdev->wext.keys =NULL ;#endif /* only initialized if we have a netdev */
net/wireless/ibss.c +2 -2
@@ -127,7 +127,7 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,return -EINVAL ;if (WARN_ON (wdev->connect_keys)) -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys = connkeys; wdev->ibss_fixed = params->channel_fixed;
@@ -161,7 +161,7 @@ static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)ASSERT_WDEV_LOCK (wdev); -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys =NULL ;rdev_set_qos_map (rdev, dev,NULL );
net/wireless/lib80211_crypt_tkip.c +1 -1
@@ -131,7 +131,7 @@ static void lib80211_tkip_deinit(void *priv)crypto_free_shash (_priv->tx_tfm_michael);crypto_free_shash (_priv->rx_tfm_michael); } -kzfree (priv); +kfree_sensitive (priv); }static inline u16 RotR1 (u16 val)
net/wireless/lib80211_crypt_wep.c +1 -1
@@ -56,7 +56,7 @@ static void *lib80211_wep_init(int keyidx)static void lib80211_wep_deinit (void *priv) { -kzfree (priv); +kfree_sensitive (priv); }/* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
net/wireless/nl80211.c +12 -12
@@ -9783,7 +9783,7 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)if ((ibss.chandef.width !=NL80211_CHAN_WIDTH_20_NOHT ) && no_ht) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; } }
@@ -9795,7 +9795,7 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)int r =validate_pae_over_nl80211 (rdev, info);if (r <0 ) { -kzfree (connkeys); +kfree_sensitive (connkeys);return r; }
@@ -9808,7 +9808,7 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)wdev_lock (dev->ieee80211_ptr); err =__cfg80211_join_ibss (rdev, dev, &ibss, connkeys);if (err) -kzfree (connkeys); +kfree_sensitive (connkeys);else if (info->attrs[NL80211_ATTR_SOCKET_OWNER ]) dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;wdev_unlock (dev->ieee80211_ptr);
@@ -10228,7 +10228,7 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)if (info->attrs[NL80211_ATTR_HT_CAPABILITY ]) {if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK ]) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; } memcpy(&connect.ht_capa,
@@ -10246,7 +10246,7 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)if (info->attrs[NL80211_ATTR_VHT_CAPABILITY ]) {if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK ]) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; } memcpy(&connect.vht_capa,
@@ -10260,7 +10260,7 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && !wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_RRM)) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; } connect.flags |=ASSOC_REQ_USE_RRM ;
@@ -10268,21 +10268,21 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) connect.pbss =nla_get_flag (info->attrs[NL80211_ATTR_PBSS ]);if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ ]) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EOPNOTSUPP ; }if (info->attrs[NL80211_ATTR_BSS_SELECT ]) {/* bss selection makes no sense if bssid is set */ if (connect.bssid) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; } err =parse_bss_select (info->attrs[NL80211_ATTR_BSS_SELECT ], wiphy, &connect.bss_select);if (err) { -kzfree (connkeys); +kfree_sensitive (connkeys);return err; } }
@@ -10312,13 +10312,13 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) info->attrs[NL80211_ATTR_FILS_ERP_REALM] || info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { -kzfree (connkeys); +kfree_sensitive (connkeys);return -EINVAL ; }if (nla_get_flag (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT ])) {if (!info->attrs[NL80211_ATTR_SOCKET_OWNER ]) { -kzfree (connkeys); +kfree_sensitive (connkeys);GENL_SET_ERR_MSG (info,"external auth requires connection ownership" );return -EINVAL ;
@@ -10331,7 +10331,7 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) err =cfg80211_connect (rdev, dev, &connect, connkeys, connect.prev_bssid);if (err) -kzfree (connkeys); +kfree_sensitive (connkeys);if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER ]) { dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
net/wireless/sme.c +3 -3
@@ -741,7 +741,7 @@ void __cfg80211_connect_result(struct net_device *dev, }if (cr->status !=WLAN_STATUS_SUCCESS ) { -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys =NULL ; wdev->ssid_len =0 ; wdev->conn_owner_nlportid =0 ;
@@ -1096,7 +1096,7 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, wdev->current_bss =NULL ; wdev->ssid_len =0 ; wdev->conn_owner_nlportid =0 ; -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys =NULL ;nl80211_send_disconnected (rdev, dev, reason, ie, ie_len, from_ap);
@@ -1276,7 +1276,7 @@ int cfg80211_disconnect(struct cfg80211_registered_device *rdev,ASSERT_WDEV_LOCK (wdev); -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys =NULL ; wdev->conn_owner_nlportid =0 ;
net/wireless/util.c +1 -1
@@ -853,7 +853,7 @@ void cfg80211_upload_connect_keys(struct wireless_dev *wdev) } } -kzfree (wdev->connect_keys); +kfree_sensitive (wdev->connect_keys); wdev->connect_keys =NULL ; }
net/wireless/wext-sme.c +1 -1
@@ -57,7 +57,7 @@ int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, err =cfg80211_connect (rdev, wdev->netdev, &wdev->wext.connect, ck, prev_bssid);if (err) -kzfree (ck); +kfree_sensitive (ck);return err; }
scripts/coccinelle/free/devm_free.cocci +2 -2
@@ -89,7 +89,7 @@ position p; ( kfree@p(x) | - kzfree@p(x) + kfree_sensitive@p(x) | krealloc@p(x, ...) |
@@ -112,7 +112,7 @@ position p != safe.p; ( * kfree@p(x) | -* kzfree@p(x) +* kfree_sensitive@p(x) | * krealloc@p(x, ...) |
scripts/coccinelle/free/ifnullfree.cocci +2 -2
@@ -21,7 +21,7 @@ expression E; ( kfree(E); | - kzfree(E); + kfree_sensitive(E); | debugfs_remove(E); |
@@ -42,7 +42,7 @@ position p; @@ * if (E != NULL) -* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| +* \(kfree@p\|kfree_sensitive@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| * usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\| * dma_pool_destroy@p\)(E);
scripts/coccinelle/free/kfree.cocci +3 -3
@@ -24,7 +24,7 @@ position p1; ( * kfree@p1(E) | -* kzfree@p1(E) +* kfree_sensitive@p1(E) ) @print expression@
@@ -68,7 +68,7 @@ while (1) { ... ( * kfree@ok(E) | -* kzfree@ok(E) +* kfree_sensitive@ok(E) ) ... when != break; when != goto l;
@@ -86,7 +86,7 @@ position free.p1!=loop.ok,p2!={print.p,sz.p}; ( * kfree@p1(E,...) | -* kzfree@p1(E,...) +* kfree_sensitive@p1(E,...) ) ... (
scripts/coccinelle/free/kfreeaddr.cocci +1 -1
@@ -20,7 +20,7 @@ position p; ( * kfree@p(&e->f) | -* kzfree@p(&e->f) +* kfree_sensitive@p(&e->f) ) @script:python depends on org@
security/apparmor/domain.c +2 -2
@@ -40,8 +40,8 @@ void aa_free_domain_entries(struct aa_domain *domain)return ;for (i =0 ; i < domain->size; i++) -kzfree (domain->table[i]); -kzfree (domain->table); +kfree_sensitive (domain->table[i]); +kfree_sensitive (domain->table); domain->table =NULL ; } }
security/apparmor/include/file.h +1 -1
@@ -72,7 +72,7 @@ static inline void aa_free_file_ctx(struct aa_file_ctx *ctx) {if (ctx) {aa_put_label (rcu_access_pointer (ctx->label)); -kzfree (ctx); +kfree_sensitive (ctx); } }
security/apparmor/policy.c +12 -12
@@ -187,9 +187,9 @@ static void aa_free_data(void *ptr, void *arg) {struct aa_data *data = ptr; -kzfree (data->data); -kzfree (data->key); -kzfree (data); +kfree_sensitive (data->data); +kfree_sensitive (data->key); +kfree_sensitive (data); }/**
@@ -217,19 +217,19 @@ void aa_free_profile(struct aa_profile *profile)aa_put_profile (rcu_access_pointer (profile->parent));aa_put_ns (profile->ns); -kzfree (profile->rename); +kfree_sensitive (profile->rename);aa_free_file_rules (&profile->file);aa_free_cap_rules (&profile->caps);aa_free_rlimit_rules (&profile->rlimits);for (i =0 ; i < profile->xattr_count; i++) -kzfree (profile->xattrs[i]); -kzfree (profile->xattrs); +kfree_sensitive (profile->xattrs[i]); +kfree_sensitive (profile->xattrs);for (i =0 ; i < profile->secmark_count; i++) -kzfree (profile->secmark[i].label); -kzfree (profile->secmark); -kzfree (profile->dirname); +kfree_sensitive (profile->secmark[i].label); +kfree_sensitive (profile->secmark); +kfree_sensitive (profile->dirname);aa_put_dfa (profile->xmatch);aa_put_dfa (profile->policy.dfa);
@@ -237,13 +237,13 @@ void aa_free_profile(struct aa_profile *profile) rht = profile->data; profile->data =NULL ;rhashtable_free_and_destroy (rht, aa_free_data,NULL ); -kzfree (rht); +kfree_sensitive (rht); } -kzfree (profile->hash); +kfree_sensitive (profile->hash);aa_put_loaddata (profile->rawdata); -kzfree (profile); +kfree_sensitive (profile); }/**
security/apparmor/policy_ns.c +3 -3
@@ -121,9 +121,9 @@ static struct aa_ns *alloc_ns(const char *prefix, const char *name)return ns; fail_unconfined: -kzfree (ns->base.hname); +kfree_sensitive (ns->base.hname); fail_ns: -kzfree (ns); +kfree_sensitive (ns);return NULL ; }
@@ -145,7 +145,7 @@ void aa_free_ns(struct aa_ns *ns) ns->unconfined->ns =NULL ;aa_free_profile (ns->unconfined); -kzfree (ns); +kfree_sensitive (ns); }/**
security/apparmor/policy_unpack.c +7 -7
@@ -163,10 +163,10 @@ static void do_loaddata_free(struct work_struct *work)aa_put_ns (ns); } -kzfree (d->hash); -kzfree (d->name); +kfree_sensitive (d->hash); +kfree_sensitive (d->name);kvfree (d->data); -kzfree (d); +kfree_sensitive (d); }void aa_loaddata_kref (struct kref *kref)
@@ -890,7 +890,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)while (unpack_strdup (e, &key,NULL )) { data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data) { -kzfree (key); +kfree_sensitive (key); goto fail; }
@@ -898,8 +898,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) data->size =unpack_blob (e, &data->data,NULL ); data->data =kvmemdup (data->data, data->size);if (data->size && !data->data) { -kzfree (data->key); -kzfree (data); +kfree_sensitive (data->key); +kfree_sensitive (data); goto fail; }
@@ -1033,7 +1033,7 @@ void aa_load_ent_free(struct aa_load_ent *ent)aa_put_profile (ent->old);aa_put_profile (ent->new);kfree (ent->ns_name); -kzfree (ent); +kfree_sensitive (ent); } }
security/keys/big_key.c +3 -3
@@ -281,7 +281,7 @@ int big_key_preparse(struct key_preparsed_payload *prep) err_fput:fput (file); err_enckey: -kzfree (enckey); +kfree_sensitive (enckey); error:big_key_free_buffer (buf);return ret;
@@ -297,7 +297,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]); }/*
@@ -329,7 +329,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 ; }
security/keys/dh.c +7 -7
@@ -58,9 +58,9 @@ static ssize_t dh_data_from_key(key_serial_t keyid, void **data)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:
security/keys/encrypted-keys/encrypted.c +7 -7
@@ -382,7 +382,7 @@ static int get_derived_key(u8 *derived_key, enum derived_key_type key_type,memcpy (derived_buf +strlen (derived_buf) +1 , master_key, master_keylen); ret =calc_hash (hash_tfm, derived_key, derived_buf, derived_buf_len); -kzfree (derived_buf); +kfree_sensitive (derived_buf);return ret; }
@@ -824,13 +824,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; }
@@ -839,7 +839,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); }/*
@@ -897,7 +897,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; }
@@ -958,7 +958,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:
@@ -973,7 +973,7 @@ static long encrypted_read(const struct key *key, char *buffer,*/ static void encrypted_destroy (struct key *key) { -kzfree (key->payload.data[0 ]); +kfree_sensitive (key->payload.data[0 ]); }struct key_type key_type_encrypted = {
security/keys/trusted-keys/trusted_tpm1.c +17 -17
@@ -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 = {
security/keys/user_defined.c +3 -3
@@ -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);
Signature · 1 line
2.18.1
PATCH 2/2 crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongSince 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.
--- .../crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 15 +++------------ .../crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 16 +++------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 4 files changed, 9 insertions(+), 35 deletions(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +3 -12
@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync_suspend (op->ce->dev); }
@@ -391,10 +388,7 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
@@ -416,10 +410,7 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +free_sensitive (op->key, op->keylen); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +3 -13
@@ -249,7 +249,6 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -memzero_explicit (backup_iv, ivsize);kfree_sensitive (backup_iv); }else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset,
@@ -367,10 +366,7 @@ void sun8i_ss_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync (op->ss->dev); }
@@ -392,10 +388,7 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ss->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
@@ -418,10 +411,7 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
drivers/crypto/amlogic/amlogic-gxl-cipher.c +2 -8
@@ -341,10 +341,7 @@ void meson_cipher_exit(struct crypto_tfm *tfm) {struct meson_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } + kfree_sensitive(op->key)crypto_free_sync_skcipher (op->fallback_tfm); }
@@ -368,10 +365,7 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (mc->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
drivers/crypto/inside-secure/safexcel_hash.c +1 -2
@@ -1081,8 +1081,7 @@ static int safexcel_hmac_init_pad(struct ahash_request *areq, }/* Avoid leaking */ -memzero_explicit (keydup, keylen); -kfree (keydup); +kfree_sensitive (keydup);if (ret)return ret;
Signature · 1 line
2.18.1
Re: [PATCH 2/2] crypto: Remove unnecessary memzero_explicit()
Quoted 3 lines · Waiman Long
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_explicit()and simplify the call sites.
2 bits of trivia:
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
Quoted 1 line
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +0
-0
[]
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 394
Quoted 12 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-4@@ -391,10 +388,7 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)
It might be a defect to set op->keylen before the kmemdup succeeds.
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 413
Quoted 9 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-4@@ -416,10 +410,7 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +free_sensitive (op->key, op->keylen);
Why not kfree_sensitive(op->key) ?
Re: [PATCH 2/2] crypto: Remove unnecessary memzero_explicit()
Quoted 8 lines · Joe Perches
Quoted 3 lines · Waiman Long
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_explicit()and simplify the call sites.2 bits of trivia:
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
Quoted 1 line
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +0
-0[]
Quoted 13 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 394
Quoted 12 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-4@@ -391,10 +388,7 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)It might be a defect to set
op->keylenbefore the kmemdup succeeds.
It could be. I can move it down after the op->key check.
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 413
Quoted 9 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-4@@ -416,10 +410,7 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +free_sensitive (op->key, op->keylen);Why not
kfree_sensitive(op->key)?
Oh, it is a bug. I will send out v2 to fix that.
Thanks for spotting it.
Cheers,
Longman
Quoted 2 lines
PATCH v2 2/2 crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongSince 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.
--- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 19 +++++------------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 20 +++++-------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 12 +++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 4 files changed, 14 insertions(+), 40 deletions(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +5 -14
@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync_suspend (op->ce->dev); }
@@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
@@ -416,14 +410,11 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +5 -15
@@ -249,7 +249,6 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -memzero_explicit (backup_iv, ivsize);kfree_sensitive (backup_iv); }else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset,
@@ -367,10 +366,7 @@ void sun8i_ss_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync (op->ss->dev); }
@@ -392,14 +388,11 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ss->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
@@ -418,14 +411,11 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
drivers/crypto/amlogic/amlogic-gxl-cipher.c +3 -9
@@ -341,10 +341,7 @@ void meson_cipher_exit(struct crypto_tfm *tfm) {struct meson_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm); }
@@ -368,14 +365,11 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (mc->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;return crypto_sync_skcipher_setkey (op->fallback_tfm, key, keylen); }
drivers/crypto/inside-secure/safexcel_hash.c +1 -2
@@ -1081,8 +1081,7 @@ static int safexcel_hmac_init_pad(struct ahash_request *areq, }/* Avoid leaking */ -memzero_explicit (keydup, keylen); -kfree (keydup); +kfree_sensitive (keydup);if (ret)return ret;
Signature · 1 line
2.18.1
kbuild test robot
build botRe: [PATCH 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongThank you for the patch! Yet something to improve:
Hi Waiman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc1 next-20200413]
[cannot apply to mmotm/master cryptodev/master crypto/master mac80211-next/master mac80211/master] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Waiman-Long/mm-treewide-Rename-kzfree-to-kfree_sensitive/20200414-052843 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8f3d9f354286745c751374f5f1fcafee6b3f3136 config: x86_64-randconfig-s1-20200414 (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/crypto/amlogic/amlogic-gxl-cipher.c: In function 'meson_cipher_exit':
>> drivers/crypto/amlogic/amlogic-gxl-cipher.c:345:2: error: expected ';' before 'crypto_free_sync_skcipher'
crypto_free_sync_skcipher(op->fallback_tfm);
^~~~~~~~~~~~~~~~~~~~~~~~~vim +345 drivers/crypto/amlogic/amlogic-gxl-cipher.c
48fe583fe54177 Corentin Labbe 2019-10-17 339
48fe583fe54177 Corentin Labbe 2019-10-17 340 void meson_cipher_exit(struct crypto_tfm *tfm)
48fe583fe54177 Corentin Labbe 2019-10-17 341 {
48fe583fe54177 Corentin Labbe 2019-10-17 342 struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm);
48fe583fe54177 Corentin Labbe 2019-10-17 343
7deb7a15114330 Waiman Long 2020-04-13 344 kfree_sensitive(op->key)48fe583fe54177 Corentin Labbe 2019-10-17 @345 crypto_free_sync_skcipher(op->fallback_tfm);48fe583fe54177 Corentin Labbe 2019-10-17 346 }48fe583fe54177 Corentin Labbe 2019-10-17 347
:::::: The code at line 345 was first introduced by commit
:::::: 48fe583fe54177bfb80f348e2a5cc34c3f710095 crypto: amlogic - Add crypto accelerator for amlogic GXL
:::::: TO: Corentin Labbe <[email protected]> :::::: CC: Herbert Xu <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH 2/2] crypto: Remove unnecessary memzero_explicit()
Quoted 44 lines · kbuild test robot
Hi Waiman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc1 next-20200413]
[cannot apply to mmotm/master cryptodev/mastercrypto/mastermac80211-next/master mac80211/master] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Waiman-Long/mm-treewide-Rename-kzfree-to-kfree_sensitive/20200414-052843 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8f3d9f354286745c751374f5f1fcafee6b3f3136 config: x86_64-randconfig-s1-20200414 (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All errors (new ones prefixed by >>):
drivers/crypto/amlogic/amlogic-gxl-cipher.c: In function 'meson_cipher_exit':Quoted 1 line
Quoted 1 line
drivers/crypto/amlogic/amlogic-gxl-cipher.c:345:2: error: expected ';' before 'crypto_free_sync_skcipher'crypto_free_sync_skcipher(op->fallback_tfm); ^~~~~~~~~~~~~~~~~~~~~~~~~vim +345
drivers/crypto/amlogic/amlogic-gxl-cipher.c48fe583fe54177 Corentin Labbe 2019-10-17 339 48fe583fe54177 Corentin Labbe 2019-10-17 340 void meson_cipher_exit(struct crypto_tfm *tfm) 48fe583fe54177 Corentin Labbe 2019-10-17 341 { 48fe583fe54177 Corentin Labbe 2019-10-17 342 struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); 48fe583fe54177 Corentin Labbe 2019-10-17 343 7deb7a15114330 Waiman Long 2020-04-13 344 kfree_sensitive(op->key)
48fe583fe54177Corentin Labbe 2019-10-17 @345crypto_free_sync_skcipher(op->fallback_tfm);48fe583fe54177Corentin Labbe 2019-10-17 346 }48fe583fe54177Corentin Labbe 2019-10-17 347:::::: The code at line 345 was first introduced by commit
::::::48fe583fe54177bfb80f348e2a5cc34c3f710095crypto: amlogic - Add crypto accelerator for amlogic GXL
Quoted 6 lines
:::::: TO: Corentin Labbe <[email protected]> :::::: CC: Herbert Xu <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
That should have been fixed in the v2 patch.
Cheers,
Longman
kbuild test robot
build botRe: [PATCH 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongThank you for the patch! Yet something to improve:
Hi Waiman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc1 next-20200413]
[cannot apply to mmotm/master cryptodev/master crypto/master mac80211-next/master mac80211/master] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Waiman-Long/mm-treewide-Rename-kzfree-to-kfree_sensitive/20200414-052843 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8f3d9f354286745c751374f5f1fcafee6b3f3136 config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c: In function 'sun8i_ce_des3_setkey':
>> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c:413:2: error: implicit declaration of function 'free_sensitive'; did you mean 'kfree_sensitive'? [-Werror=implicit-function-declaration]
413 | free_sensitive(op->key, op->keylen);
| ^~~~~~~~~~~~~~
| kfree_sensitivecc1: some warnings being treated as errors
vim +413 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
402
403 int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
404 unsigned int keylen)
405 {
406 struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm);
407 int err;
408
409 err = verify_skcipher_des3_key(tfm, key);
410 if (err)
411 return err;
412
> 413 free_sensitive(op->key, op->keylen);
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 23 lines · Waiman Long
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()tokfree_sensitive()to follow the example of the recently addedkvfree_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:
Quoted 8 lines
git grep -w --name-only kzfree |\ xargs sed -i 's/\bkzfree\b/kfree_sensitive/'followed by some editing of the
kfree_sensitive()kerneldoc and the use ofmemzero_explicit()instead ofmemset().Suggested-by Joe Perches <[email protected]>Signed-off-by Waiman Long <[email protected]>
Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongLe 14/04/2020 à 00:28, Waiman Long a écrit :
Quoted 33 lines
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_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 <[email protected]>--- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 19 +++++------------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 20 +++++-------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 12 +++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 4 files changed, 14 insertions(+), 40 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-4@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync_suspend (op->ce->dev); }@@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; }
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 395
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +2
-5-if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = 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.
Quoted 7 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +0
-0crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );@@ -416,14 +410,11 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err;
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 417
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +2
-5-if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;
Same comment as above.
Quoted 31 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +0
-0crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +1
-5@@ -249,7 +249,6 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -memzero_explicit (backup_iv, ivsize);kfree_sensitive (backup_iv); }else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset,@@ -367,10 +366,7 @@ void sun8i_ss_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync (op->ss->dev); }@@ -392,14 +388,11 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ss->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; }
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 395
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +2
-5-if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;
Same comment as above.
Quoted 7 lines
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +0
-0crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );@@ -418,14 +411,11 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ; }
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 418
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +2
-5-if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;
Same comment as above.
Quoted 23 lines
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +0
-0crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );drivers/crypto/amlogic/amlogic-gxl-cipher.c +1
-4@@ -341,10 +341,7 @@ void meson_cipher_exit(struct crypto_tfm *tfm) {struct meson_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm); }@@ -368,14 +365,11 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (mc->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; }
drivers/crypto/amlogic/amlogic-gxl-cipher.c int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 372
Quoted 10 lines
drivers/crypto/amlogic/amlogic-gxl-cipher.c +2
-5-if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } - op->keylen = keylen; +kfree_sensitive (op->key); op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA );if (!op->key)return -ENOMEM ; + op->keylen = keylen;
Same comment as above.
Quoted 9 lines
drivers/crypto/amlogic/amlogic-gxl-cipher.c +0
-0return crypto_sync_skcipher_setkey (op->fallback_tfm, key, keylen); }drivers/crypto/inside-secure/safexcel_hash.c +0
-0
drivers/crypto/inside-secure/safexcel_hash.c static int safexcel_hmac_init_pad(struct ahash_request *areq, · line 1087
Quoted 9 lines
drivers/crypto/inside-secure/safexcel_hash.c +1
-2@@ -1081,8 +1081,7 @@ static int safexcel_hmac_init_pad(struct ahash_request *areq, }/* Avoid leaking */ -memzero_explicit (keydup, keylen); -kfree (keydup); +kfree_sensitive (keydup);if (ret)return ret;
Christophe
Jason A. Donenfeld
maintainerQuoted 12 lines · Waiman Long
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_.
Quoted 7 lines
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()tokfree_sensitive()to follow the example of the recently addedkvfree_sensitive()and make the intention of the API more explicit.
Seems reasonable to me. One bikeshed, that you can safely discard and ignore as a mere bikeshed: kfree_memzero or kfree_scrub or kfree_{someverb} seems like a better function name, as it describes what the function does, rather than "_sensitive" that suggests something about the data maybe but who knows what that entails. If you disagree, not a big deal either way.
Quoted 2 lines
In addition,
memzero_explicit()is used to clear the memory to make sure that it won't get optimized away by the compiler.
This had occurred to me momentarily a number of years ago, but I was under the impression that the kernel presumes extern function calls to always imply a compiler barrier, making it difficult for the compiler to reason about what happens in/after kfree, in order to be able to optimize out the preceding memset. With LTO, that rule obviously changes. I guess new code should be written with cross-object optimizations in mind now a days? [Meanwhile, it would be sort of interesting to teach gcc about kfree to enable additional scary optimizations...]
Quoted 23 lines · Waiman Long
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()tokfree_sensitive()to follow the example of the recently addedkvfree_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:
Quoted 8 lines
git grep -w --name-only kzfree |\ xargs sed -i 's/\bkzfree\b/kfree_sensitive/'followed by some editing of the
kfree_sensitive()kerneldoc and the use ofmemzero_explicit()instead ofmemset().Suggested-by Joe Perches <[email protected]>Signed-off-by Waiman Long <[email protected]>
Makes sense. I haven't checked all the conversions and will rely on the script doing the right thing. The core MM part is correct.
Signature · 2 lines
Michal Hocko SUSE Labs
fs/btrfs/ioctl.c static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) · line 2694
Quoted 13 lines · Waiman Long
fs/btrfs/ioctl.c | 2 +-fs/btrfs/ioctl.c +1
-1@@ -2691,7 +2691,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)btrfs_put_root (root); out_free:btrfs_free_path (path); -kzfree (subvol_info); +kfree_sensitive (subvol_info);
This is not in a sensitive context so please switch it to plain kfree. With that you have my acked-by. Thanks.
Quoted 23 lines · Waiman Long
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()tokfree_sensitive()to follow the example of the recently addedkvfree_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:
Quoted 8 lines
git grep -w --name-only kzfree |\ xargs sed -i 's/\bkzfree\b/kfree_sensitive/'followed by some editing of the
kfree_sensitive()kerneldoc and the use ofmemzero_explicit()instead ofmemset().Suggested-by Joe Perches <[email protected]>Signed-off-by Waiman Long <[email protected]>
Since this changes a lot of crypto stuff, does it make sense for it to go via the crypto tree?
Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Christophe LeroyQuoted 51 lines · Christophe Leroy
Le 14/04/2020 à 00:28, Waiman Long a écrit :
Quoted 34 lines
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_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 <[email protected]>---
.../allwinner/sun8i-ce/sun8i-ce-cipher.c | 19 +++++------------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 20 +++++-------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 12 +++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +--4 files changed, 14 insertions(+), 40 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-3@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) { struct sun8i_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); - if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } + kfree_sensitive(op->key); crypto_free_sync_skcipher(op->fallback_tfm); pm_runtime_put_sync_suspend(op->ce->dev); }@@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(ce->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; }drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher · line 396
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +2
-5- if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } - op->keylen = keylen; + kfree_sensitive(op->key); op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); if (!op->key) return -ENOMEM; + op->keylen = keylen;Does it matter at all to ensure
op->keylenis not set whenof->keyis NULL ? I'm not sure.
Quoted 1 line
But if it does, then
op->keylenshould be set to 0 when freeingop->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.
Cheers,
Longman
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 16 lines · David Sterba
fs/btrfs/ioctl.c static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) · line 2694
Quoted 12 lines · Waiman Long
fs/btrfs/ioctl.c | 2 +-fs/btrfs/ioctl.c +1
-1@@ -2691,7 +2691,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)btrfs_put_root (root); out_free:btrfs_free_path (path); -kzfree (subvol_info); +kfree_sensitive (subvol_info);This is not in a sensitive context so please switch it to plain kfree. With that you have my acked-by. Thanks.
Thanks for letting me know about. I think I will send it out as a separate patch.
Cheers,
Longman
Quoted 16 lines · David Sterba
fs/btrfs/ioctl.c static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) · line 2694
Quoted 12 lines · Waiman Long
fs/btrfs/ioctl.c | 2 +-fs/btrfs/ioctl.c +1
-1@@ -2691,7 +2691,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)btrfs_put_root (root); out_free:btrfs_free_path (path); -kzfree (subvol_info); +kfree_sensitive (subvol_info);This is not in a sensitive context so please switch it to plain kfree. With that you have my acked-by. Thanks.
Thanks for letting me know about. I think I will send it out as a separate patch.
Cheers,
Longman
Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongQuoted 52 lines · Waiman Long
Quoted 51 lines · Christophe Leroy
Le 14/04/2020 à 00:28, Waiman Long a écrit :
Quoted 34 lines
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_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 <[email protected]>---
.../allwinner/sun8i-ce/sun8i-ce-cipher.c | 19 +++++------------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 20 +++++-------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 12 +++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +--4 files changed, 14 insertions(+), 40 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-3@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) { struct sun8i_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); - if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } + kfree_sensitive(op->key); crypto_free_sync_skcipher(op->fallback_tfm); pm_runtime_put_sync_suspend(op->ce->dev); }@@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(ce->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; }drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher · line 396
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +2
-5- if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } - op->keylen = keylen; + kfree_sensitive(op->key); op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); if (!op->key) return -ENOMEM; + op->keylen = keylen;Does it matter at all to ensure
op->keylenis not set whenof->keyis NULL ? I'm not sure.
Quoted 5 lines
Quoted 1 line
But if it does, then
op->keylenshould be set to 0 when freeingop->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.
Thanks
Michal
PATCH v2 3/3 btrfs: Use kfree() in btrfs_ioctl_get_subvol_info()
In reply to Waiman LongIn btrfs_ioctl_get_subvol_info(), there is a classic case where kzalloc() was incorrectly paired with kzfree(). According to David Sterba, there isn't any sensitive information in the subvol_info that needs to be cleared before freeing. So kfree_sensitive() isn't really needed, use kfree() instead.
--- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ioctl.c +1 -1
@@ -2691,7 +2691,7 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)btrfs_put_root (root); out_free:btrfs_free_path (path); -kfree_sensitive (subvol_info); +kfree (subvol_info);return ret; }
Signature · 1 line
2.18.1
Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit()
In reply to Michal SuchánekQuoted 52 lines · Michal Suchánek
Quoted 51 lines · Waiman Long
Quoted 50 lines · Christophe Leroy
Le 14/04/2020 à 00:28, Waiman Long a écrit :
Quoted 34 lines
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_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 <[email protected]>---
.../allwinner/sun8i-ce/sun8i-ce-cipher.c | 19 +++++------------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 20 +++++-------------- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 12 +++-------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +--4 files changed, 14 insertions(+), 40 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +1
-3@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) { struct sun8i_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); - if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } + kfree_sensitive(op->key); crypto_free_sync_skcipher(op->fallback_tfm); pm_runtime_put_sync_suspend(op->ce->dev); }@@ -391,14 +388,11 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(ce->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; }drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c int sun8i_ce_aes_setkey(struct crypto_skcipher · line 396
Quoted 10 lines
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +2
-5- if (op->key) { - memzero_explicit(op->key, op->keylen); - kfree(op->key); - } - op->keylen = keylen; + kfree_sensitive(op->key); op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); if (!op->key) return -ENOMEM; + op->keylen = keylen;Does it matter at all to ensure
op->keylenis not set whenof->keyis NULL ? I'm not sure.But if it does, then
op->keylenshould be set to 0 when freeingop->key.
Quoted 8 lines
Quoted 3 lines
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
Re: [PATCH v2 2/2] crypto: Remove unnecessary memzero_explicit()
Quoted 2 lines · Waiman Long
OK, I can change it to clear the key length when the allocation failed which isn't likely.
Perhaps:
kfree_sensitive(op->key); op->key = NULL; op->keylen = 0;
but I don't know that it impacts any possible state.
PATCH v3 2/3 crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongSince 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, keylen is cleared if key memory allocation fails.
--- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 23 +++++++----------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 24 +++++++------------ drivers/crypto/amlogic/amlogic-gxl-cipher.c | 14 ++++------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 4 files changed, 24 insertions(+), 40 deletions(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +9 -14
@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync_suspend (op->ce->dev); }
@@ -391,14 +388,13 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) { + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
@@ -416,14 +412,13 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) { + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +9 -15
@@ -249,7 +249,6 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -memzero_explicit (backup_iv, ivsize);kfree_sensitive (backup_iv); }else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset,
@@ -367,10 +366,7 @@ void sun8i_ss_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync (op->ss->dev); }
@@ -392,14 +388,13 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ss->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
@@ -418,14 +413,13 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );
drivers/crypto/amlogic/amlogic-gxl-cipher.c +5 -9
@@ -341,10 +341,7 @@ void meson_cipher_exit(struct crypto_tfm *tfm) {struct meson_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm); }
@@ -368,14 +365,13 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (mc->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }return crypto_sync_skcipher_setkey (op->fallback_tfm, key, keylen); }
drivers/crypto/inside-secure/safexcel_hash.c +1 -2
@@ -1081,8 +1081,7 @@ static int safexcel_hmac_init_pad(struct ahash_request *areq, }/* Avoid leaking */ -memzero_explicit (keydup, keylen); -kfree (keydup); +kfree_sensitive (keydup);if (ret)return ret;
Signature · 1 line
2.18.1
Quoted 4 lines · Waiman Long
As said by Linus:
A symmetric naming is only helpful if it implies symmetries in use. Otherwise it's actively misleading.
As the btrfs example proves - people can be tempted by this false symmetry to pair kzalloc with kzfree, which isn't what we wanted.
Quoted 18 lines
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()tokfree_sensitive()to follow the example of the recently addedkvfree_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:
Quoted 8 lines
git grep -w --name-only kzfree |\ xargs sed -i 's/\bkzfree\b/kfree_sensitive/'followed by some editing of the
kfree_sensitive()kerneldoc and the use ofmemzero_explicit()instead ofmemset().Suggested-by Joe Perches <[email protected]>Signed-off-by Waiman Long <[email protected]>
Looks good to me. Thanks for fixing this very old mistake.
Re: [PATCH v3 2/3] crypto: Remove unnecessary memzero_explicit()
In reply to Waiman LongQuoted 154 lines · Waiman Long
Since
kfree_sensitive()will do an implicitmemzero_explicit(), there is no need to callmemzero_explicit()before it. Eliminate thosememzero_explicit()and simplify the call sites. For better correctness, keylen is cleared if key memory allocation fails.Signed-off-by Waiman Long <[email protected]>--- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 23 +++++++----------- .../allwinner/sun8i-ss/sun8i-ss-cipher.c | 24 +++++++------------ drivers/crypto/amlogic/amlogic-gxl-cipher.c | 14 ++++------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 4 files changed, 24 insertions(+), 40 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +9
-14@@ -366,10 +366,7 @@ void sun8i_ce_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync_suspend (op->ce->dev); }@@ -391,14 +388,13 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ce->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) { + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );@@ -416,14 +412,13 @@ int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,if (err)return err; -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) { + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +9
-15@@ -249,7 +249,6 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) offset = areq->cryptlen - ivsize;if (rctx->op_dir &SS_DECRYPTION ) {memcpy (areq->iv, backup_iv, ivsize); -memzero_explicit (backup_iv, ivsize);kfree_sensitive (backup_iv); }else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset,@@ -367,10 +366,7 @@ void sun8i_ss_cipher_exit(struct crypto_tfm *tfm) {struct sun8i_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm);pm_runtime_put_sync (op->ss->dev); }@@ -392,14 +388,13 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (ss->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );@@ -418,14 +413,13 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key); op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }crypto_sync_skcipher_clear_flags (op->fallback_tfm,CRYPTO_TFM_REQ_MASK );crypto_sync_skcipher_set_flags (op->fallback_tfm, tfm->base.crt_flags &CRYPTO_TFM_REQ_MASK );drivers/crypto/amlogic/amlogic-gxl-cipher.c +2
-8@@ -341,10 +341,7 @@ void meson_cipher_exit(struct crypto_tfm *tfm) {struct meson_cipher_tfm_ctx *op =crypto_tfm_ctx (tfm); -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);crypto_free_sync_skcipher (op->fallback_tfm); }@@ -368,14 +365,13 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,dev_dbg (mc->dev,"ERROR: Invalid keylen %u\n" , keylen);return -EINVAL ; } -if (op->key) { -memzero_explicit (op->key, op->keylen); -kfree (op->key); - } +kfree_sensitive (op->key);
drivers/crypto/amlogic/amlogic-gxl-cipher.c int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, · line 377
Quoted 10 lines
drivers/crypto/amlogic/amlogic-gxl-cipher.c +3
-1op->keylen = keylen; op->key =kmemdup (key, keylen,GFP_KERNEL |GFP_DMA ); -if (!op->key) +if (unlikely (!op->key)) + op->keylen =0 ;return -ENOMEM ; + }return crypto_sync_skcipher_setkey (op->fallback_tfm, key, keylen); }
For sun8i-ss/sun8i-ce
For amlogic
Thanks
Quoted 26 lines · Waiman Long
mm/slab_common.c +3
-3@@ -1707,17 +1707,17 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)EXPORT_SYMBOL (krealloc);/** -* kzfree - like kfree but zero memory +* kfree_sensitive - Clear sensitive information in memory before freeing * @p: object to free memory of * * The memory of the object @p points to is zeroed before freed. -* If @p is %NULL, kzfree() does nothing. +* If @p is %NULL, kfree_sensitive() does nothing. * * Note: this function zeroes the whole allocated buffer which can be a good * deal bigger than the requested buffer size passed to kmalloc(). So be * careful when using this function in performance sensitive code. */ -void kzfree (const void *p) +void kfree_sensitive (const void *p) {size_t ks;void *mem = (void *)p;
mm/slab_common.c void kzfree(const void *p) · line 1728
Quoted 5 lines
mm/slab_common.c +1
-1@@ -1725,10 +1725,10 @@ void kzfree(const void *p)if (unlikely (ZERO_OR_NULL_PTR (mem)))return ; ks =ksize (mem); -memset (mem,0 , ks); +memzero_explicit (mem, ks);
^^^^^^^^^^^^^^^^^^^^^^^^^
This is an unrelated bug fix. It really needs to be pulled into a separate patch by itself and back ported to stable kernels.
mm/slab_common.c void kzfree(const void *p) · line 1734
Quoted 7 lines
mm/slab_common.c +1
-1kfree (mem); } -EXPORT_SYMBOL (kzfree); +EXPORT_SYMBOL (kfree_sensitive);/** * ksize - get the actual amount of memory allocated for a given object
regards,
dan carpenter
Quoted 41 lines · Dan Carpenter
Quoted 26 lines · Waiman Long
mm/slab_common.c +3
-3@@ -1707,17 +1707,17 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)EXPORT_SYMBOL (krealloc);/** -* kzfree - like kfree but zero memory +* kfree_sensitive - Clear sensitive information in memory before freeing * @p: object to free memory of * * The memory of the object @p points to is zeroed before freed. -* If @p is %NULL, kzfree() does nothing. +* If @p is %NULL, kfree_sensitive() does nothing. * * Note: this function zeroes the whole allocated buffer which can be a good * deal bigger than the requested buffer size passed to kmalloc(). So be * careful when using this function in performance sensitive code. */ -void kzfree (const void *p) +void kfree_sensitive (const void *p) {size_t ks;void *mem = (void *)p;mm/slab_common.c void kzfree(const void *p) · line 1728
Quoted 5 lines
mm/slab_common.c +1
-1@@ -1725,10 +1725,10 @@ void kzfree(const void *p)if (unlikely (ZERO_OR_NULL_PTR (mem)))return ; ks =ksize (mem); -memset (mem,0 , ks); +memzero_explicit (mem, ks);^^^^^^^^^^^^^^^^^^^^^^^^^This is an unrelated bug fix. It really needs to be pulled into a separate patch by itself and back ported to stable kernels.
Quoted 5 lines
mm/slab_common.c +1
-1kfree (mem); } -EXPORT_SYMBOL (kzfree); +EXPORT_SYMBOL (kfree_sensitive);
Quoted 5 lines
mm/slab_common.c void kzfree(const void *p) · line 1734
Quoted 2 lines
mm/slab_common.c +0
-0/** * ksize - get the actual amount of memory allocated for a given object regards,
dan carpenter
Thanks for the suggestion. I will break it out and post a version soon.
Cheers,
Longman