07 Aug, 2017

1 commit

  • commit 41cdf7a45389e01991ee31e3301ed83cb3e3f7dc upstream.

    When authencesn is used together with digest_null a crash will
    occur on the decrypt path. This is because normally we perform
    a special setup to preserve the ESN, but this is skipped if there
    is no authentication. However, on the post-authentication path
    it always expects the preservation to be in place, thus causing
    a crash when digest_null is used.

    This patch fixes this by also skipping the post-processing when
    there is no authentication.

    Fixes: 104880a6b470 ("crypto: authencesn - Convert to new AEAD...")
    Reported-by: Jan Tluka
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Herbert Xu
     

15 Jul, 2017

1 commit


12 Jul, 2017

1 commit


14 Jun, 2017

3 commits

  • commit f3ad587070d6bd961ab942b3fd7a85d00dfc934b upstream.

    crypto_gcm_setkey() was using wait_for_completion_interruptible() to
    wait for completion of async crypto op but if a signal occurs it
    may return before DMA ops of HW crypto provider finish, thus
    corrupting the data buffer that is kfree'ed in this case.

    Resolve this by using wait_for_completion() instead.

    Reported-by: Eric Biggers
    Signed-off-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Gilad Ben-Yossef
     
  • commit a5dfefb1c3f3db81662556393fd9283511e08430 upstream.

    drbg_kcapi_sym_ctr() was using wait_for_completion_interruptible() to
    wait for completion of async crypto op but if a signal occurs it
    may return before DMA ops of HW crypto provider finish, thus
    corrupting the output buffer.

    Resolve this by using wait_for_completion() instead.

    Reported-by: Eric Biggers
    Signed-off-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Gilad Ben-Yossef
     
  • commit e68368aed56324e2e38d4f6b044bb8cf82077fc2 upstream.

    public_key_verify_signature() was passing the CRYPTO_TFM_REQ_MAY_BACKLOG
    flag to akcipher_request_set_callback() but was not handling correctly
    the case where a -EBUSY error could be returned from the call to
    crypto_akcipher_verify() if backlog was used, possibly casuing
    data corruption due to use-after-free of buffers.

    Resolve this by handling -EBUSY correctly.

    Signed-off-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Gilad Ben-Yossef
     

07 Jun, 2017

1 commit

  • commit 9933e113c2e87a9f46a40fde8dafbf801dca1ab9 upstream.

    The API setkey checks for key sizes and alignment went AWOL during the
    skcipher conversion. This patch restores them.

    Fixes: 4e6c3df4d729 ("crypto: skcipher - Add low-level skcipher...")
    Reported-by: Baozeng
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Herbert Xu
     

20 May, 2017

1 commit

  • commit 2a2a251f110576b1d89efbd0662677d7e7db21a8 upstream.

    Some cipher implementations will crash if you try to use them
    without calling setkey first. This patch adds a check so that
    the accept(2) call will fail with -ENOKEY if setkey hasn't been
    done on the socket yet.

    Fixes: 400c40cf78da ("crypto: algif - add AEAD support")
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Stephan Mueller
     

21 Apr, 2017

2 commits

  • commit ef0579b64e93188710d48667cb5e014926af9f1b upstream.

    The ahash API modifies the request's callback function in order
    to clean up after itself in some corner cases (unaligned final
    and missing finup).

    When the request is complete ahash will restore the original
    callback and everything is fine. However, when the request gets
    an EBUSY on a full queue, an EINPROGRESS callback is made while
    the request is still ongoing.

    In this case the ahash API will incorrectly call its own callback.

    This patch fixes the problem by creating a temporary request
    object on the stack which is used to relay EINPROGRESS back to
    the original completion function.

    This patch also adds code to preserve the original flags value.

    Fixes: ab6bf4e5e5e4 ("crypto: hash - Fix the pointer voodoo in...")
    Reported-by: Sabrina Dubroca
    Tested-by: Sabrina Dubroca
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Herbert Xu
     
  • commit e6534aebb26e32fbab14df9c713c65e8507d17e4 upstream.

    The algif_aead completion function tries to deduce the aead_request
    from the crypto_async_request argument. This is broken because
    the API does not guarantee that the same request will be pased to
    the completion function. Only the value of req->data can be used
    in the completion function.

    This patch fixes it by storing a pointer to sk in areq and using
    that instead of passing in sk through req->data.

    Fixes: 83094e5e9e49 ("crypto: af_alg - add async support to...")
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Herbert Xu
     

30 Mar, 2017

1 commit

  • commit 6207119444595d287b1e9e83a2066c17209698f3 upstream.

    With this reproducer:
    struct sockaddr_alg alg = {
    .salg_family = 0x26,
    .salg_type = "hash",
    .salg_feat = 0xf,
    .salg_mask = 0x5,
    .salg_name = "digest_null",
    };
    int sock, sock2;

    sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
    bind(sock, (struct sockaddr *)&alg, sizeof(alg));
    sock2 = accept(sock, NULL, NULL);
    setsockopt(sock, SOL_ALG, ALG_SET_KEY, "\x9b\xca", 2);
    accept(sock2, NULL, NULL);

    ==== 8< ======== 8< ======== 8< ======== 8< ====

    one can immediatelly see an UBSAN warning:
    UBSAN: Undefined behaviour in crypto/algif_hash.c:187:7
    variable length array bound value 0 ] ? __ubsan_handle_vla_bound_not_positive+0x13d/0x188
    [] ? __ubsan_handle_out_of_bounds+0x1bc/0x1bc
    [] ? hash_accept+0x5bd/0x7d0 [algif_hash]
    [] ? hash_accept_nokey+0x3f/0x51 [algif_hash]
    [] ? hash_accept_parent_nokey+0x4a0/0x4a0 [algif_hash]
    [] ? SyS_accept+0x2b/0x40

    It is a correct warning, as hash state is propagated to accept as zero,
    but creating a zero-length variable array is not allowed in C.

    Fix this as proposed by Herbert -- do "?: 1" on that site. No sizeof or
    similar happens in the code there, so we just allocate one byte even
    though we do not use the array.

    Signed-off-by: Jiri Slaby
    Cc: Herbert Xu
    Cc: "David S. Miller" (maintainer:CRYPTO API)
    Reported-by: Sasha Levin
    Signed-off-by: Herbert Xu
    Cc: Arnd Bergmann
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

18 Mar, 2017

1 commit

  • commit 7d6e9105026788c497f0ab32fa16c82f4ab5ff61 upstream.

    An ancient gcc bug (first reported in 2003) has apparently resurfaced
    on MIPS, where kernelci.org reports an overly large stack frame in the
    whirlpool hash algorithm:

    crypto/wp512.c:987:1: warning: the frame size of 1112 bytes is larger than 1024 bytes [-Wframe-larger-than=]

    With some testing in different configurations, I'm seeing large
    variations in stack frames size up to 1500 bytes for what should have
    around 300 bytes at most. I also checked the reference implementation,
    which is essentially the same code but also comes with some test and
    benchmarking infrastructure.

    It seems that recent compiler versions on at least arm, arm64 and powerpc
    have a partial fix for this problem, but enabling "-fsched-pressure", but
    even with that fix they suffer from the issue to a certain degree. Some
    testing on arm64 shows that the time needed to hash a given amount of
    data is roughly proportional to the stack frame size here, which makes
    sense given that the wp512 implementation is doing lots of loads for
    table lookups, and the problem with the overly large stack is a result
    of doing a lot more loads and stores for spilled registers (as seen from
    inspecting the object code).

    Disabling -fschedule-insns consistently fixes the problem for wp512,
    in my collection of cross-compilers, the results are consistently better
    or identical when comparing the stack sizes in this function, though
    some architectures (notable x86) have schedule-insns disabled by
    default.

    The four columns are:
    default: -O2
    press: -O2 -fsched-pressure
    nopress: -O2 -fschedule-insns -fno-sched-pressure
    nosched: -O2 -no-schedule-insns (disables sched-pressure)

    default press nopress nosched
    alpha-linux-gcc-4.9.3 1136 848 1136 176
    am33_2.0-linux-gcc-4.9.3 2100 2076 2100 2104
    arm-linux-gnueabi-gcc-4.9.3 848 848 1048 352
    cris-linux-gcc-4.9.3 272 272 272 272
    frv-linux-gcc-4.9.3 1128 1000 1128 280
    hppa64-linux-gcc-4.9.3 1128 336 1128 184
    hppa-linux-gcc-4.9.3 644 308 644 276
    i386-linux-gcc-4.9.3 352 352 352 352
    m32r-linux-gcc-4.9.3 720 656 720 268
    microblaze-linux-gcc-4.9.3 1108 604 1108 256
    mips64-linux-gcc-4.9.3 1328 592 1328 208
    mips-linux-gcc-4.9.3 1096 624 1096 240
    powerpc64-linux-gcc-4.9.3 1088 432 1088 160
    powerpc-linux-gcc-4.9.3 1080 584 1080 224
    s390-linux-gcc-4.9.3 456 456 624 360
    sh3-linux-gcc-4.9.3 292 292 292 292
    sparc64-linux-gcc-4.9.3 992 240 992 208
    sparc-linux-gcc-4.9.3 680 592 680 312
    x86_64-linux-gcc-4.9.3 224 240 272 224
    xtensa-linux-gcc-4.9.3 1152 704 1152 304

    aarch64-linux-gcc-7.0.0 224 224 1104 208
    arm-linux-gnueabi-gcc-7.0.1 824 824 1048 352
    mips-linux-gcc-7.0.0 1120 648 1120 272
    x86_64-linux-gcc-7.0.1 240 240 304 240

    arm-linux-gnueabi-gcc-4.4.7 840 392
    arm-linux-gnueabi-gcc-4.5.4 784 728 784 320
    arm-linux-gnueabi-gcc-4.6.4 736 728 736 304
    arm-linux-gnueabi-gcc-4.7.4 944 784 944 352
    arm-linux-gnueabi-gcc-4.8.5 464 464 760 352
    arm-linux-gnueabi-gcc-4.9.3 848 848 1048 352
    arm-linux-gnueabi-gcc-5.3.1 824 824 1064 336
    arm-linux-gnueabi-gcc-6.1.1 808 808 1056 344
    arm-linux-gnueabi-gcc-7.0.1 824 824 1048 352

    Trying the same test for serpent-generic, the picture is a bit different,
    and while -fno-schedule-insns is generally better here than the default,
    -fsched-pressure wins overall, so I picked that instead.

    default press nopress nosched
    alpha-linux-gcc-4.9.3 1392 864 1392 960
    am33_2.0-linux-gcc-4.9.3 536 524 536 528
    arm-linux-gnueabi-gcc-4.9.3 552 552 776 536
    cris-linux-gcc-4.9.3 528 528 528 528
    frv-linux-gcc-4.9.3 536 400 536 504
    hppa64-linux-gcc-4.9.3 524 208 524 480
    hppa-linux-gcc-4.9.3 768 472 768 508
    i386-linux-gcc-4.9.3 564 564 564 564
    m32r-linux-gcc-4.9.3 712 576 712 532
    microblaze-linux-gcc-4.9.3 724 392 724 512
    mips64-linux-gcc-4.9.3 720 384 720 496
    mips-linux-gcc-4.9.3 728 384 728 496
    powerpc64-linux-gcc-4.9.3 704 304 704 480
    powerpc-linux-gcc-4.9.3 704 296 704 480
    s390-linux-gcc-4.9.3 560 560 592 536
    sh3-linux-gcc-4.9.3 540 540 540 540
    sparc64-linux-gcc-4.9.3 544 352 544 496
    sparc-linux-gcc-4.9.3 544 344 544 496
    x86_64-linux-gcc-4.9.3 528 536 576 528
    xtensa-linux-gcc-4.9.3 752 544 752 544

    aarch64-linux-gcc-7.0.0 432 432 656 480
    arm-linux-gnueabi-gcc-7.0.1 616 616 808 536
    mips-linux-gcc-7.0.0 720 464 720 488
    x86_64-linux-gcc-7.0.1 536 528 600 536

    arm-linux-gnueabi-gcc-4.4.7 592 440
    arm-linux-gnueabi-gcc-4.5.4 776 448 776 544
    arm-linux-gnueabi-gcc-4.6.4 776 448 776 544
    arm-linux-gnueabi-gcc-4.7.4 768 448 768 544
    arm-linux-gnueabi-gcc-4.8.5 488 488 776 544
    arm-linux-gnueabi-gcc-4.9.3 552 552 776 536
    arm-linux-gnueabi-gcc-5.3.1 552 552 776 536
    arm-linux-gnueabi-gcc-6.1.1 560 560 776 536
    arm-linux-gnueabi-gcc-7.0.1 616 616 808 536

    I did not do any runtime tests with serpent, so it is possible that stack
    frame size does not directly correlate with runtime performance here and
    it actually makes things worse, but it's more likely to help here, and
    the reduced stack frame size is probably enough reason to apply the patch,
    especially given that the crypto code is often used in deep call chains.

    Link: https://kernelci.org/build/id/58797d7559b5149efdf6c3a9/logs/
    Link: http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html
    Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11488
    Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
    Cc: Ralf Baechle
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Arnd Bergmann
     

12 Mar, 2017

1 commit

  • commit 1c68bb0f62bf8de8bb30123ea840d5168f25abea upstream.

    Running with KASAN and crypto tests currently gives

    BUG: KASAN: global-out-of-bounds in __test_aead+0x9d9/0x2200 at addr ffffffff8212fca0
    Read of size 16 by task cryptomgr_test/1107
    Address belongs to variable 0xffffffff8212fca0
    CPU: 0 PID: 1107 Comm: cryptomgr_test Not tainted 4.10.0+ #45
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014
    Call Trace:
    dump_stack+0x63/0x8a
    kasan_report.part.1+0x4a7/0x4e0
    ? __test_aead+0x9d9/0x2200
    ? crypto_ccm_init_crypt+0x218/0x3c0 [ccm]
    kasan_report+0x20/0x30
    check_memory_region+0x13c/0x1a0
    memcpy+0x23/0x50
    __test_aead+0x9d9/0x2200
    ? kasan_unpoison_shadow+0x35/0x50
    ? alg_test_akcipher+0xf0/0xf0
    ? crypto_skcipher_init_tfm+0x2e3/0x310
    ? crypto_spawn_tfm2+0x37/0x60
    ? crypto_ccm_init_tfm+0xa9/0xd0 [ccm]
    ? crypto_aead_init_tfm+0x7b/0x90
    ? crypto_alloc_tfm+0xc4/0x190
    test_aead+0x28/0xc0
    alg_test_aead+0x54/0xd0
    alg_test+0x1eb/0x3d0
    ? alg_find_test+0x90/0x90
    ? __sched_text_start+0x8/0x8
    ? __wake_up_common+0x70/0xb0
    cryptomgr_test+0x4d/0x60
    kthread+0x173/0x1c0
    ? crypto_acomp_scomp_free_ctx+0x60/0x60
    ? kthread_create_on_node+0xa0/0xa0
    ret_from_fork+0x2c/0x40
    Memory state around the buggy address:
    ffffffff8212fb80: 00 00 00 00 01 fa fa fa fa fa fa fa 00 00 00 00
    ffffffff8212fc00: 00 01 fa fa fa fa fa fa 00 00 00 00 01 fa fa fa
    >ffffffff8212fc80: fa fa fa fa 00 05 fa fa fa fa fa fa 00 00 00 00
    ^
    ffffffff8212fd00: 01 fa fa fa fa fa fa fa 00 00 00 00 01 fa fa fa
    ffffffff8212fd80: fa fa fa fa 00 00 00 00 00 05 fa fa fa fa fa fa

    This always happens on the same IV which is less than 16 bytes.

    Per Ard,

    "CCM IVs are 16 bytes, but due to the way they are constructed
    internally, the final couple of bytes of input IV are dont-cares.

    Apparently, we do read all 16 bytes, which triggers the KASAN errors."

    Fix this by padding the IV with null bytes to be at least 16 bytes.

    Fixes: 0bc5a6c5c79a ("crypto: testmgr - Disable rfc4309 test and convert test vectors")
    Acked-by: Ard Biesheuvel
    Signed-off-by: Laura Abbott
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Laura Abbott
     

15 Feb, 2017

1 commit

  • commit 0b529f143e8baad441a5aac9ad55ec2434d8fb46 upstream.

    Kernel panics when userspace program try to access AEAD interface.
    Remove node from Linked List before freeing its memory.

    Signed-off-by: Harsh Jain
    Reviewed-by: Stephan Müller
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Harsh Jain
     

09 Feb, 2017

1 commit


11 Dec, 2016

1 commit

  • Pull crypto fixes from Herbert Xu:
    "This fixes the following issues:

    - Fix pointer size when caam is used with AArch64 boot loader on
    AArch32 kernel.

    - Fix ahash state corruption in marvell driver.

    - Fix buggy algif_aed tag handling.

    - Prevent mcryptd from being used with incompatible algorithms which
    can cause crashes"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
    crypto: algif_aead - fix uninitialized variable warning
    crypto: mcryptd - Check mcryptd algorithm compatibility
    crypto: algif_aead - fix AEAD tag memory handling
    crypto: caam - fix pointer size for AArch64 boot loader, AArch32 kernel
    crypto: marvell - Don't corrupt state of an STD req for re-stepped ahash
    crypto: marvell - Don't copy hash operation twice into the SRAM

    Linus Torvalds
     

08 Dec, 2016

1 commit


07 Dec, 2016

2 commits

  • Algorithms not compatible with mcryptd could be spawned by mcryptd
    with a direct crypto_alloc_tfm invocation using a "mcryptd(alg)" name
    construct. This causes mcryptd to crash the kernel if an arbitrary
    "alg" is incompatible and not intended to be used with mcryptd. It is
    an issue if AF_ALG tries to spawn mcryptd(alg) to expose it externally.
    But such algorithms must be used internally and not be exposed.

    We added a check to enforce that only internal algorithms are allowed
    with mcryptd at the time mcryptd is spawning an algorithm.

    Link: http://marc.info/?l=linux-crypto-vger&m=148063683310477&w=2
    Cc: stable@vger.kernel.org
    Reported-by: Mikulas Patocka
    Signed-off-by: Tim Chen
    Signed-off-by: Herbert Xu

    Tim
     
  • For encryption, the AEAD ciphers require AAD || PT as input and generate
    AAD || CT || Tag as output and vice versa for decryption. Prior to this
    patch, the AF_ALG interface for AEAD ciphers requires the buffer to be
    present as input for encryption. Similarly, the output buffer for
    decryption required the presence of the tag buffer too. This implies
    that the kernel reads / writes data buffers from/to kernel space
    even though this operation is not required.

    This patch changes the AF_ALG AEAD interface to be consistent with the
    in-kernel AEAD cipher requirements.

    Due to this handling, he changes are transparent to user space with one
    exception: the return code of recv indicates the mount of output buffer.
    That output buffer has a different size compared to before the patch
    which implies that the return code of recv will also be different.
    For example, a decryption operation uses 16 bytes AAD, 16 bytes CT and
    16 bytes tag, the AF_ALG AEAD interface before showed a recv return
    code of 48 (bytes) whereas after this patch, the return code is 32
    since the tag is not returned any more.

    Reported-by: Mat Martineau
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

06 Dec, 2016

1 commit


30 Nov, 2016

2 commits

  • Both asn1 headers are included by rsa_helper.c, so rsa_helper.o
    should explicitly depend on them.

    Signed-off-by: David Michael
    Signed-off-by: Herbert Xu

    David Michael
     
  • When using SGs, only heap memory (memory that is valid as per
    virt_addr_valid) is allowed to be referenced. The CTR DRBG used to
    reference the caller-provided memory directly in an SG. In case the
    caller provided stack memory pointers, the SG mapping is not considered
    to be valid. In some cases, this would even cause a paging fault.

    The change adds a new scratch buffer that is used unconditionally to
    catch the cases where the caller-provided buffer is not suitable for
    use in an SG. The crypto operation of the CTR DRBG produces its output
    with that scratch buffer and finally copies the content of the
    scratch buffer to the caller's buffer.

    The scratch buffer is allocated during allocation time of the CTR DRBG
    as its access is protected with the DRBG mutex.

    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

25 Nov, 2016

1 commit

  • We shouldn't free cert->pub->key in x509_cert_parse() because
    x509_free_certificate() also does this:
    BUG: Double free or freeing an invalid pointer
    ...
    Call Trace:
    [] dump_stack+0x63/0x83
    [] kasan_object_err+0x21/0x70
    [] kasan_report_double_free+0x49/0x60
    [] kasan_slab_free+0x9d/0xc0
    [] kfree+0x8a/0x1a0
    [] public_key_free+0x1f/0x30
    [] x509_free_certificate+0x24/0x90
    [] x509_cert_parse+0x2bc/0x300
    [] x509_key_preparse+0x3e/0x330
    [] asymmetric_key_preparse+0x6f/0x100
    [] key_create_or_update+0x260/0x5f0
    [] SyS_add_key+0x199/0x2a0
    [] entry_SYSCALL_64_fastpath+0x1e/0xad
    Object at ffff880110bd1900, in cache kmalloc-512 size: 512
    ....
    Freed:
    PID = 2579
    [] save_stack_trace+0x1b/0x20
    [] save_stack+0x46/0xd0
    [] kasan_slab_free+0x73/0xc0
    [] kfree+0x8a/0x1a0
    [] x509_cert_parse+0x2a3/0x300
    [] x509_key_preparse+0x3e/0x330
    [] asymmetric_key_preparse+0x6f/0x100
    [] key_create_or_update+0x260/0x5f0
    [] SyS_add_key+0x199/0x2a0
    [] entry_SYSCALL_64_fastpath+0x1e/0xad

    Fixes: db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")
    Signed-off-by: Andrey Ryabinin
    Cc:
    Signed-off-by: David Howells
    Signed-off-by: James Morris

    Andrey Ryabinin
     

22 Nov, 2016

2 commits

  • The aliasing check in map_and_copy is no longer necessary because
    the IPsec ESP code no longer provides an IV that points into the
    actual request data. As this check is now triggering BUG checks
    due to the vmalloced stack code, I'm removing it.

    Reported-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • Recently an init call was added to hash_recvmsg so as to reset
    the hash state in case a sendmsg call was never made.

    Unfortunately this ended up clobbering the result if the previous
    sendmsg was done with a MSG_MORE flag. This patch fixes it by
    excluding that case when we make the init call.

    Fixes: a8348bca2944 ("algif_hash - Fix NULL hash crash with shash")
    Reported-by: Patrick Steinhardt
    Signed-off-by: Herbert Xu

    Herbert Xu
     

18 Nov, 2016

1 commit

  • Recently algif_hash has been changed to allow null hashes. This
    triggers a bug when used with an shash algorithm whereby it will
    cause a crash during the digest operation.

    This patch fixes it by avoiding the digest operation and instead
    doing an init followed by a final which avoids the buggy code in
    shash.

    This patch also ensures that the result buffer is freed after an
    error so that it is not returned as a genuine hash result on the
    next recv call.

    The shash/ahash wrapper code will be fixed later to handle this
    case correctly.

    Fixes: 493b2ed3f760 ("crypto: algif_hash - Handle NULL hashes correctly")
    Signed-off-by: Herbert Xu
    Tested-by: Laura Abbott

    Herbert Xu
     

12 Oct, 2016

1 commit

  • A good practice is to prefix the names of functions by the name
    of the subsystem.

    The kthread worker API is a mix of classic kthreads and workqueues. Each
    worker has a dedicated kthread. It runs a generic function that process
    queued works. It is implemented as part of the kthread subsystem.

    This patch renames the existing kthread worker API to use
    the corresponding name from the workqueues API prefixed by
    kthread_:

    __init_kthread_worker() -> __kthread_init_worker()
    init_kthread_worker() -> kthread_init_worker()
    init_kthread_work() -> kthread_init_work()
    insert_kthread_work() -> kthread_insert_work()
    queue_kthread_work() -> kthread_queue_work()
    flush_kthread_work() -> kthread_flush_work()
    flush_kthread_worker() -> kthread_flush_worker()

    Note that the names of DEFINE_KTHREAD_WORK*() macros stay
    as they are. It is common that the "DEFINE_" prefix has
    precedence over the subsystem names.

    Note that INIT() macros and init() functions use different
    naming scheme. There is no good solution. There are several
    reasons for this solution:

    + "init" in the function names stands for the verb "initialize"
    aka "initialize worker". While "INIT" in the macro names
    stands for the noun "INITIALIZER" aka "worker initializer".

    + INIT() macros are used only in DEFINE() macros

    + init() functions are used close to the other kthread()
    functions. It looks much better if all the functions
    use the same scheme.

    + There will be also kthread_destroy_worker() that will
    be used close to kthread_cancel_work(). It is related
    to the init() function. Again it looks better if all
    functions use the same naming scheme.

    + there are several precedents for such init() function
    names, e.g. amd_iommu_init_device(), free_area_init_node(),
    jump_label_init_type(), regmap_init_mmio_clk(),

    + It is not an argument but it was inconsistent even before.

    [arnd@arndb.de: fix linux-next merge conflict]
    Link: http://lkml.kernel.org/r/20160908135724.1311726-1-arnd@arndb.de
    Link: http://lkml.kernel.org/r/1470754545-17632-3-git-send-email-pmladek@suse.com
    Suggested-by: Andrew Morton
    Signed-off-by: Petr Mladek
    Cc: Oleg Nesterov
    Cc: Tejun Heo
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     

11 Oct, 2016

1 commit

  • Pull crypto updates from Herbert Xu:
    "Here is the crypto update for 4.9:

    API:
    - The crypto engine code now supports hashes.

    Algorithms:
    - Allow keys >= 2048 bits in FIPS mode for RSA.

    Drivers:
    - Memory overwrite fix for vmx ghash.
    - Add support for building ARM sha1-neon in Thumb2 mode.
    - Reenable ARM ghash-ce code by adding import/export.
    - Reenable img-hash by adding import/export.
    - Add support for multiple cores in omap-aes.
    - Add little-endian support for sha1-powerpc.
    - Add Cavium HWRNG driver for ThunderX SoC"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (137 commits)
    crypto: caam - treat SGT address pointer as u64
    crypto: ccp - Make syslog errors human-readable
    crypto: ccp - clean up data structure
    crypto: vmx - Ensure ghash-generic is enabled
    crypto: testmgr - add guard to dst buffer for ahash_export
    crypto: caam - Unmap region obtained by of_iomap
    crypto: sha1-powerpc - little-endian support
    crypto: gcm - Fix IV buffer size in crypto_gcm_setkey
    crypto: vmx - Fix memory corruption caused by p8_ghash
    crypto: ghash-generic - move common definitions to a new header file
    crypto: caam - fix sg dump
    hwrng: omap - Only fail if pm_runtime_get_sync returns < 0
    crypto: omap-sham - shrink the internal buffer size
    crypto: omap-sham - add support for export/import
    crypto: omap-sham - convert driver logic to use sgs for data xmit
    crypto: omap-sham - change the DMA threshold value to a define
    crypto: omap-sham - add support functions for sg based data handling
    crypto: omap-sham - rename sgl to sgl_tmp for deprecation
    crypto: omap-sham - align algorithms on word offset
    crypto: omap-sham - add context export/import stubs
    ...

    Linus Torvalds
     

10 Oct, 2016

1 commit


07 Oct, 2016

1 commit

  • Pull dmaengine updates from Vinod Koul:
    "This is bit large pile of code which bring in some nice additions:

    - Error reporting: we have added a new mechanism for users of
    dmaenegine to register a callback_result which tells them the
    result of the dma transaction. Right now only one user (ntb) is
    using it.

    - As we discussed on KS mailing list and pointed out NO_IRQ has no
    place in kernel, this also remove NO_IRQ from dmaengine subsystem
    (both arm and ppc users)

    - Support for IOMMU slave transfers and its implementation for arm.

    - To get better build coverage, enable COMPILE_TEST for bunch of
    driver, and fix the warning and sparse complaints on these.

    - Apart from above, usual updates spread across drivers"

    * tag 'dmaengine-4.9-rc1' of git://git.infradead.org/users/vkoul/slave-dma: (169 commits)
    async_pq_val: fix DMA memory leak
    dmaengine: virt-dma: move function declarations
    dmaengine: omap-dma: Enable burst and data pack for SG
    DT: dmaengine: rcar-dmac: document R8A7743/5 support
    dmaengine: fsldma: Unmap region obtained by of_iomap
    dmaengine: jz4780: fix resource leaks on error exit return
    dma-debug: fix ia64 build, use PHYS_PFN
    dmaengine: coh901318: fix integer overflow when shifting more than 32 places
    dmaengine: edma: avoid uninitialized variable use
    dma-mapping: fix m32r build warning
    dma-mapping: fix ia64 build, use PHYS_PFN
    dmaengine: ti-dma-crossbar: enable COMPILE_TEST
    dmaengine: omap-dma: enable COMPILE_TEST
    dmaengine: edma: enable COMPILE_TEST
    dmaengine: ti-dma-crossbar: Fix of_device_id data parameter usage
    dmaengine: ti-dma-crossbar: Correct type for of_find_property() third parameter
    dmaengine/ARM: omap-dma: Fix the DMAengine compile test on non OMAP configs
    dmaengine: edma: Rename set_bits and remove unused clear_bits helper
    dmaengine: edma: Use correct type for of_find_property() third parameter
    dmaengine: edma: Fix of_device_id data parameter usage (legacy vs TPCC)
    ...

    Linus Torvalds
     

05 Oct, 2016

1 commit

  • Add missing dmaengine_unmap_put(), so we don't OOM during RAID6 sync.

    Fixes: 1786b943dad0 ("async_pq_val: convert to dmaengine_unmap_data")
    Signed-off-by: Justin Maggard
    Reviewed-by: Dan Williams
    Cc:
    Signed-off-by: Vinod Koul

    Justin Maggard
     

02 Oct, 2016

3 commits

  • Add a guard to 'state' buffer and warn if its consistency after
    call to crypto_ahash_export() changes, so that any write that
    goes beyond advertised statesize (and thus causing potential
    memory corruption [1]) is more visible.

    [1] https://marc.info/?l=linux-crypto-vger&m=147467656516085

    Signed-off-by: Jan Stancek
    Cc: Herbert Xu
    Cc: Marcelo Cerri
    Signed-off-by: Herbert Xu

    Jan Stancek
     
  • The cipher block size for GCM is 16 bytes, and thus the CTR transform
    used in crypto_gcm_setkey() will also expect a 16-byte IV. However,
    the code currently reserves only 8 bytes for the IV, causing
    an out-of-bounds access in the CTR transform. This patch fixes
    the issue by setting the size of the IV buffer to 16 bytes.

    Fixes: 84c911523020 ("[CRYPTO] gcm: Add support for async ciphers")
    Signed-off-by: Ondrej Mosnacek
    Signed-off-by: Herbert Xu

    Ondrej Mosnáček
     
  • Move common values and types used by ghash-generic to a new header file
    so drivers can directly use ghash-generic as a fallback implementation.

    Fixes: cc333cd68dfa ("crypto: vmx - Adding GHASH routines for VMX module")
    Cc: stable@vger.kernel.org
    Signed-off-by: Marcelo Cerri
    Signed-off-by: Herbert Xu

    Marcelo Cerri
     

22 Sep, 2016

1 commit

  • As the software RSA implementation now produces fixed-length
    output, we need to eliminate leading zeros in the calling code
    instead.

    This patch does just that for pkcs1pad decryption while signature
    verification was fixed in an earlier patch.

    Fixes: 9b45b7bba3d2 ("crypto: rsa - Generate fixed-length output")
    Reported-by: Mat Martineau
    Signed-off-by: Herbert Xu

    Herbert Xu
     

13 Sep, 2016

3 commits

  • Remove unneeded variables and assignments.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Herbert Xu

    Masahiro Yamada
     
  • When we need to allocate a temporary blkcipher_walk_next and it
    fails, the code is supposed to take the slow path of processing
    the data block by block. However, due to an unrelated change
    we instead end up dereferencing the NULL pointer.

    This patch fixes it by moving the unrelated bsize setting out
    of the way so that we enter the slow path as inteded.

    Fixes: 7607bd8ff03b ("[CRYPTO] blkcipher: Added blkcipher_walk_virt_block")
    Cc: stable@vger.kernel.org
    Reported-by: xiakaixu
    Reported-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu
    Tested-by: Ard Biesheuvel

    Herbert Xu
     
  • The current implementation uses a global per-cpu array to store
    data which are used to derive the next IV. This is insecure as
    the attacker may change the stored data.

    This patch removes all traces of chaining and replaces it with
    multiplication of the salt and the sequence number.

    Fixes: a10f554fa7e0 ("crypto: echainiv - Add encrypted chain IV...")
    Cc: stable@vger.kernel.org
    Reported-by: Mathias Krause
    Signed-off-by: Herbert Xu

    Herbert Xu
     

07 Sep, 2016

2 commits

  • Right now attempting to read an empty hash simply returns zeroed
    bytes, this patch corrects this by calling the digest function
    using an empty input.

    Reported-by: Russell King - ARM Linux
    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • The current crypto engine allow only ablkcipher_request to be enqueued.
    Thus denying any use of it for hardware that also handle hash algo.

    This patch modify the API for allowing to enqueue ciphers and hash.

    Since omap-aes/omap-des are the only users, this patch also convert them
    to the new cryptoengine API.

    Signed-off-by: Corentin Labbe
    Signed-off-by: Herbert Xu

    Corentin LABBE