1. 05 1月, 2018 2 次提交
  2. 28 12月, 2017 6 次提交
  3. 22 12月, 2017 8 次提交
  4. 11 12月, 2017 6 次提交
    • C
      crypto: cryptd - make cryptd_max_cpu_qlen module parameter static · eaf356e4
      Colin Ian King 提交于
      The cryptd_max_cpu_qlen module parameter is local to the source and does
      not need to be in global scope, so make it static.
      
      Cleans up sparse warning:
      crypto/cryptd.c:35:14: warning: symbol 'cryptd_max_cpu_qlen' was not
      declared. Should it be static?
      Signed-off-by: NColin Ian King <colin.king@canonical.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      eaf356e4
    • H
      crypto: ecdh - fix typo in KPP dependency of CRYPTO_ECDH · b5b90077
      Hauke Mehrtens 提交于
      This fixes a typo in the CRYPTO_KPP dependency of CRYPTO_ECDH.
      
      Fixes: 3c4b2390 ("crypto: ecdh - Add ECDH software support")
      Cc: <stable@vger.kernel.org> # v4.8+
      Signed-off-by: NHauke Mehrtens <hauke@hauke-m.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      b5b90077
    • S
      crypto: af_alg - fix race accessing cipher request · d53c5135
      Stephan Mueller 提交于
      When invoking an asynchronous cipher operation, the invocation of the
      callback may be performed before the subsequent operations in the
      initial code path are invoked. The callback deletes the cipher request
      data structure which implies that after the invocation of the
      asynchronous cipher operation, this data structure must not be accessed
      any more.
      
      The setting of the return code size with the request data structure must
      therefore be moved before the invocation of the asynchronous cipher
      operation.
      
      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: NStephan Mueller <smueller@chronox.de>
      Acked-by: NJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d53c5135
    • S
      crypto: mcryptd - protect the per-CPU queue with a lock · 9abffc6f
      Sebastian Andrzej Siewior 提交于
      mcryptd_enqueue_request() grabs the per-CPU queue struct and protects
      access to it with disabled preemption. Then it schedules a worker on the
      same CPU. The worker in mcryptd_queue_worker() guards access to the same
      per-CPU variable with disabled preemption.
      
      If we take CPU-hotplug into account then it is possible that between
      queue_work_on() and the actual invocation of the worker the CPU goes
      down and the worker will be scheduled on _another_ CPU. And here the
      preempt_disable() protection does not work anymore. The easiest thing is
      to add a spin_lock() to guard access to the list.
      
      Another detail: mcryptd_queue_worker() is not processing more than
      MCRYPTD_BATCH invocation in a row. If there are still items left, then
      it will invoke queue_work() to proceed with more later. *I* would
      suggest to simply drop that check because it does not use a system
      workqueue and the workqueue is already marked as "CPU_INTENSIVE". And if
      preemption is required then the scheduler should do it.
      However if queue_work() is used then the work item is marked as CPU
      unbound. That means it will try to run on the local CPU but it may run
      on another CPU as well. Especially with CONFIG_DEBUG_WQ_FORCE_RR_CPU=y.
      Again, the preempt_disable() won't work here but lock which was
      introduced will help.
      In order to keep work-item on the local CPU (and avoid RR) I changed it
      to queue_work_on().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      9abffc6f
    • S
      crypto: af_alg - wait for data at beginning of recvmsg · 11edb555
      Stephan Mueller 提交于
      The wait for data is a non-atomic operation that can sleep and therefore
      potentially release the socket lock. The release of the socket lock
      allows another thread to modify the context data structure. The waiting
      operation for new data therefore must be called at the beginning of
      recvmsg. This prevents a race condition where checks of the members of
      the context data structure are performed by recvmsg while there is a
      potential for modification of these values.
      
      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: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      11edb555
    • E
      crypto: skcipher - set walk.iv for zero-length inputs · 2b4f27c3
      Eric Biggers 提交于
      All the ChaCha20 algorithms as well as the ARM bit-sliced AES-XTS
      algorithms call skcipher_walk_virt(), then access the IV (walk.iv)
      before checking whether any bytes need to be processed (walk.nbytes).
      
      But if the input is empty, then skcipher_walk_virt() doesn't set the IV,
      and the algorithms crash trying to use the uninitialized IV pointer.
      
      Fix it by setting the IV earlier in skcipher_walk_virt().  Also fix it
      for the AEAD walk functions.
      
      This isn't a perfect solution because we can't actually align the IV to
      ->cra_alignmask unless there are bytes to process, for one because the
      temporary buffer for the aligned IV is freed by skcipher_walk_done(),
      which is only called when there are bytes to process.  Thus, algorithms
      that require aligned IVs will still need to avoid accessing the IV when
      walk.nbytes == 0.  Still, many algorithms/architectures are fine with
      IVs having any alignment, and even for those that aren't, a misaligned
      pointer bug is much less severe than an uninitialized pointer bug.
      
      This change also matches the behavior of the older blkcipher_walk API.
      
      Fixes: 0cabf2af ("crypto: skcipher - Fix crash on zero-length input")
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Cc: <stable@vger.kernel.org> # v4.14+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      2b4f27c3
  5. 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
  6. 29 11月, 2017 11 次提交