20 Mar, 2018

1 commit

  • Make a simple helper for matching strings with sysfs
    attribute files. In most parts the same as match_string(),
    except sysfs_match_string() uses sysfs_streq() instead of
    strcmp() for matching. This is more convenient when used
    with sysfs attributes.

    Signed-off-by: Heikki Krogerus
    Reviewed-by: Mika Westerberg
    Reviewed-by: Felipe Balbi
    Tested-by: Guenter Roeck
    Signed-off-by: Greg Kroah-Hartman
    (cherry picked from commit e1fe7b6a7b376bfb54558725ddb2a89aaaa4adcc)

    Heikki Krogerus
     

03 Mar, 2018

1 commit

  • [ Upstream commit bbc25bee37d2b32cf3a1fab9195b6da3a185614a ]

    Current MIPS64r6 toolchains aren't able to generate efficient
    DMULU/DMUHU based code for the C implementation of umul_ppmm(), which
    performs an unsigned 64 x 64 bit multiply and returns the upper and
    lower 64-bit halves of the 128-bit result. Instead it widens the 64-bit
    inputs to 128-bits and emits a __multi3 intrinsic call to perform a 128
    x 128 multiply. This is both inefficient, and it results in a link error
    since we don't include __multi3 in MIPS linux.

    For example commit 90a53e4432b1 ("cfg80211: implement regdb signature
    checking") merged in v4.15-rc1 recently broke the 64r6_defconfig and
    64r6el_defconfig builds by indirectly selecting MPILIB. The same build
    errors can be reproduced on older kernels by enabling e.g. CRYPTO_RSA:

    lib/mpi/generic_mpih-mul1.o: In function `mpihelp_mul_1':
    lib/mpi/generic_mpih-mul1.c:50: undefined reference to `__multi3'
    lib/mpi/generic_mpih-mul2.o: In function `mpihelp_addmul_1':
    lib/mpi/generic_mpih-mul2.c:49: undefined reference to `__multi3'
    lib/mpi/generic_mpih-mul3.o: In function `mpihelp_submul_1':
    lib/mpi/generic_mpih-mul3.c:49: undefined reference to `__multi3'
    lib/mpi/mpih-div.o In function `mpihelp_divrem':
    lib/mpi/mpih-div.c:205: undefined reference to `__multi3'
    lib/mpi/mpih-div.c:142: undefined reference to `__multi3'

    Therefore add an efficient MIPS64r6 implementation of umul_ppmm() using
    inline assembly and the DMULU/DMUHU instructions, to prevent __multi3
    calls being emitted.

    Fixes: 7fd08ca58ae6 ("MIPS: Add build support for the MIPS R6 ISA")
    Signed-off-by: James Hogan
    Cc: Ralf Baechle
    Cc: Herbert Xu
    Cc: "David S. Miller"
    Cc: linux-mips@linux-mips.org
    Cc: linux-crypto@vger.kernel.org
    Signed-off-by: Herbert Xu
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    James Hogan
     

25 Feb, 2018

2 commits

  • commit e7c52b84fb18f08ce49b6067ae6285aca79084a8 upstream.

    We get a lot of very large stack frames using gcc-7.0.1 with the default
    -fsanitize-address-use-after-scope --param asan-stack=1 options, which can
    easily cause an overflow of the kernel stack, e.g.

    drivers/gpu/drm/i915/gvt/handlers.c:2434:1: warning: the frame size of 46176 bytes is larger than 3072 bytes
    drivers/net/wireless/ralink/rt2x00/rt2800lib.c:5650:1: warning: the frame size of 23632 bytes is larger than 3072 bytes
    lib/atomic64_test.c:250:1: warning: the frame size of 11200 bytes is larger than 3072 bytes
    drivers/gpu/drm/i915/gvt/handlers.c:2621:1: warning: the frame size of 9208 bytes is larger than 3072 bytes
    drivers/media/dvb-frontends/stv090x.c:3431:1: warning: the frame size of 6816 bytes is larger than 3072 bytes
    fs/fscache/stats.c:287:1: warning: the frame size of 6536 bytes is larger than 3072 bytes

    To reduce this risk, -fsanitize-address-use-after-scope is now split out
    into a separate CONFIG_KASAN_EXTRA Kconfig option, leading to stack
    frames that are smaller than 2 kilobytes most of the time on x86_64. An
    earlier version of this patch also prevented combining KASAN_EXTRA with
    KASAN_INLINE, but that is no longer necessary with gcc-7.0.1.

    All patches to get the frame size below 2048 bytes with CONFIG_KASAN=y
    and CONFIG_KASAN_EXTRA=n have been merged by maintainers now, so we can
    bring back that default now. KASAN_EXTRA=y still causes lots of
    warnings but now defaults to !COMPILE_TEST to disable it in
    allmodconfig, and it remains disabled in all other defconfigs since it
    is a new option. I arbitrarily raise the warning limit for KASAN_EXTRA
    to 3072 to reduce the noise, but an allmodconfig kernel still has around
    50 warnings on gcc-7.

    I experimented a bit more with smaller stack frames and have another
    follow-up series that reduces the warning limit for 64-bit architectures
    to 1280 bytes (without CONFIG_KASAN).

    With earlier versions of this patch series, I also had patches to address
    the warnings we get with KASAN and/or KASAN_EXTRA, using a
    "noinline_if_stackbloat" annotation.

    That annotation now got replaced with a gcc-8 bugfix (see
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715) and a workaround for
    older compilers, which means that KASAN_EXTRA is now just as bad as
    before and will lead to an instant stack overflow in a few extreme
    cases.

    This reverts parts of commit 3f181b4d8652 ("lib/Kconfig.debug: disable
    -Wframe-larger-than warnings with KASAN=y"). Two patches in linux-next
    should be merged first to avoid introducing warnings in an allmodconfig
    build:
    3cd890dbe2a4 ("media: dvb-frontends: fix i2c access helpers for KASAN")
    16c3ada89cff ("media: r820t: fix r820t_write_reg for KASAN")

    Do we really need to backport this?

    I think we do: without this patch, enabling KASAN will lead to
    unavoidable kernel stack overflow in certain device drivers when built
    with gcc-7 or higher on linux-4.10+ or any version that contains a
    backport of commit c5caf21ab0cf8. Most people are probably still on
    older compilers, but it will get worse over time as they upgrade their
    distros.

    The warnings we get on kernels older than this should all be for code
    that uses dangerously large stack frames, though most of them do not
    cause an actual stack overflow by themselves.The asan-stack option was
    added in linux-4.0, and commit 3f181b4d8652 ("lib/Kconfig.debug:
    disable -Wframe-larger-than warnings with KASAN=y") effectively turned
    off the warning for allmodconfig kernels, so I would like to see this
    fix backported to any kernels later than 4.0.

    I have done dozens of fixes for individual functions with stack frames
    larger than 2048 bytes with asan-stack, and I plan to make sure that
    all those fixes make it into the stable kernels as well (most are
    already there).

    Part of the complication here is that asan-stack (from 4.0) was
    originally assumed to always require much larger stacks, but that
    turned out to be a combination of multiple gcc bugs that we have now
    worked around and fixed, but sanitize-address-use-after-scope (from
    v4.10) has a much higher inherent stack usage and also suffers from at
    least three other problems that we have analyzed but not yet fixed
    upstream, each of them makes the stack usage more severe than it should
    be.

    Link: http://lkml.kernel.org/r/20171221134744.2295529-1-arnd@arndb.de
    Signed-off-by: Arnd Bergmann
    Acked-by: Andrey Ryabinin
    Cc: Mauro Carvalho Chehab
    Cc: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: Dmitry Vyukov
    Cc: Andrey Konovalov
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    [arnd: rebase to v4.9; only re-enable warning]
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Greg Kroah-Hartman

    Arnd Bergmann
     
  • [ Upstream commit 8dfd2f22d3bf3ab7714f7495ad5d897b8845e8c1 ]

    Callers of sprint_oid() do not check its return value before printing
    the result. In the case where the OID is zero-length, -EBADMSG was
    being returned without anything being written to the buffer, resulting
    in uninitialized stack memory being printed. Fix this by writing
    "(bad)" to the buffer in the cases where -EBADMSG is returned.

    Fixes: 4f73175d0375 ("X.509: Add utility functions to render OIDs as strings")
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

17 Feb, 2018

2 commits

  • commit 42440c1f9911b4b7b8ba3dc4e90c1197bc561211 upstream.

    UBSAN=y fails to build with new GCC/clang:

    arch/x86/kernel/head64.o: In function `sanitize_boot_params':
    arch/x86/include/asm/bootparam_utils.h:37: undefined reference to `__ubsan_handle_type_mismatch_v1'

    because Clang and GCC 8 slightly changed ABI for 'type mismatch' errors.
    Compiler now uses new __ubsan_handle_type_mismatch_v1() function with
    slightly modified 'struct type_mismatch_data'.

    Let's add new 'struct type_mismatch_data_common' which is independent from
    compiler's layout of 'struct type_mismatch_data'. And make
    __ubsan_handle_type_mismatch[_v1]() functions transform compiler-dependent
    type mismatch data to our internal representation. This way, we can
    support both old and new compilers with minimal amount of change.

    Link: http://lkml.kernel.org/r/20180119152853.16806-1-aryabinin@virtuozzo.com
    Signed-off-by: Andrey Ryabinin
    Reported-by: Sodagudi Prasad
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Andrey Ryabinin
     
  • commit b8fe1120b4ba342b4f156d24e952d6e686b20298 upstream.

    A vist from the spelling fairy.

    Cc: David Laight
    Cc: Andrey Ryabinin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Andrew Morton
     

31 Jan, 2018

1 commit

  • [ upstream commit 290af86629b25ffd1ed6232c4e9107da031705cb ]

    The BPF interpreter has been used as part of the spectre 2 attack CVE-2017-5715.

    A quote from goolge project zero blog:
    "At this point, it would normally be necessary to locate gadgets in
    the host kernel code that can be used to actually leak data by reading
    from an attacker-controlled location, shifting and masking the result
    appropriately and then using the result of that as offset to an
    attacker-controlled address for a load. But piecing gadgets together
    and figuring out which ones work in a speculation context seems annoying.
    So instead, we decided to use the eBPF interpreter, which is built into
    the host kernel - while there is no legitimate way to invoke it from inside
    a VM, the presence of the code in the host kernel's text section is sufficient
    to make it usable for the attack, just like with ordinary ROP gadgets."

    To make attacker job harder introduce BPF_JIT_ALWAYS_ON config
    option that removes interpreter from the kernel in favor of JIT-only mode.
    So far eBPF JIT is supported by:
    x64, arm64, arm32, sparc64, s390, powerpc64, mips64

    The start of JITed program is randomized and code page is marked as read-only.
    In addition "constant blinding" can be turned on with net.core.bpf_jit_harden

    v2->v3:
    - move __bpf_prog_ret0 under ifdef (Daniel)

    v1->v2:
    - fix init order, test_bpf and cBPF (Daniel's feedback)
    - fix offloaded bpf (Jakub's feedback)
    - add 'return 0' dummy in case something can invoke prog->bpf_func
    - retarget bpf tree. For bpf-next the patch would need one extra hunk.
    It will be sent when the trees are merged back to net-next

    Considered doing:
    int bpf_jit_enable __read_mostly = BPF_EBPF_JIT_DEFAULT;
    but it seems better to land the patch as-is and in bpf-next remove
    bpf_jit_enable global variable from all JITs, consolidate in one place
    and remove this jit_init() function.

    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Greg Kroah-Hartman

    Alexei Starovoitov
     

14 Dec, 2017

4 commits

  • [ Upstream commit 1f3c790bd5989fcfec9e53ad8fa09f5b740c958f ]

    line-range is supposed to treat "1-" as "1-endoffile", so
    handle the special case by setting last_lineno to UINT_MAX.

    Fixes this error:

    dynamic_debug:ddebug_parse_query: last-line:0 < 1st-line:1
    dynamic_debug:ddebug_exec_query: query parse failed

    Link: http://lkml.kernel.org/r/10a6a101-e2be-209f-1f41-54637824788e@infradead.org
    Signed-off-by: Randy Dunlap
    Acked-by: Jason Baron
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     
  • [ Upstream commit 36a3d1dd4e16bcd0d2ddfb4a2ec7092f0ae0d931 ]

    If the amount of resources allocated to a gen_pool exceeds 2^32 then the
    avail atomic overflows and this causes problems when clients try and
    borrow resources from the pool. This is only expected to be an issue on
    64 bit systems.

    Add the header to pull in atomic_long* operations. So
    that 32 bit systems continue to use atomic32_t but 64 bit systems can
    use atomic64_t.

    Link: http://lkml.kernel.org/r/1509033843-25667-1-git-send-email-sbates@raithlin.com
    Signed-off-by: Stephen Bates
    Reviewed-by: Logan Gunthorpe
    Reviewed-by: Mathieu Desnoyers
    Reviewed-by: Daniel Mentz
    Cc: Jonathan Corbet
    Cc: Andrew Morton
    Cc: Will Deacon
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Stephen Bates
     
  • commit 81a7be2cd69b412ab6aeacfe5ebf1bb6e5bce955 upstream.

    asn1_ber_decoder() was ignoring errors from actions associated with the
    opcodes ASN1_OP_END_SEQ_ACT, ASN1_OP_END_SET_ACT,
    ASN1_OP_END_SEQ_OF_ACT, and ASN1_OP_END_SET_OF_ACT. In practice, this
    meant the pkcs7_note_signed_info() action (since that was the only user
    of those opcodes). Fix it by checking for the error, just like the
    decoder does for actions associated with the other opcodes.

    This bug allowed users to leak slab memory by repeatedly trying to add a
    specially crafted "pkcs7_test" key (requires CONFIG_PKCS7_TEST_KEY).

    In theory, this bug could also be used to bypass module signature
    verification, by providing a PKCS#7 message that is misparsed such that
    a signature's ->authattrs do not contain its ->msgdigest. But it
    doesn't seem practical in normal cases, due to restrictions on the
    format of the ->authattrs.

    Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Reviewed-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     
  • commit e0058f3a874ebb48b25be7ff79bc3b4e59929f90 upstream.

    In asn1_ber_decoder(), indefinitely-sized ASN.1 items were being passed
    to the action functions before their lengths had been computed, using
    the bogus length of 0x80 (ASN1_INDEFINITE_LENGTH). This resulted in
    reading data past the end of the input buffer, when given a specially
    crafted message.

    Fix it by rearranging the code so that the indefinite length is resolved
    before the action is called.

    This bug was originally found by fuzzing the X.509 parser in userspace
    using libFuzzer from the LLVM project.

    KASAN report (cleaned up slightly):

    BUG: KASAN: slab-out-of-bounds in memcpy ./include/linux/string.h:341 [inline]
    BUG: KASAN: slab-out-of-bounds in x509_fabricate_name.constprop.1+0x1a4/0x940 crypto/asymmetric_keys/x509_cert_parser.c:366
    Read of size 128 at addr ffff880035dd9eaf by task keyctl/195

    CPU: 1 PID: 195 Comm: keyctl Not tainted 4.14.0-09238-g1d3b78bbc6e9 #26
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
    Call Trace:
    __dump_stack lib/dump_stack.c:17 [inline]
    dump_stack+0xd1/0x175 lib/dump_stack.c:53
    print_address_description+0x78/0x260 mm/kasan/report.c:252
    kasan_report_error mm/kasan/report.c:351 [inline]
    kasan_report+0x23f/0x350 mm/kasan/report.c:409
    memcpy+0x1f/0x50 mm/kasan/kasan.c:302
    memcpy ./include/linux/string.h:341 [inline]
    x509_fabricate_name.constprop.1+0x1a4/0x940 crypto/asymmetric_keys/x509_cert_parser.c:366
    asn1_ber_decoder+0xb4a/0x1fd0 lib/asn1_decoder.c:447
    x509_cert_parse+0x1c7/0x620 crypto/asymmetric_keys/x509_cert_parser.c:89
    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 195:
    __do_kmalloc_node mm/slab.c:3675 [inline]
    __kmalloc_node+0x47/0x60 mm/slab.c:3682
    kvmalloc ./include/linux/mm.h:540 [inline]
    SYSC_add_key security/keys/keyctl.c:104 [inline]
    SyS_add_key+0x19e/0x290 security/keys/keyctl.c:62
    entry_SYSCALL_64_fastpath+0x1f/0x96

    Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
    Reported-by: Alexander Potapenko
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

30 Nov, 2017

1 commit

  • commit 1d9ddde12e3c9bab7f3d3484eb9446315e3571ca upstream.

    On a non-preemptible kernel, if KEYCTL_DH_COMPUTE is called with the
    largest permitted inputs (16384 bits), the kernel spends 10+ seconds
    doing modular exponentiation in mpi_powm() without rescheduling. If all
    threads do it, it locks up the system. Moreover, it can cause
    rcu_sched-stall warnings.

    Notwithstanding the insanity of doing this calculation in kernel mode
    rather than in userspace, fix it by calling cond_resched() as each bit
    from the exponent is processed. It's still noninterruptible, but at
    least it's preemptible now.

    Do the cond_resched() once per bit rather than once per MPI limb because
    each limb might still easily take 100+ milliseconds on slow CPUs.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

15 Nov, 2017

1 commit

  • commit 624f5ab8720b3371367327a822c267699c1823b8 upstream.

    syzkaller reported a NULL pointer dereference in asn1_ber_decoder(). It
    can be reproduced by the following command, assuming
    CONFIG_PKCS7_TEST_KEY=y:

    keyctl add pkcs7_test desc '' @s

    The bug is that if the data buffer is empty, an integer underflow occurs
    in the following check:

    if (unlikely(dp >= datalen - 1))
    goto data_overrun_error;

    This results in the NULL data pointer being dereferenced.

    Fix it by checking for 'datalen - dp < 2' instead.

    Also fix the similar check for 'dp >= datalen - n' later in the same
    function. That one possibly could result in a buffer overread.

    The NULL pointer dereference was reproducible using the "pkcs7_test" key
    type but not the "asymmetric" key type because the "asymmetric" key type
    checks for a 0-length payload before calling into the ASN.1 decoder but
    the "pkcs7_test" key type does not.

    The bug report was:

    BUG: unable to handle kernel NULL pointer dereference at (null)
    IP: asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233
    PGD 7b708067 P4D 7b708067 PUD 7b6ee067 PMD 0
    Oops: 0000 [#1] SMP
    Modules linked in:
    CPU: 0 PID: 522 Comm: syz-executor1 Not tainted 4.14.0-rc8 #7
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.3-20171021_125229-anatol 04/01/2014
    task: ffff9b6b3798c040 task.stack: ffff9b6b37970000
    RIP: 0010:asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233
    RSP: 0018:ffff9b6b37973c78 EFLAGS: 00010216
    RAX: 0000000000000000 RBX: 0000000000000000 RCX: 000000000000021c
    RDX: ffffffff814a04ed RSI: ffffb1524066e000 RDI: ffffffff910759e0
    RBP: ffff9b6b37973d60 R08: 0000000000000001 R09: ffff9b6b3caa4180
    R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000002
    R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
    FS: 00007f10ed1f2700(0000) GS:ffff9b6b3ea00000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000000000000 CR3: 000000007b6f3000 CR4: 00000000000006f0
    Call Trace:
    pkcs7_parse_message+0xee/0x240 crypto/asymmetric_keys/pkcs7_parser.c:139
    verify_pkcs7_signature+0x33/0x180 certs/system_keyring.c:216
    pkcs7_preparse+0x41/0x70 crypto/asymmetric_keys/pkcs7_key_type.c:63
    key_create_or_update+0x180/0x530 security/keys/key.c:855
    SYSC_add_key security/keys/keyctl.c:122 [inline]
    SyS_add_key+0xbf/0x250 security/keys/keyctl.c:62
    entry_SYSCALL_64_fastpath+0x1f/0xbe
    RIP: 0033:0x4585c9
    RSP: 002b:00007f10ed1f1bd8 EFLAGS: 00000216 ORIG_RAX: 00000000000000f8
    RAX: ffffffffffffffda RBX: 00007f10ed1f2700 RCX: 00000000004585c9
    RDX: 0000000020000000 RSI: 0000000020008ffb RDI: 0000000020008000
    RBP: 0000000000000000 R08: ffffffffffffffff R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000216 R12: 00007fff1b2260ae
    R13: 00007fff1b2260af R14: 00007f10ed1f2700 R15: 0000000000000000
    Code: dd ca ff 48 8b 45 88 48 83 e8 01 4c 39 f0 0f 86 a8 07 00 00 e8 53 dd ca ff 49 8d 46 01 48 89 85 58 ff ff ff 48 8b 85 60 ff ff ff 0f b6 0c 30 89 c8 88 8d 75 ff ff ff 83 e0 1f 89 8d 28 ff ff
    RIP: asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233 RSP: ffff9b6b37973c78
    CR2: 0000000000000000

    Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
    Reported-by: syzbot
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

08 Nov, 2017

1 commit

  • commit 2eb9eabf1e868fda15808954fb29b0f105ed65f1 upstream.

    syzkaller with KASAN reported an out-of-bounds read in
    asn1_ber_decoder(). It can be reproduced by the following command,
    assuming CONFIG_X509_CERTIFICATE_PARSER=y and CONFIG_KASAN=y:

    keyctl add asymmetric desc $'\x30\x30' @s

    The bug is that the length of an ASN.1 data value isn't validated in the
    case where it is encoded using the short form, causing the decoder to
    read past the end of the input buffer. Fix it by validating the length.

    The bug report was:

    BUG: KASAN: slab-out-of-bounds in asn1_ber_decoder+0x10cb/0x1730 lib/asn1_decoder.c:233
    Read of size 1 at addr ffff88003cccfa02 by task syz-executor0/6818

    CPU: 1 PID: 6818 Comm: syz-executor0 Not tainted 4.14.0-rc7-00008-g5f479447d983 #2
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
    Call Trace:
    __dump_stack lib/dump_stack.c:16 [inline]
    dump_stack+0xb3/0x10b lib/dump_stack.c:52
    print_address_description+0x79/0x2a0 mm/kasan/report.c:252
    kasan_report_error mm/kasan/report.c:351 [inline]
    kasan_report+0x236/0x340 mm/kasan/report.c:409
    __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:427
    asn1_ber_decoder+0x10cb/0x1730 lib/asn1_decoder.c:233
    x509_cert_parse+0x1db/0x650 crypto/asymmetric_keys/x509_cert_parser.c:89
    x509_key_preparse+0x64/0x7a0 crypto/asymmetric_keys/x509_public_key.c:174
    asymmetric_key_preparse+0xcb/0x1a0 crypto/asymmetric_keys/asymmetric_type.c:388
    key_create_or_update+0x347/0xb20 security/keys/key.c:855
    SYSC_add_key security/keys/keyctl.c:122 [inline]
    SyS_add_key+0x1cd/0x340 security/keys/keyctl.c:62
    entry_SYSCALL_64_fastpath+0x1f/0xbe
    RIP: 0033:0x447c89
    RSP: 002b:00007fca7a5d3bd8 EFLAGS: 00000246 ORIG_RAX: 00000000000000f8
    RAX: ffffffffffffffda RBX: 00007fca7a5d46cc RCX: 0000000000447c89
    RDX: 0000000020006f4a RSI: 0000000020006000 RDI: 0000000020001ff5
    RBP: 0000000000000046 R08: fffffffffffffffd R09: 0000000000000000
    R10: 0000000000000002 R11: 0000000000000246 R12: 0000000000000000
    R13: 0000000000000000 R14: 00007fca7a5d49c0 R15: 00007fca7a5d4700

    Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

02 Nov, 2017

1 commit

  • commit ea6789980fdaa610d7eb63602c746bf6ec70cd2b upstream.

    This fixes CVE-2017-12193.

    Fix a case in the assoc_array implementation in which a new leaf is
    added that needs to go into a node that happens to be full, where the
    existing leaves in that node cluster together at that level to the
    exclusion of new leaf.

    What needs to happen is that the existing leaves get moved out to a new
    node, N1, at level + 1 and the existing node needs replacing with one,
    N0, that has pointers to the new leaf and to N1.

    The code that tries to do this gets this wrong in two ways:

    (1) The pointer that should've pointed from N0 to N1 is set to point
    recursively to N0 instead.

    (2) The backpointer from N0 needs to be set correctly in the case N0 is
    either the root node or reached through a shortcut.

    Fix this by removing this path and using the split_node path instead,
    which achieves the same end, but in a more general way (thanks to Eric
    Biggers for spotting the redundancy).

    The problem manifests itself as:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
    IP: assoc_array_apply_edit+0x59/0xe5

    Fixes: 3cb989501c26 ("Add a generic associative array implementation.")
    Reported-and-tested-by: WU Fan
    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    David Howells
     

27 Oct, 2017

1 commit

  • commit 192cabd6a296cbc57b3d8c05c4c89d87fc102506 upstream.

    digsig_verify() requests a user key, then accesses its payload.
    However, a revoked key has a NULL payload, and we failed to check for
    this. request_key() *does* skip revoked keys, but there is still a
    window where the key can be revoked before we acquire its semaphore.

    Fix it by checking for a NULL payload, treating it like a key which was
    already revoked at the time it was requested.

    Fixes: 051dbb918c7f ("crypto: digital signature verification support")
    Reviewed-by: James Morris
    Cc: Dmitry Kasatkin
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

12 Oct, 2017

1 commit

  • commit 656d61ce9666209c4c4a13c71902d3ee70d1ff6f upstream.

    printk_ratelimit() invokes ___ratelimit() which may invoke a normal
    printk() (pr_warn() in this particular case) to warn about suppressed
    output. Given that printk_ratelimit() may be called from anywhere, that
    pr_warn() is dangerous - it may end up deadlocking the system. Fix
    ___ratelimit() by using deferred printk().

    Sasha reported the following lockdep error:

    : Unregister pv shared memory for cpu 8
    : select_fallback_rq: 3 callbacks suppressed
    : process 8583 (trinity-c78) no longer affine to cpu8
    :
    : ======================================================
    : WARNING: possible circular locking dependency detected
    : 4.14.0-rc2-next-20170927+ #252 Not tainted
    : ------------------------------------------------------
    : migration/8/62 is trying to acquire lock:
    : (&port_lock_key){-.-.}, at: serial8250_console_write()
    :
    : but task is already holding lock:
    : (&rq->lock){-.-.}, at: sched_cpu_dying()
    :
    : which lock already depends on the new lock.
    :
    :
    : the existing dependency chain (in reverse order) is:
    :
    : -> #3 (&rq->lock){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock()
    : task_fork_fair()
    : sched_fork()
    : copy_process.part.31()
    : _do_fork()
    : kernel_thread()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #2 (&p->pi_lock){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : try_to_wake_up()
    : default_wake_function()
    : woken_wake_function()
    : __wake_up_common()
    : __wake_up_common_lock()
    : __wake_up()
    : tty_wakeup()
    : tty_port_default_wakeup()
    : tty_port_tty_wakeup()
    : uart_write_wakeup()
    : serial8250_tx_chars()
    : serial8250_handle_irq.part.25()
    : serial8250_default_handle_irq()
    : serial8250_interrupt()
    : __handle_irq_event_percpu()
    : handle_irq_event_percpu()
    : handle_irq_event()
    : handle_level_irq()
    : handle_irq()
    : do_IRQ()
    : ret_from_intr()
    : native_safe_halt()
    : default_idle()
    : arch_cpu_idle()
    : default_idle_call()
    : do_idle()
    : cpu_startup_entry()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #1 (&tty->write_wait){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : __wake_up_common_lock()
    : __wake_up()
    : tty_wakeup()
    : tty_port_default_wakeup()
    : tty_port_tty_wakeup()
    : uart_write_wakeup()
    : serial8250_tx_chars()
    : serial8250_handle_irq.part.25()
    : serial8250_default_handle_irq()
    : serial8250_interrupt()
    : __handle_irq_event_percpu()
    : handle_irq_event_percpu()
    : handle_irq_event()
    : handle_level_irq()
    : handle_irq()
    : do_IRQ()
    : ret_from_intr()
    : native_safe_halt()
    : default_idle()
    : arch_cpu_idle()
    : default_idle_call()
    : do_idle()
    : cpu_startup_entry()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #0 (&port_lock_key){-.-.}:
    : check_prev_add()
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : serial8250_console_write()
    : univ8250_console_write()
    : console_unlock()
    : vprintk_emit()
    : vprintk_default()
    : vprintk_func()
    : printk()
    : ___ratelimit()
    : __printk_ratelimit()
    : select_fallback_rq()
    : sched_cpu_dying()
    : cpuhp_invoke_callback()
    : take_cpu_down()
    : multi_cpu_stop()
    : cpu_stopper_thread()
    : smpboot_thread_fn()
    : kthread()
    : ret_from_fork()
    :
    : other info that might help us debug this:
    :
    : Chain exists of:
    : &port_lock_key --> &p->pi_lock --> &rq->lock
    :
    : Possible unsafe locking scenario:
    :
    : CPU0 CPU1
    : ---- ----
    : lock(&rq->lock);
    : lock(&p->pi_lock);
    : lock(&rq->lock);
    : lock(&port_lock_key);
    :
    : *** DEADLOCK ***
    :
    : 4 locks held by migration/8/62:
    : #0: (&p->pi_lock){-.-.}, at: sched_cpu_dying()
    : #1: (&rq->lock){-.-.}, at: sched_cpu_dying()
    : #2: (printk_ratelimit_state.lock){....}, at: ___ratelimit()
    : #3: (console_lock){+.+.}, at: vprintk_emit()
    :
    : stack backtrace:
    : CPU: 8 PID: 62 Comm: migration/8 Not tainted 4.14.0-rc2-next-20170927+ #252
    : Call Trace:
    : dump_stack()
    : print_circular_bug()
    : check_prev_add()
    : ? add_lock_to_list.isra.26()
    : ? check_usage()
    : ? kvm_clock_read()
    : ? kvm_sched_clock_read()
    : ? sched_clock()
    : ? check_preemption_disabled()
    : __lock_acquire()
    : ? __lock_acquire()
    : ? add_lock_to_list.isra.26()
    : ? debug_check_no_locks_freed()
    : ? memcpy()
    : lock_acquire()
    : ? serial8250_console_write()
    : _raw_spin_lock_irqsave()
    : ? serial8250_console_write()
    : serial8250_console_write()
    : ? serial8250_start_tx()
    : ? lock_acquire()
    : ? memcpy()
    : univ8250_console_write()
    : console_unlock()
    : ? __down_trylock_console_sem()
    : vprintk_emit()
    : vprintk_default()
    : vprintk_func()
    : printk()
    : ? show_regs_print_info()
    : ? lock_acquire()
    : ___ratelimit()
    : __printk_ratelimit()
    : select_fallback_rq()
    : sched_cpu_dying()
    : ? sched_cpu_starting()
    : ? rcutree_dying_cpu()
    : ? sched_cpu_starting()
    : cpuhp_invoke_callback()
    : ? cpu_disable_common()
    : take_cpu_down()
    : ? trace_hardirqs_off_caller()
    : ? cpuhp_invoke_callback()
    : multi_cpu_stop()
    : ? __this_cpu_preempt_check()
    : ? cpu_stop_queue_work()
    : cpu_stopper_thread()
    : ? cpu_stop_create()
    : smpboot_thread_fn()
    : ? sort_range()
    : ? schedule()
    : ? __kthread_parkme()
    : kthread()
    : ? sort_range()
    : ? kthread_create_on_node()
    : ret_from_fork()
    : process 9121 (trinity-c78) no longer affine to cpu8
    : smpboot: CPU 8 is now offline

    Link: http://lkml.kernel.org/r/20170928120405.18273-1-sergey.senozhatsky@gmail.com
    Fixes: 6b1d174b0c27b ("ratelimit: extend to print suppressed messages on release")
    Signed-off-by: Sergey Senozhatsky
    Reported-by: Sasha Levin
    Reviewed-by: Petr Mladek
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Borislav Petkov
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Sergey Senozhatsky
     

07 Sep, 2017

1 commit

  • commit dea3eb8b452e36cf2dd572b0a797915ccf452ae6 upstream.

    Using sg_miter_start and sg_miter_next, the buffer of an SG is kmap'ed
    to *buff. The current code calls sg_miter_stop (and thus kunmap) on the
    SG entry before the last access of *buff.

    The patch moves the sg_miter_stop call after the last access to *buff to
    ensure that the memory pointed to by *buff is still mapped.

    Fixes: 4816c9406430 ("lib/mpi: Fix SG miter leak")
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Stephan Mueller
     

02 Sep, 2017

1 commit

  • When building lz4 under gcc-7 we get the following bogus warning:

    CC [M] lib/lz4/lz4hc_compress.o
    lib/lz4/lz4hc_compress.c: In function ‘lz4hc_compress’:
    lib/lz4/lz4hc_compress.c:179:42: warning: ‘delta’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    chaintable[(size_t)(ptr) & MAXD_MASK] = delta;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    lib/lz4/lz4hc_compress.c:134:6: note: ‘delta’ was declared here
    u16 delta;
    ^~~~~

    This doesn't show up in the 4.4-stable tree due to us turning off
    warnings like this. It also doesn't show up in newer kernel versions as
    this code was totally rewritten.

    So for now, to get the 4.9-stable tree to build with 0 warnings on x86
    allmodconfig, let's just shut the compiler up by initializing the
    variable to 0, despite it not really doing anything.

    To be far, this code is crazy complex, so the fact that gcc can't
    determine if the variable is really used or not isn't that bad, I'd
    blame the code here instead of the compiler.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

11 Aug, 2017

1 commit

  • [ Upstream commit da0510c47519fe0999cffe316e1d370e29f952be ]

    The build of frv allmodconfig was failing with the errors like:

    /tmp/cc0JSPc3.s: Assembler messages:
    /tmp/cc0JSPc3.s:1839: Error: symbol `.LSLT0' is already defined
    /tmp/cc0JSPc3.s:1842: Error: symbol `.LASLTP0' is already defined
    /tmp/cc0JSPc3.s:1969: Error: symbol `.LELTP0' is already defined
    /tmp/cc0JSPc3.s:1970: Error: symbol `.LELT0' is already defined

    Commit 866ced950bcd ("kbuild: Support split debug info v4") introduced
    splitting the debug info and keeping that in a separate file. Somehow,
    the frv-linux gcc did not like that and I am guessing that instead of
    splitting it started copying. The first report about this is at:

    https://lists.01.org/pipermail/kbuild-all/2015-July/010527.html.

    I will try and see if this can work with frv and if still fails I will
    open a bug report with gcc. But meanwhile this is the easiest option to
    solve build failure of frv.

    Fixes: 866ced950bcd ("kbuild: Support split debug info v4")
    Link: http://lkml.kernel.org/r/1482062348-5352-1-git-send-email-sudipm.mukherjee@gmail.com
    Signed-off-by: Sudip Mukherjee
    Reported-by: Fengguang Wu
    Cc: Andi Kleen
    Cc: David Howells
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Sudip Mukherjee
     

21 Jul, 2017

1 commit

  • commit c6508a39640b9a27fc2bc10cb708152672c82045 upstream.

    commit c743f0a5c50f2fcbc628526279cfa24f3dabe182 upstream.

    More users for for_each_cpu_wrap() have appeared. Promote the construct
    to generic cpumask interface.

    The implementation is slightly modified to reduce arguments.

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Lauro Ramos Venancio
    Cc: Linus Torvalds
    Cc: Mike Galbraith
    Cc: Peter Zijlstra
    Cc: Rik van Riel
    Cc: Thomas Gleixner
    Cc: lwang@redhat.com
    Link: http://lkml.kernel.org/r/20170414122005.o35me2h5nowqkxbv@hirez.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar
    Signed-off-by: Mel Gorman
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Peter Zijlstra
     

05 Jul, 2017

1 commit

  • [ Upstream commit 602d9858f07c72eab64f5f00e2fae55f9902cfbe ]

    Some drivers do depend on page mappings to be page aligned.

    Swiotlb already enforces such alignment for mappings greater than page,
    extend that to page-sized mappings as well.

    Without this fix, nvme hits BUG() in nvme_setup_prps(), because that routine
    assumes page-aligned mappings.

    Signed-off-by: Nikita Yushchenko
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Sagi Grimberg
    Signed-off-by: Konrad Rzeszutek Wilk
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Nikita Yushchenko
     

29 Jun, 2017

1 commit

  • commit a91e0f680bcd9e10c253ae8b62462a38bd48f09f upstream.

    When using get_options() it's possible to specify a range of numbers,
    like 1-100500. The problem is that it doesn't track array size while
    calling internally to get_range() which iterates over the range and
    fills the memory with numbers.

    Link: http://lkml.kernel.org/r/2613C75C-B04D-4BFF-82A6-12F97BA0F620@gmail.com
    Signed-off-by: Ilya V. Matveychikov
    Cc: Jonathan Corbet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Ilya Matveychikov
     

24 Jun, 2017

1 commit

  • commit d41519a69b35b10af7fda867fb9100df24fdf403 upstream.

    On sparc, if we have an alloca() like situation, as is the case with
    SHASH_DESC_ON_STACK(), we can end up referencing deallocated stack
    memory. The result can be that the value is clobbered if a trap
    or interrupt arrives at just the right instruction.

    It only occurs if the function ends returning a value from that
    alloca() area and that value can be placed into the return value
    register using a single instruction.

    For example, in lib/libcrc32c.c:crc32c() we end up with a return
    sequence like:

    return %i7+8
    lduw [%o5+16], %o0 ! MEM[(u32 *)__shash_desc.1_10 + 16B],

    %o5 holds the base of the on-stack area allocated for the shash
    descriptor. But the return released the stack frame and the
    register window.

    So if an intererupt arrives between 'return' and 'lduw', then
    the value read at %o5+16 can be corrupted.

    Add a data compiler barrier to work around this problem. This is
    exactly what the gcc fix will end up doing as well, and it absolutely
    should not change the code generated for other cpus (unless gcc
    on them has the same bug :-)

    With crucial insight from Eric Sandeen.

    Reported-by: Anatoly Pugachev
    Signed-off-by: David S. Miller
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    David Miller
     

14 Jun, 2017

1 commit

  • commit f5f893c57e37ca730808cb2eee3820abd05e7507 upstream.

    Under SMAP/PAN/etc, we cannot write directly to userspace memory, so
    this rearranges the test bytes to get written through copy_to_user().
    Additionally drops the bad copy_from_user() test that would trigger a
    memcpy() against userspace on failure.

    [arnd: the test module was added in 3.14, and this backported patch
    should apply cleanly on all version from 3.14 to 4.10.
    The original patch was in 4.11 on top of a context change
    I saw the bug triggered with kselftest on a 4.4.y stable kernel]

    Signed-off-by: Kees Cook
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

14 May, 2017

1 commit

  • [ Upstream commit ddc665a4bb4b728b4e6ecec8db1b64efa9184b9c ]

    When the instruction right before the branch destination is
    a 64 bit load immediate, we currently calculate the wrong
    jump offset in the ctx->offset[] array as we only account
    one instruction slot for the 64 bit load immediate although
    it uses two BPF instructions. Fix it up by setting the offset
    into the right slot after we incremented the index.

    Before (ldimm64 test 1):

    [...]
    00000020: 52800007 mov w7, #0x0 // #0
    00000024: d2800060 mov x0, #0x3 // #3
    00000028: d2800041 mov x1, #0x2 // #2
    0000002c: eb01001f cmp x0, x1
    00000030: 54ffff82 b.cs 0x00000020
    00000034: d29fffe7 mov x7, #0xffff // #65535
    00000038: f2bfffe7 movk x7, #0xffff, lsl #16
    0000003c: f2dfffe7 movk x7, #0xffff, lsl #32
    00000040: f2ffffe7 movk x7, #0xffff, lsl #48
    00000044: d29dddc7 mov x7, #0xeeee // #61166
    00000048: f2bdddc7 movk x7, #0xeeee, lsl #16
    0000004c: f2ddddc7 movk x7, #0xeeee, lsl #32
    00000050: f2fdddc7 movk x7, #0xeeee, lsl #48
    [...]

    After (ldimm64 test 1):

    [...]
    00000020: 52800007 mov w7, #0x0 // #0
    00000024: d2800060 mov x0, #0x3 // #3
    00000028: d2800041 mov x1, #0x2 // #2
    0000002c: eb01001f cmp x0, x1
    00000030: 540000a2 b.cs 0x00000044
    00000034: d29fffe7 mov x7, #0xffff // #65535
    00000038: f2bfffe7 movk x7, #0xffff, lsl #16
    0000003c: f2dfffe7 movk x7, #0xffff, lsl #32
    00000040: f2ffffe7 movk x7, #0xffff, lsl #48
    00000044: d29dddc7 mov x7, #0xeeee // #61166
    00000048: f2bdddc7 movk x7, #0xeeee, lsl #16
    0000004c: f2ddddc7 movk x7, #0xeeee, lsl #32
    00000050: f2fdddc7 movk x7, #0xeeee, lsl #48
    [...]

    Also, add a couple of test cases to make sure JITs pass
    this test. Tested on Cavium ThunderX ARMv8. The added
    test cases all pass after the fix.

    Fixes: 8eee539ddea0 ("arm64: bpf: fix out-of-bounds read in bpf2a64_offset()")
    Reported-by: David S. Miller
    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Cc: Xi Wang
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Daniel Borkmann
     

21 Apr, 2017

1 commit

  • commit 27c0e3748e41ca79171ffa3e97415a20af6facd0 upstream.

    opposite to iov_iter_advance(); the caller is responsible for never
    using it to move back past the initial position.

    Signed-off-by: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Al Viro
     

08 Apr, 2017

1 commit

  • commit 854fbd6e5f60fe99e8e3a569865409fca378f143 upstream.

    Commit:

    aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")

    ... added logic to handle a process stack not existing, but left sp and pc
    uninitialized, which can be later reported via /proc/$pid/syscall for zombie
    processes, potentially exposing kernel memory to userspace.

    Zombie /proc/$pid/syscall before:
    -1 0xffffffff9a060100 0xffff92f42d6ad900

    Zombie /proc/$pid/syscall after:
    -1 0x0 0x0

    Reported-by: Robert Święcki
    Signed-off-by: Kees Cook
    Reviewed-by: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Fixes: aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")
    Link: http://lkml.kernel.org/r/20170323224616.GA92694@beast
    Signed-off-by: Ingo Molnar
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

26 Jan, 2017

2 commits

  • commit fff5d99225107f5f13fe4a9805adc2a1c4b5fb00 upstream.

    On architectures like arm64, swiotlb is tied intimately to the core
    architecture DMA support. In addition, ZONE_DMA cannot be disabled.

    To aid debugging and catch devices not supporting DMA to memory outside
    the 32-bit address space, add a kernel command line option
    "swiotlb=noforce", which disables the use of bounce buffers.
    If specified, trying to map memory that cannot be used with DMA will
    fail, and a rate-limited warning will be printed.

    Note that io_tlb_nslabs is set to 1, which is the minimal supported
    value.

    Signed-off-by: Geert Uytterhoeven
    Signed-off-by: Konrad Rzeszutek Wilk
    Signed-off-by: Greg Kroah-Hartman

    Geert Uytterhoeven
     
  • commit ae7871be189cb41184f1e05742b4a99e2c59774d upstream.

    Convert the flag swiotlb_force from an int to an enum, to prepare for
    the advent of more possible values.

    Suggested-by: Konrad Rzeszutek Wilk
    Signed-off-by: Geert Uytterhoeven
    Signed-off-by: Konrad Rzeszutek Wilk
    Signed-off-by: Greg Kroah-Hartman

    Geert Uytterhoeven
     

20 Jan, 2017

1 commit

  • commit b9dc6f65bc5e232d1c05fe34b5daadc7e8bbf1fb upstream.

    The logics in pipe_advance() used to release all buffers past the new
    position failed in cases when the number of buffers to release was equal
    to pipe->buffers. If that happened, none of them had been released,
    leaving pipe full. Worse, it was trivial to trigger and we end up with
    pipe full of uninitialized pages. IOW, it's an infoleak.

    Reported-by: "Alan J. Wylie"
    Tested-by: "Alan J. Wylie"
    Signed-off-by: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Al Viro
     

10 Dec, 2016

1 commit

  • This reverts commit 53855d10f4567a0577360b6448d52a863929775b.

    It shouldn't have come in yet - it depends on the changes in linux-next
    that will come in during the next merge window. As Matthew Wilcox says,
    the test suite is broken with the current state without the revert.

    Requested-by: Matthew Wilcox
    Cc: Andrew Morton
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

08 Dec, 2016

2 commits

  • Patch "lib/radix-tree: Convert to hotplug state machine" breaks the test
    suite as it adds a call to cpuhp_setup_state_nocalls() which is not
    currently emulated in the test suite. Add it, and delete the emulation
    of the old CPU hotplug mechanism.

    Link: http://lkml.kernel.org/r/1480369871-5271-36-git-send-email-mawilcox@linuxonhyperv.com
    Signed-off-by: Matthew Wilcox
    Tested-by: Kirill A. Shutemov
    Cc: Konstantin Khlebnikov
    Cc: Ross Zwisler
    Cc: Matthew Wilcox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Matthew Wilcox
     
  • Pull locking fixes from Ingo Molnar:
    "Two rtmutex race fixes (which miraculously never triggered, that we
    know of), plus two lockdep printk formatting regression fixes"

    * 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
    lockdep: Fix report formatting
    locking/rtmutex: Use READ_ONCE() in rt_mutex_owner()
    locking/rtmutex: Prevent dequeue vs. unlock race
    locking/selftest: Fix output since KERN_CONT changes

    Linus Torvalds
     

01 Dec, 2016

2 commits

  • Gcc revision 241896 implements use-after-scope detection. Will be
    available in gcc 7. Support it in KASAN.

    Gcc emits 2 new callbacks to poison/unpoison large stack objects when
    they go in/out of scope. Implement the callbacks and add a test.

    [dvyukov@google.com: v3]
    Link: http://lkml.kernel.org/r/1479998292-144502-1-git-send-email-dvyukov@google.com
    Link: http://lkml.kernel.org/r/1479226045-145148-1-git-send-email-dvyukov@google.com
    Signed-off-by: Dmitry Vyukov
    Acked-by: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: [4.0+]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dmitry Vyukov
     
  • Drivers, or other modules, that use a mixture of objects (especially
    objects embedded within other objects) would like to take advantage of
    the debugobjects facilities to help catch misuse. Currently, the
    debugobjects interface is only available to builtin drivers and requires
    a set of EXPORT_SYMBOL_GPL for use by modules.

    I am using the debugobjects in i915.ko to try and catch some invalid
    operations on embedded objects. The problem currently only presents
    itself across module unload so forcing i915 to be builtin is not an
    option.

    Link: http://lkml.kernel.org/r/20161122143039.6433-1-chris@chris-wilson.co.uk
    Signed-off-by: Chris Wilson
    Cc: "Du, Changbin"
    Cc: Thomas Gleixner
    Cc: Christian Borntraeger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chris Wilson
     

25 Nov, 2016

2 commits

  • Since the KERN_CONT changes the locking-selftest output is messed up, eg:

    ----------------------------------------------------------------------------
    | spin |wlock |rlock |mutex | wsem | rsem |
    --------------------------------------------------------------------------
    A-A deadlock:
    ok |
    ok |
    ok |
    ok |
    ok |
    ok |

    Use pr_cont() to get it looking normal again:

    ----------------------------------------------------------------------------
    | spin |wlock |rlock |mutex | wsem | rsem |
    --------------------------------------------------------------------------
    A-A deadlock: ok | ok | ok | ok | ok | ok |

    Reported-by: Christian Kujau
    Signed-off-by: Michael Ellerman
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: linuxppc-dev@ozlabs.org
    Link: http://lkml.kernel.org/r/1480027528-934-1-git-send-email-mpe@ellerman.id.au
    Signed-off-by: Ingo Molnar

    Michael Ellerman
     
  • This fixes CVE-2016-8650.

    If mpi_powm() is given a zero exponent, it wants to immediately return
    either 1 or 0, depending on the modulus. However, if the result was
    initalised with zero limb space, no limbs space is allocated and a
    NULL-pointer exception ensues.

    Fix this by allocating a minimal amount of limb space for the result when
    the 0-exponent case when the result is 1 and not touching the limb space
    when the result is 0.

    This affects the use of RSA keys and X.509 certificates that carry them.

    BUG: unable to handle kernel NULL pointer dereference at (null)
    IP: [] mpi_powm+0x32/0x7e6
    PGD 0
    Oops: 0002 [#1] SMP
    Modules linked in:
    CPU: 3 PID: 3014 Comm: keyctl Not tainted 4.9.0-rc6-fscache+ #278
    Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014
    task: ffff8804011944c0 task.stack: ffff880401294000
    RIP: 0010:[] [] mpi_powm+0x32/0x7e6
    RSP: 0018:ffff880401297ad8 EFLAGS: 00010212
    RAX: 0000000000000000 RBX: ffff88040868bec0 RCX: ffff88040868bba0
    RDX: ffff88040868b260 RSI: ffff88040868bec0 RDI: ffff88040868bee0
    RBP: ffff880401297ba8 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000047 R11: ffffffff8183b210 R12: 0000000000000000
    R13: ffff8804087c7600 R14: 000000000000001f R15: ffff880401297c50
    FS: 00007f7a7918c700(0000) GS:ffff88041fb80000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000000000000 CR3: 0000000401250000 CR4: 00000000001406e0
    Stack:
    ffff88040868bec0 0000000000000020 ffff880401297b00 ffffffff81376cd4
    0000000000000100 ffff880401297b10 ffffffff81376d12 ffff880401297b30
    ffffffff81376f37 0000000000000100 0000000000000000 ffff880401297ba8
    Call Trace:
    [] ? __sg_page_iter_next+0x43/0x66
    [] ? sg_miter_get_next_page+0x1b/0x5d
    [] ? sg_miter_next+0x17/0xbd
    [] ? mpi_read_raw_from_sgl+0xf2/0x146
    [] rsa_verify+0x9d/0xee
    [] ? pkcs1pad_sg_set_buf+0x2e/0xbb
    [] pkcs1pad_verify+0xc0/0xe1
    [] public_key_verify_signature+0x1b0/0x228
    [] x509_check_for_self_signed+0xa1/0xc4
    [] x509_cert_parse+0x167/0x1a1
    [] x509_key_preparse+0x21/0x1a1
    [] asymmetric_key_preparse+0x34/0x61
    [] key_create_or_update+0x145/0x399
    [] SyS_add_key+0x154/0x19e
    [] do_syscall_64+0x80/0x191
    [] entry_SYSCALL64_slow_path+0x25/0x25
    Code: 56 41 55 41 54 53 48 81 ec a8 00 00 00 44 8b 71 04 8b 42 04 4c 8b 67 18 45 85 f6 89 45 80 0f 84 b4 06 00 00 85 c0 75 2f 41 ff ce c7 04 24 01 00 00 00 b0 01 75 0b 48 8b 41 18 48 83 38 01 0f
    RIP [] mpi_powm+0x32/0x7e6
    RSP
    CR2: 0000000000000000
    ---[ end trace d82015255d4a5d8d ]---

    Basically, this is a backport of a libgcrypt patch:

    http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=patch;h=6e1adb05d290aeeb1c230c763970695f4a538526

    Fixes: cdec9cb5167a ("crypto: GnuPG based MPI lib - source files (part 1)")
    Signed-off-by: Andrey Ryabinin
    Signed-off-by: David Howells
    cc: Dmitry Kasatkin
    cc: linux-ima-devel@lists.sourceforge.net
    cc: stable@vger.kernel.org
    Signed-off-by: James Morris

    Andrey Ryabinin
     

22 Nov, 2016

1 commit

  • Pull sparc fixes from David Miller:

    1) With modern networking cards we can run out of 32-bit DMA space, so
    support 64-bit DMA addressing when possible on sparc64. From Dave
    Tushar.

    2) Some signal frame validation checks are inverted on sparc32, fix
    from Andreas Larsson.

    3) Lockdep tables can get too large in some circumstances on sparc64,
    add a way to adjust the size a bit. From Babu Moger.

    4) Fix NUMA node probing on some sun4v systems, from Thomas Tai.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc:
    sparc: drop duplicate header scatterlist.h
    lockdep: Limit static allocations if PROVE_LOCKING_SMALL is defined
    config: Adding the new config parameter CONFIG_PROVE_LOCKING_SMALL for sparc
    sunbmac: Fix compiler warning
    sunqe: Fix compiler warnings
    sparc64: Enable 64-bit DMA
    sparc64: Enable sun4v dma ops to use IOMMU v2 APIs
    sparc64: Bind PCIe devices to use IOMMU v2 service
    sparc64: Initialize iommu_map_table and iommu_pool
    sparc64: Add ATU (new IOMMU) support
    sparc64: Add FORCE_MAX_ZONEORDER and default to 13
    sparc64: fix compile warning section mismatch in find_node()
    sparc32: Fix inverted invalid_frame_pointer checks on sigreturns
    sparc64: Fix find_node warning if numa node cannot be found

    Linus Torvalds
     

19 Nov, 2016

1 commit

  • This new config parameter limits the space used for "Lock debugging:
    prove locking correctness" by about 4MB. The current sparc systems have
    the limitation of 32MB size for kernel size including .text, .data and
    .bss sections. With PROVE_LOCKING feature, the kernel size could grow
    beyond this limit and causing system boot-up issues. With this option,
    kernel limits the size of the entries of lock_chains, stack_trace etc.,
    so that kernel fits in required size limit. This is not visible to user
    and only used for sparc.

    Signed-off-by: Babu Moger
    Acked-by: Sam Ravnborg
    Signed-off-by: David S. Miller

    Babu Moger