1. 16 Nov, 2017 1 commit
  2. 15 Nov, 2017 1 commit
  3. 10 Nov, 2017 4 commits
    • Eric Biggers's avatar
      crypto: dh - Remove pointless checks for NULL 'p' and 'g' · ced6a586
      Eric Biggers authored
      Neither 'p' nor 'g' can be NULL, as they were unpacked using
      crypto_dh_decode_key().  And it makes no sense for them to be optional.
      So remove the NULL checks that were copy-and-pasted into both modules.
      Signed-off-by: 's avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: 's avatarTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: 's avatarHerbert Xu <herbert@gondor.apana.org.au>
    • Eric Biggers's avatar
      crypto: dh - Don't permit 'key' or 'g' size longer than 'p' · ccd9888f
      Eric Biggers authored
      The "qat-dh" DH implementation assumes that 'key' and 'g' can be copied
      into a buffer with size 'p_size'.  However it was never checked that
      that was actually the case, which most likely allowed users to cause a
      buffer underflow via KEYCTL_DH_COMPUTE.
      Fix this by updating crypto_dh_decode_key() to verify this precondition
      for all DH implementations.
      Fixes: c9839143 ("crypto: qat - Add DH support")
      Cc: <stable@vger.kernel.org> # v4.8+
      Signed-off-by: 's avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: 's avatarTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: 's avatarHerbert Xu <herbert@gondor.apana.org.au>
    • Eric Biggers's avatar
      crypto: dh - Don't permit 'p' to be 0 · 199512b1
      Eric Biggers authored
      If 'p' is 0 for the software Diffie-Hellman implementation, then
      dh_max_size() returns 0.  In the case of KEYCTL_DH_COMPUTE, this causes
      ZERO_SIZE_PTR to be passed to sg_init_one(), which with
      CONFIG_DEBUG_SG=y triggers the 'BUG_ON(!virt_addr_valid(buf));' in
      Fix this by making crypto_dh_decode_key() reject 0 for 'p'.  p=0 makes
      no sense for any DH implementation because 'p' is supposed to be a prime
      number.  Moreover, 'mod 0' is not mathematically defined.
      Bug report:
          kernel BUG at ./include/linux/scatterlist.h:140!
          invalid opcode: 0000 [#1] SMP KASAN
          CPU: 0 PID: 27112 Comm: syz-executor2 Not tainted 4.14.0-rc7-00010-gf5dbb5d0ce32-dirty #7
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.3-20171021_125229-anatol 04/01/2014
          task: ffff88006caac0c0 task.stack: ffff88006c7c8000
          RIP: 0010:sg_set_buf include/linux/scatterlist.h:140 [inline]
          RIP: 0010:sg_init_one+0x1b3/0x240 lib/scatterlist.c:156
          RSP: 0018:ffff88006c7cfb08 EFLAGS: 00010216
          RAX: 0000000000010000 RBX: ffff88006c7cfe30 RCX: 00000000000064ee
          RDX: ffffffff81cf64c3 RSI: ffffc90000d72000 RDI: ffffffff92e937e0
          RBP: ffff88006c7cfb30 R08: ffffed000d8f9fab R09: ffff88006c7cfd30
          R10: 0000000000000005 R11: ffffed000d8f9faa R12: ffff88006c7cfd30
          R13: 0000000000000000 R14: 0000000000000010 R15: ffff88006c7cfc50
          FS:  00007fce190fa700(0000) GS:ffff88003ea00000(0000) knlGS:0000000000000000
          CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
          CR2: 00007fffc6b33db8 CR3: 000000003cf64000 CR4: 00000000000006f0
          Call Trace:
           __keyctl_dh_compute+0xa95/0x19b0 security/keys/dh.c:360
           keyctl_dh_compute+0xac/0x100 security/keys/dh.c:434
           SYSC_keyctl security/keys/keyctl.c:1745 [inline]
           SyS_keyctl+0x72/0x2c0 security/keys/keyctl.c:1641
          RIP: 0033:0x4585c9
          RSP: 002b:00007fce190f9bd8 EFLAGS: 00000216 ORIG_RAX: 00000000000000fa
          RAX: ffffffffffffffda RBX: 0000000000738020 RCX: 00000000004585c9
          RDX: 000000002000d000 RSI: 0000000020000ff4 RDI: 0000000000000017
          RBP: 0000000000000046 R08: 0000000020008000 R09: 0000000000000000
          R10: 0000000000000000 R11: 0000000000000216 R12: 00007fff6e610cde
          R13: 00007fff6e610cdf R14: 00007fce190fa700 R15: 0000000000000000
          Code: 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 04 84 d2 75 33 5b 45 89 6c 24 14 41 5c 41 5d 41 5e 41 5f 5d c3 e8 fd 8f 68 ff <0f> 0b e8 f6 8f 68 ff 0f 0b e8 ef 8f 68 ff 0f 0b e8 e8 8f 68 ff 20
          RIP: sg_set_buf include/linux/scatterlist.h:140 [inline] RSP: ffff88006c7cfb08
          RIP: sg_init_one+0x1b3/0x240 lib/scatterlist.c:156 RSP: ffff88006c7cfb08
      Fixes: 802c7f1c ("crypto: dh - Add DH software implementation")
      Cc: <stable@vger.kernel.org> # v4.8+
      Reviewed-by: 's avatarTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: 's avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: 's avatarHerbert Xu <herbert@gondor.apana.org.au>
    • Eric Biggers's avatar
      crypto: dh - Fix double free of ctx->p · 12d41a02
      Eric Biggers authored
      When setting the secret with the software Diffie-Hellman implementation,
      if allocating 'g' failed (e.g. if it was longer than
      MAX_EXTERN_MPI_BITS), then 'p' was freed twice: once immediately, and
      once later when the crypto_kpp tfm was destroyed.
      Fix it by using dh_free_ctx() (renamed to dh_clear_ctx()) in the error
      paths, as that correctly sets the pointers to NULL.
      KASAN report:
          MPI: mpi too large (32760 bits)
          BUG: KASAN: use-after-free in mpi_free+0x131/0x170
          Read of size 4 at addr ffff88006c7cdf90 by task reproduce_doubl/367
          CPU: 1 PID: 367 Comm: reproduce_doubl Not tainted 4.14.0-rc7-00040-g05298abde6fe #7
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
          Call Trace:
           ? mpi_free+0x131/0x170
           ? mpi_free+0x131/0x170
           ? akcipher_register_instance+0x90/0x90
           ? akcipher_register_instance+0x90/0x90
           ? kasan_slab_free+0x12f/0x180
           ? dh_data_from_key+0x240/0x240
           ? key_create_or_update+0x1ee/0xb20
           ? key_instantiate_and_link+0x440/0x440
           ? lock_contended+0xee0/0xee0
           ? kfree+0xcf/0x210
           ? SyS_add_key+0x268/0x340
           ? __keyctl_dh_compute+0xe90/0xe90
           ? SyS_add_key+0x26d/0x340
           ? entry_SYSCALL_64_fastpath+0x5/0xbe
           ? trace_hardirqs_on_caller+0x3f4/0x560
          RIP: 0033:0x43ccf9
          RSP: 002b:00007ffeeec96158 EFLAGS: 00000246 ORIG_RAX: 00000000000000fa
          RAX: ffffffffffffffda RBX: 000000000248b9b9 RCX: 000000000043ccf9
          RDX: 00007ffeeec96170 RSI: 00007ffeeec96160 RDI: 0000000000000017
          RBP: 0000000000000046 R08: 0000000000000000 R09: 0248b9b9143dc936
          R10: 0000000000001000 R11: 0000000000000246 R12: 0000000000000000
          R13: 0000000000409670 R14: 0000000000409700 R15: 0000000000000000
          Allocated by task 367:
          Freed by task 367:
      Fixes: 802c7f1c ("crypto: dh - Add DH software implementation")
      Cc: <stable@vger.kernel.org> # v4.8+
      Signed-off-by: 's avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: 's avatarTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: 's avatarHerbert Xu <herbert@gondor.apana.org.au>
  4. 06 Nov, 2017 1 commit
  5. 03 Nov, 2017 13 commits
  6. 02 Nov, 2017 1 commit
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      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
      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: 's avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: 's avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: 's avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
  7. 18 Oct, 2017 3 commits
  8. 12 Oct, 2017 6 commits
  9. 10 Oct, 2017 1 commit
  10. 07 Oct, 2017 4 commits
  11. 22 Sep, 2017 4 commits
  12. 20 Sep, 2017 1 commit