Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Apr 01, 2024
    • Eric Biggers's avatar
      crypto: remove CONFIG_CRYPTO_STATS · 29ce50e0
      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 r...
      29ce50e0
  2. Mar 12, 2024
  3. 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
  4. May 02, 2023
  5. Mar 14, 2023
    • Herbert Xu's avatar
      crypto: api - Check CRYPTO_USER instead of NET for report · c0f9e01d
      Herbert Xu authored
      
      The report function is currently conditionalised on CONFIG_NET.
      As it's only used by CONFIG_CRYPTO_USER, conditionalising on that
      instead of CONFIG_NET makes more sense.
      
      This gets rid of a rarely used code-path.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c0f9e01d
    • Herbert Xu's avatar
      crypto: rng - Count error stats differently · 9807e49b
      Herbert Xu authored
      
      Move all stat code specific to rng into the rng code.
      
      While we're at it, change the stats so that bytes and counts
      are always incremented even in case of error.  This allows the
      reference counting to be removed as we can now increment the
      counters prior to the operation.
      
      After the operation we simply increase the error count if necessary.
      This is safe as errors can only occur synchronously (or rather,
      the existing code already ignored asynchronous errors which are
      only visible to the callback function).
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      9807e49b
  6. Apr 02, 2021
  7. Aug 07, 2020
    • Waiman Long's avatar
      mm, treewide: rename kzfree() to kfree_sensitive() · 453431a5
      Waiman Long authored
      
      As said by Linus:
      
        A symmetric naming is only helpful if it implies symmetries in use.
        Otherwise it's actively misleading.
      
        In "kzalloc()", the z is meaningful and an important part of what the
        caller wants.
      
        In "kzfree()", the z is actively detrimental, because maybe in the
        future we really _might_ want to use that "memfill(0xdeadbeef)" or
        something. The "zero" part of the interface isn't even _relevant_.
      
      The main reason that kzfree() exists is to clear sensitive information
      that should not be leaked to other future users of the same memory
      objects.
      
      Rename kzfree() to kfree_sensitive() to follow the example of the recently
      added kvfree_sensitive() and make the intention of the API more explicit.
      In addition, memzero_explicit() is used to clear the memory to make sure
      that it won't get optimized away by the compiler.
      
      The renaming is done by using the command sequence:
      
        git grep -w --name-only kzfree |\
        xargs sed -i 's/kzfree/kfree_sensitive/'
      
      followed by some editing of the kfree_sensitive() kerneldoc and adding
      a kzfree backward compatibility macro in slab.h.
      
      [akpm@linux-foundation.org: fs/crypto/inline_crypt.c needs linux/slab.h]
      [akpm@linux-foundation.org: fix fs/crypto/inline_crypt.c some more]
      
      Suggested-by: default avatarJoe Perches <joe@perches.com>
      Signed-off-by: default avatarWaiman Long <longman@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Acked-by: default avatarDavid Howells <dhowells@redhat.com>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>
      Link: http://lkml.kernel.org/r/20200616154311.12314-3-longman@redhat.com
      
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      453431a5
  8. Feb 13, 2020
  9. May 30, 2019
  10. Dec 07, 2018
  11. Nov 09, 2018
    • Eric Biggers's avatar
      crypto: user - clean up report structure copying · 37db69e0
      Eric Biggers authored
      There have been a pretty ridiculous number of issues with initializing
      the report structures that are copied to userspace by NETLINK_CRYPTO.
      Commit 4473710d ("crypto: user - Prepare for CRYPTO_MAX_ALG_NAME
      expansion") replaced some strncpy()s with strlcpy()s, thereby
      introducing information leaks.  Later two other people tried to replace
      other strncpy()s with strlcpy() too, which would have introduced even
      more information leaks:
      
          - https://lore.kernel.org/patchwork/patch/954991/
          - https://patchwork.kernel.org/patch/10434351/
      
      Commit cac5818c
      
       ("crypto: user - Implement a generic crypto
      statistics") also uses the buggy strlcpy() approach and therefore leaks
      uninitialized memory to userspace.  A fix was proposed, but it was
      originally incomplete.
      
      Seeing as how apparently no one can get this right with the current
      approach, change all the reporting functions to:
      
      - Start by memsetting the report structure to 0.  This guarantees it's
        always initialized, regardless of what happens later.
      - Initialize all strings using strscpy().  This is safe after the
        memset, ensures null termination of long strings, avoids unnecessary
        work, and avoids the -Wstringop-truncation warnings from gcc.
      - Use sizeof(var) instead of sizeof(type).  This is more robust against
        copy+paste errors.
      
      For simplicity, also reuse the -EMSGSIZE return value from nla_put().
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      37db69e0
  12. Sep 28, 2018
  13. Jul 28, 2017
  14. Jun 10, 2017
  15. Jan 12, 2017
    • Gideon Israel Dsouza's avatar
      crypto: Replaced gcc specific attributes with macros from compiler.h · d8c34b94
      Gideon Israel Dsouza authored
      Continuing from this commit: 52f5684c
      
      
      ("kernel: use macros from compiler.h instead of __attribute__((...))")
      
      I submitted 4 total patches. They are part of task I've taken up to
      increase compiler portability in the kernel. I've cleaned up the
      subsystems under /kernel /mm /block and /security, this patch targets
      /crypto.
      
      There is <linux/compiler.h> which provides macros for various gcc specific
      constructs. Eg: __weak for __attribute__((weak)). I've cleaned all
      instances of gcc specific attributes with the right macros for the crypto
      subsystem.
      
      I had to make one additional change into compiler-gcc.h for the case when
      one wants to use this: __attribute__((aligned) and not specify an alignment
      factor. From the gcc docs, this will result in the largest alignment for
      that data type on the target machine so I've named the macro
      __aligned_largest. Please advise if another name is more appropriate.
      
      Signed-off-by: default avatarGideon Israel Dsouza <gidisrael@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      d8c34b94
  16. Jun 22, 2015
    • Herbert Xu's avatar
      crypto: rng - Do not free default RNG when it becomes unused · 7cecadb7
      Herbert Xu authored
      
      Currently we free the default RNG when its use count hits zero.
      This was OK when the IV generators would latch onto the RNG at
      instance creation time and keep it until the instance is torn
      down.
      
      Now that IV generators only keep the RNG reference during init
      time this scheme causes the default RNG to come and go at a high
      frequencey.  This is highly undesirable as we want to keep a single
      RNG in use unless the admin wants it to be removed.
      
      This patch changes the scheme so that the system RNG once allocated
      is never removed unless a specifically requested.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7cecadb7
  17. Apr 21, 2015
  18. Apr 20, 2015
  19. Feb 19, 2013
    • Mathias Krause's avatar
      crypto: user - fix info leaks in report API · 9a5467bf
      Mathias Krause authored
      
      Three errors resulting in kernel memory disclosure:
      
      1/ The structures used for the netlink based crypto algorithm report API
      are located on the stack. As snprintf() does not fill the remainder of
      the buffer with null bytes, those stack bytes will be disclosed to users
      of the API. Switch to strncpy() to fix this.
      
      2/ crypto_report_one() does not initialize all field of struct
      crypto_user_alg. Fix this to fix the heap info leak.
      
      3/ For the module name we should copy only as many bytes as
      module_name() returns -- not as much as the destination buffer could
      hold. But the current code does not and therefore copies random data
      from behind the end of the module name, as the module name is always
      shorter than CRYPTO_MAX_ALG_NAME.
      
      Also switch to use strncpy() to copy the algorithm's name and
      driver_name. They are strings, after all.
      
      Signed-off-by: default avatarMathias Krause <minipli@googlemail.com>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      9a5467bf
  20. Apr 02, 2012
  21. Nov 10, 2011
  22. Oct 21, 2011
  23. Jul 26, 2011
  24. Mar 30, 2010
    • Tejun Heo's avatar
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo authored
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        bloc...
      5a0e3ad6
  25. Aug 12, 2009
  26. Aug 29, 2008