Skip to content
Snippets Groups Projects
  1. Mar 22, 2024
  2. Mar 13, 2024
  3. Mar 08, 2024
  4. Mar 01, 2024
    • Eric Biggers's avatar
      crypto: remove CONFIG_CRYPTO_STATS · 2beb81fb
      Eric Biggers authored
      Remove support for the "Crypto usage statistics" feature
      (CONFIG_CRYPTO_STATS).  This feature does not appear to have ever been
      used, and it is harmful because it significantly reduces performance and
      is a large maintenance burden.
      
      Covering each of these points in detail:
      
      1. Feature is not being used
      
      Since these generic crypto statistics are only readable using netlink,
      it's fairly straightforward to look for programs that use them.  I'm
      unable to find any evidence that any such programs exist.  For example,
      Debian Code Search returns no hits except the kernel header and kernel
      code itself and translations of the kernel header:
      https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
      
      The patch series that added this feature in 2018
      (https://lore.kernel.org/linux-crypto/1537351855-16618-1-git-send-email-clabbe@baylibre.com/)
      said "The goal is to have an ifconfig for crypto device."  This doesn't
      appear to have happened.
      
      It's not clear that there is real demand for crypto statistics.  Just
      because the kernel provides other types of statistics such as I/O and
      networking statistics and some people find those useful does not mean
      that crypto statistics are useful too.
      
      Further evidence that programs are not using CONFIG_CRYPTO_STATS is that
      it was able to be disabled in RHEL and Fedora as a bug fix
      (https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
      
      Even further evidence comes from the fact that there are and have been
      bugs in how the stats work, but they were never reported.  For example,
      before Linux v6.7 hash stats were double-counted in most cases.
      
      There has also never been any documentation for this feature, so it
      might be hard to use even if someone wanted to.
      
      2. CONFIG_CRYPTO_STATS significantly reduces performance
      
      Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of
      the crypto API, even if no program ever retrieves the statistics.  This
      primarily affects systems with large number of CPUs.  For example,
      https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576
      
       reported
      that Lustre client encryption performance improved from 21.7GB/s to
      48.2GB/s by disabling CONFIG_CRYPTO_STATS.
      
      It can be argued that this means that CONFIG_CRYPTO_STATS should be
      optimized with per-cpu counters similar to many of the networking
      counters.  But no one has done this in 5+ years.  This is consistent
      with the fact that the feature appears to be unused, so there seems to
      be little interest in improving it as opposed to just disabling it.
      
      It can be argued that because CONFIG_CRYPTO_STATS is off by default,
      performance doesn't matter.  But Linux distros tend to error on the side
      of enabling options.  The option is enabled in Ubuntu and Arch Linux,
      and until recently was enabled in RHEL and Fedora (see above).  So, even
      just having the option available is harmful to users.
      
      3. CONFIG_CRYPTO_STATS is a large maintenance burden
      
      There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS,
      spread among 32 files.  It significantly complicates much of the
      implementation of the crypto API.  After the initial submission, many
      fixes and refactorings have consumed effort of multiple people to keep
      this feature "working".  We should be spending this effort elsewhere.
      
      Cc: Corentin Labbe <clabbe@baylibre.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Acked-by: default avatarCorentin Labbe <clabbe@baylibre.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      2beb81fb
    • Herbert Xu's avatar
      crypto: dh - Make public key test FIPS-only · f66a211e
      Herbert Xu authored
      
      The function dh_is_pubkey_valid was added to for FIPS but it was
      only partially conditional to fips_enabled.
      
      In particular, the first test in the function relies on the last
      test to work properly, but the last test is only run in FIPS mode.
      
      Fix this inconsistency by making the whole function conditional
      on fips_enabled.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      f66a211e
  5. Feb 24, 2024
  6. Feb 22, 2024
  7. Feb 09, 2024
  8. Feb 02, 2024
  9. Jan 26, 2024
  10. Jan 23, 2024
  11. Dec 29, 2023
  12. Dec 22, 2023
  13. Dec 15, 2023
    • Herbert Xu's avatar
      crypto: api - Disallow identical driver names · 27016f75
      Herbert Xu authored
      
      Disallow registration of two algorithms with identical driver names.
      
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      27016f75
    • Tom Zanussi's avatar
      crypto: iaa - Add support for deflate-iaa compression algorithm · 2ec6761d
      Tom Zanussi authored
      
      This patch registers the deflate-iaa deflate compression algorithm and
      hooks it up to the IAA hardware using the 'fixed' compression mode
      introduced in the previous patch.
      
      Because the IAA hardware has a 4k history-window limitation, only
      buffers <= 4k, or that have been compressed using a <= 4k history
      window, are technically compliant with the deflate spec, which allows
      for a window of up to 32k.  Because of this limitation, the IAA fixed
      mode deflate algorithm is given its own algorithm name, 'deflate-iaa'.
      
      With this change, the deflate-iaa crypto algorithm is registered and
      operational, and compression and decompression operations are fully
      enabled following the successful binding of the first IAA workqueue
      to the iaa_crypto sub-driver.
      
      when there are no IAA workqueues bound to the driver, the IAA crypto
      algorithm can be unregistered by removing the module.
      
      A new iaa_crypto 'verify_compress' driver attribute is also added,
      allowing the user to toggle compression verification.  If set, each
      compress will be internally decompressed and the contents verified,
      returning error codes if unsuccessful.  This can be toggled with 0/1:
      
        echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress
      
      The default setting is '1' - verify all compresses.
      
      The verify_compress value setting at the time the algorithm is
      registered is captured in the algorithm's crypto_ctx and used for all
      compresses when using the algorithm.
      
      [ Based on work originally by George Powley, Jing Lin and Kyung Min
      Park ]
      
      Signed-off-by: default avatarTom Zanussi <tom.zanussi@linux.intel.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      2ec6761d
  14. Dec 08, 2023
    • Herbert Xu's avatar
      crypto: algif_skcipher - Fix stream cipher chaining · 99bd99d3
      Herbert Xu authored
      
      Unlike algif_aead which is always issued in one go (thus limiting
      the maximum size of the request), algif_skcipher has always allowed
      unlimited input data by cutting them up as necessary and feeding
      the fragments to the underlying algorithm one at a time.
      
      However, because of deficiencies in the API, this has been broken
      for most stream ciphers such as arc4 or chacha.  This is because
      they have an internal state in addition to the IV that must be
      preserved in order to continue processing.
      
      Fix this by using the new skcipher state API.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      99bd99d3
    • Herbert Xu's avatar
      crypto: arc4 - Add internal state · 47309ea1
      Herbert Xu authored
      
      The arc4 algorithm has always had internal state.  It's been buggy
      from day one in that the state has been stored in the shared tfm
      object.  That means two users sharing the same tfm will end up
      affecting each other's output, or worse, they may end up with the
      same output.
      
      Fix this by declaring an internal state and storing the state there
      instead of within the tfm context.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      47309ea1
    • Herbert Xu's avatar
      crypto: skcipher - Make use of internal state · 662ea18d
      Herbert Xu authored
      
      This patch adds code to the skcipher/lskcipher API to make use
      of the internal state if present.  In particular, the skcipher
      lskcipher wrapper will allocate a buffer for the IV/state and
      feed that to the underlying lskcipher algorithm.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      662ea18d
    • Herbert Xu's avatar
      crypto: skcipher - Add internal state support · 0ae4dcc1
      Herbert Xu authored
      
      Unlike chaining modes such as CBC, stream ciphers other than CTR
      usually hold an internal state that must be preserved if the
      operation is to be done piecemeal.  This has not been represented
      in the API, resulting in the inability to split up stream cipher
      operations.
      
      This patch adds the basic representation of an internal state to
      skcipher and lskcipher.  In the interest of backwards compatibility,
      the default has been set such that existing users are assumed to
      be operating in one go as opposed to piecemeal.
      
      With the new API, each lskcipher/skcipher algorithm has a new
      attribute called statesize.  For skcipher, this is the size of
      the buffer that can be exported or imported similar to ahash.
      For lskcipher, instead of providing a buffer of ivsize, the user
      now has to provide a buffer of ivsize + statesize.
      
      Each skcipher operation is assumed to be final as they are now,
      but this may be overridden with a request flag.  When the override
      occurs, the user may then export the partial state and reimport
      it later.
      
      For lskcipher operations this is reversed.  All operations are
      not final and the state will be exported unless the FINAL bit is
      set.  However, the CONT bit still has to be set for the state
      to be used.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      0ae4dcc1
    • Herbert Xu's avatar
      crypto: cfb,ofb - Remove cfb and ofb · 412ac51c
      Herbert Xu authored
          
      Remove the unused algorithms CFB/OFB.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      412ac51c
    • Herbert Xu's avatar
      crypto: testmgr - Remove cfb and ofb · d4bd2102
      Herbert Xu authored
          
      Remove test vectors for CFB/OFB.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      d4bd2102
    • Herbert Xu's avatar
      crypto: tcrypt - Remove cfb and ofb · 1c95b546
      Herbert Xu authored
          
      Remove tests for CFB/OFB.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1c95b546
    • Herbert Xu's avatar
      crypto: af_alg - Disallow multiple in-flight AIO requests · 67b164a8
      Herbert Xu authored
      
      Having multiple in-flight AIO requests results in unpredictable
      output because they all share the same IV.  Fix this by only allowing
      one request at a time.
      
      Fixes: 83094e5e ("crypto: af_alg - add async support to algif_aead")
      Fixes: a596999b ("crypto: algif - change algif_skcipher to be asynchronous")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      67b164a8
  15. Nov 17, 2023
  16. Nov 07, 2023
    • Dmitry Safonov's avatar
      crypto: ahash - Set using_shash for cloned ahash wrapper over shash · 9aedd10f
      Dmitry Safonov authored
      
      The cloned child of ahash that uses shash under the hood should use
      shash helpers (like crypto_shash_setkey()).
      
      The following panic may be observed on TCP-AO selftests:
      
      > ==================================================================
      > BUG: KASAN: wild-memory-access in crypto_mod_get+0x1b/0x60
      > Write of size 4 at addr 5d5be0ff5c415e14 by task connect_ipv4/1397
      >
      > CPU: 0 PID: 1397 Comm: connect_ipv4 Tainted: G        W          6.6.0+ #47
      > Call Trace:
      >  <TASK>
      >  dump_stack_lvl+0x46/0x70
      >  kasan_report+0xc3/0xf0
      >  kasan_check_range+0xec/0x190
      >  crypto_mod_get+0x1b/0x60
      >  crypto_spawn_alg+0x53/0x140
      >  crypto_spawn_tfm2+0x13/0x60
      >  hmac_init_tfm+0x25/0x60
      >  crypto_ahash_setkey+0x8b/0x100
      >  tcp_ao_add_cmd+0xe7a/0x1120
      >  do_tcp_setsockopt+0x5ed/0x12a0
      >  do_sock_setsockopt+0x82/0x100
      >  __sys_setsockopt+0xe9/0x160
      >  __x64_sys_setsockopt+0x60/0x70
      >  do_syscall_64+0x3c/0xe0
      >  entry_SYSCALL_64_after_hwframe+0x46/0x4e
      > ==================================================================
      > general protection fault, probably for non-canonical address 0x5d5be0ff5c415e14: 0000 [#1] PREEMPT SMP KASAN
      > CPU: 0 PID: 1397 Comm: connect_ipv4 Tainted: G    B   W          6.6.0+ #47
      > Call Trace:
      >  <TASK>
      >  ? die_addr+0x3c/0xa0
      >  ? exc_general_protection+0x144/0x210
      >  ? asm_exc_general_protection+0x22/0x30
      >  ? add_taint+0x26/0x90
      >  ? crypto_mod_get+0x20/0x60
      >  ? crypto_mod_get+0x1b/0x60
      >  ? ahash_def_finup_done1+0x58/0x80
      >  crypto_spawn_alg+0x53/0x140
      >  crypto_spawn_tfm2+0x13/0x60
      >  hmac_init_tfm+0x25/0x60
      >  crypto_ahash_setkey+0x8b/0x100
      >  tcp_ao_add_cmd+0xe7a/0x1120
      >  do_tcp_setsockopt+0x5ed/0x12a0
      >  do_sock_setsockopt+0x82/0x100
      >  __sys_setsockopt+0xe9/0x160
      >  __x64_sys_setsockopt+0x60/0x70
      >  do_syscall_64+0x3c/0xe0
      >  entry_SYSCALL_64_after_hwframe+0x46/0x4e
      >  </TASK>
      > RIP: 0010:crypto_mod_get+0x20/0x60
      
      Make sure that the child/clone has using_shash set when parent is
      an shash user.
      
      Fixes: 2f1f34c1 ("crypto: ahash - optimize performance when wrapping shash")
      Cc: David Ahern <dsahern@kernel.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Dmitry Safonov <0x7f454c46@gmail.com>
      Cc: Eric Biggers <ebiggers@google.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Francesco Ruggeri <fruggeri05@gmail.com>
      To: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: Salam Noureddine <noureddine@arista.com>
      Cc: netdev@vger.kernel.org
      Cc: linux-crypto@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarDmitry Safonov <dima@arista.com>
      Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      9aedd10f
    • Herbert Xu's avatar
      crypto: jitterentropy - Hide esoteric Kconfig options under FIPS and EXPERT · e7ed6473
      Herbert Xu authored
      
      As JITTERENTROPY is selected by default if you enable the CRYPTO
      API, any Kconfig options added there will show up for every single
      user.  Hide the esoteric options under EXPERT as well as FIPS so
      that only distro makers will see them.
      
      Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Reviewed-by: default avatarStephan Mueller <smueller@chronox.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      e7ed6473
  17. Nov 01, 2023
  18. Oct 31, 2023
    • Mimi Zohar's avatar
      certs: Only allow certs signed by keys on the builtin keyring · b4650306
      Mimi Zohar authored
      
      Originally the secondary trusted keyring provided a keyring to which extra
      keys may be added, provided those keys were not blacklisted and were
      vouched for by a key built into the kernel or already in the secondary
      trusted keyring.
      
      On systems with the machine keyring configured, additional keys may also
      be vouched for by a key on the machine keyring.
      
      Prevent loading additional certificates directly onto the secondary
      keyring, vouched for by keys on the machine keyring, yet allow these
      certificates to be loaded onto other trusted keyrings.
      
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      b4650306
Loading