1. 05 1月, 2018 1 次提交
  2. 28 12月, 2017 3 次提交
    • J
      crypto: aesni - Fix out-of-bounds access of the AAD buffer in generic-gcm-aesni · 1ecdd37e
      Junaid Shahid 提交于
      The aesni_gcm_enc/dec functions can access memory after the end of
      the AAD buffer if the AAD length is not a multiple of 4 bytes.
      It didn't matter with rfc4106-gcm-aesni as in that case the AAD was
      always followed by the 8 byte IV, but that is no longer the case with
      generic-gcm-aesni. This can potentially result in accessing a page that
      is not mapped and thus causing the machine to crash. This patch fixes
      that by reading the last <16 byte block of the AAD byte-by-byte and
      optionally via an 8-byte load if the block was at least 8 bytes.
      
      Fixes: 0487ccac ("crypto: aesni - make non-AVX AES-GCM work with any aadlen")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NJunaid Shahid <junaids@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1ecdd37e
    • J
      crypto: aesni - Fix out-of-bounds access of the data buffer in generic-gcm-aesni · b20209c9
      Junaid Shahid 提交于
      The aesni_gcm_enc/dec functions can access memory before the start of
      the data buffer if the length of the data buffer is less than 16 bytes.
      This is because they perform the read via a single 16-byte load. This
      can potentially result in accessing a page that is not mapped and thus
      causing the machine to crash. This patch fixes that by reading the
      partial block byte-by-byte and optionally an via 8-byte load if the block
      was at least 8 bytes.
      
      Fixes: 0487ccac ("crypto: aesni - make non-AVX AES-GCM work with any aadlen")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NJunaid Shahid <junaids@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      b20209c9
    • E
      crypto: x86/twofish-3way - Fix %rbp usage · d8c7fe9f
      Eric Biggers 提交于
      Using %rbp as a temporary register breaks frame pointer convention and
      breaks stack traces when unwinding from an interrupt in the crypto code.
      
      In twofish-3way, we can't simply replace %rbp with another register
      because there are none available.  Instead, we use the stack to hold the
      values that %rbp, %r11, and %r12 were holding previously.  Each of these
      values represents the half of the output from the previous Feistel round
      that is being passed on unchanged to the following round.  They are only
      used once per round, when they are exchanged with %rax, %rbx, and %rcx.
      
      As a result, we free up 3 registers (one per block) and can reassign
      them so that %rbp is not used, and additionally %r14 and %r15 are not
      used so they do not need to be saved/restored.
      
      There may be a small overhead caused by replacing 'xchg REG, REG' with
      the needed sequence 'mov MEM, REG; mov REG, MEM; mov REG, REG' once per
      round.  But, counterintuitively, when I tested "ctr-twofish-3way" on a
      Haswell processor, the new version was actually about 2% faster.
      (Perhaps 'xchg' is not as well optimized as plain moves.)
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d8c7fe9f
  3. 22 12月, 2017 2 次提交
  4. 29 11月, 2017 2 次提交
    • E
      crypto: x86/chacha20 - Remove cra_alignmask · 796c99fb
      Eric Biggers 提交于
      Now that the generic ChaCha20 implementation no longer needs a
      cra_alignmask, the x86 one doesn't either -- given that the x86
      implementation doesn't need the alignment itself.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      796c99fb
    • E
      crypto: salsa20 - fix blkcipher_walk API usage · ecaaab56
      Eric Biggers 提交于
      When asked to encrypt or decrypt 0 bytes, both the generic and x86
      implementations of Salsa20 crash in blkcipher_walk_done(), either when
      doing 'kfree(walk->buffer)' or 'free_page((unsigned long)walk->page)',
      because walk->buffer and walk->page have not been initialized.
      
      The bug is that Salsa20 is calling blkcipher_walk_done() even when
      nothing is in 'walk.nbytes'.  But blkcipher_walk_done() is only meant to
      be called when a nonzero number of bytes have been provided.
      
      The broken code is part of an optimization that tries to make only one
      call to salsa20_encrypt_bytes() to process inputs that are not evenly
      divisible by 64 bytes.  To fix the bug, just remove this "optimization"
      and use the blkcipher_walk API the same way all the other users do.
      
      Reproducer:
      
          #include <linux/if_alg.h>
          #include <sys/socket.h>
          #include <unistd.h>
      
          int main()
          {
                  int algfd, reqfd;
                  struct sockaddr_alg addr = {
                          .salg_type = "skcipher",
                          .salg_name = "salsa20",
                  };
                  char key[16] = { 0 };
      
                  algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
                  bind(algfd, (void *)&addr, sizeof(addr));
                  reqfd = accept(algfd, 0, 0);
                  setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, sizeof(key));
                  read(reqfd, key, sizeof(key));
          }
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Fixes: eb6f13eb ("[CRYPTO] salsa20_generic: Fix multi-page processing")
      Cc: <stable@vger.kernel.org> # v2.6.25+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ecaaab56
  5. 03 11月, 2017 2 次提交
  6. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  7. 12 10月, 2017 1 次提交
  8. 07 10月, 2017 1 次提交
  9. 22 9月, 2017 2 次提交
  10. 20 9月, 2017 12 次提交
  11. 09 8月, 2017 1 次提交
  12. 04 8月, 2017 1 次提交
    • A
      crypto: algapi - make crypto_xor() take separate dst and src arguments · 45fe93df
      Ard Biesheuvel 提交于
      There are quite a number of occurrences in the kernel of the pattern
      
        if (dst != src)
                memcpy(dst, src, walk.total % AES_BLOCK_SIZE);
        crypto_xor(dst, final, walk.total % AES_BLOCK_SIZE);
      
      or
      
        crypto_xor(keystream, src, nbytes);
        memcpy(dst, keystream, nbytes);
      
      where crypto_xor() is preceded or followed by a memcpy() invocation
      that is only there because crypto_xor() uses its output parameter as
      one of the inputs. To avoid having to add new instances of this pattern
      in the arm64 code, which will be refactored to implement non-SIMD
      fallbacks, add an alternative implementation called crypto_xor_cpy(),
      taking separate input and output arguments. This removes the need for
      the separate memcpy().
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      45fe93df
  13. 05 7月, 2017 1 次提交
  14. 30 6月, 2017 1 次提交
  15. 19 6月, 2017 1 次提交
  16. 23 5月, 2017 1 次提交
    • E
      crypto: x86/aes - Don't use %rbp as temporary register · 9417cd1c
      Eric Biggers 提交于
      When using the "aes-asm" implementation of AES (*not* the AES-NI
      implementation) on an x86_64, v4.12-rc1 kernel with lockdep enabled, the
      following warning was reported, along with a long unwinder dump:
      
      	WARNING: kernel stack regs at ffffc90000643558 in kworker/u4:2:155 has bad 'bp' value 000000000000001c
      
      The problem is that aes_enc_block() and aes_dec_block() use %rbp as a
      temporary register, which breaks stack traces if an interrupt occurs.
      
      Fix this by replacing %rbp with %r9, which was being used to hold the
      saved value of %rbp.  This required rearranging the AES round macro
      slightly since %r9d cannot be used as the target of a move from %ah-%dh.
      
      Performance is essentially unchanged --- actually about 0.2% faster than
      before.  Interestingly, I also measured aes-generic as being nearly 7%
      faster than aes-asm, so perhaps aes-asm has outlived its usefulness...
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      9417cd1c
  17. 18 5月, 2017 7 次提交