1. 06 1月, 2023 1 次提交
  2. 26 11月, 2022 1 次提交
    • A
      use less confusing names for iov_iter direction initializers · de4eda9d
      Al Viro 提交于
      READ/WRITE proved to be actively confusing - the meanings are
      "data destination, as used with read(2)" and "data source, as
      used with write(2)", but people keep interpreting those as
      "we read data from it" and "we write data to it", i.e. exactly
      the wrong way.
      
      Call them ITER_DEST and ITER_SOURCE - at least that is harder
      to misinterpret...
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      de4eda9d
  3. 18 11月, 2022 2 次提交
  4. 04 11月, 2022 1 次提交
  5. 12 10月, 2022 2 次提交
    • J
      treewide: use get_random_{u8,u16}() when possible, part 1 · 7e3cf084
      Jason A. Donenfeld 提交于
      Rather than truncate a 32-bit value to a 16-bit value or an 8-bit value,
      simply use the get_random_{u8,u16}() functions, which are faster than
      wasting the additional bytes from a 32-bit value. This was done
      mechanically with this coccinelle script:
      
      @@
      expression E;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u16;
      typedef __be16;
      typedef __le16;
      typedef u8;
      @@
      (
      - (get_random_u32() & 0xffff)
      + get_random_u16()
      |
      - (get_random_u32() & 0xff)
      + get_random_u8()
      |
      - (get_random_u32() % 65536)
      + get_random_u16()
      |
      - (get_random_u32() % 256)
      + get_random_u8()
      |
      - (get_random_u32() >> 16)
      + get_random_u16()
      |
      - (get_random_u32() >> 24)
      + get_random_u8()
      |
      - (u16)get_random_u32()
      + get_random_u16()
      |
      - (u8)get_random_u32()
      + get_random_u8()
      |
      - (__be16)get_random_u32()
      + (__be16)get_random_u16()
      |
      - (__le16)get_random_u32()
      + (__le16)get_random_u16()
      |
      - prandom_u32_max(65536)
      + get_random_u16()
      |
      - prandom_u32_max(256)
      + get_random_u8()
      |
      - E->inet_id = get_random_u32()
      + E->inet_id = get_random_u16()
      )
      
      @@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u16;
      identifier v;
      @@
      - u16 v = get_random_u32();
      + u16 v = get_random_u16();
      
      @@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u8;
      identifier v;
      @@
      - u8 v = get_random_u32();
      + u8 v = get_random_u8();
      
      @@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u16;
      u16 v;
      @@
      -  v = get_random_u32();
      +  v = get_random_u16();
      
      @@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u8;
      u8 v;
      @@
      -  v = get_random_u32();
      +  v = get_random_u8();
      
      // Find a potential literal
      @literal_mask@
      expression LITERAL;
      type T;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      position p;
      @@
      
              ((T)get_random_u32()@p & (LITERAL))
      
      // Examine limits
      @script:python add_one@
      literal << literal_mask.LITERAL;
      RESULT;
      @@
      
      value = None
      if literal.startswith('0x'):
              value = int(literal, 16)
      elif literal[0] in '123456789':
              value = int(literal, 10)
      if value is None:
              print("I don't know how to handle %s" % (literal))
              cocci.include_match(False)
      elif value < 256:
              coccinelle.RESULT = cocci.make_ident("get_random_u8")
      elif value < 65536:
              coccinelle.RESULT = cocci.make_ident("get_random_u16")
      else:
              print("Skipping large mask of %s" % (literal))
              cocci.include_match(False)
      
      // Replace the literal mask with the calculated result.
      @plus_one@
      expression literal_mask.LITERAL;
      position literal_mask.p;
      identifier add_one.RESULT;
      identifier FUNC;
      @@
      
      -       (FUNC()@p & (LITERAL))
      +       (RESULT() & LITERAL)
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NYury Norov <yury.norov@gmail.com>
      Acked-by: NJakub Kicinski <kuba@kernel.org>
      Acked-by: Toke Høiland-Jørgensen <toke@toke.dk> # for sch_cake
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      7e3cf084
    • J
      treewide: use prandom_u32_max() when possible, part 1 · 81895a65
      Jason A. Donenfeld 提交于
      Rather than incurring a division or requesting too many random bytes for
      the given range, use the prandom_u32_max() function, which only takes
      the minimum required bytes from the RNG and avoids divisions. This was
      done mechanically with this coccinelle script:
      
      @basic@
      expression E;
      type T;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u64;
      @@
      (
      - ((T)get_random_u32() % (E))
      + prandom_u32_max(E)
      |
      - ((T)get_random_u32() & ((E) - 1))
      + prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2)
      |
      - ((u64)(E) * get_random_u32() >> 32)
      + prandom_u32_max(E)
      |
      - ((T)get_random_u32() & ~PAGE_MASK)
      + prandom_u32_max(PAGE_SIZE)
      )
      
      @multi_line@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      identifier RAND;
      expression E;
      @@
      
      -       RAND = get_random_u32();
              ... when != RAND
      -       RAND %= (E);
      +       RAND = prandom_u32_max(E);
      
      // Find a potential literal
      @literal_mask@
      expression LITERAL;
      type T;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      position p;
      @@
      
              ((T)get_random_u32()@p & (LITERAL))
      
      // Add one to the literal.
      @script:python add_one@
      literal << literal_mask.LITERAL;
      RESULT;
      @@
      
      value = None
      if literal.startswith('0x'):
              value = int(literal, 16)
      elif literal[0] in '123456789':
              value = int(literal, 10)
      if value is None:
              print("I don't know how to handle %s" % (literal))
              cocci.include_match(False)
      elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1:
              print("Skipping 0x%x for cleanup elsewhere" % (value))
              cocci.include_match(False)
      elif value & (value + 1) != 0:
              print("Skipping 0x%x because it's not a power of two minus one" % (value))
              cocci.include_match(False)
      elif literal.startswith('0x'):
              coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1))
      else:
              coccinelle.RESULT = cocci.make_expr("%d" % (value + 1))
      
      // Replace the literal mask with the calculated result.
      @plus_one@
      expression literal_mask.LITERAL;
      position literal_mask.p;
      expression add_one.RESULT;
      identifier FUNC;
      @@
      
      -       (FUNC()@p & (LITERAL))
      +       prandom_u32_max(RESULT)
      
      @collapse_ret@
      type T;
      identifier VAR;
      expression E;
      @@
      
       {
      -       T VAR;
      -       VAR = (E);
      -       return VAR;
      +       return E;
       }
      
      @drop_var@
      type T;
      identifier VAR;
      @@
      
       {
      -       T VAR;
              ... when != VAR
       }
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NYury Norov <yury.norov@gmail.com>
      Reviewed-by: NKP Singh <kpsingh@kernel.org>
      Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 and sbitmap
      Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> # for drbd
      Acked-by: NJakub Kicinski <kuba@kernel.org>
      Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390
      Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
      Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      81895a65
  6. 02 9月, 2022 1 次提交
  7. 19 8月, 2022 2 次提交
    • R
      crypto: testmgr - don't generate WARN for missing modules · a76bd86a
      Robert Elliott 提交于
      This userspace command:
          modprobe tcrypt
      or
          modprobe tcrypt mode=0
      
      runs all the tcrypt test cases numbered <200 (i.e., all the
      test cases calling tcrypt_test() and returning return values).
      
      Tests are sparsely numbered from 0 to 1000. For example:
          modprobe tcrypt mode=12
      tests sha512, and
          modprobe tcrypt mode=152
      tests rfc4543(gcm(aes))) - AES-GCM as GMAC
      
      The test manager generates WARNING crashdumps every time it attempts
      a test using an algorithm that is not available (not built-in to the
      kernel or available as a module):
      
          alg: skcipher: failed to allocate transform for ecb(arc4): -2
          ------------[ cut here ]-----------
          alg: self-tests for ecb(arc4) (ecb(arc4)) failed (rc=-2)
          WARNING: CPU: 9 PID: 4618 at crypto/testmgr.c:5777
      alg_test+0x30b/0x510
          [50 more lines....]
      
          ---[ end trace 0000000000000000 ]---
      
      If the kernel is compiled with CRYPTO_USER_API_ENABLE_OBSOLETE
      disabled (the default), then these algorithms are not compiled into
      the kernel or made into modules and trigger WARNINGs:
          arc4 tea xtea khazad anubis xeta seed
      
      Additionally, any other algorithms that are not enabled in .config
      will generate WARNINGs. In RHEL 9.0, for example, the default
      selection of algorithms leads to 16 WARNING dumps.
      
      One attempt to fix this was by modifying tcrypt_test() to check
      crypto_has_alg() and immediately return 0 if crypto_has_alg() fails,
      rather than proceed and return a non-zero error value that causes
      the caller (alg_test() in crypto/testmgr.c) to invoke WARN().
      That knocks out too many algorithms, though; some combinations
      like ctr(des3_ede) would work.
      
      Instead, change the condition on the WARN to ignore a return
      value is ENOENT, which is the value returned when the algorithm
      or combination of algorithms doesn't exist. Add a pr_warn to
      communicate that information in case the WARN is skipped.
      
      This approach allows algorithm tests to work that are combinations,
      not provided by one driver, like ctr(blowfish).
      
      Result - no more WARNINGs:
      modprobe tcrypt
      [  115.541765] tcrypt: testing md5
      [  115.556415] tcrypt: testing sha1
      [  115.570463] tcrypt: testing ecb(des)
      [  115.585303] cryptomgr: alg: skcipher: failed to allocate transform for ecb(des): -2
      [  115.593037] cryptomgr: alg: self-tests for ecb(des) using ecb(des) failed (rc=-2)
      [  115.593038] tcrypt: testing cbc(des)
      [  115.610641] cryptomgr: alg: skcipher: failed to allocate transform for cbc(des): -2
      [  115.618359] cryptomgr: alg: self-tests for cbc(des) using cbc(des) failed (rc=-2)
      ...
      Signed-off-by: NRobert Elliott <elliott@hpe.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      a76bd86a
    • L
      crypto: testmgr - extend acomp tests for NULL destination buffer · 5a4c2936
      Lucas Segarra Fernandez 提交于
      Acomp API supports NULL destination buffer for compression
      and decompression requests. In such cases allocation is
      performed by API.
      
      Add test cases for crypto_acomp_compress() and crypto_acomp_decompress()
      with dst buffer allocated by API.
      
      Tests will only run if CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y.
      Signed-off-by: NLucas Segarra Fernandez <lucas.segarra.fernandez@intel.com>
      Reviewed-by: NGiovanni Cabiddu <giovanni.cabiddu@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      5a4c2936
  8. 15 7月, 2022 1 次提交
  9. 10 6月, 2022 4 次提交
  10. 08 4月, 2022 1 次提交
  11. 08 3月, 2022 1 次提交
  12. 03 3月, 2022 3 次提交
    • N
      crypto: dh - disallow plain "dh" usage in FIPS mode · 32f07cc4
      Nicolai Stange 提交于
      SP800-56Arev3, sec. 5.5.2 ("Assurance of Domain-Parameter Validity")
      asserts that an implementation needs to verify domain paramtere validity,
      which boils down to either
      - the domain parameters corresponding to some known safe-prime group
        explicitly listed to be approved in the document or
      - for parameters conforming to a "FIPS 186-type parameter-size set",
        that the implementation needs to perform an explicit domain parameter
        verification, which would require access to the "seed" and "counter"
        values used in their generation.
      
      The latter is not easily feasible and moreover, SP800-56Arev3 states that
      safe-prime groups are preferred and that FIPS 186-type parameter sets
      should only be supported for backward compatibility, if it all.
      
      Mark "dh" as not fips_allowed in testmgr. Note that the safe-prime
      ffdheXYZ(dh) wrappers are not affected by this change: as these enforce
      some approved safe-prime group each, their usage is still allowed in FIPS
      mode.
      
      This change will effectively render the keyctl(KEYCTL_DH_COMPUTE) syscall
      unusable in FIPS mode, but it has been brought up that this might even be
      a good thing ([1]).
      
      [1] https://lore.kernel.org/r/20211217055227.GA20698@gondor.apana.org.auSigned-off-by: NNicolai Stange <nstange@suse.de>
      Reviewed-by: NHannes Reinecke <hare@suse.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      32f07cc4
    • N
      crypto: api - allow algs only in specific constructions in FIPS mode · d6097b8d
      Nicolai Stange 提交于
      Currently we do not distinguish between algorithms that fail on
      the self-test vs. those which are disabled in FIPS mode (not allowed).
      Both are marked as having failed the self-test.
      
      Recently the need arose to allow the usage of certain algorithms only
      as arguments to specific template instantiations in FIPS mode. For
      example, standalone "dh" must be blocked, but e.g. "ffdhe2048(dh)" is
      allowed. Other potential use cases include "cbcmac(aes)", which must
      only be used with ccm(), or "ghash", which must be used only for
      gcm().
      
      This patch allows this scenario by adding a new flag FIPS_INTERNAL to
      indicate those algorithms that are not FIPS-allowed. They can then be
      used as template arguments only, i.e. when looked up via
      crypto_grab_spawn() to be more specific. The FIPS_INTERNAL bit gets
      propagated upwards recursively into the surrounding template
      instances, until the construction eventually matches an explicit
      testmgr entry with ->fips_allowed being set, if any.
      
      The behaviour to skip !->fips_allowed self-test executions in FIPS
      mode will be retained. Note that this effectively means that
      FIPS_INTERNAL algorithms are handled very similarly to the INTERNAL
      ones in this regard. It is expected that the FIPS_INTERNAL algorithms
      will receive sufficient testing when the larger constructions they're
      a part of, if any, get exercised by testmgr.
      
      Note that as a side-effect of this patch algorithms which are not
      FIPS-allowed will now return ENOENT instead of ELIBBAD. Hopefully
      this is not an issue as some people were relying on this already.
      
      Link: https://lore.kernel.org/r/YeEVSaMEVJb3cQkq@gondor.apana.org.auOriginally-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NNicolai Stange <nstange@suse.de>
      Reviewed-by: NHannes Reinecke <hare@suse.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d6097b8d
    • N
      crypto: testmgr - add known answer tests for ffdheXYZ(dh) templates · 60a273e9
      Nicolai Stange 提交于
      Add known answer tests for the ffdhe2048(dh), ffdhe3072(dh), ffdhe4096(dh),
      ffdhe6144(dh) and ffdhe8192(dh) templates introduced with the previous
      patch to the testmgr. All TVs have been generated with OpenSSL.
      Signed-off-by: NNicolai Stange <nstange@suse.de>
      Reviewed-by: NHannes Reinecke <hare@suse.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      60a273e9
  13. 11 2月, 2022 1 次提交
  14. 31 1月, 2022 1 次提交
  15. 26 11月, 2021 1 次提交
  16. 08 10月, 2021 1 次提交
  17. 21 8月, 2021 1 次提交
  18. 28 6月, 2021 1 次提交
  19. 28 5月, 2021 2 次提交
  20. 26 3月, 2021 2 次提交
  21. 12 3月, 2021 1 次提交
  22. 07 3月, 2021 1 次提交
  23. 10 2月, 2021 1 次提交
  24. 29 1月, 2021 5 次提交
  25. 03 1月, 2021 1 次提交
  26. 06 11月, 2020 1 次提交
    • E
      crypto: testmgr - WARN on test failure · 09a5ef96
      Eric Biggers 提交于
      Currently, by default crypto self-test failures only result in a
      pr_warn() message and an "unknown" status in /proc/crypto.  Both of
      these are easy to miss.  There is also an option to panic the kernel
      when a test fails, but that can't be the default behavior.
      
      A crypto self-test failure always indicates a kernel bug, however, and
      there's already a standard way to report (recoverable) kernel bugs --
      the WARN() family of macros.  WARNs are noisier and harder to miss, and
      existing test systems already know to look for them in dmesg or via
      /proc/sys/kernel/tainted.
      
      Therefore, call WARN() when an algorithm fails its self-tests.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      09a5ef96