Skip to content
Snippets Groups Projects
  1. Dec 11, 2019
    • Herbert Xu's avatar
      crypto: api - Fix race condition in crypto_spawn_alg · 73669cc5
      Herbert Xu authored
      
      The function crypto_spawn_alg is racy because it drops the lock
      before shooting the dying algorithm.  The algorithm could disappear
      altogether before we shoot it.
      
      This patch fixes it by moving the shooting into the locked section.
      
      Fixes: 6bfd4809 ("[CRYPTO] api: Added spawns")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      73669cc5
    • Eric Biggers's avatar
      crypto: cipher - remove crt_u.cipher (struct cipher_tfm) · e8cfed5e
      Eric Biggers authored
      
      Of the three fields in crt_u.cipher (struct cipher_tfm), ->cit_setkey()
      is pointless because it always points to setkey() in crypto/cipher.c.
      
      ->cit_decrypt_one() and ->cit_encrypt_one() are slightly less pointless,
      since if the algorithm doesn't have an alignmask, they are set directly
      to ->cia_encrypt() and ->cia_decrypt().  However, this "optimization"
      isn't worthwhile because:
      
      - The "cipher" algorithm type is the only algorithm still using crt_u,
        so it's bloating every struct crypto_tfm for every algorithm type.
      
      - If the algorithm has an alignmask, this "optimization" actually makes
        things slower, as it causes 2 indirect calls per block rather than 1.
      
      - It adds extra code complexity.
      
      - Some templates already call ->cia_encrypt()/->cia_decrypt() directly
        instead of going through ->cit_encrypt_one()/->cit_decrypt_one().
      
      - The "cipher" algorithm type never gives optimal performance anyway.
        For that, a higher-level type such as skcipher needs to be used.
      
      Therefore, just remove the extra indirection, and make
      crypto_cipher_setkey(), crypto_cipher_encrypt_one(), and
      crypto_cipher_decrypt_one() be direct calls into crypto/cipher.c.
      
      Also remove the unused function crypto_cipher_cast().
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      e8cfed5e
    • Eric Biggers's avatar
      crypto: compress - remove crt_u.compress (struct compress_tfm) · c441a909
      Eric Biggers authored
      
      crt_u.compress (struct compress_tfm) is pointless because its two
      fields, ->cot_compress() and ->cot_decompress(), always point to
      crypto_compress() and crypto_decompress().
      
      Remove this pointless indirection, and just make crypto_comp_compress()
      and crypto_comp_decompress() be direct calls to what used to be
      crypto_compress() and crypto_decompress().
      
      Also remove the unused function crypto_comp_cast().
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c441a909
    • Eric Biggers's avatar
      crypto: api - remove another reference to blkcipher · 0a940d4e
      Eric Biggers authored
      
      Update a comment to refer to crypto_alloc_skcipher() rather than
      crypto_alloc_blkcipher() (the latter having been removed).
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      0a940d4e
  2. Nov 17, 2019
    • Herbert Xu's avatar
      crypto: api - Add softdep on cryptomgr · 8ab23d54
      Herbert Xu authored
      
      The crypto API requires cryptomgr to be present for probing to work
      so we need a softdep to ensure that cryptomgr is added to the
      initramfs.
      
      This was usually not a problem because until very recently it was
      not practical to build crypto API as module but with the recent
      work to eliminate direct AES users this is now possible.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      8ab23d54
  3. Nov 01, 2019
    • Eric Biggers's avatar
      crypto: skcipher - remove the "blkcipher" algorithm type · c65058b7
      Eric Biggers authored
      
      Now that all "blkcipher" algorithms have been converted to "skcipher",
      remove the blkcipher algorithm type.
      
      The skcipher (symmetric key cipher) algorithm type was introduced a few
      years ago to replace both blkcipher and ablkcipher (synchronous and
      asynchronous block cipher).  The advantages of skcipher include:
      
        - A much less confusing name, since none of these algorithm types have
          ever actually been for raw block ciphers, but rather for all
          length-preserving encryption modes including block cipher modes of
          operation, stream ciphers, and other length-preserving modes.
      
        - It unified blkcipher and ablkcipher into a single algorithm type
          which supports both synchronous and asynchronous implementations.
          Note, blkcipher already operated only on scatterlists, so the fact
          that skcipher does too isn't a regression in functionality.
      
        - Better type safety by using struct skcipher_alg, struct
          crypto_skcipher, etc. instead of crypto_alg, crypto_tfm, etc.
      
        - It sometimes simplifies the implementations of algorithms.
      
      Also, the blkcipher API was no longer being tested.
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c65058b7
  4. May 30, 2019
  5. Jul 18, 2018
  6. Apr 20, 2018
  7. Mar 30, 2018
    • Herbert Xu's avatar
      crypto: api - Keep failed instances alive · eb02c38f
      Herbert Xu authored
      
      This patch reverts commit 9c521a20 ("crypto: api - remove
      instance when test failed") and fixes the underlying problem
      in a different way.
      
      To recap, prior to the reverted commit, an instance that fails
      a self-test is kept around.  However, it would satisfy any new
      lookups against its name and therefore the system may accumlulate
      an unbounded number of failed instances for the same algorithm
      name.
      
      The reverted commit fixed it by unregistering the instance.  Hoever,
      this still does not prevent the creation of the same failed instance
      over and over again each time the name is looked up.
      
      This patch fixes it by keeping the failed instance around, just as
      we would if it were a normal algorithm.  However, the lookup code
      has been udpated so that we do not attempt to create another
      instance as long as this failed one is still registered.  Of course,
      you could still force a new creation by deleting the instance from
      user-space.
      
      A new error (ELIBBAD) has been commandeered for this purpose and
      will be returned when all registered algorithm of a given name
      have failed the self-test.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      eb02c38f
    • Herbert Xu's avatar
      crypto: api - Make crypto_alg_lookup static · 3ca1e994
      Herbert Xu authored
      
      The function crypto_alg_lookup is only usd within the crypto API
      and should be not be exported to the modules.  This patch marks
      it as a static function.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3ca1e994
    • Herbert Xu's avatar
      crypto: api - Remove unused crypto_type lookup function · 4989d4f0
      Herbert Xu authored
      
      The lookup function in crypto_type was only used for the implicit
      IV generators which have been completely removed from the crypto
      API.
      
      This patch removes the lookup function as it is now useless.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      4989d4f0
  8. Jan 05, 2018
  9. Dec 22, 2017
  10. Nov 03, 2017
  11. Mar 02, 2017
  12. Nov 28, 2016
  13. Oct 21, 2016
  14. Oct 20, 2015
    • Herbert Xu's avatar
      crypto: api - Only abort operations on fatal signal · 3fc89adb
      Herbert Xu authored
      
      Currently a number of Crypto API operations may fail when a signal
      occurs.  This causes nasty problems as the caller of those operations
      are often not in a good position to restart the operation.
      
      In fact there is currently no need for those operations to be
      interrupted by user signals at all.  All we need is for them to
      be killable.
      
      This patch replaces the relevant calls of signal_pending with
      fatal_signal_pending, and wait_for_completion_interruptible with
      wait_for_completion_killable, respectively.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3fc89adb
  15. Mar 31, 2015
    • Stephan Mueller's avatar
      crypto: api - prevent helper ciphers from being used · 06ca7f68
      Stephan Mueller authored
      
      Several hardware related cipher implementations are implemented as
      follows: a "helper" cipher implementation is registered with the
      kernel crypto API.
      
      Such helper ciphers are never intended to be called by normal users. In
      some cases, calling them via the normal crypto API may even cause
      failures including kernel crashes. In a normal case, the "wrapping"
      ciphers that use the helpers ensure that these helpers are invoked
      such that they cannot cause any calamity.
      
      Considering the AF_ALG user space interface, unprivileged users can
      call all ciphers registered with the crypto API, including these
      helper ciphers that are not intended to be called directly. That
      means, with AF_ALG user space may invoke these helper ciphers
      and may cause undefined states or side effects.
      
      To avoid any potential side effects with such helpers, the patch
      prevents the helpers to be called directly. A new cipher type
      flag is added: CRYPTO_ALG_INTERNAL. This flag shall be used
      to mark helper ciphers. These ciphers can only be used if the
      caller invoke the cipher with CRYPTO_ALG_INTERNAL in the type and
      mask field.
      
      Signed-off-by: default avatarStephan Mueller <smueller@chronox.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      06ca7f68
  16. Nov 24, 2014
  17. Sep 08, 2013
  18. Aug 20, 2013
  19. Jun 25, 2013
    • Herbert Xu's avatar
      crypto: algboss - Hold ref count on larval · 939e1779
      Herbert Xu authored
      
      On Thu, Jun 20, 2013 at 10:00:21AM +0200, Daniel Borkmann wrote:
      > After having fixed a NULL pointer dereference in SCTP 1abd165e ("net:
      > sctp: fix NULL pointer dereference in socket destruction"), I ran into
      > the following NULL pointer dereference in the crypto subsystem with
      > the same reproducer, easily hit each time:
      > 
      > BUG: unable to handle kernel NULL pointer dereference at (null)
      > IP: [<ffffffff81070321>] __wake_up_common+0x31/0x90
      > PGD 0
      > Oops: 0000 [#1] SMP
      > Modules linked in: padlock_sha(F-) sha256_generic(F) sctp(F) libcrc32c(F) [..]
      > CPU: 6 PID: 3326 Comm: cryptomgr_probe Tainted: GF            3.10.0-rc5+ #1
      > Hardware name: Dell Inc. PowerEdge T410/0H19HD, BIOS 1.6.3 02/01/2011
      > task: ffff88007b6cf4e0 ti: ffff88007b7cc000 task.ti: ffff88007b7cc000
      > RIP: 0010:[<ffffffff81070321>]  [<ffffffff81070321>] __wake_up_common+0x31/0x90
      > RSP: 0018:ffff88007b7cde08  EFLAGS: 00010082
      > RAX: ffffffffffffffe8 RBX: ffff88003756c130 RCX: 0000000000000000
      > RDX: 0000000000000000 RSI: 0000000000000003 RDI: ffff88003756c130
      > RBP: ffff88007b7cde48 R08: 0000000000000000 R09: ffff88012b173200
      > R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000282
      > R13: ffff88003756c138 R14: 0000000000000000 R15: 0000000000000000
      > FS:  0000000000000000(0000) GS:ffff88012fc60000(0000) knlGS:0000000000000000
      > CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
      > CR2: 0000000000000000 CR3: 0000000001a0b000 CR4: 00000000000007e0
      > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      > DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
      > Stack:
      >  ffff88007b7cde28 0000000300000000 ffff88007b7cde28 ffff88003756c130
      >  0000000000000282 ffff88003756c128 ffffffff81227670 0000000000000000
      >  ffff88007b7cde78 ffffffff810722b7 ffff88007cdcf000 ffffffff81a90540
      > Call Trace:
      >  [<ffffffff81227670>] ? crypto_alloc_pcomp+0x20/0x20
      >  [<ffffffff810722b7>] complete_all+0x47/0x60
      >  [<ffffffff81227708>] cryptomgr_probe+0x98/0xc0
      >  [<ffffffff81227670>] ? crypto_alloc_pcomp+0x20/0x20
      >  [<ffffffff8106760e>] kthread+0xce/0xe0
      >  [<ffffffff81067540>] ? kthread_freezable_should_stop+0x70/0x70
      >  [<ffffffff815450dc>] ret_from_fork+0x7c/0xb0
      >  [<ffffffff81067540>] ? kthread_freezable_should_stop+0x70/0x70
      > Code: 41 56 41 55 41 54 53 48 83 ec 18 66 66 66 66 90 89 75 cc 89 55 c8
      >       4c 8d 6f 08 48 8b 57 08 41 89 cf 4d 89 c6 48 8d 42 e
      > RIP  [<ffffffff81070321>] __wake_up_common+0x31/0x90
      >  RSP <ffff88007b7cde08>
      > CR2: 0000000000000000
      > ---[ end trace b495b19270a4d37e ]---
      > 
      > My assumption is that the following is happening: the minimal SCTP
      > tool runs under ``echo 1 > /proc/sys/net/sctp/auth_enable'', hence
      > it's making use of crypto_alloc_hash() via sctp_auth_init_hmacs().
      > It forks itself, heavily allocates, binds, listens and waits in
      > accept on sctp sockets, and then randomly kills some of them (no
      > need for an actual client in this case to hit this). Then, again,
      > allocating, binding, etc, and then killing child processes.
      > 
      > The problem that might be happening here is that cryptomgr requests
      > the module to probe/load through cryptomgr_schedule_probe(), but
      > before the thread handler cryptomgr_probe() returns, we return from
      > the wait_for_completion_interruptible() function and probably already
      > have cleared up larval, thus we run into a NULL pointer dereference
      > when in cryptomgr_probe() complete_all() is being called.
      > 
      > If we wait with wait_for_completion() instead, this panic will not
      > occur anymore. This is valid, because in case a signal is pending,
      > cryptomgr_probe() returns from probing anyway with properly calling
      > complete_all().
      
      The use of wait_for_completion_interruptible is intentional so that
      we don't lock up the thread if a bug causes us to never wake up.
      
      This bug is caused by the helper thread using the larval without
      holding a reference count on it.  If the helper thread completes
      after the original thread requesting for help has gone away and
      destroyed the larval, then we get the crash above.
      
      So the fix is to hold a reference count on the larval.
      
      Cc: <stable@vger.kernel.org> # 3.6+
      Reported-by: default avatarDaniel Borkmann <dborkman@redhat.com>
      Tested-by: default avatarDaniel Borkmann <dborkman@redhat.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      939e1779
  20. Feb 16, 2010
  21. Jul 14, 2009
  22. Jul 08, 2009
  23. Jun 02, 2009
  24. Apr 21, 2009
  25. Feb 26, 2009
    • Herbert Xu's avatar
      crypto: api - Fix module load deadlock with fallback algorithms · a760a665
      Herbert Xu authored
      
      With the mandatory algorithm testing at registration, we have
      now created a deadlock with algorithms requiring fallbacks.
      This can happen if the module containing the algorithm requiring
      fallback is loaded first, without the fallback module being loaded
      first.  The system will then try to test the new algorithm, find
      that it needs to load a fallback, and then try to load that.
      
      As both algorithms share the same module alias, it can attempt
      to load the original algorithm again and block indefinitely.
      
      As algorithms requiring fallbacks are a special case, we can fix
      this by giving them a different module alias than the rest.  Then
      it's just a matter of using the right aliases according to what
      algorithms we're trying to find.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      a760a665
  26. Feb 18, 2009
    • Herbert Xu's avatar
      crypto: api - Fix crypto_alloc_tfm/create_create_tfm return convention · 3f683d61
      Herbert Xu authored
      
      This is based on a report and patch by Geert Uytterhoeven.
      
      The functions crypto_alloc_tfm and create_create_tfm return a
      pointer that needs to be adjusted by the caller when successful
      and otherwise an error value.  This means that the caller has
      to check for the error and only perform the adjustment if the
      pointer returned is valid.
      
      Since all callers want to make the adjustment and we know how
      to adjust it ourselves, it's much easier to just return adjusted
      pointer directly.
      
      The only caveat is that we have to return a void * instead of
      struct crypto_tfm *.  However, this isn't that bad because both
      of these functions are for internal use only (by types code like
      shash.c, not even algorithms code).
      
      This patch also moves crypto_alloc_tfm into crypto/internal.h
      (crypto_create_tfm is already there) to reflect this.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3f683d61
    • Herbert Xu's avatar
      crypto: api - crypto_alg_mod_lookup either tested or untested · ff753308
      Herbert Xu authored
      
      As it stands crypto_alg_mod_lookup will search either tested or
      untested algorithms, but never both at the same time.  However,
      we need exactly that when constructing givcipher and aead so
      this patch adds support for that by setting the tested bit in
      type but clearing it in mask.  This combination is currently
      unused.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ff753308
  27. Feb 05, 2009
  28. Dec 25, 2008
    • Herbert Xu's avatar
      crypto: api - Rebirth of crypto_alloc_tfm · 7b0bac64
      Herbert Xu authored
      
      This patch reintroduces a completely revamped crypto_alloc_tfm.
      The biggest change is that we now take two crypto_type objects
      when allocating a tfm, a frontend and a backend.  In fact this
      simply formalises what we've been doing behind the API's back.
      
      For example, as it stands crypto_alloc_ahash may use an
      actual ahash algorithm or a crypto_hash algorithm.  Putting
      this in the API allows us to do this much more cleanly.
      
      The existing types will be converted across gradually.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7b0bac64
    • Herbert Xu's avatar
      crypto: api - Move type exit function into crypto_tfm · 4a779486
      Herbert Xu authored
      
      The type exit function needs to undo any allocations done by the type
      init function.  However, the type init function may differ depending
      on the upper-level type of the transform (e.g., a crypto_blkcipher
      instantiated as a crypto_ablkcipher).
      
      So we need to move the exit function out of the lower-level
      structure and into crypto_tfm itself.
      
      As it stands this is a no-op since nobody uses exit functions at
      all.  However, all cases where a lower-level type is instantiated
      as a different upper-level type (such as blkcipher as ablkcipher)
      will be converted such that they allocate the underlying transform
      and use that instead of casting (e.g., crypto_ablkcipher casted
      into crypto_blkcipher).  That will need to use a different exit
      function depending on the upper-level type.
      
      This patch also allows the type init/exit functions to call (or not)
      cra_init/cra_exit instead of always calling them from the top level.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      4a779486
  29. Aug 29, 2008
  30. Jul 10, 2008
Loading