Skip to content
Snippets Groups Projects
  1. Oct 02, 2024
    • Al Viro's avatar
      move asm/unaligned.h to linux/unaligned.h · 5f60d5f6
      Al Viro authored
      asm/unaligned.h is always an include of asm-generic/unaligned.h;
      might as well move that thing to linux/unaligned.h and include
      that - there's nothing arch-specific in that header.
      
      auto-generated by the following:
      
      for i in `git grep -l -w asm/unaligned.h`; do
      	sed -i -e "s/asm\/unaligned.h/linux\/unaligned.h/" $i
      done
      for i in `git grep -l -w asm-generic/unaligned.h`; do
      	sed -i -e "s/asm-generic\/unaligned.h/linux\/unaligned.h/" $i
      done
      git mv include/asm-generic/unaligned.h include/linux/unaligned.h
      git mv tools/include/asm-generic/unaligned.h tools/include/linux/unaligned.h
      sed -i -e "/unaligned.h/d" include/asm-generic/Kbuild
      sed -i -e "s/__ASM_GENERIC/__LINUX/" include/linux/unaligned.h tools/include/linux/unaligned.h
      5f60d5f6
  2. Sep 20, 2024
  3. Sep 13, 2024
  4. Sep 06, 2024
    • Herbert Xu's avatar
      crypto: testmgr - Hide ENOENT errors · 4eded6d1
      Herbert Xu authored
      
      When a crypto algorithm with a higher priority is registered, it
      kills the spawns of all lower-priority algorithms.  Thus it is to
      be expected for an algorithm to go away at any time, even during
      a self-test.  This is now much more common with asynchronous testing.
      
      Remove the printk when an ENOENT is encountered during a self-test.
      This is not really an error since the algorithm being tested is no
      longer there (i.e., it didn't fail the test which is what we care
      about).
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      4eded6d1
    • Herbert Xu's avatar
      crypto: algboss - Pass instance creation error up · 795f85fc
      Herbert Xu authored
      
      Pass any errors we get during instance creation up through the
      larval.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      795f85fc
    • Herbert Xu's avatar
      crypto: api - Fix generic algorithm self-test races · e7a4142b
      Herbert Xu authored
      
      On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
      >
      > Given below in defconfig form, use 'make olddefconfig' to apply.  The failures
      > are nondeterministic and sometimes there are different ones, for example:
      >
      > [    0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
      > [    0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
      > [    0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
      > [    0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
      > [    0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
      > [    0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
      >
      > Modules are not enabled, maybe that matters (I haven't checked yet).
      
      Yes I think that was the key.  This triggers a massive self-test
      run which executes in parallel and reveals a few race conditions
      in the system.  I think it boils down to the following scenario:
      
      Base algorithm X-generic, X-optimised
      Template Y
      Optimised algorithm Y-X-optimised
      
      Everything gets registered, and then the self-tests are started.
      When Y-X-optimised gets tested, it requests the creation of the
      generic Y(X-generic).  Which then itself undergoes testing.
      
      The race is that after Y(X-generic) gets registered, but just
      before it gets tested, X-optimised finally finishes self-testing
      which then causes all spawns of X-generic to be destroyed.  So
      by the time the self-test for Y(X-generic) comes along, it can
      no longer find the algorithm.  This error then bubbles up all
      the way up to the self-test of Y-X-optimised which then fails.
      
      Note that there is some complexity that I've omitted here because
      when the generic self-test fails to find Y(X-generic) it actually
      triggers the construction of it again which then fails for various
      other reasons (these are not important because the construction
      should *not* be triggered at this point).
      
      So in a way the error is expected, and we should probably remove
      the pr_err for the case where ENOENT is returned for the algorithm
      that we're currently testing.
      
      The solution is two-fold.  First when an algorithm undergoes
      self-testing it should not trigger its construction.  Secondly
      if an instance larval fails to materialise due to it being destroyed
      by a more optimised algorithm coming along, it should obviously
      retry the construction.
      
      Remove the check in __crypto_alg_lookup that stops a larval from
      matching new requests based on differences in the mask.  It is better
      to block new requests even if it is wrong and then simply retry the
      lookup.  If this ends up being the wrong larval it will sort iself
      out during the retry.
      
      Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
      as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.
      
      Also block the instance creation during self-testing in the function
      crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
      field.
      
      Finally change the return value when crypto_alg_lookup fails in
      crypto_larval_wait to EAGAIN to redo the lookup.
      
      Fixes: 37da5d0f ("crypto: api - Do not wait for tests during registration")
      Reported-by: default avatarEric Biggers <ebiggers@kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      e7a4142b
  5. Aug 30, 2024
  6. Aug 24, 2024
    • Herbert Xu's avatar
      crypto: simd - Do not call crypto_alloc_tfm during registration · 3c44d31c
      Herbert Xu authored
      
      Algorithm registration is usually carried out during module init,
      where as little work as possible should be carried out.  The SIMD
      code violated this rule by allocating a tfm, this then triggers a
      full test of the algorithm which may dead-lock in certain cases.
      
      SIMD is only allocating the tfm to get at the alg object, which is
      in fact already available as it is what we are registering.  Use
      that directly and remove the crypto_alloc_tfm call.
      
      Also remove some obsolete and unused SIMD API.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3c44d31c
    • Herbert Xu's avatar
      crypto: api - Do not wait for tests during registration · 37da5d0f
      Herbert Xu authored
      
      As registration is usually carried out during module init, this
      is a context where as little work as possible should be carried
      out.  Testing may trigger module loads of underlying components,
      which could even lead back to the module that is registering at
      the moment.  This may lead to dead-locks outside of the Crypto API.
      
      Avoid this by not waiting for the tests to complete.  They will
      be scheduled but completion will be asynchronous.  Any users will
      still wait for completion.
      
      Reported-by: default avatarRussell King <linux@armlinux.org.uk>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      37da5d0f
    • Herbert Xu's avatar
      crypto: api - Remove instance larval fulfilment · 96ad5955
      Herbert Xu authored
      
      In order to allow testing to complete asynchronously after the
      registration process, instance larvals need to complete prior
      to having a test result.  Support this by redoing the lookup for
      instance larvals after completion.   This should locate the pending
      test larval and then repeat the wait on that (if it is still pending).
      
      As the lookup is now repeated there is no longer any need to compute
      the fulfilment status and all that code can be removed.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      96ad5955
    • Stephan Mueller's avatar
      crypto: jitter - set default OSR to 3 · 95a798d2
      Stephan Mueller authored
      
      The user space Jitter RNG library uses the oversampling rate of 3 which
      implies that each time stamp is credited with 1/3 bit of entropy. To
      obtain 256 bits of entropy, 768 time stamps need to be sampled. The
      increase in OSR is applied based on a report where the Jitter RNG is
      used on a system exhibiting a challenging environment to collect
      entropy.
      
      This OSR default value is now applied to the Linux kernel version of
      the Jitter RNG as well.
      
      The increase in the OSR from 1 to 3 also implies that the Jitter RNG is
      now slower by default.
      
      Reported-by: default avatarJeff Barnes <jeffbarnes@microsoft.com>
      Signed-off-by: default avatarStephan Mueller <smueller@chronox.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      95a798d2
  7. Aug 17, 2024
  8. Aug 02, 2024
    • Helge Deller's avatar
      crypto: xor - fix template benchmarking · ab9a244c
      Helge Deller authored
      
      Commit c055e3ea ("crypto: xor - use ktime for template benchmarking")
      switched from using jiffies to ktime-based performance benchmarking.
      
      This works nicely on machines which have a fine-grained ktime()
      clocksource as e.g. x86 machines with TSC.
      But other machines, e.g. my 4-way HP PARISC server, don't have such
      fine-grained clocksources, which is why it seems that 800 xor loops
      take zero seconds, which then shows up in the logs as:
      
       xor: measuring software checksum speed
          8regs           : -1018167296 MB/sec
          8regs_prefetch  : -1018167296 MB/sec
          32regs          : -1018167296 MB/sec
          32regs_prefetch : -1018167296 MB/sec
      
      Fix this with some small modifications to the existing code to improve
      the algorithm to always produce correct results without introducing
      major delays for architectures with a fine-grained ktime()
      clocksource:
      a) Delay start of the timing until ktime() just advanced. On machines
      with a fast ktime() this should be just one additional ktime() call.
      b) Count the number of loops. Run at minimum 800 loops and finish
      earliest when the ktime() counter has progressed.
      
      With that the throughput can now be calculated more accurately under all
      conditions.
      
      Fixes: c055e3ea ("crypto: xor - use ktime for template benchmarking")
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Tested-by: default avatarJohn David Anglin <dave.anglin@bell.net>
      
      v2:
      - clean up coding style (noticed & suggested by Herbert Xu)
      - rephrased & fixed typo in commit message
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ab9a244c
  9. Jul 12, 2024
  10. Jun 28, 2024
  11. Jun 16, 2024
  12. Jun 07, 2024
  13. May 31, 2024
  14. May 17, 2024
  15. May 14, 2024
    • Joachim Vandersmissen's avatar
      certs: Add ECDSA signature verification self-test · 747ae818
      Joachim Vandersmissen authored
      
      Commit c27b2d20 ("crypto: testmgr - allow ecdsa-nist-p256 and -p384
      in FIPS mode") enabled support for ECDSA in crypto/testmgr.c. The
      PKCS#7 signature verification API builds upon the KCAPI primitives to
      perform its high-level operations. Therefore, this change in testmgr.c
      also allows ECDSA to be used by the PKCS#7 signature verification API
      (in FIPS mode).
      
      However, from a FIPS perspective, the PKCS#7 signature verification API
      is a distinct "service" from the KCAPI primitives. This is because the
      PKCS#7 API performs a "full" signature verification, which consists of
      both hashing the data to be verified, and the public key operation.
      On the other hand, the KCAPI primitive does not perform this hashing
      step - it accepts pre-hashed data from the caller and only performs the
      public key operation.
      
      For this reason, the ECDSA self-tests in crypto/testmgr.c are not
      sufficient to cover ECDSA signature verification offered by the PKCS#7
      API. This is reflected by the self-test already present in this file
      for RSA PKCS#1 v1.5 signature verification.
      
      The solution is simply to add a second self-test here for ECDSA. P-256
      with SHA-256 hashing was chosen as those parameters should remain
      FIPS-approved for the foreseeable future, while keeping the performance
      impact to a minimum. The ECDSA certificate and PKCS#7 signed data was
      generated using OpenSSL. The input data is identical to the input data
      for the existing RSA self-test.
      
      Signed-off-by: default avatarJoachim Vandersmissen <git@jvdsn.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      747ae818
    • Joachim Vandersmissen's avatar
      certs: Move RSA self-test data to separate file · 8cd9f234
      Joachim Vandersmissen authored
      
      In preparation of adding new ECDSA self-tests, the existing data for
      the RSA self-tests is moved to a separate file. This file is only
      compiled if the new CONFIG_FIPS_SIGNATURE_SELFTEST_RSA configuration
      option is set, which ensures that the required dependencies (RSA,
      SHA-256) are present. Otherwise, the kernel would panic when trying to
      execute the self-test.
      The introduction of this new option, rather than adding the
      dependencies to the existing CONFIG_FIPS_SIGNATURE_SELFTEST option,
      allows for additional self-tests to be added for different algorithms.
      The kernel can then be configured to only execute the self-tests for
      those algorithms that are included.
      
      Signed-off-by: default avatarJoachim Vandersmissen <git@jvdsn.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      8cd9f234
    • Jens Axboe's avatar
      net: change proto and proto_ops accept type · 92ef0fd5
      Jens Axboe authored
      
      Rather than pass in flags, error pointer, and whether this is a kernel
      invocation or not, add a struct proto_accept_arg struct as the argument.
      This then holds all of these arguments, and prepares accept for being
      able to pass back more information.
      
      No functional changes in this patch.
      
      Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      92ef0fd5
  16. May 13, 2024
  17. May 10, 2024
  18. Apr 26, 2024
    • Stefan Berger's avatar
      crypto: ecdh - Initialize ctx->private_key in proper byte order · 01474b70
      Stefan Berger authored
      
      The private key in ctx->private_key is currently initialized in reverse
      byte order in ecdh_set_secret and whenever the key is needed in proper
      byte order the variable priv is introduced and the bytes from
      ctx->private_key are copied into priv while being byte-swapped
      (ecc_swap_digits). To get rid of the unnecessary byte swapping initialize
      ctx->private_key in proper byte order and clean up all functions that were
      previously using priv or were called with ctx->private_key:
      
      - ecc_gen_privkey: Directly initialize the passed ctx->private_key with
        random bytes filling all the digits of the private key. Get rid of the
        priv variable. This function only has ecdh_set_secret as a caller to
        create NIST P192/256/384 private keys.
      
      - crypto_ecdh_shared_secret: Called only from ecdh_compute_value with
        ctx->private_key. Get rid of the priv variable and work with the passed
        private_key directly.
      
      - ecc_make_pub_key: Called only from ecdh_compute_value with
        ctx->private_key. Get rid of the priv variable and work with the passed
        private_key directly.
      
      Cc: Salvatore Benedetto <salvatore.benedetto@intel.com>
      Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Acked-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      01474b70
    • Stefan Berger's avatar
      crypto: ecdh - Pass private key in proper byte order to check valid key · bd955a4e
      Stefan Berger authored
      
      ecc_is_key_valid expects a key with the most significant digit in the last
      entry of the digit array. Currently ecdh_set_secret passes a reversed key
      to ecc_is_key_valid that then passes the rather simple test checking
      whether the private key is in range [2, n-3]. For all current ecdh-
      supported curves (NIST P192/256/384) the 'n' parameter is a rather large
      number, therefore easily passing this test.
      
      Throughout the ecdh and ecc codebase the variable 'priv' is used for a
      private_key holding the bytes in proper byte order. Therefore, introduce
      priv in ecdh_set_secret and copy the bytes from ctx->private_key into
      priv in proper byte order by using ecc_swap_digits. Pass priv to
      ecc_is_valid_key.
      
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: Salvatore Benedetto <salvatore.benedetto@intel.com>
      Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Acked-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      bd955a4e
    • Hailey Mothershead's avatar
      crypto: aead,cipher - zeroize key buffer after use · 23e4099b
      Hailey Mothershead authored
      
      I.G 9.7.B for FIPS 140-3 specifies that variables temporarily holding
      cryptographic information should be zeroized once they are no longer
      needed. Accomplish this by using kfree_sensitive for buffers that
      previously held the private key.
      
      Signed-off-by: default avatarHailey Mothershead <hailmo@amazon.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      23e4099b
  19. Apr 24, 2024
  20. Apr 12, 2024
Loading