01 Feb, 2020

1 commit

  • commit 37f96694cf73ba116993a9d2d99ad6a75fa7fdb0 upstream.

    As af_alg_release_parent may be called from BH context (most notably
    due to an async request that only completes after socket closure,
    or as reported here because of an RCU-delayed sk_destruct call), we
    must use bh_lock_sock instead of lock_sock.

    Reported-by: syzbot+c2f1558d49e25cc36e5e@syzkaller.appspotmail.com
    Reported-by: Eric Dumazet
    Fixes: c840ac6af3f8 ("crypto: af_alg - Disallow bind/setkey/...")
    Cc:
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Herbert Xu
     

13 Dec, 2019

1 commit

  • commit 64e7f852c47ce99f6c324c46d6a299a5a7ebead9 upstream.

    when libkcapi test is executed using HW accelerator, cipher operation
    return -74.Since af_alg_async_cb->ki_complete treat err as unsigned int,
    libkcapi receive 429467222 even though it expect -ve value.

    Hence its required to cast resultlen to int so that proper
    error is returned to libkcapi.

    AEAD one shot non-aligned test 2(libkcapi test)
    ./../bin/kcapi -x 10 -c "gcm(aes)" -i 7815d4b06ae50c9c56e87bd7
    -k ea38ac0c9b9998c80e28fb496a2b88d9 -a
    "853f98a750098bec1aa7497e979e78098155c877879556bb51ddeb6374cbaefc"
    -t "c4ce58985b7203094be1d134c1b8ab0b" -q
    "b03692f86d1b8b39baf2abb255197c98"

    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Cc:
    Signed-off-by: Ayush Sawal
    Signed-off-by: Atul Gupta
    Signed-off-by: Herbert Xu
    Signed-off-by: Ayush Sawal
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Ayush Sawal
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 3029 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070032.746973796@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

06 Mar, 2019

1 commit

  • Pull crypto update from Herbert Xu:
    "API:
    - Add helper for simple skcipher modes.
    - Add helper to register multiple templates.
    - Set CRYPTO_TFM_NEED_KEY when setkey fails.
    - Require neither or both of export/import in shash.
    - AEAD decryption test vectors are now generated from encryption
    ones.
    - New option CONFIG_CRYPTO_MANAGER_EXTRA_TESTS that includes random
    fuzzing.

    Algorithms:
    - Conversions to skcipher and helper for many templates.
    - Add more test vectors for nhpoly1305 and adiantum.

    Drivers:
    - Add crypto4xx prng support.
    - Add xcbc/cmac/ecb support in caam.
    - Add AES support for Exynos5433 in s5p.
    - Remove sha384/sha512 from artpec7 as hardware cannot do partial
    hash"

    [ There is a merge of the Freescale SoC tree in order to pull in changes
    required by patches to the caam/qi2 driver. ]

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (174 commits)
    crypto: s5p - add AES support for Exynos5433
    dt-bindings: crypto: document Exynos5433 SlimSSS
    crypto: crypto4xx - add missing of_node_put after of_device_is_available
    crypto: cavium/zip - fix collision with generic cra_driver_name
    crypto: af_alg - use struct_size() in sock_kfree_s()
    crypto: caam - remove redundant likely/unlikely annotation
    crypto: s5p - update iv after AES-CBC op end
    crypto: x86/poly1305 - Clear key material from stack in SSE2 variant
    crypto: caam - generate hash keys in-place
    crypto: caam - fix DMA mapping xcbc key twice
    crypto: caam - fix hash context DMA unmap size
    hwrng: bcm2835 - fix probe as platform device
    crypto: s5p-sss - Use AES_BLOCK_SIZE define instead of number
    crypto: stm32 - drop pointless static qualifier in stm32_hash_remove()
    crypto: chelsio - Fixed Traffic Stall
    crypto: marvell - Remove set but not used variable 'ivsize'
    crypto: ccp - Update driver messages to remove some confusion
    crypto: adiantum - add 1536 and 4096-byte test vectors
    crypto: nhpoly1305 - add a test vector with len % 16 != 0
    crypto: arm/aes-ce - update IV after partial final CTR block
    ...

    Linus Torvalds
     

28 Feb, 2019

1 commit

  • Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes, in particular in the
    context in which this code is being used.

    So, change the following form:

    sizeof(*sgl) + sizeof(sgl->sg[0]) * (MAX_SGL_ENTS + 1)

    to :

    struct_size(sgl, sg, MAX_SGL_ENTS + 1)

    This code was detected with the help of Coccinelle.

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Herbert Xu

    Gustavo A. R. Silva
     

19 Feb, 2019

1 commit

  • KASAN has found use-after-free in sockfs_setattr.
    The existed commit 6d8c50dcb029 ("socket: close race condition between sock_close()
    and sockfs_setattr()") is to fix this simillar issue, but it seems to ignore
    that crypto module forgets to set the sk to NULL after af_alg_release.

    KASAN report details as below:
    BUG: KASAN: use-after-free in sockfs_setattr+0x120/0x150
    Write of size 4 at addr ffff88837b956128 by task syz-executor0/4186

    CPU: 2 PID: 4186 Comm: syz-executor0 Not tainted xxx + #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
    1.10.2-1ubuntu1 04/01/2014
    Call Trace:
    dump_stack+0xca/0x13e
    print_address_description+0x79/0x330
    ? vprintk_func+0x5e/0xf0
    kasan_report+0x18a/0x2e0
    ? sockfs_setattr+0x120/0x150
    sockfs_setattr+0x120/0x150
    ? sock_register+0x2d0/0x2d0
    notify_change+0x90c/0xd40
    ? chown_common+0x2ef/0x510
    chown_common+0x2ef/0x510
    ? chmod_common+0x3b0/0x3b0
    ? __lock_is_held+0xbc/0x160
    ? __sb_start_write+0x13d/0x2b0
    ? __mnt_want_write+0x19a/0x250
    do_fchownat+0x15c/0x190
    ? __ia32_sys_chmod+0x80/0x80
    ? trace_hardirqs_on_thunk+0x1a/0x1c
    __x64_sys_fchownat+0xbf/0x160
    ? lockdep_hardirqs_on+0x39a/0x5e0
    do_syscall_64+0xc8/0x580
    entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x462589
    Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89
    f7 48 89 d6 48 89
    ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 3d 01 f0 ff ff 73 01 c3
    48 c7 c1 bc ff ff
    ff f7 d8 64 89 01 48
    RSP: 002b:00007fb4b2c83c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
    RAX: ffffffffffffffda RBX: 000000000072bfa0 RCX: 0000000000462589
    RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000007
    RBP: 0000000000000005 R08: 0000000000001000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 00007fb4b2c846bc
    R13: 00000000004bc733 R14: 00000000006f5138 R15: 00000000ffffffff

    Allocated by task 4185:
    kasan_kmalloc+0xa0/0xd0
    __kmalloc+0x14a/0x350
    sk_prot_alloc+0xf6/0x290
    sk_alloc+0x3d/0xc00
    af_alg_accept+0x9e/0x670
    hash_accept+0x4a3/0x650
    __sys_accept4+0x306/0x5c0
    __x64_sys_accept4+0x98/0x100
    do_syscall_64+0xc8/0x580
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    Freed by task 4184:
    __kasan_slab_free+0x12e/0x180
    kfree+0xeb/0x2f0
    __sk_destruct+0x4e6/0x6a0
    sk_destruct+0x48/0x70
    __sk_free+0xa9/0x270
    sk_free+0x2a/0x30
    af_alg_release+0x5c/0x70
    __sock_release+0xd3/0x280
    sock_close+0x1a/0x20
    __fput+0x27f/0x7f0
    task_work_run+0x136/0x1b0
    exit_to_usermode_loop+0x1a7/0x1d0
    do_syscall_64+0x461/0x580
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    Syzkaller reproducer:
    r0 = perf_event_open(&(0x7f0000000000)={0x0, 0x70, 0x0, 0x0, 0x0, 0x0,
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @perf_config_ext}, 0x0, 0x0,
    0xffffffffffffffff, 0x0)
    r1 = socket$alg(0x26, 0x5, 0x0)
    getrusage(0x0, 0x0)
    bind(r1, &(0x7f00000001c0)=@alg={0x26, 'hash\x00', 0x0, 0x0,
    'sha256-ssse3\x00'}, 0x80)
    r2 = accept(r1, 0x0, 0x0)
    r3 = accept4$unix(r2, 0x0, 0x0, 0x0)
    r4 = dup3(r3, r0, 0x0)
    fchownat(r4, &(0x7f00000000c0)='\x00', 0x0, 0x0, 0x1000)

    Fixes: 6d8c50dcb029 ("socket: close race condition between sock_close() and sockfs_setattr()")
    Signed-off-by: Mao Wenan
    Signed-off-by: David S. Miller

    Mao Wenan
     

18 Jan, 2019

3 commits


24 Oct, 2018

1 commit

  • This reverts commit dd979b4df817e9976f18fb6f9d134d6bc4a3c317.

    This broke tcp_poll for SMC fallback: An AF_SMC socket establishes an
    internal TCP socket for the initial handshake with the remote peer.
    Whenever the SMC connection can not be established this TCP socket is
    used as a fallback. All socket operations on the SMC socket are then
    forwarded to the TCP socket. In case of poll, the file->private_data
    pointer references the SMC socket because the TCP socket has no file
    assigned. This causes tcp_poll to wait on the wrong socket.

    Signed-off-by: Karsten Graul
    Signed-off-by: David S. Miller

    Karsten Graul
     

31 Jul, 2018

1 commit


19 Jul, 2018

1 commit


13 Jul, 2018

1 commit

  • The RX SGL in processing is already registered with the RX SGL tracking
    list to support proper cleanup. The cleanup code path uses the
    sg_num_bytes variable which must therefore be always initialized, even
    in the error code path.

    Signed-off-by: Stephan Mueller
    Reported-by: syzbot+9c251bdd09f83b92ba95@syzkaller.appspotmail.com
    #syz test: https://github.com/google/kmsan.git master
    CC: #4.14
    Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

29 Jun, 2018

1 commit

  • The poll() changes were not well thought out, and completely
    unexplained. They also caused a huge performance regression, because
    "->poll()" was no longer a trivial file operation that just called down
    to the underlying file operations, but instead did at least two indirect
    calls.

    Indirect calls are sadly slow now with the Spectre mitigation, but the
    performance problem could at least be largely mitigated by changing the
    "->get_poll_head()" operation to just have a per-file-descriptor pointer
    to the poll head instead. That gets rid of one of the new indirections.

    But that doesn't fix the new complexity that is completely unwarranted
    for the regular case. The (undocumented) reason for the poll() changes
    was some alleged AIO poll race fixing, but we don't make the common case
    slower and more complex for some uncommon special case, so this all
    really needs way more explanations and most likely a fundamental
    redesign.

    [ This revert is a revert of about 30 different commits, not reverted
    individually because that would just be unnecessarily messy - Linus ]

    Cc: Al Viro
    Cc: Christoph Hellwig
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

07 Jun, 2018

2 commits

  • Pull overflow updates from Kees Cook:
    "This adds the new overflow checking helpers and adds them to the
    2-factor argument allocators. And this adds the saturating size
    helpers and does a treewide replacement for the struct_size() usage.
    Additionally this adds the overflow testing modules to make sure
    everything works.

    I'm still working on the treewide replacements for allocators with
    "simple" multiplied arguments:

    *alloc(a * b, ...) -> *alloc_array(a, b, ...)

    and

    *zalloc(a * b, ...) -> *calloc(a, b, ...)

    as well as the more complex cases, but that's separable from this
    portion of the series. I expect to have the rest sent before -rc1
    closes; there are a lot of messy cases to clean up.

    Summary:

    - Introduce arithmetic overflow test helper functions (Rasmus)

    - Use overflow helpers in 2-factor allocators (Kees, Rasmus)

    - Introduce overflow test module (Rasmus, Kees)

    - Introduce saturating size helper functions (Matthew, Kees)

    - Treewide use of struct_size() for allocators (Kees)"

    * tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    treewide: Use struct_size() for devm_kmalloc() and friends
    treewide: Use struct_size() for vmalloc()-family
    treewide: Use struct_size() for kmalloc()-family
    device: Use overflow helpers for devm_kmalloc()
    mm: Use overflow helpers in kvmalloc()
    mm: Use overflow helpers in kmalloc_array*()
    test_overflow: Add memory allocation overflow tests
    overflow.h: Add allocation size calculation helpers
    test_overflow: Report test failures
    test_overflow: macrofy some more, do more tests for free
    lib: add runtime test of check_*_overflow functions
    compiler.h: enable builtin overflow checkers and add fallback code

    Linus Torvalds
     
  • Replaces open-coded struct size calculations with struct_size() for
    devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
    manually adjusted) from the following Coccinelle script:

    // Direct reference to struct field.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // Same pattern, but can't trivially locate the trailing element name,
    // or variable name.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    expression SOMETHING, COUNT, ELEMENT;
    @@

    - alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
    + alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

    Signed-off-by: Kees Cook

    Kees Cook
     

26 May, 2018

2 commits


08 Apr, 2018

1 commit

  • syzbot reported :

    BUG: KMSAN: uninit-value in alg_bind+0xe3/0xd90 crypto/af_alg.c:162

    We need to check addr_len before dereferencing sa (or uaddr)

    Fixes: bb30b8848c85 ("crypto: af_alg - whitelist mask and type")
    Signed-off-by: Eric Dumazet
    Reported-by: syzbot
    Cc: Stephan Mueller
    Cc: Herbert Xu
    Signed-off-by: David S. Miller

    Eric Dumazet
     

12 Feb, 2018

1 commit

  • This is the mindless scripted replacement of kernel use of POLL*
    variables as described by Al, done by this script:

    for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
    L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
    for f in $L; do sed -i "-es/^\([^\"]*\)\(\\)/\\1E\\2/" $f; done
    done

    with de-mangling cleanups yet to come.

    NOTE! On almost all architectures, the EPOLL* constants have the same
    values as the POLL* constants do. But they keyword here is "almost".
    For various bad reasons they aren't the same, and epoll() doesn't
    actually work quite correctly in some cases due to this on Sparc et al.

    The next patch from Al will sort out the final differences, and we
    should be all done.

    Scripted-by: Al Viro
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

01 Feb, 2018

1 commit

  • Pull crypto updates from Herbert Xu:
    "API:
    - Enforce the setting of keys for keyed aead/hash/skcipher
    algorithms.
    - Add multibuf speed tests in tcrypt.

    Algorithms:
    - Improve performance of sha3-generic.
    - Add native sha512 support on arm64.
    - Add v8.2 Crypto Extentions version of sha3/sm3 on arm64.
    - Avoid hmac nesting by requiring underlying algorithm to be unkeyed.
    - Add cryptd_max_cpu_qlen module parameter to cryptd.

    Drivers:
    - Add support for EIP97 engine in inside-secure.
    - Add inline IPsec support to chelsio.
    - Add RevB core support to crypto4xx.
    - Fix AEAD ICV check in crypto4xx.
    - Add stm32 crypto driver.
    - Add support for BCM63xx platforms in bcm2835 and remove bcm63xx.
    - Add Derived Key Protocol (DKP) support in caam.
    - Add Samsung Exynos True RNG driver.
    - Add support for Exynos5250+ SoCs in exynos PRNG driver"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (166 commits)
    crypto: picoxcell - Fix error handling in spacc_probe()
    crypto: arm64/sha512 - fix/improve new v8.2 Crypto Extensions code
    crypto: arm64/sm3 - new v8.2 Crypto Extensions implementation
    crypto: arm64/sha3 - new v8.2 Crypto Extensions implementation
    crypto: testmgr - add new testcases for sha3
    crypto: sha3-generic - export init/update/final routines
    crypto: sha3-generic - simplify code
    crypto: sha3-generic - rewrite KECCAK transform to help the compiler optimize
    crypto: sha3-generic - fixes for alignment and big endian operation
    crypto: aesni - handle zero length dst buffer
    crypto: artpec6 - remove select on non-existing CRYPTO_SHA384
    hwrng: bcm2835 - Remove redundant dev_err call in bcm2835_rng_probe()
    crypto: stm32 - remove redundant dev_err call in stm32_cryp_probe()
    crypto: axis - remove unnecessary platform_get_resource() error check
    crypto: testmgr - test misuse of result in ahash
    crypto: inside-secure - make function safexcel_try_push_requests static
    crypto: aes-generic - fix aes-generic regression on powerpc
    crypto: chelsio - Fix indentation warning
    crypto: arm64/sha1-ce - get rid of literal pool
    crypto: arm64/sha2-ce - move the round constant table to .rodata section
    ...

    Linus Torvalds
     

31 Jan, 2018

1 commit

  • Pull poll annotations from Al Viro:
    "This introduces a __bitwise type for POLL### bitmap, and propagates
    the annotations through the tree. Most of that stuff is as simple as
    'make ->poll() instances return __poll_t and do the same to local
    variables used to hold the future return value'.

    Some of the obvious brainos found in process are fixed (e.g. POLLIN
    misspelled as POLL_IN). At that point the amount of sparse warnings is
    low and most of them are for genuine bugs - e.g. ->poll() instance
    deciding to return -EINVAL instead of a bitmap. I hadn't touched those
    in this series - it's large enough as it is.

    Another problem it has caught was eventpoll() ABI mess; select.c and
    eventpoll.c assumed that corresponding POLL### and EPOLL### were
    equal. That's true for some, but not all of them - EPOLL### are
    arch-independent, but POLL### are not.

    The last commit in this series separates userland POLL### values from
    the (now arch-independent) kernel-side ones, converting between them
    in the few places where they are copied to/from userland. AFAICS, this
    is the least disruptive fix preserving poll(2) ABI and making epoll()
    work on all architectures.

    As it is, it's simply broken on sparc - try to give it EPOLLWRNORM and
    it will trigger only on what would've triggered EPOLLWRBAND on other
    architectures. EPOLLWRBAND and EPOLLRDHUP, OTOH, are never triggered
    at all on sparc. With this patch they should work consistently on all
    architectures"

    * 'misc.poll' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (37 commits)
    make kernel-side POLL... arch-independent
    eventpoll: no need to mask the result of epi_item_poll() again
    eventpoll: constify struct epoll_event pointers
    debugging printk in sg_poll() uses %x to print POLL... bitmap
    annotate poll(2) guts
    9p: untangle ->poll() mess
    ->si_band gets POLL... bitmap stored into a user-visible long field
    ring_buffer_poll_wait() return value used as return value of ->poll()
    the rest of drivers/*: annotate ->poll() instances
    media: annotate ->poll() instances
    fs: annotate ->poll() instances
    ipc, kernel, mm: annotate ->poll() instances
    net: annotate ->poll() instances
    apparmor: annotate ->poll() instances
    tomoyo: annotate ->poll() instances
    sound: annotate ->poll() instances
    acpi: annotate ->poll() instances
    crypto: annotate ->poll() instances
    block: annotate ->poll() instances
    x86: annotate ->poll() instances
    ...

    Linus Torvalds
     

12 Jan, 2018

1 commit

  • The user space interface allows specifying the type and mask field used
    to allocate the cipher. Only a subset of the possible flags are intended
    for user space. Therefore, white-list the allowed flags.

    In case the user space caller uses at least one non-allowed flag, EINVAL
    is returned.

    Reported-by: syzbot
    Cc:
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

06 Jan, 2018

1 commit

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

    - racy use of ctx->rcvused in af_alg

    - algif_aead crash in chacha20poly1305

    - freeing bogus pointer in pcrypt

    - build error on MIPS in mpi

    - memory leak in inside-secure

    - memory overwrite in inside-secure

    - NULL pointer dereference in inside-secure

    - state corruption in inside-secure

    - build error without CRYPTO_GF128MUL in chelsio

    - use after free in n2"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
    crypto: inside-secure - do not use areq->result for partial results
    crypto: inside-secure - fix request allocations in invalidation path
    crypto: inside-secure - free requests even if their handling failed
    crypto: inside-secure - per request invalidation
    lib/mpi: Fix umul_ppmm() for MIPS64r6
    crypto: pcrypt - fix freeing pcrypt instances
    crypto: n2 - cure use after free
    crypto: af_alg - Fix race around ctx->rcvused by making it atomic_t
    crypto: chacha20poly1305 - validate the digest size
    crypto: chelsio - select CRYPTO_GF128MUL

    Linus Torvalds
     

23 Dec, 2017

1 commit

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

    - fix chacha20 crash on zero-length input due to unset IV

    - fix potential race conditions in mcryptd with spinlock

    - only wait once at top of algif recvmsg to avoid inconsistencies

    - fix potential use-after-free in algif_aead/algif_skcipher"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
    crypto: af_alg - fix race accessing cipher request
    crypto: mcryptd - protect the per-CPU queue with a lock
    crypto: af_alg - wait for data at beginning of recvmsg
    crypto: skcipher - set walk.iv for zero-length inputs

    Linus Torvalds
     

22 Dec, 2017

2 commits


12 Dec, 2017

1 commit

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

    - buffer overread in RSA

    - potential use after free in algif_aead.

    - error path null pointer dereference in af_alg

    - forbid combinations such as hmac(hmac(sha3)) which may crash

    - crash in salsa20 due to incorrect API usage"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
    crypto: salsa20 - fix blkcipher_walk API usage
    crypto: hmac - require that the underlying hash algorithm is unkeyed
    crypto: af_alg - fix NULL pointer dereference in
    crypto: algif_aead - fix reference counting of null skcipher
    crypto: rsa - fix buffer overread when stripping leading zeroes

    Linus Torvalds
     

11 Dec, 2017

1 commit

  • 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: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Reported-by: syzbot
    Cc: # v4.14+
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

29 Nov, 2017

1 commit

  • 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: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Reported-by: syzbot
    Cc: # v4.14+
    Signed-off-by: Eric Biggers
    Reviewed-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Eric Biggers
     

28 Nov, 2017

1 commit


24 Nov, 2017

1 commit

  • 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:
    Fixes: e870456d8e7c8 ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae43 ("crypto: algif_aead - overhaul memory management")
    Reported-by: Romain Izard
    Signed-off-by: Stephan Mueller
    Tested-by: Romain Izard
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

03 Nov, 2017

1 commit


20 Sep, 2017

1 commit

  • When two adjacent TX SGL are processed and parts of both TX SGLs
    are pulled into the per-request TX SGL, the wrong per-request
    TX SGL entries were updated.

    This fixes a NULL pointer dereference when a cipher implementation walks
    the TX SGL where some of the SGL entries were NULL.

    Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory...")
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

22 Aug, 2017

1 commit

  • When a page is assigned to a TX SGL, call get_page to increment the
    reference counter. It is possible that one page is referenced in
    multiple SGLs:

    - in the global TX SGL in case a previous af_alg_pull_tsgl only
    reassigned parts of a page to a per-request TX SGL

    - in the per-request TX SGL as assigned by af_alg_pull_tsgl

    Note, multiple requests can be active at the same time whose TX SGLs all
    point to different parts of the same page.

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

    Stephan Mueller
     

09 Aug, 2017

1 commit

  • Consolidate following data structures:

    skcipher_async_req, aead_async_req -> af_alg_async_req
    skcipher_rsgl, aead_rsql -> af_alg_rsgl
    skcipher_tsgl, aead_tsql -> af_alg_tsgl
    skcipher_ctx, aead_ctx -> af_alg_ctx

    Consolidate following functions:

    skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
    skcipher_writable, aead_writable -> af_alg_writable
    skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
    skcipher_readable, aead_readable -> af_alg_readable
    aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
    aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
    aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
    aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
    aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
    aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
    aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
    aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
    aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
    aead_sendpage, skcipher_sendpage -> af_alg_sendpage
    aead_async_cb, skcipher_async_cb -> af_alg_async_cb
    aead_poll, skcipher_poll -> af_alg_poll

    Split out the following common code from recvmsg:

    af_alg_alloc_areq: allocation of the request data structure for the
    cipher operation

    af_alg_get_rsgl: creation of the RX SGL anchored in the request data
    structure

    The following changes to the implementation without affecting the
    functionality have been applied to synchronize slightly different code
    bases in algif_skcipher and algif_aead:

    The wakeup in af_alg_wait_for_data is triggered when either more data
    is received or the indicator that more data is to be expected is
    released. The first is triggered by user space, the second is
    triggered by the kernel upon finishing the processing of data
    (i.e. the kernel is ready for more).

    af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
    Return code determination is consistent with algif_skcipher. The
    scope of the variable i is reduced to match algif_aead. The type of the
    variable i is switched from int to unsigned int to match algif_aead.

    af_alg_sendpage does not contain the superfluous err = 0 from
    aead_sendpage.

    af_alg_async_cb requires to store the number of output bytes in
    areq->outlen before the AIO callback is triggered.

    The POLLIN / POLLRDNORM is now set when either not more data is given or
    the kernel is supplied with data. This is consistent to the wakeup from
    sleep when the kernel waits for data.

    The request data structure is extended by the field last_rsgl which
    points to the last RX SGL list entry. This shall help recvmsg
    implementation to chain the RX SGL to other SG(L)s if needed. It is
    currently used by algif_aead which chains the tag SGL to the RX SGL
    during decryption.

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

    Stephan Mueller
     

12 Jul, 2017

1 commit

  • crypto: af_alg - Avoid sock_graft call warning

    The newly added sock_graft warning triggers in af_alg_accept.
    It's harmless as we're essentially doing sock->sk = sock->sk.

    The sock_graft call is actually redundant because all the work
    it does is subsumed by sock_init_data. However, it was added
    to placate SELinux as it uses it to initialise its internal state.

    This patch avoisd the warning by making the SELinux call directly.

    Reported-by: Linus Torvalds
    Signed-off-by: Herbert Xu
    Acked-by: David S. Miller

    Herbert Xu
     

10 Apr, 2017

1 commit

  • This patch removes the hard-coded 64-byte limit on the length
    of the algorithm name through bind(2). The address length can
    now exceed that. The user-space structure remains unchanged.
    In order to use a longer name simply extend the salg_name array
    beyond its defined 64 bytes length.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

10 Mar, 2017

1 commit

  • Lockdep issues a circular dependency warning when AFS issues an operation
    through AF_RXRPC from a context in which the VFS/VM holds the mmap_sem.

    The theory lockdep comes up with is as follows:

    (1) If the pagefault handler decides it needs to read pages from AFS, it
    calls AFS with mmap_sem held and AFS begins an AF_RXRPC call, but
    creating a call requires the socket lock:

    mmap_sem must be taken before sk_lock-AF_RXRPC

    (2) afs_open_socket() opens an AF_RXRPC socket and binds it. rxrpc_bind()
    binds the underlying UDP socket whilst holding its socket lock.
    inet_bind() takes its own socket lock:

    sk_lock-AF_RXRPC must be taken before sk_lock-AF_INET

    (3) Reading from a TCP socket into a userspace buffer might cause a fault
    and thus cause the kernel to take the mmap_sem, but the TCP socket is
    locked whilst doing this:

    sk_lock-AF_INET must be taken before mmap_sem

    However, lockdep's theory is wrong in this instance because it deals only
    with lock classes and not individual locks. The AF_INET lock in (2) isn't
    really equivalent to the AF_INET lock in (3) as the former deals with a
    socket entirely internal to the kernel that never sees userspace. This is
    a limitation in the design of lockdep.

    Fix the general case by:

    (1) Double up all the locking keys used in sockets so that one set are
    used if the socket is created by userspace and the other set is used
    if the socket is created by the kernel.

    (2) Store the kern parameter passed to sk_alloc() in a variable in the
    sock struct (sk_kern_sock). This informs sock_lock_init(),
    sock_init_data() and sk_clone_lock() as to the lock keys to be used.

    Note that the child created by sk_clone_lock() inherits the parent's
    kern setting.

    (3) Add a 'kern' parameter to ->accept() that is analogous to the one
    passed in to ->create() that distinguishes whether kernel_accept() or
    sys_accept4() was the caller and can be passed to sk_alloc().

    Note that a lot of accept functions merely dequeue an already
    allocated socket. I haven't touched these as the new socket already
    exists before we get the parameter.

    Note also that there are a couple of places where I've made the accepted
    socket unconditionally kernel-based:

    irda_accept()
    rds_rcp_accept_one()
    tcp_accept_from_sock()

    because they follow a sock_create_kern() and accept off of that.

    Whilst creating this, I noticed that lustre and ocfs don't create sockets
    through sock_create_kern() and thus they aren't marked as for-kernel,
    though they appear to be internal. I wonder if these should do that so
    that they use the new set of lock keys.

    Signed-off-by: David Howells
    Signed-off-by: David S. Miller

    David Howells
     

18 Jan, 2016

1 commit