1. 12 2月, 2015 1 次提交
  2. 11 2月, 2015 1 次提交
  3. 04 2月, 2015 1 次提交
    • A
      crypto: switch af_alg_make_sg() to iov_iter · 1d10eb2f
      Al Viro 提交于
      With that, all ->sendmsg() instances are converted to iov_iter primitives
      and are agnostic wrt the kind of iov_iter they are working with.
      So's the last remaining ->recvmsg() instance that wasn't kind-agnostic yet.
      All ->sendmsg() and ->recvmsg() advance ->msg_iter by the amount actually
      copied and none of them modifies the underlying iovec, etc.
      
      Cc: linux-crypto@vger.kernel.org
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      1d10eb2f
  4. 13 1月, 2015 1 次提交
    • M
      crypto: add missing crypto module aliases · 3e14dcf7
      Mathias Krause 提交于
      Commit 5d26a105 ("crypto: prefix module autoloading with "crypto-"")
      changed the automatic module loading when requesting crypto algorithms
      to prefix all module requests with "crypto-". This requires all crypto
      modules to have a crypto specific module alias even if their file name
      would otherwise match the requested crypto algorithm.
      
      Even though commit 5d26a105 added those aliases for a vast amount of
      modules, it was missing a few. Add the required MODULE_ALIAS_CRYPTO
      annotations to those files to make them get loaded automatically, again.
      This fixes, e.g., requesting 'ecb(blowfish-generic)', which used to work
      with kernels v3.18 and below.
      
      Also change MODULE_ALIAS() lines to MODULE_ALIAS_CRYPTO(). The former
      won't work for crypto modules any more.
      
      Fixes: 5d26a105 ("crypto: prefix module autoloading with "crypto-"")
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: NMathias Krause <minipli@googlemail.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      3e14dcf7
  5. 22 12月, 2014 1 次提交
    • R
      crypto: af_alg - fix backlog handling · 7e77bdeb
      Rabin Vincent 提交于
      If a request is backlogged, it's complete() handler will get called
      twice: once with -EINPROGRESS, and once with the final error code.
      
      af_alg's complete handler, unlike other users, does not handle the
      -EINPROGRESS but instead always completes the completion that recvmsg()
      is waiting on.  This can lead to a return to user space while the
      request is still pending in the driver.  If userspace closes the sockets
      before the requests are handled by the driver, this will lead to
      use-after-frees (and potential crashes) in the kernel due to the tfm
      having been freed.
      
      The crashes can be easily reproduced (for example) by reducing the max
      queue length in cryptod.c and running the following (from
      http://www.chronox.de/libkcapi.html) on AES-NI capable hardware:
      
       $ while true; do kcapi -x 1 -e -c '__ecb-aes-aesni' \
          -k 00000000000000000000000000000000 \
          -p 00000000000000000000000000000000 >/dev/null & done
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NRabin Vincent <rabin.vincent@axis.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      7e77bdeb
  6. 11 12月, 2014 1 次提交
  7. 10 12月, 2014 1 次提交
    • A
      put iov_iter into msghdr · c0371da6
      Al Viro 提交于
      Note that the code _using_ ->msg_iter at that point will be very
      unhappy with anything other than unshifted iovec-backed iov_iter.
      We still need to convert users to proper primitives.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      c0371da6
  8. 05 12月, 2014 2 次提交
  9. 02 12月, 2014 1 次提交
    • S
      crypto: algif_skcipher - initialize upon init request · f26b7b80
      Stephan Mueller 提交于
      When using the algif_skcipher, the following call sequence causess a
      re-initialization:
      
      1. sendmsg with ALG_SET_OP and iov == NULL, iovlen == 0 (i.e
      initializing the cipher, but not sending data)
      
      2. sendmsg with msg->msg-controllen == 0 and iov != NULL (using the initalized
      cipher handle by sending data)
      
      In step 2, the cipher operation type (encryption or decryption) is reset
      to always decryption, because the local variable of enc is put into
      ctx->enc as ctx->user is still zero.
      
      The same applies when all send data is processed and ctx->used falls to
      zero followed by user space to send new data.
      
      This patch changes the behavior to only reset the cipher operation type
      (and the IV) if such configuration request is received.
      Signed-off-by: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      f26b7b80
  10. 01 12月, 2014 1 次提交
  11. 28 11月, 2014 1 次提交
  12. 27 11月, 2014 1 次提交
  13. 26 11月, 2014 3 次提交
  14. 25 11月, 2014 1 次提交
    • D
      crypto: algif - add and use sock_kzfree_s() instead of memzero_explicit() · 79e88659
      Daniel Borkmann 提交于
      Commit e1bd95bf ("crypto: algif - zeroize IV buffer") and
      2a6af25b ("crypto: algif - zeroize message digest buffer")
      added memzero_explicit() calls on buffers that are later on
      passed back to sock_kfree_s().
      
      This is a discussed follow-up that, instead, extends the sock
      API and adds sock_kzfree_s(), which internally uses kzfree()
      instead of kfree() for passing the buffers back to slab.
      
      Having sock_kzfree_s() allows to keep the changes more minimal
      by just having a drop-in replacement instead of adding
      memzero_explicit() calls everywhere before sock_kfree_s().
      
      In kzfree(), the compiler is not allowed to optimize the memset()
      away and thus there's no need for memzero_explicit(). Both,
      sock_kfree_s() and sock_kzfree_s() are wrappers for
      __sock_kfree_s() and call into kfree() resp. kzfree(); here,
      __sock_kfree_s() needs to be explicitly inlined as we want the
      compiler to optimize the call and condition away and thus it
      produces e.g. on x86_64 the _same_ assembler output for
      sock_kfree_s() before and after, and thus also allows for
      avoiding code duplication.
      
      Cc: David S. Miller <davem@davemloft.net>
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      79e88659
  15. 24 11月, 2014 4 次提交
  16. 12 11月, 2014 2 次提交
  17. 10 11月, 2014 1 次提交
  18. 24 10月, 2014 2 次提交
  19. 17 10月, 2014 1 次提交
    • D
      crypto: memzero_explicit - make sure to clear out sensitive data · 7185ad26
      Daniel Borkmann 提交于
      Recently, in commit 13aa93c70e71 ("random: add and use memzero_explicit()
      for clearing data"), we have found that GCC may optimize some memset()
      cases away when it detects a stack variable is not being used anymore
      and going out of scope. This can happen, for example, in cases when we
      are clearing out sensitive information such as keying material or any
      e.g. intermediate results from crypto computations, etc.
      
      With the help of Coccinelle, we can figure out and fix such occurences
      in the crypto subsytem as well. Julia Lawall provided the following
      Coccinelle program:
      
        @@
        type T;
        identifier x;
        @@
      
        T x;
        ... when exists
            when any
        -memset
        +memzero_explicit
           (&x,
        -0,
           ...)
        ... when != x
            when strict
      
        @@
        type T;
        identifier x;
        @@
      
        T x[...];
        ... when exists
            when any
        -memset
        +memzero_explicit
           (x,
        -0,
           ...)
        ... when != x
            when strict
      
      Therefore, make use of the drop-in replacement memzero_explicit() for
      exactly such cases instead of using memset().
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Cc: Julia Lawall <julia.lawall@lip6.fr>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Theodore Ts'o <tytso@mit.edu>
      Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
      Acked-by: NHannes Frederic Sowa <hannes@stressinduktion.org>
      Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      7185ad26
  20. 14 10月, 2014 2 次提交
  21. 07 10月, 2014 2 次提交
  22. 06 10月, 2014 2 次提交
  23. 03 10月, 2014 2 次提交
    • D
      X.509: If available, use the raw subjKeyId to form the key description · dd2f6c44
      David Howells 提交于
      Module signing matches keys by comparing against the key description exactly.
      However, the way the key description gets constructed got changed to be
      composed of the subject name plus the certificate serial number instead of the
      subject name and the subjectKeyId.  I changed this to avoid problems with
      certificates that don't *have* a subjectKeyId.
      
      Instead, if available, use the raw subjectKeyId to form the key description
      and only use the serial number if the subjectKeyId doesn't exist.
      Reported-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      dd2f6c44
    • D
      KEYS: handle error code encoded in pointer · 40b50e80
      Dmitry Kasatkin 提交于
      If hexlen is odd then function returns an error.
      Use IS_ERR to check for error, otherwise invalid pointer
      is used and kernel gives oops:
      
      [  132.816522] BUG: unable to handle kernel paging request at
      ffffffffffffffea
      [  132.819902] IP: [<ffffffff812bfc20>] asymmetric_key_id_same+0x14/0x36
      [  132.820302] PGD 1a12067 PUD 1a14067 PMD 0
      [  132.820302] Oops: 0000 [#1] SMP
      [  132.820302] Modules linked in: bridge(E) stp(E) llc(E) evdev(E)
      serio_raw(E) i2c_piix4(E) button(E) fuse(E)
      [  132.820302] CPU: 0 PID: 2993 Comm: cat Tainted: G            E
      3.16.0-kds+ #2847
      [  132.820302] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      [  132.820302] task: ffff88004249a430 ti: ffff880056640000 task.ti:
      ffff880056640000
      [  132.820302] RIP: 0010:[<ffffffff812bfc20>]  [<ffffffff812bfc20>]
      asymmetric_key_id_same+0x14/0x36
      [  132.820302] RSP: 0018:ffff880056643930  EFLAGS: 00010246
      [  132.820302] RAX: 0000000000000000 RBX: ffffffffffffffea RCX:
      ffff880056643ae0
      [  132.820302] RDX: 000000000000005e RSI: ffffffffffffffea RDI:
      ffff88005bac9300
      [  132.820302] RBP: ffff880056643948 R08: 0000000000000003 R09:
      00000007504aa01a
      [  132.820302] R10: 0000000000000000 R11: 0000000000000000 R12:
      ffff88005d68ca40
      [  132.820302] R13: 0000000000000101 R14: 0000000000000000 R15:
      ffff88005bac5280
      [  132.820302] FS:  00007f67a153c740(0000) GS:ffff88005da00000(0000)
      knlGS:0000000000000000
      [  132.820302] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
      [  132.820302] CR2: ffffffffffffffea CR3: 000000002e663000 CR4:
      00000000000006f0
      [  132.820302] Stack:
      [  132.820302]  ffffffff812bfc66 ffff880056643ae0 ffff88005bac5280
      ffff880056643958
      [  132.820302]  ffffffff812bfc9d ffff880056643980 ffffffff812971d9
      ffff88005ce930c1
      [  132.820302]  ffff88005ce930c0 0000000000000000 ffff8800566439c8
      ffffffff812fb753
      [  132.820302] Call Trace:
      [  132.820302]  [<ffffffff812bfc66>] ? asymmetric_match_key_ids+0x24/0x42
      [  132.820302]  [<ffffffff812bfc9d>] asymmetric_key_cmp+0x19/0x1b
      [  132.820302]  [<ffffffff812971d9>] keyring_search_iterator+0x74/0xd7
      [  132.820302]  [<ffffffff812fb753>] assoc_array_subtree_iterate+0x67/0xd2
      [  132.820302]  [<ffffffff81297165>] ? key_default_cmp+0x20/0x20
      [  132.820302]  [<ffffffff812fbaa1>] assoc_array_iterate+0x19/0x1e
      [  132.820302]  [<ffffffff81297332>] search_nested_keyrings+0xf6/0x2b6
      [  132.820302]  [<ffffffff810728da>] ? sched_clock_cpu+0x91/0xa2
      [  132.820302]  [<ffffffff810860d2>] ? mark_held_locks+0x58/0x6e
      [  132.820302]  [<ffffffff810a137d>] ? current_kernel_time+0x77/0xb8
      [  132.820302]  [<ffffffff81297871>] keyring_search_aux+0xe1/0x14c
      [  132.820302]  [<ffffffff812977fc>] ? keyring_search_aux+0x6c/0x14c
      [  132.820302]  [<ffffffff8129796b>] keyring_search+0x8f/0xb6
      [  132.820302]  [<ffffffff812bfc84>] ? asymmetric_match_key_ids+0x42/0x42
      [  132.820302]  [<ffffffff81297165>] ? key_default_cmp+0x20/0x20
      [  132.820302]  [<ffffffff812ab9e3>] asymmetric_verify+0xa4/0x214
      [  132.820302]  [<ffffffff812ab90e>] integrity_digsig_verify+0xb1/0xe2
      [  132.820302]  [<ffffffff812abe41>] ? evm_verifyxattr+0x6a/0x7a
      [  132.820302]  [<ffffffff812b0390>] ima_appraise_measurement+0x160/0x370
      [  132.820302]  [<ffffffff81161db2>] ? d_absolute_path+0x5b/0x7a
      [  132.820302]  [<ffffffff812ada30>] process_measurement+0x322/0x404
      Reported-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      40b50e80
  24. 02 10月, 2014 1 次提交
  25. 22 9月, 2014 1 次提交
    • D
      KEYS: Check hex2bin()'s return when generating an asymmetric key ID · d1ac5540
      David Howells 提交于
      As it stands, the code to generate an asymmetric key ID prechecks the hex
      string it is given whilst determining the length, before it allocates the
      buffer for hex2bin() to translate into - which mean that checking the result of
      hex2bin() is redundant.
      
      Unfortunately, hex2bin() is marked as __must_check, which means that the
      following warning may be generated if the return value isn't checked:
      
      	crypto/asymmetric_keys/asymmetric_type.c: In function
      	asymmetric_key_hex_to_key_id:
      	crypto/asymmetric_keys/asymmetric_type.c:110: warning: ignoring return
      	value of hex2bin, declared with attribute warn_unused_result
      
      The warning can't be avoided by casting the result to void.
      
      Instead, use strlen() to check the length of the string and ignore the fact
      that the string might not be entirely valid hex until after the allocation has
      been done - in which case we can use the result of hex2bin() for this.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      d1ac5540
  26. 17 9月, 2014 3 次提交
    • D
      PKCS#7: Handle PKCS#7 messages that contain no X.509 certs · 757932e6
      David Howells 提交于
      The X.509 certificate list in a PKCS#7 message is optional.  To save space, we
      can omit the inclusion of any X.509 certificates if we are sure that we can
      look the relevant public key up by the serial number and issuer given in a
      signed info block.
      
      This also supports use of a signed info block for which we can't find a
      matching X.509 cert in the certificate list, though it be populated.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NVivek Goyal <vgoyal@redhat.com>
      757932e6
    • D
      PKCS#7: Better handling of unsupported crypto · 41559420
      David Howells 提交于
      Provide better handling of unsupported crypto when verifying a PKCS#7 message.
      If we can't bridge the gap between a pair of X.509 certs or between a signed
      info block and an X.509 cert because it involves some crypto we don't support,
      that's not necessarily the end of the world as there may be other ways points
      at which we can intersect with a ring of trusted keys.
      
      Instead, only produce ENOPKG immediately if all the signed info blocks in a
      PKCS#7 message require unsupported crypto to bridge to the first X.509 cert.
      Otherwise, we defer the generation of ENOPKG until we get ENOKEY during trust
      validation.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NVivek Goyal <vgoyal@redhat.com>
      41559420
    • D
      KEYS: Overhaul key identification when searching for asymmetric keys · 46963b77
      David Howells 提交于
      Make use of the new match string preparsing to overhaul key identification
      when searching for asymmetric keys.  The following changes are made:
      
       (1) Use the previously created asymmetric_key_id struct to hold the following
           key IDs derived from the X.509 certificate or PKCS#7 message:
      
      	id: serial number + issuer
      	skid: subjKeyId + subject
      	authority: authKeyId + issuer
      
       (2) Replace the hex fingerprint attached to key->type_data[1] with an
           asymmetric_key_ids struct containing the id and the skid (if present).
      
       (3) Make the asymmetric_type match data preparse select one of two searches:
      
           (a) An iterative search for the key ID given if prefixed with "id:".  The
           	 prefix is expected to be followed by a hex string giving the ID to
           	 search for.  The criterion key ID is checked against all key IDs
           	 recorded on the key.
      
           (b) A direct search if the key ID is not prefixed with "id:".  This will
           	 look for an exact match on the key description.
      
       (4) Make x509_request_asymmetric_key() take a key ID.  This is then converted
           into "id:<hex>" and passed into keyring_search() where match preparsing
           will turn it back into a binary ID.
      
       (5) X.509 certificate verification then takes the authority key ID and looks
           up a key that matches it to find the public key for the certificate
           signature.
      
       (6) PKCS#7 certificate verification then takes the id key ID and looks up a
           key that matches it to find the public key for the signed information
           block signature.
      
      Additional changes:
      
       (1) Multiple subjKeyId and authKeyId values on an X.509 certificate cause the
           cert to be rejected with -EBADMSG.
      
       (2) The 'fingerprint' ID is gone.  This was primarily intended to convey PGP
           public key fingerprints.  If PGP is supported in future, this should
           generate a key ID that carries the fingerprint.
      
       (3) Th ca_keyid= kernel command line option is now converted to a key ID and
           used to match the authority key ID.  Possibly this should only match the
           actual authKeyId part and not the issuer as well.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NVivek Goyal <vgoyal@redhat.com>
      46963b77