1. 08 12月, 2017 7 次提交
    • E
      X.509: fix comparisons of ->pkey_algo · 54c1fb39
      Eric Biggers 提交于
      ->pkey_algo used to be an enum, but was changed to a string by commit
      4e8ae72a ("X.509: Make algo identifiers text instead of enum").  But
      two comparisons were not updated.  Fix them to use strcmp().
      
      This bug broke signature verification in certain configurations,
      depending on whether the string constants were deduplicated or not.
      
      Fixes: 4e8ae72a ("X.509: Make algo identifiers text instead of enum")
      Cc: <stable@vger.kernel.org> # v4.6+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      54c1fb39
    • E
      X.509: use crypto_shash_digest() · aa330036
      Eric Biggers 提交于
      Use crypto_shash_digest() instead of crypto_shash_init() followed by
      crypto_shash_finup().  (For simplicity only; they are equivalent.)
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      aa330036
    • E
      KEYS: be careful with error codes in public_key_verify_signature() · 72f9a07b
      Eric Biggers 提交于
      In public_key_verify_signature(), if akcipher_request_alloc() fails, we
      return -ENOMEM.  But that error code was set 25 lines above, and by
      accident someone could easily insert new code in between that assigns to
      'ret', which would introduce a signature verification bypass.  Make the
      code clearer by moving the -ENOMEM down to where it is used.
      
      Additionally, the callers of public_key_verify_signature() only consider
      a negative return value to be an error.  This means that if any positive
      return value is accidentally introduced deeper in the call stack (e.g.
      'return EBADMSG' instead of 'return -EBADMSG' somewhere in RSA),
      signature verification will be bypassed.  Make things more robust by
      having public_key_verify_signature() warn about positive errors and
      translate them into -EINVAL.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      72f9a07b
    • E
      pkcs7: use crypto_shash_digest() · a80745a6
      Eric Biggers 提交于
      Use crypto_shash_digest() instead of crypto_shash_init() followed by
      crypto_shash_finup().  (For simplicity only; they are equivalent.)
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      a80745a6
    • E
      pkcs7: fix check for self-signed certificate · 7204eb85
      Eric Biggers 提交于
      pkcs7_validate_trust_one() used 'x509->next == x509' to identify a
      self-signed certificate.  That's wrong; ->next is simply the link in the
      linked list of certificates in the PKCS#7 message.  It should be
      checking ->signer instead.  Fix it.
      
      Fortunately this didn't actually matter because when we re-visited
      'x509' on the next iteration via 'x509->signer', it was already seen and
      not verified, so we returned -ENOKEY anyway.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Reviewed-by: NJames Morris <james.l.morris@oracle.com>
      7204eb85
    • E
      pkcs7: return correct error code if pkcs7_check_authattrs() fails · 8ecb506d
      Eric Biggers 提交于
      If pkcs7_check_authattrs() returns an error code, we should pass that
      error code on, rather than using ENOMEM.
      
      Fixes: 99db4435 ("PKCS#7: Appropriately restrict authenticated attributes and content type")
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Reviewed-by: NJames Morris <james.l.morris@oracle.com>
      8ecb506d
    • E
      X.509: reject invalid BIT STRING for subjectPublicKey · 0f30cbea
      Eric Biggers 提交于
      Adding a specially crafted X.509 certificate whose subjectPublicKey
      ASN.1 value is zero-length caused x509_extract_key_data() to set the
      public key size to SIZE_MAX, as it subtracted the nonexistent BIT STRING
      metadata byte.  Then, x509_cert_parse() called kmemdup() with that bogus
      size, triggering the WARN_ON_ONCE() in kmalloc_slab().
      
      This appears to be harmless, but it still must be fixed since WARNs are
      never supposed to be user-triggerable.
      
      Fix it by updating x509_cert_parse() to validate that the value has a
      BIT STRING metadata byte, and that the byte is 0 which indicates that
      the number of bits in the bitstring is a multiple of 8.
      
      It would be nice to handle the metadata byte in asn1_ber_decoder()
      instead.  But that would be tricky because in the general case a BIT
      STRING could be implicitly tagged, and/or could legitimately have a
      length that is not a whole number of bytes.
      
      Here was the WARN (cleaned up slightly):
      
          WARNING: CPU: 1 PID: 202 at mm/slab_common.c:971 kmalloc_slab+0x5d/0x70 mm/slab_common.c:971
          Modules linked in:
          CPU: 1 PID: 202 Comm: keyctl Tainted: G    B            4.14.0-09238-g1d3b78bb #26
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
          task: ffff880033014180 task.stack: ffff8800305c8000
          Call Trace:
           __do_kmalloc mm/slab.c:3706 [inline]
           __kmalloc_track_caller+0x22/0x2e0 mm/slab.c:3726
           kmemdup+0x17/0x40 mm/util.c:118
           kmemdup include/linux/string.h:414 [inline]
           x509_cert_parse+0x2cb/0x620 crypto/asymmetric_keys/x509_cert_parser.c:106
           x509_key_preparse+0x61/0x750 crypto/asymmetric_keys/x509_public_key.c:174
           asymmetric_key_preparse+0xa4/0x150 crypto/asymmetric_keys/asymmetric_type.c:388
           key_create_or_update+0x4d4/0x10a0 security/keys/key.c:850
           SYSC_add_key security/keys/keyctl.c:122 [inline]
           SyS_add_key+0xe8/0x290 security/keys/keyctl.c:62
           entry_SYSCALL_64_fastpath+0x1f/0x96
      
      Fixes: 42d5ec27 ("X.509: Add an ASN.1 decoder")
      Cc: <stable@vger.kernel.org> # v3.7+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Reviewed-by: NJames Morris <james.l.morris@oracle.com>
      0f30cbea
  2. 29 11月, 2017 5 次提交
    • 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
    • E
      crypto: hmac - require that the underlying hash algorithm is unkeyed · af3ff804
      Eric Biggers 提交于
      Because the HMAC template didn't check that its underlying hash
      algorithm is unkeyed, trying to use "hmac(hmac(sha3-512-generic))"
      through AF_ALG or through KEYCTL_DH_COMPUTE resulted in the inner HMAC
      being used without having been keyed, resulting in sha3_update() being
      called without sha3_init(), causing a stack buffer overflow.
      
      This is a very old bug, but it seems to have only started causing real
      problems when SHA-3 support was added (requires CONFIG_CRYPTO_SHA3)
      because the innermost hash's state is ->import()ed from a zeroed buffer,
      and it just so happens that other hash algorithms are fine with that,
      but SHA-3 is not.  However, there could be arch or hardware-dependent
      hash algorithms also affected; I couldn't test everything.
      
      Fix the bug by introducing a function crypto_shash_alg_has_setkey()
      which tests whether a shash algorithm is keyed.  Then update the HMAC
      template to require that its underlying hash algorithm is unkeyed.
      
      Here is a reproducer:
      
          #include <linux/if_alg.h>
          #include <sys/socket.h>
      
          int main()
          {
              int algfd;
              struct sockaddr_alg addr = {
                  .salg_type = "hash",
                  .salg_name = "hmac(hmac(sha3-512-generic))",
              };
              char key[4096] = { 0 };
      
              algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
              bind(algfd, (const struct sockaddr *)&addr, sizeof(addr));
              setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, sizeof(key));
          }
      
      Here was the KASAN report from syzbot:
      
          BUG: KASAN: stack-out-of-bounds in memcpy include/linux/string.h:341  [inline]
          BUG: KASAN: stack-out-of-bounds in sha3_update+0xdf/0x2e0  crypto/sha3_generic.c:161
          Write of size 4096 at addr ffff8801cca07c40 by task syzkaller076574/3044
      
          CPU: 1 PID: 3044 Comm: syzkaller076574 Not tainted 4.14.0-mm1+ #25
          Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  Google 01/01/2011
          Call Trace:
            __dump_stack lib/dump_stack.c:17 [inline]
            dump_stack+0x194/0x257 lib/dump_stack.c:53
            print_address_description+0x73/0x250 mm/kasan/report.c:252
            kasan_report_error mm/kasan/report.c:351 [inline]
            kasan_report+0x25b/0x340 mm/kasan/report.c:409
            check_memory_region_inline mm/kasan/kasan.c:260 [inline]
            check_memory_region+0x137/0x190 mm/kasan/kasan.c:267
            memcpy+0x37/0x50 mm/kasan/kasan.c:303
            memcpy include/linux/string.h:341 [inline]
            sha3_update+0xdf/0x2e0 crypto/sha3_generic.c:161
            crypto_shash_update+0xcb/0x220 crypto/shash.c:109
            shash_finup_unaligned+0x2a/0x60 crypto/shash.c:151
            crypto_shash_finup+0xc4/0x120 crypto/shash.c:165
            hmac_finup+0x182/0x330 crypto/hmac.c:152
            crypto_shash_finup+0xc4/0x120 crypto/shash.c:165
            shash_digest_unaligned+0x9e/0xd0 crypto/shash.c:172
            crypto_shash_digest+0xc4/0x120 crypto/shash.c:186
            hmac_setkey+0x36a/0x690 crypto/hmac.c:66
            crypto_shash_setkey+0xad/0x190 crypto/shash.c:64
            shash_async_setkey+0x47/0x60 crypto/shash.c:207
            crypto_ahash_setkey+0xaf/0x180 crypto/ahash.c:200
            hash_setkey+0x40/0x90 crypto/algif_hash.c:446
            alg_setkey crypto/af_alg.c:221 [inline]
            alg_setsockopt+0x2a1/0x350 crypto/af_alg.c:254
            SYSC_setsockopt net/socket.c:1851 [inline]
            SyS_setsockopt+0x189/0x360 net/socket.c:1830
            entry_SYSCALL_64_fastpath+0x1f/0x96
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      af3ff804
    • E
      crypto: af_alg - fix NULL pointer dereference in · 887207ed
      Eric Biggers 提交于
       af_alg_free_areq_sgls()
      
      If allocating the ->tsgl member of 'struct af_alg_async_req' failed,
      during cleanup we dereferenced the NULL ->tsgl pointer in
      af_alg_free_areq_sgls(), because ->tsgl_entries was nonzero.
      
      Fix it by only freeing the ->tsgl list if it is non-NULL.
      
      This affected both algif_skcipher and algif_aead.
      
      Fixes: e870456d ("crypto: algif_skcipher - overhaul memory management")
      Fixes: d887c52d ("crypto: algif_aead - overhaul memory management")
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Cc: <stable@vger.kernel.org> # v4.14+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      887207ed
    • E
      crypto: algif_aead - fix reference counting of null skcipher · b32a7dc8
      Eric Biggers 提交于
      In the AEAD interface for AF_ALG, the reference to the "null skcipher"
      held by each tfm was being dropped in the wrong place -- when each
      af_alg_ctx was freed instead of when the aead_tfm was freed.  As
      discovered by syzkaller, a specially crafted program could use this to
      cause the null skcipher to be freed while it is still in use.
      
      Fix it by dropping the reference in the right place.
      
      Fixes: 72548b09 ("crypto: algif_aead - copy AAD from src to dst")
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Cc: <stable@vger.kernel.org> # v4.14+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      b32a7dc8
    • E
      crypto: rsa - fix buffer overread when stripping leading zeroes · d2890c37
      Eric Biggers 提交于
      In rsa_get_n(), if the buffer contained all 0's and "FIPS mode" is
      enabled, we would read one byte past the end of the buffer while
      scanning the leading zeroes.  Fix it by checking 'n_sz' before '!*ptr'.
      
      This bug was reachable by adding a specially crafted key of type
      "asymmetric" (requires CONFIG_RSA and CONFIG_X509_CERTIFICATE_PARSER).
      
      KASAN report:
      
          BUG: KASAN: slab-out-of-bounds in rsa_get_n+0x19e/0x1d0 crypto/rsa_helper.c:33
          Read of size 1 at addr ffff88003501a708 by task keyctl/196
      
          CPU: 1 PID: 196 Comm: keyctl Not tainted 4.14.0-09238-g1d3b78bb #26
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
          Call Trace:
           rsa_get_n+0x19e/0x1d0 crypto/rsa_helper.c:33
           asn1_ber_decoder+0x82a/0x1fd0 lib/asn1_decoder.c:328
           rsa_set_pub_key+0xd3/0x320 crypto/rsa.c:278
           crypto_akcipher_set_pub_key ./include/crypto/akcipher.h:364 [inline]
           pkcs1pad_set_pub_key+0xae/0x200 crypto/rsa-pkcs1pad.c:117
           crypto_akcipher_set_pub_key ./include/crypto/akcipher.h:364 [inline]
           public_key_verify_signature+0x270/0x9d0 crypto/asymmetric_keys/public_key.c:106
           x509_check_for_self_signed+0x2ea/0x480 crypto/asymmetric_keys/x509_public_key.c:141
           x509_cert_parse+0x46a/0x620 crypto/asymmetric_keys/x509_cert_parser.c:129
           x509_key_preparse+0x61/0x750 crypto/asymmetric_keys/x509_public_key.c:174
           asymmetric_key_preparse+0xa4/0x150 crypto/asymmetric_keys/asymmetric_type.c:388
           key_create_or_update+0x4d4/0x10a0 security/keys/key.c:850
           SYSC_add_key security/keys/keyctl.c:122 [inline]
           SyS_add_key+0xe8/0x290 security/keys/keyctl.c:62
           entry_SYSCALL_64_fastpath+0x1f/0x96
      
          Allocated by task 196:
           __do_kmalloc mm/slab.c:3711 [inline]
           __kmalloc_track_caller+0x118/0x2e0 mm/slab.c:3726
           kmemdup+0x17/0x40 mm/util.c:118
           kmemdup ./include/linux/string.h:414 [inline]
           x509_cert_parse+0x2cb/0x620 crypto/asymmetric_keys/x509_cert_parser.c:106
           x509_key_preparse+0x61/0x750 crypto/asymmetric_keys/x509_public_key.c:174
           asymmetric_key_preparse+0xa4/0x150 crypto/asymmetric_keys/asymmetric_type.c:388
           key_create_or_update+0x4d4/0x10a0 security/keys/key.c:850
           SYSC_add_key security/keys/keyctl.c:122 [inline]
           SyS_add_key+0xe8/0x290 security/keys/keyctl.c:62
           entry_SYSCALL_64_fastpath+0x1f/0x96
      
      Fixes: 5a7de973 ("crypto: rsa - return raw integers for the ASN.1 parser")
      Cc: <stable@vger.kernel.org> # v4.8+
      Cc: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NJames Morris <james.l.morris@oracle.com>
      Reviewed-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d2890c37
  3. 25 11月, 2017 1 次提交
    • O
      crypto: skcipher - Fix skcipher_walk_aead_common · c14ca838
      Ondrej Mosnáček 提交于
      The skcipher_walk_aead_common function calls scatterwalk_copychunks on
      the input and output walks to skip the associated data. If the AD end
      at an SG list entry boundary, then after these calls the walks will
      still be pointing to the end of the skipped region.
      
      These offsets are later checked for alignment in skcipher_walk_next,
      so the skcipher_walk may detect the alignment incorrectly.
      
      This patch fixes it by calling scatterwalk_done after the copychunks
      calls to ensure that the offsets refer to the right SG list entry.
      
      Fixes: b286d8b1 ("crypto: skcipher - Add skcipher walk interface")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NOndrej Mosnacek <omosnacek@gmail.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      c14ca838
  4. 24 11月, 2017 2 次提交
    • S
      crypto: af_alg - remove locking in async callback · 7d2c3f54
      Stephan Mueller 提交于
      The code paths protected by the socket-lock do not use or modify the
      socket in a non-atomic fashion. The actions pertaining the socket do not
      even need to be handled as an atomic operation. Thus, the socket-lock
      can be safely ignored.
      
      This fixes a bug regarding scheduling in atomic as the callback function
      may be invoked in interrupt context.
      
      In addition, the sock_hold is moved before the AIO encrypt/decrypt
      operation to ensure that the socket is always present. This avoids a
      tiny race window where the socket is unprotected and yet used by the AIO
      operation.
      
      Finally, the release of resources for a crypto operation is moved into a
      common function of af_alg_free_resources.
      
      Cc: <stable@vger.kernel.org>
      Fixes: e870456d ("crypto: algif_skcipher - overhaul memory management")
      Fixes: d887c52d ("crypto: algif_aead - overhaul memory management")
      Reported-by: NRomain Izard <romain.izard.pro@gmail.com>
      Signed-off-by: NStephan Mueller <smueller@chronox.de>
      Tested-by: NRomain Izard <romain.izard.pro@gmail.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      7d2c3f54
    • S
      crypto: algif_aead - skip SGL entries with NULL page · 8e1fa89a
      Stephan Mueller 提交于
      The TX SGL may contain SGL entries that are assigned a NULL page. This
      may happen if a multi-stage AIO operation is performed where the data
      for each stage is pointed to by one SGL entry. Upon completion of that
      stage, af_alg_pull_tsgl will assign NULL to the SGL entry.
      
      The NULL cipher used to copy the AAD from TX SGL to the destination
      buffer, however, cannot handle the case where the SGL starts with an SGL
      entry having a NULL page. Thus, the code needs to advance the start
      pointer into the SGL to the first non-NULL entry.
      
      This fixes a crash visible on Intel x86 32 bit using the libkcapi test
      suite.
      
      Cc: <stable@vger.kernel.org>
      Fixes: 72548b09 ("crypto: algif_aead - copy AAD from src to dst")
      Signed-off-by: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      8e1fa89a
  5. 16 11月, 2017 2 次提交
  6. 10 11月, 2017 4 次提交
    • E
      crypto: dh - Remove pointless checks for NULL 'p' and 'g' · ced6a586
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ced6a586
    • E
      crypto: dh - Don't permit 'key' or 'g' size longer than 'p' · ccd9888f
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ccd9888f
    • E
      crypto: dh - Don't permit 'p' to be 0 · 199512b1
      Eric Biggers 提交于
      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
      sg_set_buf().
      
      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
           entry_SYSCALL_64_fastpath+0x1f/0xbe
          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: NTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      199512b1
    • E
      crypto: dh - Fix double free of ctx->p · 12d41a02
      Eric Biggers 提交于
      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:
           dump_stack+0xb3/0x10b
           ? mpi_free+0x131/0x170
           print_address_description+0x79/0x2a0
           ? mpi_free+0x131/0x170
           kasan_report+0x236/0x340
           ? akcipher_register_instance+0x90/0x90
           __asan_report_load4_noabort+0x14/0x20
           mpi_free+0x131/0x170
           ? akcipher_register_instance+0x90/0x90
           dh_exit_tfm+0x3d/0x140
           crypto_kpp_exit_tfm+0x52/0x70
           crypto_destroy_tfm+0xb3/0x250
           __keyctl_dh_compute+0x640/0xe90
           ? 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+0xb3/0xf1
           ? __keyctl_dh_compute+0xe90/0xe90
           ? SyS_add_key+0x26d/0x340
           ? entry_SYSCALL_64_fastpath+0x5/0xbe
           ? trace_hardirqs_on_caller+0x3f4/0x560
           SyS_keyctl+0x72/0x2c0
           entry_SYSCALL_64_fastpath+0x1f/0xbe
          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:
           save_stack_trace+0x16/0x20
           kasan_kmalloc+0xeb/0x180
           kmem_cache_alloc_trace+0x114/0x300
           mpi_alloc+0x4b/0x230
           mpi_read_raw_data+0xbe/0x360
           dh_set_secret+0x1dc/0x460
           __keyctl_dh_compute+0x623/0xe90
           keyctl_dh_compute+0xb3/0xf1
           SyS_keyctl+0x72/0x2c0
           entry_SYSCALL_64_fastpath+0x1f/0xbe
      
          Freed by task 367:
           save_stack_trace+0x16/0x20
           kasan_slab_free+0xab/0x180
           kfree+0xb5/0x210
           mpi_free+0xcb/0x170
           dh_set_secret+0x2d7/0x460
           __keyctl_dh_compute+0x623/0xe90
           keyctl_dh_compute+0xb3/0xf1
           SyS_keyctl+0x72/0x2c0
           entry_SYSCALL_64_fastpath+0x1f/0xbe
      
      Fixes: 802c7f1c ("crypto: dh - Add DH software implementation")
      Cc: <stable@vger.kernel.org> # v4.8+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      12d41a02
  7. 06 11月, 2017 1 次提交
  8. 03 11月, 2017 13 次提交
  9. 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
  10. 18 10月, 2017 3 次提交
  11. 12 10月, 2017 1 次提交