Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 May 2019 03:15:06 +0000 (20:15 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 May 2019 03:15:06 +0000 (20:15 -0700)
Pull crypto update from Herbert Xu:
 "API:
   - Add support for AEAD in simd
   - Add fuzz testing to testmgr
   - Add panic_on_fail module parameter to testmgr
   - Use per-CPU struct instead multiple variables in scompress
   - Change verify API for akcipher

  Algorithms:
   - Convert x86 AEAD algorithms over to simd
   - Forbid 2-key 3DES in FIPS mode
   - Add EC-RDSA (GOST 34.10) algorithm

  Drivers:
   - Set output IV with ctr-aes in crypto4xx
   - Set output IV in rockchip
   - Fix potential length overflow with hashing in sun4i-ss
   - Fix computation error with ctr in vmx
   - Add SM4 protected keys support in ccree
   - Remove long-broken mxc-scc driver
   - Add rfc4106(gcm(aes)) cipher support in cavium/nitrox"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (179 commits)
  crypto: ccree - use a proper le32 type for le32 val
  crypto: ccree - remove set but not used variable 'du_size'
  crypto: ccree - Make cc_sec_disable static
  crypto: ccree - fix spelling mistake "protedcted" -> "protected"
  crypto: caam/qi2 - generate hash keys in-place
  crypto: caam/qi2 - fix DMA mapping of stack memory
  crypto: caam/qi2 - fix zero-length buffer DMA mapping
  crypto: stm32/cryp - update to return iv_out
  crypto: stm32/cryp - remove request mutex protection
  crypto: stm32/cryp - add weak key check for DES
  crypto: atmel - remove set but not used variable 'alg_name'
  crypto: picoxcell - Use dev_get_drvdata()
  crypto: crypto4xx - get rid of redundant using_sd variable
  crypto: crypto4xx - use sync skcipher for fallback
  crypto: crypto4xx - fix cfb and ofb "overran dst buffer" issues
  crypto: crypto4xx - fix ctr-aes missing output IV
  crypto: ecrdsa - select ASN1 and OID_REGISTRY for EC-RDSA
  crypto: ux500 - use ccflags-y instead of CFLAGS_<basename>.o
  crypto: ccree - handle tee fips error during power management resume
  crypto: ccree - add function to handle cryptocell tee fips error
  ...

14 files changed:
1  2 
arch/arm64/crypto/aes-ce-ccm-glue.c
arch/arm64/crypto/aes-neonbs-glue.c
arch/arm64/crypto/chacha-neon-glue.c
arch/arm64/crypto/crct10dif-ce-glue.c
arch/arm64/crypto/ghash-ce-glue.c
arch/arm64/crypto/nhpoly1305-neon-glue.c
arch/arm64/crypto/sha256-glue.c
arch/powerpc/include/asm/Kbuild
crypto/lrw.c
crypto/testmgr.h
crypto/xts.c
drivers/md/dm-integrity.c
fs/cifs/misc.c
security/keys/trusted.c

@@@ -14,6 -14,7 +14,7 @@@
  #include <crypto/aes.h>
  #include <crypto/scatterwalk.h>
  #include <crypto/internal/aead.h>
+ #include <crypto/internal/simd.h>
  #include <crypto/internal/skcipher.h>
  #include <linux/module.h>
  
@@@ -109,7 -110,7 +110,7 @@@ static int ccm_init_mac(struct aead_req
  static void ccm_update_mac(struct crypto_aes_ctx *key, u8 mac[], u8 const in[],
                           u32 abytes, u32 *macp)
  {
-       if (may_use_simd()) {
+       if (crypto_simd_usable()) {
                kernel_neon_begin();
                ce_aes_ccm_auth_data(mac, in, abytes, macp, key->key_enc,
                                     num_rounds(key));
@@@ -255,7 -256,7 +256,7 @@@ static int ccm_encrypt(struct aead_requ
  
        err = skcipher_walk_aead_encrypt(&walk, req, false);
  
-       if (may_use_simd()) {
+       if (crypto_simd_usable()) {
                while (walk.nbytes) {
                        u32 tail = walk.nbytes % AES_BLOCK_SIZE;
  
@@@ -313,7 -314,7 +314,7 @@@ static int ccm_decrypt(struct aead_requ
  
        err = skcipher_walk_aead_decrypt(&walk, req, false);
  
-       if (may_use_simd()) {
+       if (crypto_simd_usable()) {
                while (walk.nbytes) {
                        u32 tail = walk.nbytes % AES_BLOCK_SIZE;
  
@@@ -372,7 -373,7 +373,7 @@@ static struct aead_alg ccm_aes_alg = 
  
  static int __init aes_mod_init(void)
  {
 -      if (!(elf_hwcap & HWCAP_AES))
 +      if (!cpu_have_named_feature(AES))
                return -ENODEV;
        return crypto_register_aead(&ccm_aes_alg);
  }
@@@ -288,7 -288,7 +288,7 @@@ static int ctr_encrypt_sync(struct skci
        struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
        struct aesbs_ctr_ctx *ctx = crypto_skcipher_ctx(tfm);
  
-       if (!may_use_simd())
+       if (!crypto_simd_usable())
                return aes_ctr_encrypt_fallback(&ctx->fallback, req);
  
        return ctr_encrypt(req);
@@@ -304,6 -304,8 +304,8 @@@ static int __xts_crypt(struct skcipher_
        int err;
  
        err = skcipher_walk_virt(&walk, req, false);
+       if (err)
+               return err;
  
        kernel_neon_begin();
        neon_aes_ecb_encrypt(walk.iv, walk.iv, ctx->twkey, ctx->key.rounds, 1);
@@@ -440,7 -442,7 +442,7 @@@ static int __init aes_init(void
        int err;
        int i;
  
 -      if (!(elf_hwcap & HWCAP_ASIMD))
 +      if (!cpu_have_named_feature(ASIMD))
                return -ENODEV;
  
        err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
@@@ -21,6 -21,7 +21,7 @@@
  
  #include <crypto/algapi.h>
  #include <crypto/chacha.h>
+ #include <crypto/internal/simd.h>
  #include <crypto/internal/skcipher.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
@@@ -90,7 -91,7 +91,7 @@@ static int chacha_neon(struct skcipher_
        struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
        struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
  
-       if (req->cryptlen <= CHACHA_BLOCK_SIZE || !may_use_simd())
+       if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable())
                return crypto_chacha_crypt(req);
  
        return chacha_neon_stream_xor(req, ctx, req->iv);
@@@ -104,7 -105,7 +105,7 @@@ static int xchacha_neon(struct skcipher
        u32 state[16];
        u8 real_iv[16];
  
-       if (req->cryptlen <= CHACHA_BLOCK_SIZE || !may_use_simd())
+       if (req->cryptlen <= CHACHA_BLOCK_SIZE || !crypto_simd_usable())
                return crypto_xchacha_crypt(req);
  
        crypto_chacha_init(state, ctx, req->iv);
@@@ -173,7 -174,7 +174,7 @@@ static struct skcipher_alg algs[] = 
  
  static int __init chacha_simd_mod_init(void)
  {
 -      if (!(elf_hwcap & HWCAP_ASIMD))
 +      if (!cpu_have_named_feature(ASIMD))
                return -ENODEV;
  
        return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
@@@ -16,6 -16,7 +16,7 @@@
  #include <linux/string.h>
  
  #include <crypto/internal/hash.h>
+ #include <crypto/internal/simd.h>
  
  #include <asm/neon.h>
  #include <asm/simd.h>
@@@ -38,7 -39,7 +39,7 @@@ static int crct10dif_update_pmull_p8(st
  {
        u16 *crc = shash_desc_ctx(desc);
  
-       if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && may_use_simd()) {
+       if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && crypto_simd_usable()) {
                kernel_neon_begin();
                *crc = crc_t10dif_pmull_p8(*crc, data, length);
                kernel_neon_end();
@@@ -54,7 -55,7 +55,7 @@@ static int crct10dif_update_pmull_p64(s
  {
        u16 *crc = shash_desc_ctx(desc);
  
-       if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && may_use_simd()) {
+       if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && crypto_simd_usable()) {
                kernel_neon_begin();
                *crc = crc_t10dif_pmull_p64(*crc, data, length);
                kernel_neon_end();
@@@ -101,7 -102,7 +102,7 @@@ static struct shash_alg crc_t10dif_alg[
  
  static int __init crc_t10dif_mod_init(void)
  {
 -      if (elf_hwcap & HWCAP_PMULL)
 +      if (cpu_have_named_feature(PMULL))
                return crypto_register_shashes(crc_t10dif_alg,
                                               ARRAY_SIZE(crc_t10dif_alg));
        else
  
  static void __exit crc_t10dif_mod_exit(void)
  {
 -      if (elf_hwcap & HWCAP_PMULL)
 +      if (cpu_have_named_feature(PMULL))
                crypto_unregister_shashes(crc_t10dif_alg,
                                          ARRAY_SIZE(crc_t10dif_alg));
        else
@@@ -17,6 -17,7 +17,7 @@@
  #include <crypto/gf128mul.h>
  #include <crypto/internal/aead.h>
  #include <crypto/internal/hash.h>
+ #include <crypto/internal/simd.h>
  #include <crypto/internal/skcipher.h>
  #include <crypto/scatterwalk.h>
  #include <linux/cpufeature.h>
@@@ -89,7 -90,7 +90,7 @@@ static void ghash_do_update(int blocks
                                                struct ghash_key const *k,
                                                const char *head))
  {
-       if (likely(may_use_simd())) {
+       if (likely(crypto_simd_usable())) {
                kernel_neon_begin();
                simd_update(blocks, dg, src, key, head);
                kernel_neon_end();
@@@ -441,7 -442,7 +442,7 @@@ static int gcm_encrypt(struct aead_requ
  
        err = skcipher_walk_aead_encrypt(&walk, req, false);
  
-       if (likely(may_use_simd() && walk.total >= 2 * AES_BLOCK_SIZE)) {
+       if (likely(crypto_simd_usable() && walk.total >= 2 * AES_BLOCK_SIZE)) {
                u32 const *rk = NULL;
  
                kernel_neon_begin();
                put_unaligned_be32(2, iv + GCM_IV_SIZE);
  
                while (walk.nbytes >= (2 * AES_BLOCK_SIZE)) {
-                       int blocks = walk.nbytes / AES_BLOCK_SIZE;
+                       const int blocks =
+                               walk.nbytes / (2 * AES_BLOCK_SIZE) * 2;
                        u8 *dst = walk.dst.virt.addr;
                        u8 *src = walk.src.virt.addr;
+                       int remaining = blocks;
  
                        do {
                                __aes_arm64_encrypt(ctx->aes_key.key_enc,
  
                                dst += AES_BLOCK_SIZE;
                                src += AES_BLOCK_SIZE;
-                       } while (--blocks > 0);
+                       } while (--remaining > 0);
  
-                       ghash_do_update(walk.nbytes / AES_BLOCK_SIZE, dg,
+                       ghash_do_update(blocks, dg,
                                        walk.dst.virt.addr, &ctx->ghash_key,
                                        NULL, pmull_ghash_update_p64);
  
@@@ -563,7 -566,7 +566,7 @@@ static int gcm_decrypt(struct aead_requ
  
        err = skcipher_walk_aead_decrypt(&walk, req, false);
  
-       if (likely(may_use_simd() && walk.total >= 2 * AES_BLOCK_SIZE)) {
+       if (likely(crypto_simd_usable() && walk.total >= 2 * AES_BLOCK_SIZE)) {
                u32 const *rk = NULL;
  
                kernel_neon_begin();
                put_unaligned_be32(2, iv + GCM_IV_SIZE);
  
                while (walk.nbytes >= (2 * AES_BLOCK_SIZE)) {
-                       int blocks = walk.nbytes / AES_BLOCK_SIZE;
+                       int blocks = walk.nbytes / (2 * AES_BLOCK_SIZE) * 2;
                        u8 *dst = walk.dst.virt.addr;
                        u8 *src = walk.src.virt.addr;
  
@@@ -704,10 -707,10 +707,10 @@@ static int __init ghash_ce_mod_init(voi
  {
        int ret;
  
 -      if (!(elf_hwcap & HWCAP_ASIMD))
 +      if (!cpu_have_named_feature(ASIMD))
                return -ENODEV;
  
 -      if (elf_hwcap & HWCAP_PMULL)
 +      if (cpu_have_named_feature(PMULL))
                ret = crypto_register_shashes(ghash_alg,
                                              ARRAY_SIZE(ghash_alg));
        else
        if (ret)
                return ret;
  
 -      if (elf_hwcap & HWCAP_PMULL) {
 +      if (cpu_have_named_feature(PMULL)) {
                ret = crypto_register_aead(&gcm_aes_alg);
                if (ret)
                        crypto_unregister_shashes(ghash_alg,
  
  static void __exit ghash_ce_mod_exit(void)
  {
 -      if (elf_hwcap & HWCAP_PMULL)
 +      if (cpu_have_named_feature(PMULL))
                crypto_unregister_shashes(ghash_alg, ARRAY_SIZE(ghash_alg));
        else
                crypto_unregister_shash(ghash_alg);
@@@ -9,6 -9,7 +9,7 @@@
  #include <asm/neon.h>
  #include <asm/simd.h>
  #include <crypto/internal/hash.h>
+ #include <crypto/internal/simd.h>
  #include <crypto/nhpoly1305.h>
  #include <linux/module.h>
  
@@@ -25,7 -26,7 +26,7 @@@ static void _nh_neon(const u32 *key, co
  static int nhpoly1305_neon_update(struct shash_desc *desc,
                                  const u8 *src, unsigned int srclen)
  {
-       if (srclen < 64 || !may_use_simd())
+       if (srclen < 64 || !crypto_simd_usable())
                return crypto_nhpoly1305_update(desc, src, srclen);
  
        do {
@@@ -56,7 -57,7 +57,7 @@@ static struct shash_alg nhpoly1305_alg 
  
  static int __init nhpoly1305_mod_init(void)
  {
 -      if (!(elf_hwcap & HWCAP_ASIMD))
 +      if (!cpu_have_named_feature(ASIMD))
                return -ENODEV;
  
        return crypto_register_shash(&nhpoly1305_alg);
@@@ -14,6 -14,7 +14,7 @@@
  #include <asm/neon.h>
  #include <asm/simd.h>
  #include <crypto/internal/hash.h>
+ #include <crypto/internal/simd.h>
  #include <crypto/sha.h>
  #include <crypto/sha256_base.h>
  #include <linux/cryptohash.h>
@@@ -89,7 -90,7 +90,7 @@@ static int sha256_update_neon(struct sh
  {
        struct sha256_state *sctx = shash_desc_ctx(desc);
  
-       if (!may_use_simd())
+       if (!crypto_simd_usable())
                return sha256_base_do_update(desc, data, len,
                                (sha256_block_fn *)sha256_block_data_order);
  
  static int sha256_finup_neon(struct shash_desc *desc, const u8 *data,
                             unsigned int len, u8 *out)
  {
-       if (!may_use_simd()) {
+       if (!crypto_simd_usable()) {
                if (len)
                        sha256_base_do_update(desc, data, len,
                                (sha256_block_fn *)sha256_block_data_order);
@@@ -173,7 -174,7 +174,7 @@@ static int __init sha256_mod_init(void
        if (ret)
                return ret;
  
 -      if (elf_hwcap & HWCAP_ASIMD) {
 +      if (cpu_have_named_feature(ASIMD)) {
                ret = crypto_register_shashes(neon_algs, ARRAY_SIZE(neon_algs));
                if (ret)
                        crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
  
  static void __exit sha256_mod_fini(void)
  {
 -      if (elf_hwcap & HWCAP_ASIMD)
 +      if (cpu_have_named_feature(ASIMD))
                crypto_unregister_shashes(neon_algs, ARRAY_SIZE(neon_algs));
        crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
  }
@@@ -8,5 -8,7 +8,6 @@@ generic-y += irq_regs.
  generic-y += local64.h
  generic-y += mcs_spinlock.h
  generic-y += preempt.h
 -generic-y += rwsem.h
  generic-y += vtime.h
  generic-y += msi.h
+ generic-y += simd.h
diff --combined crypto/lrw.c
@@@ -162,8 -162,10 +162,10 @@@ static int xor_tweak(struct skcipher_re
        }
  
        err = skcipher_walk_virt(&w, req, false);
-       iv = (__be32 *)w.iv;
+       if (err)
+               return err;
  
+       iv = (__be32 *)w.iv;
        counter[0] = be32_to_cpu(iv[3]);
        counter[1] = be32_to_cpu(iv[2]);
        counter[2] = be32_to_cpu(iv[1]);
@@@ -212,12 -214,8 +214,12 @@@ static void crypt_done(struct crypto_as
  {
        struct skcipher_request *req = areq->data;
  
 -      if (!err)
 +      if (!err) {
 +              struct rctx *rctx = skcipher_request_ctx(req);
 +
 +              rctx->subreq.base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
                err = xor_tweak_post(req);
 +      }
  
        skcipher_request_complete(req, err);
  }
@@@ -435,7 -433,7 +437,7 @@@ static void __exit crypto_module_exit(v
        crypto_unregister_template(&crypto_tmpl);
  }
  
module_init(crypto_module_init);
subsys_initcall(crypto_module_init);
  module_exit(crypto_module_exit);
  
  MODULE_LICENSE("GPL");
diff --combined crypto/testmgr.h
@@@ -25,6 -25,8 +25,8 @@@
  #ifndef _CRYPTO_TESTMGR_H
  #define _CRYPTO_TESTMGR_H
  
+ #include <linux/oid_registry.h>
  #define MAX_IVLEN             32
  
  /*
@@@ -34,6 -36,8 +36,8 @@@
   * @digest:   Pointer to expected digest
   * @psize:    Length of source data in bytes
   * @ksize:    Length of @key in bytes (0 if no key)
+  * @setkey_error: Expected error from setkey()
+  * @digest_error: Expected error from digest()
   */
  struct hash_testvec {
        const char *key;
@@@ -41,6 -45,8 +45,8 @@@
        const char *digest;
        unsigned short psize;
        unsigned short ksize;
+       int setkey_error;
+       int digest_error;
  };
  
  /*
   * @ptext:    Pointer to plaintext
   * @ctext:    Pointer to ciphertext
   * @len:      Length of @ptext and @ctext in bytes
-  * @fail:     If set to one, the test need to fail
   * @wk:               Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
   *            ( e.g. test needs to fail due to a weak key )
   * @fips_skip:        Skip the test vector in FIPS mode
   * @generates_iv: Encryption should ignore the given IV, and output @iv_out.
   *              Decryption takes @iv_out.  Needed for AES Keywrap ("kw(aes)").
+  * @setkey_error: Expected error from setkey()
+  * @crypt_error: Expected error from encrypt() and decrypt()
   */
  struct cipher_testvec {
        const char *key;
        const char *iv_out;
        const char *ptext;
        const char *ctext;
-       bool fail;
        unsigned char wk; /* weak key flag */
-       unsigned char klen;
+       unsigned short klen;
        unsigned short len;
        bool fips_skip;
        bool generates_iv;
+       int setkey_error;
+       int crypt_error;
  };
  
  /*
@@@ -82,7 -90,6 +90,6 @@@
   * @ctext:    Pointer to the full authenticated ciphertext.  For AEADs that
   *            produce a separate "ciphertext" and "authentication tag", these
   *            two parts are concatenated: ciphertext || tag.
-  * @fail:     setkey() failure expected?
   * @novrfy:   Decryption verification failure expected?
   * @wk:               Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
   *            (e.g. setkey() needs to fail due to a weak key)
@@@ -90,6 -97,9 +97,9 @@@
   * @plen:     Length of @ptext in bytes
   * @alen:     Length of @assoc in bytes
   * @clen:     Length of @ctext in bytes
+  * @setkey_error: Expected error from setkey()
+  * @setauthsize_error: Expected error from setauthsize()
+  * @crypt_error: Expected error from encrypt() and decrypt()
   */
  struct aead_testvec {
        const char *key;
        const char *ptext;
        const char *assoc;
        const char *ctext;
-       bool fail;
        unsigned char novrfy;
        unsigned char wk;
        unsigned char klen;
        unsigned short plen;
        unsigned short clen;
        unsigned short alen;
+       int setkey_error;
+       int setauthsize_error;
+       int crypt_error;
  };
  
  struct cprng_testvec {
@@@ -135,13 -147,16 +147,16 @@@ struct drbg_testvec 
  
  struct akcipher_testvec {
        const unsigned char *key;
+       const unsigned char *params;
        const unsigned char *m;
        const unsigned char *c;
        unsigned int key_len;
+       unsigned int param_len;
        unsigned int m_size;
        unsigned int c_size;
        bool public_key_vec;
        bool siggen_sigver_test;
+       enum OID algo;
  };
  
  struct kpp_testvec {
@@@ -550,6 -565,160 +565,160 @@@ static const struct akcipher_testvec rs
        }
  };
  
+ /*
+  * EC-RDSA test vectors are generated by gost-engine.
+  */
+ static const struct akcipher_testvec ecrdsa_tv_template[] = {
+       {
+       .key =
+       "\x04\x40\xd5\xa7\x77\xf9\x26\x2f\x8c\xbd\xcc\xe3\x1f\x01\x94\x05"
+       "\x3d\x2f\xec\xb5\x00\x34\xf5\x51\x6d\x3b\x90\x4b\x23\x28\x6f\x1d"
+       "\xc8\x36\x61\x60\x36\xec\xbb\xb4\x0b\x95\x4e\x54\x4f\x15\x21\x05"
+       "\xd8\x52\x66\x44\x31\x7e\x5d\xc5\xd1\x26\x00\x5f\x60\xd8\xf0\xc7"
+       "\x27\xfc",
+       .key_len = 66,
+       .params = /* OID_gostCPSignA */
+       "\x30\x13\x06\x07\x2a\x85\x03\x02\x02\x23\x01\x06\x08\x2a\x85\x03"
+       "\x07\x01\x01\x02\x02",
+       .param_len = 21,
+       .c =
+       "\x41\x32\x09\x73\xa4\xc1\x38\xd6\x63\x7d\x8b\xf7\x50\x3f\xda\x9f"
+       "\x68\x48\xc1\x50\xe3\x42\x3a\x9b\x2b\x28\x12\x2a\xa7\xc2\x75\x31"
+       "\x65\x77\x8c\x3c\x9e\x0d\x56\xb2\xf9\xdc\x04\x33\x3e\xb0\x9e\xf9"
+       "\x74\x4e\x59\xb3\x83\xf2\x91\x27\xda\x5e\xc7\x33\xc0\xc1\x8f\x41",
+       .c_size = 64,
+       .algo = OID_gost2012PKey256,
+       .m =
+       "\x75\x1b\x9b\x40\x25\xb9\x96\xd2\x9b\x00\x41\xb3\x58\xbf\x23\x14"
+       "\x79\xd2\x76\x64\xa3\xbd\x66\x10\x79\x05\x5a\x06\x42\xec\xb9\xc9",
+       .m_size = 32,
+       .public_key_vec = true,
+       .siggen_sigver_test = true,
+       },
+       {
+       .key =
+       "\x04\x40\x66\x6f\xd6\xb7\x06\xd0\xf5\xa5\x6f\x69\x5c\xa5\x13\x45"
+       "\x14\xdd\xcb\x12\x9c\x1b\xf5\x28\x64\x7a\x49\x48\x29\x14\x66\x42"
+       "\xb8\x1b\x5c\xf9\x56\x6d\x08\x3b\xce\xbb\x62\x2f\xc2\x3c\xc5\x49"
+       "\x93\x27\x70\x20\xcc\x79\xeb\xdc\x76\x8e\x48\x6e\x04\x96\xc3\x29"
+       "\xa0\x73",
+       .key_len = 66,
+       .params = /* OID_gostCPSignB */
+       "\x30\x13\x06\x07\x2a\x85\x03\x02\x02\x23\x02\x06\x08\x2a\x85\x03"
+       "\x07\x01\x01\x02\x02",
+       .param_len = 21,
+       .c =
+       "\x45\x6d\x4a\x03\x1d\x5c\x0b\x17\x79\xe7\x19\xdb\xbf\x81\x9f\x82"
+       "\xae\x06\xda\xf5\x47\x00\x05\x80\xc3\x16\x06\x9a\x8e\x7c\xb2\x8e"
+       "\x7f\x74\xaa\xec\x6b\x7b\x7f\x8b\xc6\x0b\x10\x42\x4e\x91\x2c\xdf"
+       "\x7b\x8b\x15\xf4\x9e\x59\x0f\xc7\xa4\x68\x2e\xce\x89\xdf\x84\xe9",
+       .c_size = 64,
+       .algo = OID_gost2012PKey256,
+       .m =
+       "\xd0\x54\x00\x27\x6a\xeb\xce\x6c\xf5\xf6\xfb\x57\x18\x18\x21\x13"
+       "\x11\x23\x4a\x70\x43\x52\x7a\x68\x11\x65\x45\x37\xbb\x25\xb7\x40",
+       .m_size = 32,
+       .public_key_vec = true,
+       .siggen_sigver_test = true,
+       },
+       {
+       .key =
+       "\x04\x40\x05\x91\xa9\x7d\xcb\x87\xdc\x98\xa1\xbf\xff\xdd\x20\x61"
+       "\xaa\x58\x3b\x2d\x8e\x9c\x41\x9d\x4f\xc6\x23\x17\xf9\xca\x60\x65"
+       "\xbc\x97\x97\xf6\x6b\x24\xe8\xac\xb1\xa7\x61\x29\x3c\x71\xdc\xad"
+       "\xcb\x20\xbe\x96\xe8\xf4\x44\x2e\x49\xd5\x2c\xb9\xc9\x3b\x9c\xaa"
+       "\xba\x15",
+       .key_len = 66,
+       .params = /* OID_gostCPSignC */
+       "\x30\x13\x06\x07\x2a\x85\x03\x02\x02\x23\x03\x06\x08\x2a\x85\x03"
+       "\x07\x01\x01\x02\x02",
+       .param_len = 21,
+       .c =
+       "\x3b\x2e\x2e\x74\x74\x47\xda\xea\x93\x90\x6a\xe2\xf5\xf5\xe6\x46"
+       "\x11\xfc\xab\xdc\x52\xbc\x58\xdb\x45\x44\x12\x4a\xf7\xd0\xab\xc9"
+       "\x73\xba\x64\xab\x0d\xac\x4e\x72\x10\xa8\x04\xf6\x1e\xe0\x48\x6a"
+       "\xcd\xe8\xe3\x78\x73\x77\x82\x24\x8d\xf1\xd3\xeb\x4c\x25\x7e\xc0",
+       .c_size = 64,
+       .algo = OID_gost2012PKey256,
+       .m =
+       "\x52\x33\xf4\x3f\x7b\x5d\xcf\x20\xee\xe4\x5c\xab\x0b\x3f\x14\xd6"
+       "\x9f\x16\xc6\x1c\xb1\x3f\x84\x41\x69\xec\x34\xfd\xf1\xf9\xa3\x39",
+       .m_size = 32,
+       .public_key_vec = true,
+       .siggen_sigver_test = true,
+       },
+       {
+       .key =
+       "\x04\x81\x80\x85\x46\x8f\x16\xf8\x7a\x7e\x4a\xc3\x81\x9e\xf1\x6e"
+       "\x94\x1e\x5d\x02\x87\xea\xfa\xa0\x0a\x17\x70\x49\x64\xad\x95\x68"
+       "\x60\x0a\xf0\x57\x29\x41\x79\x30\x3c\x61\x69\xf2\xa6\x94\x87\x17"
+       "\x54\xfa\x97\x2c\xe6\x1e\x0a\xbb\x55\x10\x57\xbe\xf7\xc1\x77\x2b"
+       "\x11\x74\x0a\x50\x37\x14\x10\x2a\x45\xfc\x7a\xae\x1c\x4c\xce\x08"
+       "\x05\xb7\xa4\x50\xc8\x3d\x39\x3d\xdc\x5c\x8f\x96\x6c\xe7\xfc\x21"
+       "\xc3\x2d\x1e\x9f\x11\xb3\xec\x22\x18\x8a\x8c\x08\x6b\x8b\xed\xf5"
+       "\xc5\x47\x3c\x7e\x73\x59\x44\x1e\x77\x83\x84\x52\x9e\x3b\x7d\xff"
+       "\x9d\x86\x1a",
+       .key_len = 131,
+       .params = /* OID_gostTC26Sign512A */
+       "\x30\x0b\x06\x09\x2a\x85\x03\x07\x01\x02\x01\x02\x01",
+       .param_len = 13,
+       .c =
+       "\x92\x81\x74\x5f\x95\x48\x38\x87\xd9\x8f\x5e\xc8\x8a\xbb\x01\x4e"
+       "\xb0\x75\x3c\x2f\xc7\x5a\x08\x4c\x68\xab\x75\x01\x32\x75\x75\xb5"
+       "\x37\xe0\x74\x6d\x94\x84\x31\x2a\x6b\xf4\xf7\xb7\xa7\x39\x7b\x46"
+       "\x07\xf0\x98\xbd\x33\x18\xa1\x72\xb2\x6d\x54\xe3\xde\x91\xc2\x2e"
+       "\x4f\x6a\xf8\xb7\xec\xa8\x83\xc9\x8f\xd9\xce\x7c\x45\x06\x02\xf4"
+       "\x4f\x21\xb5\x24\x3d\xb4\xb5\xd8\x58\x42\xbe\x2d\x29\xae\x93\xc0"
+       "\x13\x41\x96\x35\x08\x69\xe8\x36\xc7\xd1\x83\x81\xd7\xca\xfb\xc0"
+       "\xd2\xb7\x78\x32\x3e\x30\x1a\x1e\xce\xdc\x34\x35\xc6\xad\x68\x24",
+       .c_size = 128,
+       .algo = OID_gost2012PKey512,
+       .m =
+       "\x1f\x70\xb5\xe9\x55\x12\xd6\x88\xcc\x55\xb9\x0c\x7f\xc4\x94\xf2"
+       "\x04\x77\x41\x12\x02\xd6\xf1\x1f\x83\x56\xe9\xd6\x5a\x6a\x72\xb9"
+       "\x6e\x8e\x24\x2a\x84\xf1\xba\x67\xe8\xbf\xff\xc1\xd3\xde\xfb\xc6"
+       "\xa8\xf6\x80\x01\xb9\x27\xac\xd8\x45\x96\x66\xa1\xee\x48\x08\x3f",
+       .m_size = 64,
+       .public_key_vec = true,
+       .siggen_sigver_test = true,
+       },
+       {
+       .key =
+       "\x04\x81\x80\x28\xf3\x2b\x92\x04\x32\xea\x66\x20\xde\xa0\x2f\x74"
+       "\xbf\x2d\xf7\xb5\x30\x76\xb1\xc8\xee\x38\x9f\xea\xe5\xad\xc6\xa3"
+       "\x28\x1e\x51\x3d\x67\xa3\x41\xcc\x6b\x81\xe2\xe2\x9e\x82\xf3\x78"
+       "\x56\xd7\x2e\xb2\xb5\xbe\xb4\x50\x21\x05\xe5\x29\x82\xef\x15\x1b"
+       "\xc0\xd7\x30\xd6\x2f\x96\xe8\xff\x99\x4c\x25\xcf\x9a\xfc\x54\x30"
+       "\xce\xdf\x59\xe9\xc6\x45\xce\xe4\x22\xe8\x01\xd5\xcd\x2f\xaa\x78"
+       "\x99\xc6\x04\x1e\x6f\x4c\x25\x6a\x76\xad\xff\x48\xf3\xb3\xb4\xd6"
+       "\x14\x5c\x2c\x0e\xea\xa2\x4b\xb9\x7e\x89\x77\x02\x3a\x29\xc8\x16"
+       "\x8e\x78\x48",
+       .key_len = 131,
+       .params = /* OID_gostTC26Sign512B */
+       "\x30\x0b\x06\x09\x2a\x85\x03\x07\x01\x02\x01\x02\x02",
+       .param_len = 13,
+       .c =
+       "\x0a\xed\xb6\x27\xea\xa7\xa6\x7e\x2f\xc1\x02\x21\x74\xce\x27\xd2"
+       "\xee\x8a\x92\x4d\xa9\x43\x2d\xa4\x5b\xdc\x23\x02\xfc\x3a\xf3\xb2"
+       "\x10\x93\x0b\x40\x1b\x75\x95\x3e\x39\x41\x37\xb9\xab\x51\x09\xeb"
+       "\xf1\xb9\x49\x58\xec\x58\xc7\xf9\x2e\xb9\xc9\x40\xf2\x00\x39\x7e"
+       "\x3f\xde\x72\xe3\x85\x67\x06\xbe\xd8\xb8\xc1\x81\x1e\xe3\x0a\xfe"
+       "\xce\xd3\x77\x92\x56\x8c\x58\xf9\x37\x60\x2d\xe6\x8b\x66\xa3\xdd"
+       "\xd2\xf0\xf8\xda\x1b\x20\xbc\x9c\xec\x29\x5d\xd1\x8f\xcc\x37\xd1"
+       "\x3b\x8d\xb7\xc1\xe0\xb8\x3b\xef\x14\x1b\x87\xbc\xc1\x03\x9a\x93",
+       .c_size = 128,
+       .algo = OID_gost2012PKey512,
+       .m =
+       "\x11\x24\x21\x27\xf2\x42\x9f\xce\x5a\xf9\x01\x70\xe0\x07\x2b\x57"
+       "\xfb\x7d\x77\x5e\x74\x66\xe6\xa5\x40\x4c\x1a\x85\x18\xff\xd0\x63"
+       "\xe0\x39\xd3\xd6\xe5\x17\xf8\xc3\x4b\xc6\x1c\x33\x1a\xca\xa6\x66"
+       "\x6d\xf4\xd2\x45\xc2\x83\xa0\x42\x95\x05\x9d\x89\x8e\x0a\xca\xcc",
+       .m_size = 64,
+       .public_key_vec = true,
+       .siggen_sigver_test = true,
+       },
+ };
  /*
   * PKCS#1 RSA test vectors. Obtained from CAVS testing.
   */
@@@ -5634,49 -5803,7 +5803,49 @@@ static const struct hash_testvec poly13
                .psize          = 80,
                .digest         = "\x13\x00\x00\x00\x00\x00\x00\x00"
                                  "\x00\x00\x00\x00\x00\x00\x00\x00",
 -      },
 +      }, { /* Regression test for overflow in AVX2 implementation */
 +              .plaintext      = "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff\xff\xff\xff\xff"
 +                                "\xff\xff\xff\xff",
 +              .psize          = 300,
 +              .digest         = "\xfb\x5e\x96\xd8\x61\xd5\xc7\xc8"
 +                                "\x78\xe5\x87\xcc\x2d\x5a\x22\xe1",
 +      }
  };
  
  /* NHPoly1305 test vectors from https://github.com/google/adiantum */
@@@ -7084,7 -7211,7 +7253,7 @@@ static const struct cipher_testvec des_
                          "\xb4\x99\x26\xf7\x1f\xe1\xd4\x90",
                .len    = 24,
        }, { /* Weak key */
-               .fail   = true,
+               .setkey_error = -EINVAL,
                .wk     = 1,
                .key    = "\x01\x01\x01\x01\x01\x01\x01\x01",
                .klen   = 8,
diff --combined crypto/xts.c
@@@ -137,12 -137,8 +137,12 @@@ static void crypt_done(struct crypto_as
  {
        struct skcipher_request *req = areq->data;
  
 -      if (!err)
 +      if (!err) {
 +              struct rctx *rctx = skcipher_request_ctx(req);
 +
 +              rctx->subreq.base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
                err = xor_tweak_post(req);
 +      }
  
        skcipher_request_complete(req, err);
  }
@@@ -363,7 -359,7 +363,7 @@@ static void __exit crypto_module_exit(v
        crypto_unregister_template(&crypto_tmpl);
  }
  
module_init(crypto_module_init);
subsys_initcall(crypto_module_init);
  module_exit(crypto_module_exit);
  
  MODULE_LICENSE("GPL");
@@@ -532,7 -532,6 +532,6 @@@ static void section_mac(struct dm_integ
        unsigned j, size;
  
        desc->tfm = ic->journal_mac;
-       desc->flags = 0;
  
        r = crypto_shash_init(desc);
        if (unlikely(r)) {
@@@ -913,7 -912,7 +912,7 @@@ static void copy_from_journal(struct dm
  static bool ranges_overlap(struct dm_integrity_range *range1, struct dm_integrity_range *range2)
  {
        return range1->logical_sector < range2->logical_sector + range2->n_sectors &&
 -             range2->logical_sector + range2->n_sectors > range2->logical_sector;
 +             range1->logical_sector + range1->n_sectors > range2->logical_sector;
  }
  
  static bool add_new_range(struct dm_integrity_c *ic, struct dm_integrity_range *new_range, bool check_waiting)
@@@ -959,6 -958,8 +958,6 @@@ static void remove_range_unlocked(struc
                struct dm_integrity_range *last_range =
                        list_first_entry(&ic->wait_list, struct dm_integrity_range, wait_entry);
                struct task_struct *last_range_task;
 -              if (!ranges_overlap(range, last_range))
 -                      break;
                last_range_task = last_range->task;
                list_del(&last_range->wait_entry);
                if (!add_new_range(ic, last_range, false)) {
@@@ -1276,7 -1277,6 +1275,6 @@@ static void integrity_sector_checksum(s
        unsigned digest_size;
  
        req->tfm = ic->internal_hash;
-       req->flags = 0;
  
        r = crypto_shash_init(req);
        if (unlikely(r < 0)) {
@@@ -3183,7 -3183,7 +3181,7 @@@ static int dm_integrity_ctr(struct dm_t
                        journal_watermark = val;
                else if (sscanf(opt_string, "commit_time:%u%c", &val, &dummy) == 1)
                        sync_msec = val;
 -              else if (!memcmp(opt_string, "meta_device:", strlen("meta_device:"))) {
 +              else if (!strncmp(opt_string, "meta_device:", strlen("meta_device:"))) {
                        if (ic->meta_dev) {
                                dm_put_device(ti, ic->meta_dev);
                                ic->meta_dev = NULL;
                                goto bad;
                        }
                        ic->sectors_per_block = val >> SECTOR_SHIFT;
 -              } else if (!memcmp(opt_string, "internal_hash:", strlen("internal_hash:"))) {
 +              } else if (!strncmp(opt_string, "internal_hash:", strlen("internal_hash:"))) {
                        r = get_alg_and_key(opt_string, &ic->internal_hash_alg, &ti->error,
                                            "Invalid internal_hash argument");
                        if (r)
                                goto bad;
 -              } else if (!memcmp(opt_string, "journal_crypt:", strlen("journal_crypt:"))) {
 +              } else if (!strncmp(opt_string, "journal_crypt:", strlen("journal_crypt:"))) {
                        r = get_alg_and_key(opt_string, &ic->journal_crypt_alg, &ti->error,
                                            "Invalid journal_crypt argument");
                        if (r)
                                goto bad;
 -              } else if (!memcmp(opt_string, "journal_mac:", strlen("journal_mac:"))) {
 +              } else if (!strncmp(opt_string, "journal_mac:", strlen("journal_mac:"))) {
                        r = get_alg_and_key(opt_string, &ic->journal_mac_alg,  &ti->error,
                                            "Invalid journal_mac argument");
                        if (r)
@@@ -3614,7 -3614,7 +3612,7 @@@ static struct target_type integrity_tar
        .io_hints               = dm_integrity_io_hints,
  };
  
 -int __init dm_integrity_init(void)
 +static int __init dm_integrity_init(void)
  {
        int r;
  
        return r;
  }
  
 -void dm_integrity_exit(void)
 +static void __exit dm_integrity_exit(void)
  {
        dm_unregister_target(&integrity_target);
        kmem_cache_destroy(journal_io_cache);
diff --combined fs/cifs/misc.c
@@@ -501,7 -501,8 +501,7 @@@ is_valid_oplock_break(char *buffer, str
                                           CIFS_INODE_DOWNGRADE_OPLOCK_TO_L2,
                                           &pCifsInode->flags);
  
 -                              queue_work(cifsoplockd_wq,
 -                                         &netfile->oplock_break);
 +                              cifs_queue_oplock_break(netfile);
                                netfile->oplock_break_cancelled = false;
  
                                spin_unlock(&tcon->open_file_lock);
@@@ -606,28 -607,6 +606,28 @@@ void cifs_put_writer(struct cifsInodeIn
        spin_unlock(&cinode->writers_lock);
  }
  
 +/**
 + * cifs_queue_oplock_break - queue the oplock break handler for cfile
 + *
 + * This function is called from the demultiplex thread when it
 + * receives an oplock break for @cfile.
 + *
 + * Assumes the tcon->open_file_lock is held.
 + * Assumes cfile->file_info_lock is NOT held.
 + */
 +void cifs_queue_oplock_break(struct cifsFileInfo *cfile)
 +{
 +      /*
 +       * Bump the handle refcount now while we hold the
 +       * open_file_lock to enforce the validity of it for the oplock
 +       * break handler. The matching put is done at the end of the
 +       * handler.
 +       */
 +      cifsFileInfo_get(cfile);
 +
 +      queue_work(cifsoplockd_wq, &cfile->oplock_break);
 +}
 +
  void cifs_done_oplock_break(struct cifsInodeInfo *cinode)
  {
        clear_bit(CIFS_INODE_PENDING_OPLOCK_BREAK, &cinode->flags);
@@@ -789,11 -768,6 +789,11 @@@ cifs_aio_ctx_alloc(void
  {
        struct cifs_aio_ctx *ctx;
  
 +      /*
 +       * Must use kzalloc to initialize ctx->bv to NULL and ctx->direct_io
 +       * to false so that we know when we have to unreference pages within
 +       * cifs_aio_ctx_release()
 +       */
        ctx = kzalloc(sizeof(struct cifs_aio_ctx), GFP_KERNEL);
        if (!ctx)
                return NULL;
@@@ -812,23 -786,7 +812,23 @@@ cifs_aio_ctx_release(struct kref *refco
                                        struct cifs_aio_ctx, refcount);
  
        cifsFileInfo_put(ctx->cfile);
 -      kvfree(ctx->bv);
 +
 +      /*
 +       * ctx->bv is only set if setup_aio_ctx_iter() was call successfuly
 +       * which means that iov_iter_get_pages() was a success and thus that
 +       * we have taken reference on pages.
 +       */
 +      if (ctx->bv) {
 +              unsigned i;
 +
 +              for (i = 0; i < ctx->npages; i++) {
 +                      if (ctx->should_dirty)
 +                              set_page_dirty(ctx->bv[i].bv_page);
 +                      put_page(ctx->bv[i].bv_page);
 +              }
 +              kvfree(ctx->bv);
 +      }
 +
        kfree(ctx);
  }
  
@@@ -959,7 -917,6 +959,6 @@@ cifs_alloc_hash(const char *name
        }
  
        (*sdesc)->shash.tfm = *shash;
-       (*sdesc)->shash.flags = 0x0;
        return 0;
  }
  
diff --combined security/keys/trusted.c
@@@ -55,7 -55,6 +55,6 @@@ static struct sdesc *init_sdesc(struct 
        if (!sdesc)
                return ERR_PTR(-ENOMEM);
        sdesc->shash.tfm = alg;
-       sdesc->shash.flags = 0x0;
        return sdesc;
  }
  
@@@ -125,7 -124,7 +124,7 @@@ out
   */
  int TSS_authhmac(unsigned char *digest, const unsigned char *key,
                        unsigned int keylen, unsigned char *h1,
 -                      unsigned char *h2, unsigned char h3, ...)
 +                      unsigned char *h2, unsigned int h3, ...)
  {
        unsigned char paramdigest[SHA1_DIGEST_SIZE];
        struct sdesc *sdesc;
        int ret;
        va_list argp;
  
 +      if (!chip)
 +              return -ENODEV;
 +
        sdesc = init_sdesc(hashalg);
        if (IS_ERR(sdesc)) {
                pr_info("trusted_key: can't alloc %s\n", hash_alg);
                return PTR_ERR(sdesc);
        }
  
 -      c = h3;
 +      c = !!h3;
        ret = crypto_shash_init(&sdesc->shash);
        if (ret < 0)
                goto out;
@@@ -199,9 -195,6 +198,9 @@@ int TSS_checkhmac1(unsigned char *buffe
        va_list argp;
        int ret;
  
 +      if (!chip)
 +              return -ENODEV;
 +
        bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
        tag = LOAD16(buffer, 0);
        ordinal = command;
@@@ -369,9 -362,6 +368,9 @@@ int trusted_tpm_send(unsigned char *cmd
  {
        int rc;
  
 +      if (!chip)
 +              return -ENODEV;
 +
        dump_tpm_buf(cmd);
        rc = tpm_send(chip, cmd, buflen);
        dump_tpm_buf(cmd);
@@@ -438,9 -428,6 +437,9 @@@ int oiap(struct tpm_buf *tb, uint32_t *
  {
        int ret;
  
 +      if (!chip)
 +              return -ENODEV;
 +
        INIT_BUF(tb);
        store16(tb, TPM_TAG_RQU_COMMAND);
        store32(tb, TPM_OIAP_SIZE);
@@@ -1257,13 -1244,9 +1256,13 @@@ static int __init init_trusted(void
  {
        int ret;
  
 +      /* encrypted_keys.ko depends on successful load of this module even if
 +       * TPM is not used.
 +       */
        chip = tpm_default_chip();
        if (!chip)
 -              return -ENOENT;
 +              return 0;
 +
        ret = init_digests();
        if (ret < 0)
                goto err_put;
@@@ -1285,12 -1268,10 +1284,12 @@@ err_put
  
  static void __exit cleanup_trusted(void)
  {
 -      put_device(&chip->dev);
 -      kfree(digests);
 -      trusted_shash_release();
 -      unregister_key_type(&key_type_trusted);
 +      if (chip) {
 +              put_device(&chip->dev);
 +              kfree(digests);
 +              trusted_shash_release();
 +              unregister_key_type(&key_type_trusted);
 +      }
  }
  
  late_initcall(init_trusted);