commit 01de23e3018bc24808c658a8399f3896a7f9fbaf
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Tue Aug 13 12:39:34 2019 +0100

    Linux 3.16.72

commit d5534b2998f7c7009e600d57f27f68ed45779da2
Author: Jason Yan <yanaijie@huawei.com>
Date:   Tue Sep 25 10:56:54 2018 +0800

    scsi: libsas: fix a race condition when smp task timeout
    
    commit b90cd6f2b905905fb42671009dc0e27c310a16ae upstream.
    
    When the lldd is processing the complete sas task in interrupt and set the
    task stat as SAS_TASK_STATE_DONE, the smp timeout timer is able to be
    triggered at the same time. And smp_task_timedout() will complete the task
    wheter the SAS_TASK_STATE_DONE is set or not. Then the sas task may freed
    before lldd end the interrupt process. Thus a use-after-free will happen.
    
    Fix this by calling the complete() only when SAS_TASK_STATE_DONE is not
    set. And remove the check of the return value of the del_timer(). Once the
    LLDD sets DONE, it must call task->done(), which will call
    smp_task_done()->complete() and the task will be completed and freed
    correctly.
    
    Reported-by: chenxiang <chenxiang66@hisilicon.com>
    Signed-off-by: Jason Yan <yanaijie@huawei.com>
    CC: John Garry <john.garry@huawei.com>
    CC: Johannes Thumshirn <jthumshirn@suse.de>
    CC: Ewan Milne <emilne@redhat.com>
    CC: Christoph Hellwig <hch@lst.de>
    CC: Tomas Henzl <thenzl@redhat.com>
    CC: Dan Williams <dan.j.williams@intel.com>
    CC: Hannes Reinecke <hare@suse.com>
    Reviewed-by: Hannes Reinecke <hare@suse.com>
    Reviewed-by: John Garry <john.garry@huawei.com>
    Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3d8b3d0384f709126beef6b917b7e97c23f18e74
Author: Florian Westphal <fw@strlen.de>
Date:   Mon Apr 1 13:08:54 2019 +0200

    netfilter: ctnetlink: don't use conntrack/expect object addresses as id
    
    commit 3c79107631db1f7fd32cf3f7368e4672004a3010 upstream.
    
    else, we leak the addresses to userspace via ctnetlink events
    and dumps.
    
    Compute an ID on demand based on the immutable parts of nf_conn struct.
    
    Another advantage compared to using an address is that there is no
    immediate re-use of the same ID in case the conntrack entry is freed and
    reallocated again immediately.
    
    Fixes: 3583240249ef ("[NETFILTER]: nf_conntrack_expect: kill unique ID")
    Fixes: 7f85f914721f ("[NETFILTER]: nf_conntrack: kill unique ID")
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    [bwh: Backported to 3.16:
     - Include <net/netns/hash.h> in nf_conntrack_core.c
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 9ebeec41ed3f52fd94267f25f8b9bf3f4cbf1e4e
Author: Eric Dumazet <edumazet@google.com>
Date:   Wed Mar 27 12:40:33 2019 -0700

    inet: switch IP ID generator to siphash
    
    commit df453700e8d81b1bdafdf684365ee2b9431fb702 upstream.
    
    According to Amit Klein and Benny Pinkas, IP ID generation is too weak
    and might be used by attackers.
    
    Even with recent net_hash_mix() fix (netns: provide pure entropy for net_hash_mix())
    having 64bit key and Jenkins hash is risky.
    
    It is time to switch to siphash and its 128bit keys.
    
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reported-by: Amit Klein <aksecurity@gmail.com>
    Reported-by: Benny Pinkas <benny@pinkas.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a78ff0010f999bc2b0346ec2a89896af3f5c2ca8
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Sun Jan 8 13:54:00 2017 +0100

    siphash: add cryptographically secure PRF
    
    commit 2c956a60778cbb6a27e0c7a8a52a91378c90e1d1 upstream.
    
    SipHash is a 64-bit keyed hash function that is actually a
    cryptographically secure PRF, like HMAC. Except SipHash is super fast,
    and is meant to be used as a hashtable keyed lookup function, or as a
    general PRF for short input use cases, such as sequence numbers or RNG
    chaining.
    
    For the first usage:
    
    There are a variety of attacks known as "hashtable poisoning" in which an
    attacker forms some data such that the hash of that data will be the
    same, and then preceeds to fill up all entries of a hashbucket. This is
    a realistic and well-known denial-of-service vector. Currently
    hashtables use jhash, which is fast but not secure, and some kind of
    rotating key scheme (or none at all, which isn't good). SipHash is meant
    as a replacement for jhash in these cases.
    
    There are a modicum of places in the kernel that are vulnerable to
    hashtable poisoning attacks, either via userspace vectors or network
    vectors, and there's not a reliable mechanism inside the kernel at the
    moment to fix it. The first step toward fixing these issues is actually
    getting a secure primitive into the kernel for developers to use. Then
    we can, bit by bit, port things over to it as deemed appropriate.
    
    While SipHash is extremely fast for a cryptographically secure function,
    it is likely a bit slower than the insecure jhash, and so replacements
    will be evaluated on a case-by-case basis based on whether or not the
    difference in speed is negligible and whether or not the current jhash usage
    poses a real security risk.
    
    For the second usage:
    
    A few places in the kernel are using MD5 or SHA1 for creating secure
    sequence numbers, syn cookies, port numbers, or fast random numbers.
    SipHash is a faster and more fitting, and more secure replacement for MD5
    in those situations. Replacing MD5 and SHA1 with SipHash for these uses is
    obvious and straight-forward, and so is submitted along with this patch
    series. There shouldn't be much of a debate over its efficacy.
    
    Dozens of languages are already using this internally for their hash
    tables and PRFs. Some of the BSDs already use this in their kernels.
    SipHash is a widely known high-speed solution to a widely known set of
    problems, and it's time we catch-up.
    
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
    Reviewed-by: Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Eric Biggers <ebiggers3@gmail.com>
    Cc: David Laight <David.Laight@aculab.com>
    Cc: Eric Dumazet <eric.dumazet@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 6caabe4c7dab391fcd7ee36e6cba75697b9e7871
Author: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date:   Wed Mar 25 17:07:45 2015 +0100

    ipv6: hash net ptr into fragmentation bucket selection
    
    commit 5a352dd0a3aac03b443c94828dfd7144261c8636 upstream.
    
    As namespaces are sometimes used with overlapping ip address ranges,
    we should also use the namespace as input to the hash to select the ip
    fragmentation counter bucket.
    
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Flavio Leitner <fbl@redhat.com>
    Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit dde9f922112630b4509176ce6df872787e0573fb
Author: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date:   Wed Apr 8 17:01:22 2015 +0200

    ipv4: ip_tunnel: use net namespace from rtable not socket
    
    commit 926a882f6916fd76b6f8ee858d45a2241c5e7999 upstream.
    
    The socket parameter might legally be NULL, thus sock_net is sometimes
    causing a NULL pointer dereference. Using net_device pointer in dst_entry
    is more reliable.
    
    Fixes: b6a7719aedd7e5c ("ipv4: hash net ptr into fragmentation bucket selection")
    Reported-by: Rick Jones <rick.jones2@hp.com>
    Cc: Rick Jones <rick.jones2@hp.com>
    Cc: David S. Miller <davem@davemloft.net>
    Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 1c1e2a916e2715188dc0ad492dbe42e6379c1a66
Author: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date:   Wed Mar 25 17:07:44 2015 +0100

    ipv4: hash net ptr into fragmentation bucket selection
    
    commit b6a7719aedd7e5c0f2df7641aa47386111682df4 upstream.
    
    As namespaces are sometimes used with overlapping ip address ranges,
    we should also use the namespace as input to the hash to select the ip
    fragmentation counter bucket.
    
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Flavio Leitner <fbl@redhat.com>
    Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 66d7c265f2b1358c389b825fd017eb82ebbba229
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Thu Mar 19 11:22:32 2015 +0100

    ipv6: call ipv6_proxy_select_ident instead of ipv6_select_ident in udp6_ufo_fragment
    
    commit 8e199dfd82ee097b522b00344af6448715d8ee0c upstream.
    
    Matt Grant reported frequent crashes in ipv6_select_ident when
    udp6_ufo_fragment is called from openvswitch on a skb that doesn't
    have a dst_entry set.
    
    ipv6_proxy_select_ident generates the frag_id without using the dst
    associated with the skb.  This approach was suggested by Vladislav
    Yasevich.
    
    Fixes: 0508c07f5e0c ("ipv6: Select fragment id during UFO segmentation if not set.")
    Cc: Vladislav Yasevich <vyasevic@redhat.com>
    Reported-by: Matt Grant <matt@mattgrant.net.nz>
    Tested-by: Matt Grant <matt@mattgrant.net.nz>
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Acked-by: Vladislav Yasevich <vyasevic@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit dbac56343705df2d24e3588a6ef421d386eda7be
Author: Vlad Yasevich <vyasevich@gmail.com>
Date:   Mon Feb 9 09:38:21 2015 -0500

    ipv6: Make __ipv6_select_ident static
    
    commit 8381eacf5c3b35cf7755f4bc521c4d56d24c1cd9 upstream.
    
    Make __ipv6_select_ident() static as it isn't used outside
    the file.
    
    Fixes: 0508c07f5e0c9 (ipv6: Select fragment id during UFO segmentation if not set.)
    Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 40abf106876af3fef2aea449d1099cd01c5deb19
Author: Vlad Yasevich <vyasevich@gmail.com>
Date:   Mon Feb 9 09:38:20 2015 -0500

    ipv6: Fix fragment id assignment on LE arches.
    
    commit 51f30770e50eb787200f30a79105e2615b379334 upstream.
    
    Recent commit:
    0508c07f5e0c94f38afd5434e8b2a55b84553077
    Author: Vlad Yasevich <vyasevich@gmail.com>
    Date:   Tue Feb 3 16:36:15 2015 -0500
    
        ipv6: Select fragment id during UFO segmentation if not set.
    
    Introduced a bug on LE in how ipv6 fragment id is assigned.
    This was cought by nightly sparce check:
    
    Resolve the following sparce error:
     net/ipv6/output_core.c:57:38: sparse: incorrect type in assignment
     (different base types)
       net/ipv6/output_core.c:57:38:    expected restricted __be32
    [usertype] ip6_frag_id
       net/ipv6/output_core.c:57:38:    got unsigned int [unsigned]
    [assigned] [usertype] id
    
    Fixes: 0508c07f5e0c9 (ipv6: Select fragment id during UFO segmentation if not set.)
    Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 13e380ca38fe5be2f044e8c5559f30e5b6359a58
Author: Vlad Yasevich <vyasevich@gmail.com>
Date:   Tue Feb 3 16:36:16 2015 -0500

    Revert "drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO packets"
    
    commit 72f6510745592c87f612f62ae4f16bb002934df4 upstream.
    
    This reverts commit 5188cd44c55db3e92cd9e77a40b5baa7ed4340f7.
    
    Now that GSO layer can track if fragment id has been selected
    and can allocate one if necessary, we don't need to do this in
    tap and macvtap.  This reverts most of the code and only keeps
    the new ipv6 fragment id generation function that is still needed.
    
    Fixes: 3d0ad09412ff (drivers/net: Disable UFO through virtio)
    Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2e095ca0c58515774e6dd45f1f698682c073237f
Author: Vlad Yasevich <vyasevich@gmail.com>
Date:   Tue Feb 3 16:36:15 2015 -0500

    ipv6: Select fragment id during UFO segmentation if not set.
    
    commit 0508c07f5e0c94f38afd5434e8b2a55b84553077 upstream.
    
    If the IPv6 fragment id has not been set and we perform
    fragmentation due to UFO, select a new fragment id.
    We now consider a fragment id of 0 as unset and if id selection
    process returns 0 (after all the pertrubations), we set it to
    0x80000000, thus giving us ample space not to create collisions
    with the next packet we may have to fragment.
    
    When doing UFO integrity checking, we also select the
    fragment id if it has not be set yet.   This is stored into
    the skb_shinfo() thus allowing UFO to function correclty.
    
    This patch also removes duplicate fragment id generation code
    and moves ipv6_select_ident() into the header as it may be
    used during GSO.
    
    Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 05f4b670242e2b27c95d6eca88ac1fbf79c27a56
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Fri Aug 9 20:09:49 2019 +0100

    Revert "inet: update the IP ID generation algorithm to higher standards."
    
    This reverts commit 8b197d3ce585d6777197e0633d71e5af7d98cb35, which
    was a stable-specific improvement to IP ID selection.  I will apply
    the upstream changes instead.
    
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2ed58e578b03269b23eb7119fb38478725ae6470
Author: Juergen Gross <jgross@suse.com>
Date:   Wed Jun 19 11:00:56 2019 +0200

    xen: let alloc_xenballooned_pages() fail if not enough memory free
    
    commit a1078e821b605813b63bf6bca414a85f804d5c66 upstream.
    
    Instead of trying to allocate pages with GFP_USER in
    add_ballooned_pages() check the available free memory via
    si_mem_available(). GFP_USER is far less limiting memory exhaustion
    than the test via si_mem_available().
    
    This will avoid dom0 running out of memory due to excessive foreign
    page mappings especially on ARM and on x86 in PVH mode, as those don't
    have a pre-ballooned area which can be used for foreign mappings.
    
    As the normal ballooning suffers from the same problem don't balloon
    down more than si_mem_available() pages in one iteration. At the same
    time limit the default maximum number of retries.
    
    This is part of XSA-300.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    [bwh: Backported to 3.16: adjust context, indentation]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 30416b602f90b87f2a93b842b959b6186554ec6e
Author: Igor Redko <redkoi@virtuozzo.com>
Date:   Thu Mar 17 14:19:05 2016 -0700

    mm/page_alloc.c: calculate 'available' memory in a separate function
    
    commit d02bd27bd33dd7e8d22594cd568b81be0cb584cd upstream.
    
    Add a new field, VIRTIO_BALLOON_S_AVAIL, to virtio_balloon memory
    statistics protocol, corresponding to 'Available' in /proc/meminfo.
    
    It indicates to the hypervisor how big the balloon can be inflated
    without pushing the guest system to swap.  This metric would be very
    useful in VM orchestration software to improve memory management of
    different VMs under overcommit.
    
    This patch (of 2):
    
    Factor out calculation of the available memory counter into a separate
    exportable function, in order to be able to use it in other parts of the
    kernel.
    
    In particular, it appears a relevant metric to report to the hypervisor
    via virtio-balloon statistics interface (in a followup patch).
    
    Signed-off-by: Igor Redko <redkoi@virtuozzo.com>
    Signed-off-by: Denis V. Lunev <den@openvz.org>
    Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.16 as dependency of commit a1078e821b60
     "xen: let alloc_xenballooned_pages() fail if not enough memory free"]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit b6c00d28303041dd969a2ec1b75c5b28646ca8eb
Author: Johannes Weiner <hannes@cmpxchg.org>
Date:   Thu Jan 14 15:20:18 2016 -0800

    proc: meminfo: estimate available memory more conservatively
    
    commit 84ad5802a33a4964a49b8f7d24d80a214a096b19 upstream.
    
    The MemAvailable item in /proc/meminfo is to give users a hint of how
    much memory is allocatable without causing swapping, so it excludes the
    zones' low watermarks as unavailable to userspace.
    
    However, for a userspace allocation, kswapd will actually reclaim until
    the free pages hit a combination of the high watermark and the page
    allocator's lowmem protection that keeps a certain amount of DMA and
    DMA32 memory from userspace as well.
    
    Subtract the full amount we know to be unavailable to userspace from the
    number of free pages when calculating MemAvailable.
    
    Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: Mel Gorman <mgorman@suse.de>
    Acked-by: Michal Hocko <mhocko@suse.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 05429983fa0fa3bfa1b8436beb63913d9d4aad1a
Author: Denis Efremov <efremov@ispras.ru>
Date:   Fri Jul 12 21:55:23 2019 +0300

    floppy: fix out-of-bounds read in copy_buffer
    
    commit da99466ac243f15fbba65bd261bfc75ffa1532b6 upstream.
    
    This fixes a global out-of-bounds read access in the copy_buffer
    function of the floppy driver.
    
    The FDDEFPRM ioctl allows one to set the geometry of a disk.  The sect
    and head fields (unsigned int) of the floppy_drive structure are used to
    compute the max_sector (int) in the make_raw_rw_request function.  It is
    possible to overflow the max_sector.  Next, max_sector is passed to the
    copy_buffer function and used in one of the memcpy calls.
    
    An unprivileged user could trigger the bug if the device is accessible,
    but requires a floppy disk to be inserted.
    
    The patch adds the check for the .sect * .head multiplication for not
    overflowing in the set_geometry function.
    
    The bug was found by syzkaller.
    
    Signed-off-by: Denis Efremov <efremov@ispras.ru>
    Tested-by: Willy Tarreau <w@1wt.eu>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fbf6a95d0a3d410ee2f4530e243b77beee87c76a
Author: Denis Efremov <efremov@ispras.ru>
Date:   Fri Jul 12 21:55:22 2019 +0300

    floppy: fix invalid pointer dereference in drive_name
    
    commit 9b04609b784027968348796a18f601aed9db3789 upstream.
    
    This fixes the invalid pointer dereference in the drive_name function of
    the floppy driver.
    
    The native_format field of the struct floppy_drive_params is used as
    floppy_type array index in the drive_name function.  Thus, the field
    should be checked the same way as the autodetect field.
    
    To trigger the bug, one could use a value out of range and set the drive
    parameters with the FDSETDRVPRM ioctl.  Next, FDGETDRVTYP ioctl should
    be used to call the drive_name.  A floppy disk is not required to be
    inserted.
    
    CAP_SYS_ADMIN is required to call FDSETDRVPRM.
    
    The patch adds the check for a value of the native_format field to be in
    the '0 <= x < ARRAY_SIZE(floppy_type)' range of the floppy_type array
    indices.
    
    The bug was found by syzkaller.
    
    Signed-off-by: Denis Efremov <efremov@ispras.ru>
    Tested-by: Willy Tarreau <w@1wt.eu>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.16: Drop changes in compat_setdrvprm(), as compat
     ioctls go via fd_ioctl_locked() after translation in compat_ioctl.c.]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 59fbdf8b65a4f09d8043dded8a4b8e0d603eee27
Author: Denis Efremov <efremov@ispras.ru>
Date:   Fri Jul 12 21:55:21 2019 +0300

    floppy: fix out-of-bounds read in next_valid_format
    
    commit 5635f897ed83fd539df78e98ba69ee91592f9bb8 upstream.
    
    This fixes a global out-of-bounds read access in the next_valid_format
    function of the floppy driver.
    
    The values from autodetect field of the struct floppy_drive_params are
    used as indices for the floppy_type array in the next_valid_format
    function 'floppy_type[DP->autodetect[probed_format]].sect'.
    
    To trigger the bug, one could use a value out of range and set the drive
    parameters with the FDSETDRVPRM ioctl.  A floppy disk is not required to
    be inserted.
    
    CAP_SYS_ADMIN is required to call FDSETDRVPRM.
    
    The patch adds the check for values of the autodetect field to be in the
    '0 <= x < ARRAY_SIZE(floppy_type)' range of the floppy_type array indices.
    
    The bug was found by syzkaller.
    
    Signed-off-by: Denis Efremov <efremov@ispras.ru>
    Tested-by: Willy Tarreau <w@1wt.eu>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.16: Drop changes in compat_setdrvprm(), as compat
     ioctls go via fd_ioctl_locked() after translation in compat_ioctl.c.]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a36b6459cbff32a0ef228241c99d6586ca7e944c
Author: Denis Efremov <efremov@ispras.ru>
Date:   Fri Jul 12 21:55:20 2019 +0300

    floppy: fix div-by-zero in setup_format_params
    
    commit f3554aeb991214cbfafd17d55e2bfddb50282e32 upstream.
    
    This fixes a divide by zero error in the setup_format_params function of
    the floppy driver.
    
    Two consecutive ioctls can trigger the bug: The first one should set the
    drive geometry with such .sect and .rate values for the F_SECT_PER_TRACK
    to become zero.  Next, the floppy format operation should be called.
    
    A floppy disk is not required to be inserted.  An unprivileged user
    could trigger the bug if the device is accessible.
    
    The patch checks F_SECT_PER_TRACK for a non-zero value in the
    set_geometry function.  The proper check should involve a reasonable
    upper limit for the .sect and .rate fields, but it could change the
    UAPI.
    
    The patch also checks F_SECT_PER_TRACK in the setup_format_params, and
    cancels the formatting operation in case of zero.
    
    The bug was found by syzkaller.
    
    Signed-off-by: Denis Efremov <efremov@ispras.ru>
    Tested-by: Willy Tarreau <w@1wt.eu>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 929606ae749185c940a5476d3a0e8d8e7c9c1db6
Author: Michael Neuling <mikey@neuling.org>
Date:   Fri Jul 19 15:05:02 2019 +1000

    powerpc/tm: Fix oops on sigreturn on systems without TM
    
    commit f16d80b75a096c52354c6e0a574993f3b0dfbdfe upstream.
    
    On systems like P9 powernv where we have no TM (or P8 booted with
    ppc_tm=off), userspace can construct a signal context which still has
    the MSR TS bits set. The kernel tries to restore this context which
    results in the following crash:
    
      Unexpected TM Bad Thing exception at c0000000000022fc (msr 0x8000000102a03031) tm_scratch=800000020280f033
      Oops: Unrecoverable exception, sig: 6 [#1]
      LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
      Modules linked in:
      CPU: 0 PID: 1636 Comm: sigfuz Not tainted 5.2.0-11043-g0a8ad0ffa4 #69
      NIP:  c0000000000022fc LR: 00007fffb2d67e48 CTR: 0000000000000000
      REGS: c00000003fffbd70 TRAP: 0700   Not tainted  (5.2.0-11045-g7142b497d8)
      MSR:  8000000102a03031 <SF,VEC,VSX,FP,ME,IR,DR,LE,TM[E]>  CR: 42004242  XER: 00000000
      CFAR: c0000000000022e0 IRQMASK: 0
      GPR00: 0000000000000072 00007fffb2b6e560 00007fffb2d87f00 0000000000000669
      GPR04: 00007fffb2b6e728 0000000000000000 0000000000000000 00007fffb2b6f2a8
      GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
      GPR12: 0000000000000000 00007fffb2b76900 0000000000000000 0000000000000000
      GPR16: 00007fffb2370000 00007fffb2d84390 00007fffea3a15ac 000001000a250420
      GPR20: 00007fffb2b6f260 0000000010001770 0000000000000000 0000000000000000
      GPR24: 00007fffb2d843a0 00007fffea3a14a0 0000000000010000 0000000000800000
      GPR28: 00007fffea3a14d8 00000000003d0f00 0000000000000000 00007fffb2b6e728
      NIP [c0000000000022fc] rfi_flush_fallback+0x7c/0x80
      LR [00007fffb2d67e48] 0x7fffb2d67e48
      Call Trace:
      Instruction dump:
      e96a0220 e96a02a8 e96a0330 e96a03b8 394a0400 4200ffdc 7d2903a6 e92d0c00
      e94d0c08 e96d0c10 e82d0c18 7db242a6 <4c000024> 7db243a6 7db142a6 f82d0c18
    
    The problem is the signal code assumes TM is enabled when
    CONFIG_PPC_TRANSACTIONAL_MEM is enabled. This may not be the case as
    with P9 powernv or if `ppc_tm=off` is used on P8.
    
    This means any local user can crash the system.
    
    Fix the problem by returning a bad stack frame to the user if they try
    to set the MSR TS bits with sigreturn() on systems where TM is not
    supported.
    
    Found with sigfuz kernel selftest on P9.
    
    This fixes CVE-2019-13648.
    
    Fixes: 2b0a576d15e0 ("powerpc: Add new transactional memory state to the signal context")
    Reported-by: Praveen Pandey <Praveen.Pandey@in.ibm.com>
    Signed-off-by: Michael Neuling <mikey@neuling.org>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20190719050502.405-1-mikey@neuling.org
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 754d0ca82fed0ad682e875bea824c348d597ca28
Author: Grant Hernandez <granthernandez@google.com>
Date:   Sat Jul 13 01:00:12 2019 -0700

    Input: gtco - bounds check collection indent level
    
    commit 2a017fd82c5402b3c8df5e3d6e5165d9e6147dc1 upstream.
    
    The GTCO tablet input driver configures itself from an HID report sent
    via USB during the initial enumeration process. Some debugging messages
    are generated during the parsing. A debugging message indentation
    counter is not bounds checked, leading to the ability for a specially
    crafted HID report to cause '-' and null bytes be written past the end
    of the indentation array. As long as the kernel has CONFIG_DYNAMIC_DEBUG
    enabled, this code will not be optimized out.  This was discovered
    during code review after a previous syzkaller bug was found in this
    driver.
    
    Signed-off-by: Grant Hernandez <granthernandez@google.com>
    Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit ebb8302ce770e8c455d9209cb598f4cd03021e42
Author: Vladis Dronov <vdronov@redhat.com>
Date:   Tue Jul 30 11:33:45 2019 +0200

    Bluetooth: hci_uart: check for missing tty operations
    
    commit b36a1552d7319bbfd5cf7f08726c23c5c66d4f73 upstream.
    
    Certain ttys operations (pty_unix98_ops) lack tiocmget() and tiocmset()
    functions which are called by the certain HCI UART protocols (hci_ath,
    hci_bcm, hci_intel, hci_mrvl, hci_qca) via hci_uart_set_flow_control()
    or directly. This leads to an execution at NULL and can be triggered by
    an unprivileged user. Fix this by adding a helper function and a check
    for the missing tty operations in the protocols code.
    
    This fixes CVE-2019-10207. The Fixes: lines list commits where calls to
    tiocm[gs]et() or hci_uart_set_flow_control() were added to the HCI UART
    protocols.
    
    Link: https://syzkaller.appspot.com/bug?id=1b42faa2848963564a5b1b7f8c837ea7b55ffa50
    Reported-by: syzbot+79337b501d6aa974d0f6@syzkaller.appspotmail.com
    Fixes: b3190df62861 ("Bluetooth: Support for Atheros AR300x serial chip")
    Fixes: 118612fb9165 ("Bluetooth: hci_bcm: Add suspend/resume PM functions")
    Fixes: ff2895592f0f ("Bluetooth: hci_intel: Add Intel baudrate configuration support")
    Fixes: 162f812f23ba ("Bluetooth: hci_uart: Add Marvell support")
    Fixes: fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990")
    Signed-off-by: Vladis Dronov <vdronov@redhat.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
    Reviewed-by: Yu-Chen, Cho <acho@suse.com>
    Tested-by: Yu-Chen, Cho <acho@suse.com>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.16:
     - Only hci_ath is affected
     - There is no serdev support]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 6c74f68cf3ca570f39ff8a9e3b0ae357839c4560
Author: Jason Wang <jasowang@redhat.com>
Date:   Fri May 17 00:29:52 2019 -0400

    vhost: scsi: add weight support
    
    commit c1ea02f15ab5efb3e93fc3144d895410bf79fcf2 upstream.
    
    This patch will check the weight and exit the loop if we exceeds the
    weight. This is useful for preventing scsi kthread from hogging cpu
    which is guest triggerable.
    
    This addresses CVE-2019-3900.
    
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Stefan Hajnoczi <stefanha@redhat.com>
    Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver")
    Signed-off-by: Jason Wang <jasowang@redhat.com>
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
    [bwh: Backported to 3.16:
     - Drop changes in vhost_scsi_ctl_handle_vq()
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit f3a64b1071c414e59233b769110872a026f8d254
Author: Jason Wang <jasowang@redhat.com>
Date:   Fri May 17 00:29:50 2019 -0400

    vhost_net: fix possible infinite loop
    
    commit e2412c07f8f3040593dfb88207865a3cd58680c0 upstream.
    
    When the rx buffer is too small for a packet, we will discard the vq
    descriptor and retry it for the next packet:
    
    while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
                                                  &busyloop_intr))) {
    ...
            /* On overrun, truncate and discard */
            if (unlikely(headcount > UIO_MAXIOV)) {
                    iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1);
                    err = sock->ops->recvmsg(sock, &msg,
                                             1, MSG_DONTWAIT | MSG_TRUNC);
                    pr_debug("Discarded rx packet: len %zd\n", sock_len);
                    continue;
            }
    ...
    }
    
    This makes it possible to trigger a infinite while..continue loop
    through the co-opreation of two VMs like:
    
    1) Malicious VM1 allocate 1 byte rx buffer and try to slow down the
       vhost process as much as possible e.g using indirect descriptors or
       other.
    2) Malicious VM2 generate packets to VM1 as fast as possible
    
    Fixing this by checking against weight at the end of RX and TX
    loop. This also eliminate other similar cases when:
    
    - userspace is consuming the packets in the meanwhile
    - theoretical TOCTOU attack if guest moving avail index back and forth
      to hit the continue after vhost find guest just add new buffers
    
    This addresses CVE-2019-3900.
    
    Fixes: d8316f3991d20 ("vhost: fix total length when packets are too short")
    Fixes: 3a4d5c94e9593 ("vhost_net: a kernel-level virtio server")
    Signed-off-by: Jason Wang <jasowang@redhat.com>
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    [bwh: Backported to 3.16:
     - Both Tx modes are handled in one loop in handle_tx()
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2a59b04bcdb2f009906982e711b20bcd40fd253f
Author: Jason Wang <jasowang@redhat.com>
Date:   Fri May 17 00:29:49 2019 -0400

    vhost: introduce vhost_exceeds_weight()
    
    commit e82b9b0727ff6d665fff2d326162b460dded554d upstream.
    
    We used to have vhost_exceeds_weight() for vhost-net to:
    
    - prevent vhost kthread from hogging the cpu
    - balance the time spent between TX and RX
    
    This function could be useful for vsock and scsi as well. So move it
    to vhost.c. Device must specify a weight which counts the number of
    requests, or it can also specific a byte_weight which counts the
    number of bytes that has been processed.
    
    Signed-off-by: Jason Wang <jasowang@redhat.com>
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    [bwh: Backported to 3.16:
     - Drop changes to vhost_vsock
     - In vhost_net, both Tx modes are handled in one loop in handle_tx()
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e22aecb0e563f5e9705dcfb55231fd079041ff1c
Author: Jason Wang <jasowang@redhat.com>
Date:   Fri Jul 20 08:15:15 2018 +0800

    vhost_net: introduce vhost_exceeds_weight()
    
    commit 272f35cba53d088085e5952fd81d7a133ab90789 upstream.
    
    Signed-off-by: Jason Wang <jasowang@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e1c88f2d7b15ef771eb3604ebd66e2ab9be544cd
Author: Paolo Abeni <pabeni@redhat.com>
Date:   Tue Apr 24 10:34:36 2018 +0200

    vhost_net: use packet weight for rx handler, too
    
    commit db688c24eada63b1efe6d0d7d835e5c3bdd71fd3 upstream.
    
    Similar to commit a2ac99905f1e ("vhost-net: set packet weight of
    tx polling to 2 * vq size"), we need a packet-based limit for
    handler_rx, too - elsewhere, under rx flood with small packets,
    tx can be delayed for a very long time, even without busypolling.
    
    The pkt limit applied to handle_rx must be the same applied by
    handle_tx, or we will get unfair scheduling between rx and tx.
    Tying such limit to the queue length makes it less effective for
    large queue length values and can introduce large process
    scheduler latencies, so a constant valued is used - likewise
    the existing bytes limit.
    
    The selected limit has been validated with PVP[1] performance
    test with different queue sizes:
    
    queue size              256     512     1024
    
    baseline                366     354     362
    weight 128              715     723     670
    weight 256              740     745     733
    weight 512              600     460     583
    weight 1024             423     427     418
    
    A packet weight of 256 gives peek performances in under all the
    tested scenarios.
    
    No measurable regression in unidirectional performance tests has
    been detected.
    
    [1] https://developers.redhat.com/blog/2017/06/05/measuring-and-comparing-open-vswitch-performance/
    
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>
    Acked-by: Jason Wang <jasowang@redhat.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 531f2623d039cb524125c76dbaf9e18be2d01e51
Author: haibinzhang(张海斌) <haibinzhang@tencent.com>
Date:   Mon Apr 9 07:22:17 2018 +0000

    vhost-net: set packet weight of tx polling to 2 * vq size
    
    commit a2ac99905f1ea8b15997a6ec39af69aa28a3653b upstream.
    
    handle_tx will delay rx for tens or even hundreds of milliseconds when tx busy
    polling udp packets with small length(e.g. 1byte udp payload), because setting
    VHOST_NET_WEIGHT takes into account only sent-bytes but no single packet length.
    
    Ping-Latencies shown below were tested between two Virtual Machines using
    netperf (UDP_STREAM, len=1), and then another machine pinged the client:
    
    vq size=256
    Packet-Weight   Ping-Latencies(millisecond)
                       min      avg       max
    Origin           3.319   18.489    57.303
    64               1.643    2.021     2.552
    128              1.825    2.600     3.224
    256              1.997    2.710     4.295
    512              1.860    3.171     4.631
    1024             2.002    4.173     9.056
    2048             2.257    5.650     9.688
    4096             2.093    8.508    15.943
    
    vq size=512
    Packet-Weight   Ping-Latencies(millisecond)
                       min      avg       max
    Origin           6.537   29.177    66.245
    64               2.798    3.614     4.403
    128              2.861    3.820     4.775
    256              3.008    4.018     4.807
    512              3.254    4.523     5.824
    1024             3.079    5.335     7.747
    2048             3.944    8.201    12.762
    4096             4.158   11.057    19.985
    
    Seems pretty consistent, a small dip at 2 VQ sizes.
    Ring size is a hint from device about a burst size it can tolerate. Based on
    benchmarks, set the weight to 2 * vq size.
    
    To evaluate this change, another tests were done using netperf(RR, TX) between
    two machines with Intel(R) Xeon(R) Gold 6133 CPU @ 2.50GHz, and vq size was
    tweaked through qemu. Results shown below does not show obvious changes.
    
    vq size=256 TCP_RR                vq size=512 TCP_RR
    size/sessions/+thu%/+normalize%   size/sessions/+thu%/+normalize%
       1/       1/  -7%/        -2%      1/       1/   0%/        -2%
       1/       4/  +1%/         0%      1/       4/  +1%/         0%
       1/       8/  +1%/        -2%      1/       8/   0%/        +1%
      64/       1/  -6%/         0%     64/       1/  +7%/        +3%
      64/       4/   0%/        +2%     64/       4/  -1%/        +1%
      64/       8/   0%/         0%     64/       8/  -1%/        -2%
     256/       1/  -3%/        -4%    256/       1/  -4%/        -2%
     256/       4/  +3%/        +4%    256/       4/  +1%/        +2%
     256/       8/  +2%/         0%    256/       8/  +1%/        -1%
    
    vq size=256 UDP_RR                vq size=512 UDP_RR
    size/sessions/+thu%/+normalize%   size/sessions/+thu%/+normalize%
       1/       1/  -5%/        +1%      1/       1/  -3%/        -2%
       1/       4/  +4%/        +1%      1/       4/  -2%/        +2%
       1/       8/  -1%/        -1%      1/       8/  -1%/         0%
      64/       1/  -2%/        -3%     64/       1/  +1%/        +1%
      64/       4/  -5%/        -1%     64/       4/  +2%/         0%
      64/       8/   0%/        -1%     64/       8/  -2%/        +1%
     256/       1/  +7%/        +1%    256/       1/  -7%/         0%
     256/       4/  +1%/        +1%    256/       4/  -3%/        -4%
     256/       8/  +2%/        +2%    256/       8/  +1%/        +1%
    
    vq size=256 TCP_STREAM            vq size=512 TCP_STREAM
    size/sessions/+thu%/+normalize%   size/sessions/+thu%/+normalize%
      64/       1/   0%/        -3%     64/       1/   0%/         0%
      64/       4/  +3%/        -1%     64/       4/  -2%/        +4%
      64/       8/  +9%/        -4%     64/       8/  -1%/        +2%
     256/       1/  +1%/        -4%    256/       1/  +1%/        +1%
     256/       4/  -1%/        -1%    256/       4/  -3%/         0%
     256/       8/  +7%/        +5%    256/       8/  -3%/         0%
     512/       1/  +1%/         0%    512/       1/  -1%/        -1%
     512/       4/  +1%/        -1%    512/       4/   0%/         0%
     512/       8/  +7%/        -5%    512/       8/  +6%/        -1%
    1024/       1/   0%/        -1%   1024/       1/   0%/        +1%
    1024/       4/  +3%/         0%   1024/       4/  +1%/         0%
    1024/       8/  +8%/        +5%   1024/       8/  -1%/         0%
    2048/       1/  +2%/        +2%   2048/       1/  -1%/         0%
    2048/       4/  +1%/         0%   2048/       4/   0%/        -1%
    2048/       8/  -2%/         0%   2048/       8/   5%/        -1%
    4096/       1/  -2%/         0%   4096/       1/  -2%/         0%
    4096/       4/  +2%/         0%   4096/       4/   0%/         0%
    4096/       8/  +9%/        -2%   4096/       8/  -5%/        -1%
    
    Acked-by: Michael S. Tsirkin <mst@redhat.com>
    Signed-off-by: Haibin Zhang <haibinzhang@tencent.com>
    Signed-off-by: Yunfang Tai <yunfangtai@tencent.com>
    Signed-off-by: Lidong Chen <lidongchen@tencent.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 822ef687a0a8e92fab6c12e3c2b5e1a5f1a97d54
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Jul 17 21:18:59 2019 +0200

    x86/speculation/swapgs: Exclude ATOMs from speculation through SWAPGS
    
    commit f36cf386e3fec258a341d446915862eded3e13d8 upstream.
    
    Intel provided the following information:
    
     On all current Atom processors, instructions that use a segment register
     value (e.g. a load or store) will not speculatively execute before the
     last writer of that segment retires. Thus they will not use a
     speculatively written segment value.
    
    That means on ATOMs there is no speculation through SWAPGS, so the SWAPGS
    entry paths can be excluded from the extra LFENCE if PTI is disabled.
    
    Create a separate bug flag for the through SWAPGS speculation and mark all
    out-of-order ATOMs and AMD/HYGON CPUs as not affected. The in-order ATOMs
    are excluded from the whole mitigation mess anyway.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
    Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
    [bwh: Backported to 3.16:
     - There's no whitelist entry (or any support) for Hygon CPUs
     - Use the next available X86_BUG number
     - Adjust context, indentation]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e191f5119eba311b3585492174825db763eeb3b9
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Jul 15 11:51:39 2019 -0500

    x86/entry/64: Use JMP instead of JMPQ
    
    commit 64dbc122b20f75183d8822618c24f85144a5a94d upstream.
    
    Somehow the swapgs mitigation entry code patch ended up with a JMPQ
    instruction instead of JMP, where only the short jump is needed.  Some
    assembler versions apparently fail to optimize JMPQ into a two-byte JMP
    when possible, instead always using a 7-byte JMP with relocation.  For
    some reason that makes the entry code explode with a #GP during boot.
    
    Change it back to "JMP" as originally intended.
    
    Fixes: 18ec54fdd6d1 ("x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations")
    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    [bwh: Backported to 3.16: adjust filename, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit bba3308d5fe2c8c4605db3ea868ba57ad990d27d
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Jul 8 11:52:26 2019 -0500

    x86/speculation: Enable Spectre v1 swapgs mitigations
    
    commit a2059825986a1c8143fd6698774fa9d83733bb11 upstream.
    
    The previous commit added macro calls in the entry code which mitigate the
    Spectre v1 swapgs issue if the X86_FEATURE_FENCE_SWAPGS_* features are
    enabled.  Enable those features where applicable.
    
    The mitigations may be disabled with "nospectre_v1" or "mitigations=off".
    
    There are different features which can affect the risk of attack:
    
    - When FSGSBASE is enabled, unprivileged users are able to place any
      value in GS, using the wrgsbase instruction.  This means they can
      write a GS value which points to any value in kernel space, which can
      be useful with the following gadget in an interrupt/exception/NMI
      handler:
    
            if (coming from user space)
                    swapgs
            mov %gs:<percpu_offset>, %reg1
            // dependent load or store based on the value of %reg
            // for example: mov %(reg1), %reg2
    
      If an interrupt is coming from user space, and the entry code
      speculatively skips the swapgs (due to user branch mistraining), it
      may speculatively execute the GS-based load and a subsequent dependent
      load or store, exposing the kernel data to an L1 side channel leak.
    
      Note that, on Intel, a similar attack exists in the above gadget when
      coming from kernel space, if the swapgs gets speculatively executed to
      switch back to the user GS.  On AMD, this variant isn't possible
      because swapgs is serializing with respect to future GS-based
      accesses.
    
      NOTE: The FSGSBASE patch set hasn't been merged yet, so the above case
            doesn't exist quite yet.
    
    - When FSGSBASE is disabled, the issue is mitigated somewhat because
      unprivileged users must use prctl(ARCH_SET_GS) to set GS, which
      restricts GS values to user space addresses only.  That means the
      gadget would need an additional step, since the target kernel address
      needs to be read from user space first.  Something like:
    
            if (coming from user space)
                    swapgs
            mov %gs:<percpu_offset>, %reg1
            mov (%reg1), %reg2
            // dependent load or store based on the value of %reg2
            // for example: mov %(reg2), %reg3
    
      It's difficult to audit for this gadget in all the handlers, so while
      there are no known instances of it, it's entirely possible that it
      exists somewhere (or could be introduced in the future).  Without
      tooling to analyze all such code paths, consider it vulnerable.
    
      Effects of SMAP on the !FSGSBASE case:
    
      - If SMAP is enabled, and the CPU reports RDCL_NO (i.e., not
        susceptible to Meltdown), the kernel is prevented from speculatively
        reading user space memory, even L1 cached values.  This effectively
        disables the !FSGSBASE attack vector.
    
      - If SMAP is enabled, but the CPU *is* susceptible to Meltdown, SMAP
        still prevents the kernel from speculatively reading user space
        memory.  But it does *not* prevent the kernel from reading the
        user value from L1, if it has already been cached.  This is probably
        only a small hurdle for an attacker to overcome.
    
    Thanks to Dave Hansen for contributing the speculative_smap() function.
    
    Thanks to Andrew Cooper for providing the inside scoop on whether swapgs
    is serializing on AMD.
    
    [ tglx: Fixed the USER fence decision and polished the comment as suggested
            by Dave Hansen ]
    
    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Dave Hansen <dave.hansen@intel.com>
    [bwh: Backported to 3.16:
     - Check for X86_FEATURE_KAISER instead of X86_FEATURE_PTI
     - mitigations= parameter is x86-only here
     - powerpc doesn't have Spectre mitigations
     - Don't use __ro_after_init
     - Adjust filename, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 79969c78fd8622fa7e7f925acd483eb01714efa4
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Jul 8 11:52:25 2019 -0500

    x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations
    
    commit 18ec54fdd6d18d92025af097cd042a75cf0ea24c upstream.
    
    Spectre v1 isn't only about array bounds checks.  It can affect any
    conditional checks.  The kernel entry code interrupt, exception, and NMI
    handlers all have conditional swapgs checks.  Those may be problematic in
    the context of Spectre v1, as kernel code can speculatively run with a user
    GS.
    
    For example:
    
            if (coming from user space)
                    swapgs
            mov %gs:<percpu_offset>, %reg
            mov (%reg), %reg1
    
    When coming from user space, the CPU can speculatively skip the swapgs, and
    then do a speculative percpu load using the user GS value.  So the user can
    speculatively force a read of any kernel value.  If a gadget exists which
    uses the percpu value as an address in another load/store, then the
    contents of the kernel value may become visible via an L1 side channel
    attack.
    
    A similar attack exists when coming from kernel space.  The CPU can
    speculatively do the swapgs, causing the user GS to get used for the rest
    of the speculative window.
    
    The mitigation is similar to a traditional Spectre v1 mitigation, except:
    
      a) index masking isn't possible; because the index (percpu offset)
         isn't user-controlled; and
    
      b) an lfence is needed in both the "from user" swapgs path and the
         "from kernel" non-swapgs path (because of the two attacks described
         above).
    
    The user entry swapgs paths already have SWITCH_TO_KERNEL_CR3, which has a
    CR3 write when PTI is enabled.  Since CR3 writes are serializing, the
    lfences can be skipped in those cases.
    
    On the other hand, the kernel entry swapgs paths don't depend on PTI.
    
    To avoid unnecessary lfences for the user entry case, create two separate
    features for alternative patching:
    
      X86_FEATURE_FENCE_SWAPGS_USER
      X86_FEATURE_FENCE_SWAPGS_KERNEL
    
    Use these features in entry code to patch in lfences where needed.
    
    The features aren't enabled yet, so there's no functional change.
    
    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Dave Hansen <dave.hansen@intel.com>
    [bwh: Backported to 3.16:
     - Assign the CPU feature bits from word 7
     - Add FENCE_SWAPGS_KERNEL_ENTRY to NMI entry, since it does not
       use paranoid_entry
     - Add a return after .Lerror_entry_from_usermode_after_swapgs, done
       upstream by commit f10750536fa7 "x86/entry/64: Fix irqflag tracing wrt
       context tracking"
     - Include <asm/cpufeatures.h> in calling.h
     - Adjust filenames, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 66084b820dc7bb91a2bcc91897a969cd7e10eb6e
Author: Wanpeng Li <wanpeng.li@hotmail.com>
Date:   Fri Sep 30 09:01:06 2016 +0800

    x86/entry/64: Fix context tracking state warning when load_gs_index fails
    
    commit 2fa5f04f85730d0c4f49f984b7efeb4f8d5bd1fc upstream.
    
    This warning:
    
     WARNING: CPU: 0 PID: 3331 at arch/x86/entry/common.c:45 enter_from_user_mode+0x32/0x50
     CPU: 0 PID: 3331 Comm: ldt_gdt_64 Not tainted 4.8.0-rc7+ #13
     Call Trace:
      dump_stack+0x99/0xd0
      __warn+0xd1/0xf0
      warn_slowpath_null+0x1d/0x20
      enter_from_user_mode+0x32/0x50
      error_entry+0x6d/0xc0
      ? general_protection+0x12/0x30
      ? native_load_gs_index+0xd/0x20
      ? do_set_thread_area+0x19c/0x1f0
      SyS_set_thread_area+0x24/0x30
      do_int80_syscall_32+0x7c/0x220
      entry_INT80_compat+0x38/0x50
    
    ... can be reproduced by running the GS testcase of the ldt_gdt test unit in
    the x86 selftests.
    
    do_int80_syscall_32() will call enter_form_user_mode() to convert context
    tracking state from user state to kernel state. The load_gs_index() call
    can fail with user gsbase, gsbase will be fixed up and proceed if this
    happen.
    
    However, enter_from_user_mode() will be called again in the fixed up path
    though it is context tracking kernel state currently.
    
    This patch fixes it by just fixing up gsbase and telling lockdep that IRQs
    are off once load_gs_index() failed with user gsbase.
    
    Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
    Acked-by: Andy Lutomirski <luto@kernel.org>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: http://lkml.kernel.org/r/1475197266-3440-1-git-send-email-wanpeng.li@hotmail.com
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16 as dependency of commit 18ec54fdd6d1
     "x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations":
     - Adjust filename]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5a4fb6148e386ad99d6cc0bb1bc737d66d4b546d
Author: Andy Lutomirski <luto@kernel.org>
Date:   Fri Jul 3 12:44:27 2015 -0700

    x86/entry/64: Really create an error-entry-from-usermode code path
    
    commit cb6f64ed5a04036eef07e70b57dd5dd78f2fbcef upstream.
    
    In 539f51136500 ("x86/asm/entry/64: Disentangle error_entry/exit
    gsbase/ebx/usermode code"), I arranged the code slightly wrong
    -- IRET faults would skip the code path that was intended to
    execute on all error entries from user mode.  Fix it up.
    
    While we're at it, make all the labels in error_entry local.
    
    This does not fix a bug, but we'll need it, and it slightly
    shrinks the code.
    
    Signed-off-by: Andy Lutomirski <luto@kernel.org>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: Denys Vlasenko <vda.linux@googlemail.com>
    Cc: Frederic Weisbecker <fweisbec@gmail.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Oleg Nesterov <oleg@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: paulmck@linux.vnet.ibm.com
    Link: http://lkml.kernel.org/r/91e17891e49fa3d61357eadc451529ad48143ee1.1435952415.git.luto@kernel.org
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16 as dependency of commit 18ec54fdd6d1
     "x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations":
     - Adjust filename, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit bb0737d1733aad51597b4f3004f7d93e0c38b011
Author: Andy Lutomirski <luto@kernel.org>
Date:   Tue Jun 9 12:36:01 2015 -0700

    x86/asm/entry/64: Disentangle error_entry/exit gsbase/ebx/usermode code
    
    commit 539f5113650068ba221197f190267ab727296ef5 upstream.
    
    The error_entry/error_exit code to handle gsbase and whether we
    return to user mdoe was a mess:
    
     - error_sti was misnamed.  In particular, it did not enable interrupts.
    
     - Error handling for gs_change was hopelessly tangled the normal
       usermode path.  Separate it out.  This saves a branch in normal
       entries from kernel mode.
    
     - The comments were bad.
    
    Fix it up.  As a nice side effect, there's now a code path that
    happens on error entries from user mode.  We'll use it soon.
    
    Signed-off-by: Andy Lutomirski <luto@kernel.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: http://lkml.kernel.org/r/f1be898ab93360169fb845ab85185948832209ee.1433878454.git.luto@kernel.org
    [ Prettified it, clarified comments some more. ]
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16 as dependency of commit 18ec54fdd6d1
     "x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations":
     - We do not use %ebx as a flag since we already have a backport of commit
       b3681dd548d0 "x86/entry/64: Remove %ebx handling from error_entry/exit",
       so don't add the comments about that
     - Adjust filename, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e3b7a57c6f349d6c2c869936a557e4b590325b60
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Thu Aug 8 20:11:40 2019 +0100

    x86: cpufeatures: Renumber feature word 7
    
    Use the same bit numbers for all features that are also present in
    4.4.y and 4.9.y, to make further backports slightly easier.
    
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 7c2c1c91af0139b30adffa9a738c7a6ade08d457
Author: Al Viro <viro@zeniv.linux.org.uk>
Date:   Wed May 1 22:46:11 2019 -0400

    ufs: fix braino in ufs_get_inode_gid() for solaris UFS flavour
    
    commit 4e9036042fedaffcd868d7f7aa948756c48c637d upstream.
    
    To choose whether to pick the GID from the old (16bit) or new (32bit)
    field, we should check if the old gid field is set to 0xffff.  Mainline
    checks the old *UID* field instead - cut'n'paste from the corresponding
    code in ufs_get_inode_uid().
    
    Fixes: 252e211e90ce
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e4fa924b76b937592f80c934f6500bbcc81ea63a
Author: Willem de Bruijn <willemb@google.com>
Date:   Mon Apr 29 11:53:18 2019 -0400

    packet: validate msg_namelen in send directly
    
    commit 486efdc8f6ce802b27e15921d2353cc740c55451 upstream.
    
    Packet sockets in datagram mode take a destination address. Verify its
    length before passing to dev_hard_header.
    
    Prior to 2.6.14-rc3, the send code ignored sll_halen. This is
    established behavior. Directly compare msg_namelen to dev->addr_len.
    
    Change v1->v2: initialize addr in all paths
    
    Fixes: 6b8d95f1795c4 ("packet: validate address length if non-zero")
    Suggested-by: David Laight <David.Laight@aculab.com>
    Signed-off-by: Willem de Bruijn <willemb@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 665da3a451d3e7bebfb1c29cb7b1cc9a5607c450
Author: Willem de Bruijn <willemb@google.com>
Date:   Mon Apr 29 11:46:55 2019 -0400

    packet: in recvmsg msg_name return at least sizeof sockaddr_ll
    
    commit b2cf86e1563e33a14a1c69b3e508d15dc12f804c upstream.
    
    Packet send checks that msg_name is at least sizeof sockaddr_ll.
    Packet recv must return at least this length, so that its output
    can be passed unmodified to packet send.
    
    This ceased to be true since adding support for lladdr longer than
    sll_addr. Since, the return value uses true address length.
    
    Always return at least sizeof sockaddr_ll, even if address length
    is shorter. Zero the padding bytes.
    
    Change v1->v2: do not overwrite zeroed padding again. use copy_len.
    
    Fixes: 0fb375fb9b93 ("[AF_PACKET]: Allow for > 8 byte hardware addresses.")
    Suggested-by: David Laight <David.Laight@aculab.com>
    Signed-off-by: Willem de Bruijn <willemb@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5e7bde8cedb6c11128c4f2836a9d695ac0d0a03c
Author: Eric Dumazet <edumazet@google.com>
Date:   Tue Apr 30 06:27:58 2019 -0700

    l2ip: fix possible use-after-free
    
    commit a622b40035d16196bf19b2b33b854862595245fc upstream.
    
    Before taking a refcount on a rcu protected structure,
    we need to make sure the refcount is not zero.
    
    syzbot reported :
    
    refcount_t: increment on 0; use-after-free.
    WARNING: CPU: 1 PID: 23533 at lib/refcount.c:156 refcount_inc_checked lib/refcount.c:156 [inline]
    WARNING: CPU: 1 PID: 23533 at lib/refcount.c:156 refcount_inc_checked+0x61/0x70 lib/refcount.c:154
    Kernel panic - not syncing: panic_on_warn set ...
    CPU: 1 PID: 23533 Comm: syz-executor.2 Not tainted 5.1.0-rc7+ #93
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Call Trace:
     __dump_stack lib/dump_stack.c:77 [inline]
     dump_stack+0x172/0x1f0 lib/dump_stack.c:113
     panic+0x2cb/0x65c kernel/panic.c:214
     __warn.cold+0x20/0x45 kernel/panic.c:571
     report_bug+0x263/0x2b0 lib/bug.c:186
     fixup_bug arch/x86/kernel/traps.c:179 [inline]
     fixup_bug arch/x86/kernel/traps.c:174 [inline]
     do_error_trap+0x11b/0x200 arch/x86/kernel/traps.c:272
     do_invalid_op+0x37/0x50 arch/x86/kernel/traps.c:291
     invalid_op+0x14/0x20 arch/x86/entry/entry_64.S:973
    RIP: 0010:refcount_inc_checked lib/refcount.c:156 [inline]
    RIP: 0010:refcount_inc_checked+0x61/0x70 lib/refcount.c:154
    Code: 1d 98 2b 2a 06 31 ff 89 de e8 db 2c 40 fe 84 db 75 dd e8 92 2b 40 fe 48 c7 c7 20 7a a1 87 c6 05 78 2b 2a 06 01 e8 7d d9 12 fe <0f> 0b eb c1 90 90 90 90 90 90 90 90 90 90 90 55 48 89 e5 41 57 41
    RSP: 0018:ffff888069f0fba8 EFLAGS: 00010286
    RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
    RDX: 000000000000f353 RSI: ffffffff815afcb6 RDI: ffffed100d3e1f67
    RBP: ffff888069f0fbb8 R08: ffff88809b1845c0 R09: ffffed1015d23ef1
    R10: ffffed1015d23ef0 R11: ffff8880ae91f787 R12: ffff8880a8f26968
    R13: 0000000000000004 R14: dffffc0000000000 R15: ffff8880a49a6440
     l2tp_tunnel_inc_refcount net/l2tp/l2tp_core.h:240 [inline]
     l2tp_tunnel_get+0x250/0x580 net/l2tp/l2tp_core.c:173
     pppol2tp_connect+0xc00/0x1c70 net/l2tp/l2tp_ppp.c:702
     __sys_connect+0x266/0x330 net/socket.c:1808
     __do_sys_connect net/socket.c:1819 [inline]
     __se_sys_connect net/socket.c:1816 [inline]
     __x64_sys_connect+0x73/0xb0 net/socket.c:1816
    
    Fixes: 54652eb12c1b ("l2tp: hold tunnel while looking up sessions in l2tp_netlink")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Cc: Guillaume Nault <g.nault@alphalink.fr>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: use atomic not refcount API]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 53b7d31459a52b1c95e2eede00c1fb0341bda4ab
Author: Eric Dumazet <edumazet@google.com>
Date:   Sat Apr 27 16:49:06 2019 -0700

    ipv6/flowlabel: wait rcu grace period before put_pid()
    
    commit 6c0afef5fb0c27758f4d52b2210c61b6bd8b4470 upstream.
    
    syzbot was able to catch a use-after-free read in pid_nr_ns() [1]
    
    ip6fl_seq_show() seems to use RCU protection, dereferencing fl->owner.pid
    but fl_free() releases fl->owner.pid before rcu grace period is started.
    
    [1]
    
    BUG: KASAN: use-after-free in pid_nr_ns+0x128/0x140 kernel/pid.c:407
    Read of size 4 at addr ffff888094012a04 by task syz-executor.0/18087
    
    CPU: 0 PID: 18087 Comm: syz-executor.0 Not tainted 5.1.0-rc6+ #89
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Call Trace:
     __dump_stack lib/dump_stack.c:77 [inline]
     dump_stack+0x172/0x1f0 lib/dump_stack.c:113
     print_address_description.cold+0x7c/0x20d mm/kasan/report.c:187
     kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
     __asan_report_load4_noabort+0x14/0x20 mm/kasan/generic_report.c:131
     pid_nr_ns+0x128/0x140 kernel/pid.c:407
     ip6fl_seq_show+0x2f8/0x4f0 net/ipv6/ip6_flowlabel.c:794
     seq_read+0xad3/0x1130 fs/seq_file.c:268
     proc_reg_read+0x1fe/0x2c0 fs/proc/inode.c:227
     do_loop_readv_writev fs/read_write.c:701 [inline]
     do_loop_readv_writev fs/read_write.c:688 [inline]
     do_iter_read+0x4a9/0x660 fs/read_write.c:922
     vfs_readv+0xf0/0x160 fs/read_write.c:984
     kernel_readv fs/splice.c:358 [inline]
     default_file_splice_read+0x475/0x890 fs/splice.c:413
     do_splice_to+0x12a/0x190 fs/splice.c:876
     splice_direct_to_actor+0x2d2/0x970 fs/splice.c:953
     do_splice_direct+0x1da/0x2a0 fs/splice.c:1062
     do_sendfile+0x597/0xd00 fs/read_write.c:1443
     __do_sys_sendfile64 fs/read_write.c:1498 [inline]
     __se_sys_sendfile64 fs/read_write.c:1490 [inline]
     __x64_sys_sendfile64+0x15a/0x220 fs/read_write.c:1490
     do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
     entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x458da9
    Code: ad b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 <48> 3d 01 f0 ff ff 0f 83 7b b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00
    RSP: 002b:00007f300d24bc78 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
    RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 0000000000458da9
    RDX: 00000000200000c0 RSI: 0000000000000008 RDI: 0000000000000007
    RBP: 000000000073bf00 R08: 0000000000000000 R09: 0000000000000000
    R10: 000000000000005a R11: 0000000000000246 R12: 00007f300d24c6d4
    R13: 00000000004c5fa3 R14: 00000000004da748 R15: 00000000ffffffff
    
    Allocated by task 17543:
     save_stack+0x45/0xd0 mm/kasan/common.c:75
     set_track mm/kasan/common.c:87 [inline]
     __kasan_kmalloc mm/kasan/common.c:497 [inline]
     __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:470
     kasan_slab_alloc+0xf/0x20 mm/kasan/common.c:505
     slab_post_alloc_hook mm/slab.h:437 [inline]
     slab_alloc mm/slab.c:3393 [inline]
     kmem_cache_alloc+0x11a/0x6f0 mm/slab.c:3555
     alloc_pid+0x55/0x8f0 kernel/pid.c:168
     copy_process.part.0+0x3b08/0x7980 kernel/fork.c:1932
     copy_process kernel/fork.c:1709 [inline]
     _do_fork+0x257/0xfd0 kernel/fork.c:2226
     __do_sys_clone kernel/fork.c:2333 [inline]
     __se_sys_clone kernel/fork.c:2327 [inline]
     __x64_sys_clone+0xbf/0x150 kernel/fork.c:2327
     do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
     entry_SYSCALL_64_after_hwframe+0x49/0xbe
    
    Freed by task 7789:
     save_stack+0x45/0xd0 mm/kasan/common.c:75
     set_track mm/kasan/common.c:87 [inline]
     __kasan_slab_free+0x102/0x150 mm/kasan/common.c:459
     kasan_slab_free+0xe/0x10 mm/kasan/common.c:467
     __cache_free mm/slab.c:3499 [inline]
     kmem_cache_free+0x86/0x260 mm/slab.c:3765
     put_pid.part.0+0x111/0x150 kernel/pid.c:111
     put_pid+0x20/0x30 kernel/pid.c:105
     fl_free+0xbe/0xe0 net/ipv6/ip6_flowlabel.c:102
     ip6_fl_gc+0x295/0x3e0 net/ipv6/ip6_flowlabel.c:152
     call_timer_fn+0x190/0x720 kernel/time/timer.c:1325
     expire_timers kernel/time/timer.c:1362 [inline]
     __run_timers kernel/time/timer.c:1681 [inline]
     __run_timers kernel/time/timer.c:1649 [inline]
     run_timer_softirq+0x652/0x1700 kernel/time/timer.c:1694
     __do_softirq+0x266/0x95a kernel/softirq.c:293
    
    The buggy address belongs to the object at ffff888094012a00
     which belongs to the cache pid_2 of size 88
    The buggy address is located 4 bytes inside of
     88-byte region [ffff888094012a00, ffff888094012a58)
    The buggy address belongs to the page:
    page:ffffea0002500480 count:1 mapcount:0 mapping:ffff88809a483080 index:0xffff888094012980
    flags: 0x1fffc0000000200(slab)
    raw: 01fffc0000000200 ffffea00018a3508 ffffea0002524a88 ffff88809a483080
    raw: ffff888094012980 ffff888094012000 000000010000001b 0000000000000000
    page dumped because: kasan: bad access detected
    
    Memory state around the buggy address:
     ffff888094012900: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
     ffff888094012980: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
    >ffff888094012a00: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
                       ^
     ffff888094012a80: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
     ffff888094012b00: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
    
    Fixes: 4f82f45730c6 ("net ip6 flowlabel: Make owner a union of struct pid * and kuid_t")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Cc: Eric W. Biederman <ebiederm@xmission.com>
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: Move the release_net() call too, not that it does
     anything.]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 9fd1512321314137f0e7c1366a1041ac6774fb8e
Author: Willem de Bruijn <willemb@google.com>
Date:   Thu Apr 25 12:06:54 2019 -0400

    ipv6: invert flowlabel sharing check in process and user mode
    
    commit 95c169251bf734aa555a1e8043e4d88ec97a04ec upstream.
    
    A request for a flowlabel fails in process or user exclusive mode must
    fail if the caller pid or uid does not match. Invert the test.
    
    Previously, the test was unsafe wrt PID recycling, but indeed tested
    for inequality: fl1->owner != fl->owner
    
    Fixes: 4f82f45730c68 ("net ip6 flowlabel: Make owner a union of struct pid* and kuid_t")
    Signed-off-by: Willem de Bruijn <willemb@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5a95f35b57aed9e4c550c0b17d6c61afd089ad48
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Thu Apr 25 16:13:58 2019 -0700

    slip: make slhc_free() silently accept an error pointer
    
    commit baf76f0c58aec435a3a864075b8f6d8ee5d1f17e upstream.
    
    This way, slhc_free() accepts what slhc_init() returns, whether that is
    an error or not.
    
    In particular, the pattern in sl_alloc_bufs() is
    
            slcomp = slhc_init(16, 16);
            ...
            slhc_free(slcomp);
    
    for the error handling path, and rather than complicate that code, just
    make it ok to always free what was returned by the init function.
    
    That's what the code used to do before commit 4ab42d78e37a ("ppp, slip:
    Validate VJ compression slot parameters completely") when slhc_init()
    just returned NULL for the error case, with no actual indication of the
    details of the error.
    
    Reported-by: syzbot+45474c076a4927533d2e@syzkaller.appspotmail.com
    Fixes: 4ab42d78e37a ("ppp, slip: Validate VJ compression slot parameters completely")
    Acked-by: Ben Hutchings <ben@decadent.org.uk>
    Cc: David Miller <davem@davemloft.net>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit be90e624dd07070c18544c86896c4184a4f5cd0a
Author: YueHaibing <yuehaibing@huawei.com>
Date:   Thu Apr 25 22:24:05 2019 -0700

    fs/proc/proc_sysctl.c: Fix a NULL pointer dereference
    
    commit 89189557b47b35683a27c80ee78aef18248eefb4 upstream.
    
    Syzkaller report this:
    
      sysctl could not get directory: /net//bridge -12
      kasan: CONFIG_KASAN_INLINE enabled
      kasan: GPF could be caused by NULL-ptr deref or user memory access
      general protection fault: 0000 [#1] SMP KASAN PTI
      CPU: 1 PID: 7027 Comm: syz-executor.0 Tainted: G         C        5.1.0-rc3+ #8
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      RIP: 0010:__write_once_size include/linux/compiler.h:220 [inline]
      RIP: 0010:__rb_change_child include/linux/rbtree_augmented.h:144 [inline]
      RIP: 0010:__rb_erase_augmented include/linux/rbtree_augmented.h:186 [inline]
      RIP: 0010:rb_erase+0x5f4/0x19f0 lib/rbtree.c:459
      Code: 00 0f 85 60 13 00 00 48 89 1a 48 83 c4 18 5b 5d 41 5c 41 5d 41 5e 41 5f c3 48 89 f2 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 <80> 3c 02 00 0f 85 75 0c 00 00 4d 85 ed 4c 89 2e 74 ce 4c 89 ea 48
      RSP: 0018:ffff8881bb507778 EFLAGS: 00010206
      RAX: dffffc0000000000 RBX: ffff8881f224b5b8 RCX: ffffffff818f3f6a
      RDX: 000000000000000a RSI: 0000000000000050 RDI: ffff8881f224b568
      RBP: 0000000000000000 R08: ffffed10376a0ef4 R09: ffffed10376a0ef4
      R10: 0000000000000001 R11: ffffed10376a0ef4 R12: ffff8881f224b558
      R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
      FS:  00007f3e7ce13700(0000) GS:ffff8881f7300000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fd60fbe9398 CR3: 00000001cb55c001 CR4: 00000000007606e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      PKRU: 55555554
      Call Trace:
       erase_entry fs/proc/proc_sysctl.c:178 [inline]
       erase_header+0xe3/0x160 fs/proc/proc_sysctl.c:207
       start_unregistering fs/proc/proc_sysctl.c:331 [inline]
       drop_sysctl_table+0x558/0x880 fs/proc/proc_sysctl.c:1631
       get_subdir fs/proc/proc_sysctl.c:1022 [inline]
       __register_sysctl_table+0xd65/0x1090 fs/proc/proc_sysctl.c:1335
       br_netfilter_init+0x68/0x1000 [br_netfilter]
       do_one_initcall+0xbc/0x47d init/main.c:901
       do_init_module+0x1b5/0x547 kernel/module.c:3456
       load_module+0x6405/0x8c10 kernel/module.c:3804
       __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
       do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      Modules linked in: br_netfilter(+) backlight comedi(C) hid_sensor_hub max3100 ti_ads8688 udc_core fddi snd_mona leds_gpio rc_streamzap mtd pata_netcell nf_log_common rc_winfast udp_tunnel snd_usbmidi_lib snd_usb_toneport snd_usb_line6 snd_rawmidi snd_seq_device snd_hwdep videobuf2_v4l2 videobuf2_common videodev media videobuf2_vmalloc videobuf2_memops rc_gadmei_rm008z 8250_of smm665 hid_tmff hid_saitek hwmon_vid rc_ati_tv_wonder_hd_600 rc_core pata_pdc202xx_old dn_rtmsg as3722 ad714x_i2c ad714x snd_soc_cs4265 hid_kensington panel_ilitek_ili9322 drm drm_panel_orientation_quirks ipack cdc_phonet usbcore phonet hid_jabra hid extcon_arizona can_dev industrialio_triggered_buffer kfifo_buf industrialio adm1031 i2c_mux_ltc4306 i2c_mux ipmi_msghandler mlxsw_core snd_soc_cs35l34 snd_soc_core snd_pcm_dmaengine snd_pcm snd_timer ac97_bus snd_compress snd soundcore gpio_da9055 uio ecdh_generic mdio_thunder of_mdio fixed_phy libphy mdio_cavium iptable_security iptable_raw iptable_mangle
       iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_filter bpfilter ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel hsr veth netdevsim vxcan batman_adv cfg80211 rfkill chnl_net caif nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun joydev mousedev ppdev tpm kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel aesni_intel ide_pci_generic piix aes_x86_64 crypto_simd cryptd ide_core glue_helper input_leds psmouse intel_agp intel_gtt serio_raw ata_generic i2c_piix4 agpgart pata_acpi parport_pc parport floppy rtc_cmos sch_fq_codel ip_tables x_tables sha1_ssse3 sha1_generic ipv6 [last unloaded: br_netfilter]
      Dumping ftrace buffer:
         (ftrace buffer empty)
      ---[ end trace 68741688d5fbfe85 ]---
    
    commit 23da9588037e ("fs/proc/proc_sysctl.c: fix NULL pointer
    dereference in put_links") forgot to handle start_unregistering() case,
    while header->parent is NULL, it calls erase_header() and as seen in the
    above syzkaller call trace, accessing &header->parent->root will trigger
    a NULL pointer dereference.
    
    As that commit explained, there is also no need to call
    start_unregistering() if header->parent is NULL.
    
    Link: http://lkml.kernel.org/r/20190409153622.28112-1-yuehaibing@huawei.com
    Fixes: 23da9588037e ("fs/proc/proc_sysctl.c: fix NULL pointer dereference in put_links")
    Fixes: 0e47c99d7fe25 ("sysctl: Replace root_list with links between sysctl_table_sets")
    Signed-off-by: YueHaibing <yuehaibing@huawei.com>
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Cc: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit ab4c96f002e2f2e6a35fcf616cc4cf19101eb14c
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Tue Apr 23 22:03:18 2019 +0200

    trace: Fix preempt_enable_no_resched() abuse
    
    commit d6097c9e4454adf1f8f2c9547c2fa6060d55d952 upstream.
    
    Unless the very next line is schedule(), or implies it, one must not use
    preempt_enable_no_resched(). It can cause a preemption to go missing and
    thereby cause arbitrary delays, breaking the PREEMPT=y invariant.
    
    Link: http://lkml.kernel.org/r/20190423200318.GY14281@hirez.programming.kicks-ass.net
    
    Cc: Waiman Long <longman@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: the arch/x86 maintainers <x86@kernel.org>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Tim Chen <tim.c.chen@linux.intel.com>
    Cc: huang ying <huang.ying.caritas@gmail.com>
    Cc: Roman Gushchin <guro@fb.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Fixes: 2c2d7329d8af ("tracing/ftrace: use preempt_enable_no_resched_notrace in ring_buffer_time_stamp()")
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit d9cf789e11de92d01b499a5505374121559199cd
Author: Eric Dumazet <edumazet@google.com>
Date:   Tue Apr 23 09:43:26 2019 -0700

    l2tp: use rcu_dereference_sk_user_data() in l2tp_udp_encap_recv()
    
    commit c1c477217882c610a2ba0268f5faf36c9c092528 upstream.
    
    Canonical way to fetch sk_user_data from an encap_rcv() handler called
    from UDP stack in rcu protected section is to use rcu_dereference_sk_user_data(),
    otherwise compiler might read it multiple times.
    
    Fixes: d00fa9adc528 ("il2tp: fix races with tunnel socket close")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Cc: James Chapman <jchapman@katalix.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit f007a3d2a304a1d78aca6c761ad4436504d5063a
Author: Xie XiuQi <xiexiuqi@huawei.com>
Date:   Sat Apr 20 16:34:16 2019 +0800

    sched/numa: Fix a possible divide-by-zero
    
    commit a860fa7b96e1a1c974556327aa1aee852d434c21 upstream.
    
    sched_clock_cpu() may not be consistent between CPUs. If a task
    migrates to another CPU, then se.exec_start is set to that CPU's
    rq_clock_task() by update_stats_curr_start(). Specifically, the new
    value might be before the old value due to clock skew.
    
    So then if in numa_get_avg_runtime() the expression:
    
      'now - p->last_task_numa_placement'
    
    ends up as -1, then the divider '*period + 1' in task_numa_placement()
    is 0 and things go bang. Similar to update_curr(), check if time goes
    backwards to avoid this.
    
    [ peterz: Wrote new changelog. ]
    [ mingo: Tweaked the code comment. ]
    
    Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: cj.chengjian@huawei.com
    Link: http://lkml.kernel.org/r/20190425080016.GX11158@hirez.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2d399f685b07d23fdd4a8d3b1a1ea8c9f2dd9457
Author: Malte Leip <malte@leip.net>
Date:   Sun Apr 14 12:00:12 2019 +0200

    usb: usbip: fix isoc packet num validation in get_pipe
    
    commit c409ca3be3c6ff3a1eeb303b191184e80d412862 upstream.
    
    Change the validation of number_of_packets in get_pipe to compare the
    number of packets to a fixed maximum number of packets allowed, set to
    be 1024. This number was chosen due to it being used by other drivers as
    well, for example drivers/usb/host/uhci-q.c
    
    Background/reason:
    The get_pipe function in stub_rx.c validates the number of packets in
    isochronous mode and aborts with an error if that number is too large,
    in order to prevent malicious input from possibly triggering large
    memory allocations. This was previously done by checking whether
    pdu->u.cmd_submit.number_of_packets is bigger than the number of packets
    that would be needed for pdu->u.cmd_submit.transfer_buffer_length bytes
    if all except possibly the last packet had maximum length, given by
    usb_endpoint_maxp(epd) *  usb_endpoint_maxp_mult(epd). This leads to an
    error if URBs with packets shorter than the maximum possible length are
    submitted, which is allowed according to
    Documentation/driver-api/usb/URB.rst and occurs for example with the
    snd-usb-audio driver.
    
    Fixes: c6688ef9f297 ("usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input")
    Signed-off-by: Malte Leip <malte@leip.net>
    Acked-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: adjust filenames]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit ef6b71388a795e0142c23b5c45266d41f8c4cd2b
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Mon Apr 22 11:16:04 2019 -0400

    USB: w1 ds2490: Fix bug caused by improper use of altsetting array
    
    commit c114944d7d67f24e71562fcfc18d550ab787e4d4 upstream.
    
    The syzkaller USB fuzzer spotted a slab-out-of-bounds bug in the
    ds2490 driver.  This bug is caused by improper use of the altsetting
    array in the usb_interface structure (the array's entries are not
    always stored in numerical order), combined with a naive assumption
    that all interfaces probed by the driver will have the expected number
    of altsettings.
    
    The bug can be fixed by replacing references to the possibly
    non-existent intf->altsetting[alt] entry with the guaranteed-to-exist
    intf->cur_altsetting entry.
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Reported-and-tested-by: syzbot+d65f673b847a1a96cdba@syzkaller.appspotmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5133454a1f3a7f22412ab083f7ff53f822d50f49
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Tue Apr 23 14:48:29 2019 -0400

    USB: yurex: Fix protection fault after device removal
    
    commit ef61eb43ada6c1d6b94668f0f514e4c268093ff3 upstream.
    
    The syzkaller USB fuzzer found a general-protection-fault bug in the
    yurex driver.  The fault occurs when a device has been unplugged; the
    driver's interrupt-URB handler logs an error message referring to the
    device by name, after the device has been unregistered and its name
    deallocated.
    
    This problem is caused by the fact that the interrupt URB isn't
    cancelled until the driver's private data structure is released, which
    can happen long after the device is gone.  The cure is to make sure
    that the interrupt URB is killed before yurex_disconnect() returns;
    this is exactly the sort of thing that usb_poison_urb() was meant for.
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Reported-and-tested-by: syzbot+2eb9121678bdb36e6d57@syzkaller.appspotmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fd83bef7a9dedfd8d227dace8f98400ca7937d54
Author: Eric Dumazet <edumazet@google.com>
Date:   Wed Apr 24 05:35:00 2019 -0700

    net/rose: fix unbound loop in rose_loopback_timer()
    
    commit 0453c682459583910d611a96de928f4442205493 upstream.
    
    This patch adds a limit on the number of skbs that fuzzers can queue
    into loopback_queue. 1000 packets for rose loopback seems more than enough.
    
    Then, since we now have multiple cpus in most linux hosts,
    we also need to limit the number of skbs rose_loopback_timer()
    can dequeue at each round.
    
    rose_loopback_queue() can be drop-monitor friendly, calling
    consume_skb() or kfree_skb() appropriately.
    
    Finally, use mod_timer() instead of del_timer() + add_timer()
    
    syzbot report was :
    
    rcu: INFO: rcu_preempt self-detected stall on CPU
    rcu:    0-...!: (10499 ticks this GP) idle=536/1/0x4000000000000002 softirq=103291/103291 fqs=34
    rcu:     (t=10500 jiffies g=140321 q=323)
    rcu: rcu_preempt kthread starved for 10426 jiffies! g140321 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402 ->cpu=1
    rcu: RCU grace-period kthread stack dump:
    rcu_preempt     I29168    10      2 0x80000000
    Call Trace:
     context_switch kernel/sched/core.c:2877 [inline]
     __schedule+0x813/0x1cc0 kernel/sched/core.c:3518
     schedule+0x92/0x180 kernel/sched/core.c:3562
     schedule_timeout+0x4db/0xfd0 kernel/time/timer.c:1803
     rcu_gp_fqs_loop kernel/rcu/tree.c:1971 [inline]
     rcu_gp_kthread+0x962/0x17b0 kernel/rcu/tree.c:2128
     kthread+0x357/0x430 kernel/kthread.c:253
     ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
    NMI backtrace for cpu 0
    CPU: 0 PID: 7632 Comm: kworker/0:4 Not tainted 5.1.0-rc5+ #172
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Workqueue: events iterate_cleanup_work
    Call Trace:
     <IRQ>
     __dump_stack lib/dump_stack.c:77 [inline]
     dump_stack+0x172/0x1f0 lib/dump_stack.c:113
     nmi_cpu_backtrace.cold+0x63/0xa4 lib/nmi_backtrace.c:101
     nmi_trigger_cpumask_backtrace+0x1be/0x236 lib/nmi_backtrace.c:62
     arch_trigger_cpumask_backtrace+0x14/0x20 arch/x86/kernel/apic/hw_nmi.c:38
     trigger_single_cpu_backtrace include/linux/nmi.h:164 [inline]
     rcu_dump_cpu_stacks+0x183/0x1cf kernel/rcu/tree.c:1223
     print_cpu_stall kernel/rcu/tree.c:1360 [inline]
     check_cpu_stall kernel/rcu/tree.c:1434 [inline]
     rcu_pending kernel/rcu/tree.c:3103 [inline]
     rcu_sched_clock_irq.cold+0x500/0xa4a kernel/rcu/tree.c:2544
     update_process_times+0x32/0x80 kernel/time/timer.c:1635
     tick_sched_handle+0xa2/0x190 kernel/time/tick-sched.c:161
     tick_sched_timer+0x47/0x130 kernel/time/tick-sched.c:1271
     __run_hrtimer kernel/time/hrtimer.c:1389 [inline]
     __hrtimer_run_queues+0x33e/0xde0 kernel/time/hrtimer.c:1451
     hrtimer_interrupt+0x314/0x770 kernel/time/hrtimer.c:1509
     local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1035 [inline]
     smp_apic_timer_interrupt+0x120/0x570 arch/x86/kernel/apic/apic.c:1060
     apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:807
    RIP: 0010:__sanitizer_cov_trace_pc+0x0/0x50 kernel/kcov.c:95
    Code: 89 25 b4 6e ec 08 41 bc f4 ff ff ff e8 cd 5d ea ff 48 c7 05 9e 6e ec 08 00 00 00 00 e9 a4 e9 ff ff 90 90 90 90 90 90 90 90 90 <55> 48 89 e5 48 8b 75 08 65 48 8b 04 25 00 ee 01 00 65 8b 15 c8 60
    RSP: 0018:ffff8880ae807ce0 EFLAGS: 00000286 ORIG_RAX: ffffffffffffff13
    RAX: ffff88806fd40640 RBX: dffffc0000000000 RCX: ffffffff863fbc56
    RDX: 0000000000000100 RSI: ffffffff863fbc1d RDI: ffff88808cf94228
    RBP: ffff8880ae807d10 R08: ffff88806fd40640 R09: ffffed1015d00f8b
    R10: ffffed1015d00f8a R11: 0000000000000003 R12: ffff88808cf941c0
    R13: 00000000fffff034 R14: ffff8882166cd840 R15: 0000000000000000
     rose_loopback_timer+0x30d/0x3f0 net/rose/rose_loopback.c:91
     call_timer_fn+0x190/0x720 kernel/time/timer.c:1325
     expire_timers kernel/time/timer.c:1362 [inline]
     __run_timers kernel/time/timer.c:1681 [inline]
     __run_timers kernel/time/timer.c:1649 [inline]
     run_timer_softirq+0x652/0x1700 kernel/time/timer.c:1694
     __do_softirq+0x266/0x95a kernel/softirq.c:293
     do_softirq_own_stack+0x2a/0x40 arch/x86/entry/entry_64.S:1027
    
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: Also move assignments to
     loopback_timer.{data,function} into rose_loopback_init(), done upstream
     in commit 4966babd904d "net/rose: Convert timers to use timer_setup()".]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit aa7ead1a7cd91f3df142f80c38dc67d2f9fec56a
Author: Frank Sorenson <sorenson@redhat.com>
Date:   Tue Apr 16 08:37:27 2019 -0500

    cifs: do not attempt cifs operation on smb2+ rename error
    
    commit 652727bbe1b17993636346716ae5867627793647 upstream.
    
    A path-based rename returning EBUSY will incorrectly try opening
    the file with a cifs (NT Create AndX) operation on an smb2+ mount,
    which causes the server to force a session close.
    
    If the mount is smb2+, skip the fallback.
    
    Signed-off-by: Frank Sorenson <sorenson@redhat.com>
    Signed-off-by: Steve French <stfrench@microsoft.com>
    Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 213bca68d77954ccdb66fcc6702c419d503e633d
Author: Jeff Layton <jlayton@kernel.org>
Date:   Wed Apr 17 12:58:28 2019 -0400

    ceph: ensure d_name stability in ceph_dentry_hash()
    
    commit 76a495d666e5043ffc315695f8241f5e94a98849 upstream.
    
    Take the d_lock here to ensure that d_name doesn't change.
    
    Signed-off-by: Jeff Layton <jlayton@kernel.org>
    Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
    Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3ecce420e73ec4562a052fe8f81451725f0a2bb0
Author: Johannes Berg <johannes.berg@intel.com>
Date:   Mon Apr 15 11:39:33 2019 +0200

    mac80211: don't attempt to rename ERR_PTR() debugfs dirs
    
    commit 517879147493a5e1df6b89a50f708f1133fcaddb upstream.
    
    We need to dereference the directory to get its parent to
    be able to rename it, so it's clearly not safe to try to
    do this with ERR_PTR() pointers. Skip in this case.
    
    It seems that this is most likely what was causing the
    report by syzbot, but I'm not entirely sure as it didn't
    come with a reproducer this time.
    
    Reported-by: syzbot+4ece1a28b8f4730547c9@syzkaller.appspotmail.com
    Signed-off-by: Johannes Berg <johannes.berg@intel.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit de190e903119b4a86e0745efed2e0caee47bf605
Author: Florian Westphal <fw@strlen.de>
Date:   Mon Apr 15 00:43:00 2019 +0200

    netfilter: ebtables: CONFIG_COMPAT: drop a bogus WARN_ON
    
    commit 7caa56f006e9d712b44f27b32520c66420d5cbc6 upstream.
    
    It means userspace gave us a ruleset where there is some other
    data after the ebtables target but before the beginning of the next rule.
    
    Fixes: 81e675c227ec ("netfilter: ebtables: add CONFIG_COMPAT support")
    Reported-by: syzbot+659574e7bcc7f7eb4df7@syzkaller.appspotmail.com
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3b2cfcaa66b7401284014bae6714800b011166f3
Author: Hangbin Liu <liuhangbin@gmail.com>
Date:   Fri Apr 19 14:31:00 2019 +0800

    team: fix possible recursive locking when add slaves
    
    commit 925b0c841e066b488cc3a60272472b2c56300704 upstream.
    
    If we add a bond device which is already the master of the team interface,
    we will hold the team->lock in team_add_slave() first and then request the
    lock in team_set_mac_address() again. The functions are called like:
    
    - team_add_slave()
     - team_port_add()
       - team_port_enter()
         - team_modeop_port_enter()
           - __set_port_dev_addr()
             - dev_set_mac_address()
               - bond_set_mac_address()
                 - dev_set_mac_address()
                   - team_set_mac_address
    
    Although team_upper_dev_link() would check the upper devices but it is
    called too late. Fix it by adding a checking before processing the slave.
    
    v2: Do not split the string in netdev_err()
    
    Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
    Acked-by: Jiri Pirko <jiri@mellanox.com>
    Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: netlink doesn't support extack]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fb2d3ede3cb8bf86ef32bf07d03d243e813308d6
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Fri Apr 19 13:52:38 2019 -0400

    USB: core: Fix bug caused by duplicate interface PM usage counter
    
    commit c2b71462d294cf517a0bc6e4fd6424d7cee5596f upstream.
    
    The syzkaller fuzzer reported a bug in the USB hub driver which turned
    out to be caused by a negative runtime-PM usage counter.  This allowed
    a hub to be runtime suspended at a time when the driver did not expect
    it.  The symptom is a WARNING issued because the hub's status URB is
    submitted while it is already active:
    
            URB 0000000031fb463e submitted while active
            WARNING: CPU: 0 PID: 2917 at drivers/usb/core/urb.c:363
    
    The negative runtime-PM usage count was caused by an unfortunate
    design decision made when runtime PM was first implemented for USB.
    At that time, USB class drivers were allowed to unbind from their
    interfaces without balancing the usage counter (i.e., leaving it with
    a positive count).  The core code would take care of setting the
    counter back to 0 before allowing another driver to bind to the
    interface.
    
    Later on when runtime PM was implemented for the entire kernel, the
    opposite decision was made: Drivers were required to balance their
    runtime-PM get and put calls.  In order to maintain backward
    compatibility, however, the USB subsystem adapted to the new
    implementation by keeping an independent usage counter for each
    interface and using it to automatically adjust the normal usage
    counter back to 0 whenever a driver was unbound.
    
    This approach involves duplicating information, but what is worse, it
    doesn't work properly in cases where a USB class driver delays
    decrementing the usage counter until after the driver's disconnect()
    routine has returned and the counter has been adjusted back to 0.
    Doing so would cause the usage counter to become negative.  There's
    even a warning about this in the USB power management documentation!
    
    As it happens, this is exactly what the hub driver does.  The
    kick_hub_wq() routine increments the runtime-PM usage counter, and the
    corresponding decrement is carried out by hub_event() in the context
    of the hub_wq work-queue thread.  This work routine may sometimes run
    after the driver has been unbound from its interface, and when it does
    it causes the usage counter to go negative.
    
    It is not possible for hub_disconnect() to wait for a pending
    hub_event() call to finish, because hub_disconnect() is called with
    the device lock held and hub_event() acquires that lock.  The only
    feasible fix is to reverse the original design decision: remove the
    duplicate interface-specific usage counter and require USB drivers to
    balance their runtime PM gets and puts.  As far as I know, all
    existing drivers currently do this.
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Reported-and-tested-by: syzbot+7634edaea4d0b341c625@syzkaller.appspotmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16:
     - Adjust documentation filename
     - Don't add ReST markup in documentation
     - Update use of pm_usage_cnt in poseidon driver, which has been
       removed upstream]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 4c55614ffb6af212aa7626bb64ff974361a594b7
Author: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Date:   Thu Apr 18 17:50:20 2019 -0700

    mm/vmstat.c: fix /proc/vmstat format for CONFIG_DEBUG_TLBFLUSH=y CONFIG_SMP=n
    
    commit e8277b3b52240ec1caad8e6df278863e4bf42eac upstream.
    
    Commit 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
    depends on skipping vmstat entries with empty name introduced in
    7aaf77272358 ("mm: don't show nr_indirectly_reclaimable in
    /proc/vmstat") but reverted in b29940c1abd7 ("mm: rename and change
    semantics of nr_indirectly_reclaimable_bytes").
    
    So skipping no longer works and /proc/vmstat has misformatted lines " 0".
    
    This patch simply shows debug counters "nr_tlb_remote_*" for UP.
    
    Link: http://lkml.kernel.org/r/155481488468.467.4295519102880913454.stgit@buzz
    Fixes: 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
    Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
    Acked-by: Vlastimil Babka <vbabka@suse.cz>
    Cc: Roman Gushchin <guro@fb.com>
    Cc: Jann Horn <jannh@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 58ef1dd56dd25b8d503cf25cf9917b2776988415
Author: Masami Hiramatsu <mhiramat@kernel.org>
Date:   Sun Feb 24 01:50:49 2019 +0900

    x86/kprobes: Avoid kretprobe recursion bug
    
    commit b191fa96ea6dc00d331dcc28c1f7db5e075693a0 upstream.
    
    Avoid kretprobe recursion loop bg by setting a dummy
    kprobes to current_kprobe per-CPU variable.
    
    This bug has been introduced with the asm-coded trampoline
    code, since previously it used another kprobe for hooking
    the function return placeholder (which only has a nop) and
    trampoline handler was called from that kprobe.
    
    This revives the old lost kprobe again.
    
    With this fix, we don't see deadlock anymore.
    
    And you can see that all inner-called kretprobe are skipped.
    
      event_1                                  235               0
      event_2                                19375           19612
    
    The 1st column is recorded count and the 2nd is missed count.
    Above shows (event_1 rec) + (event_2 rec) ~= (event_2 missed)
    (some difference are here because the counter is racy)
    
    Reported-by: Andrea Righi <righi.andrea@gmail.com>
    Tested-by: Andrea Righi <righi.andrea@gmail.com>
    Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
    Acked-by: Steven Rostedt <rostedt@goodmis.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Fixes: c9becf58d935 ("[PATCH] kretprobe: kretprobe-booster")
    Link: http://lkml.kernel.org/r/155094064889.6137.972160690963039.stgit@devbox
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 51d68a4c8e5309c4f8bdcb71d8535215246210f8
Author: Masami Hiramatsu <mhiramat@kernel.org>
Date:   Sun Feb 24 01:50:20 2019 +0900

    kprobes: Mark ftrace mcount handler functions nokprobe
    
    commit fabe38ab6b2bd9418350284c63825f13b8a6abba upstream.
    
    Mark ftrace mcount handler functions nokprobe since
    probing on these functions with kretprobe pushes
    return address incorrectly on kretprobe shadow stack.
    
    Reported-by: Francis Deslauriers <francis.deslauriers@efficios.com>
    Tested-by: Andrea Righi <righi.andrea@gmail.com>
    Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
    Acked-by: Steven Rostedt <rostedt@goodmis.org>
    Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: http://lkml.kernel.org/r/155094062044.6137.6419622920568680640.stgit@devbox
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16: there is no ftrace_ops_assist_func()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2b487afcd06e39e9af6074f5ecb2e2025b84a95d
Author: Masami Hiramatsu <mhiramat@kernel.org>
Date:   Sun Feb 24 01:49:52 2019 +0900

    x86/kprobes: Verify stack frame on kretprobe
    
    commit 3ff9c075cc767b3060bdac12da72fc94dd7da1b8 upstream.
    
    Verify the stack frame pointer on kretprobe trampoline handler,
    If the stack frame pointer does not match, it skips the wrong
    entry and tries to find correct one.
    
    This can happen if user puts the kretprobe on the function
    which can be used in the path of ftrace user-function call.
    Such functions should not be probed, so this adds a warning
    message that reports which function should be blacklisted.
    
    Tested-by: Andrea Righi <righi.andrea@gmail.com>
    Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
    Acked-by: Steven Rostedt <rostedt@goodmis.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: http://lkml.kernel.org/r/155094059185.6137.15527904013362842072.stgit@devbox
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit f96f1647cf6b35c0e13b3f6e0df9585cf88e6d2f
Author: Jie Liu <liujie165@huawei.com>
Date:   Tue Apr 16 13:10:09 2019 +0800

    tipc: set sysctl_tipc_rmem and named_timeout right range
    
    commit 4bcd4ec1017205644a2697bccbc3b5143f522f5f upstream.
    
    We find that sysctl_tipc_rmem and named_timeout do not have the right minimum
    setting. sysctl_tipc_rmem should be larger than zero, like sysctl_tcp_rmem.
    And named_timeout as a timeout setting should be not less than zero.
    
    Fixes: cc79dd1ba9c10 ("tipc: change socket buffer overflow control to respect sk_rcvbuf")
    Fixes: a5325ae5b8bff ("tipc: add name distributor resiliency queue")
    Signed-off-by: Jie Liu <liujie165@huawei.com>
    Reported-by: Qiang Ning <ningqiang1@huawei.com>
    Reviewed-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
    Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: only the tipc_rmem sysctl exists here]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit dbcb50792a5175b222c181bafa51f470550ba827
Author: Takashi Iwai <tiwai@suse.de>
Date:   Tue Apr 16 17:06:33 2019 +0200

    ALSA: core: Fix card races between register and disconnect
    
    commit 2a3f7221acddfe1caa9ff09b3a8158c39b2fdeac upstream.
    
    There is a small race window in the card disconnection code that
    allows the registration of another card with the very same card id.
    This leads to a warning in procfs creation as caught by syzkaller.
    
    The problem is that we delete snd_cards and snd_cards_lock entries at
    the very beginning of the disconnection procedure.  This makes the
    slot available to be assigned for another card object while the
    disconnection procedure is being processed.  Then it becomes possible
    to issue a procfs registration with the existing file name although we
    check the conflict beforehand.
    
    The fix is simply to move the snd_cards and snd_cards_lock clearances
    at the end of the disconnection procedure.  The references to these
    entries are merely either from the global proc files like
    /proc/asound/cards or from the card registration / disconnection, so
    it should be fine to shift at the very end.
    
    Reported-by: syzbot+48df349490c36f9f54ab@syzkaller.appspotmail.com
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 1fc39f2cb2a42af109e3dd80b163ee3541d56e01
Author: Phil Auld <pauld@redhat.com>
Date:   Tue Mar 19 09:00:05 2019 -0400

    sched/fair: Limit sched_cfs_period_timer() loop to avoid hard lockup
    
    commit 2e8e19226398db8265a8e675fcc0118b9e80c9e8 upstream.
    
    With extremely short cfs_period_us setting on a parent task group with a large
    number of children the for loop in sched_cfs_period_timer() can run until the
    watchdog fires. There is no guarantee that the call to hrtimer_forward_now()
    will ever return 0.  The large number of children can make
    do_sched_cfs_period_timer() take longer than the period.
    
     NMI watchdog: Watchdog detected hard LOCKUP on cpu 24
     RIP: 0010:tg_nop+0x0/0x10
      <IRQ>
      walk_tg_tree_from+0x29/0xb0
      unthrottle_cfs_rq+0xe0/0x1a0
      distribute_cfs_runtime+0xd3/0xf0
      sched_cfs_period_timer+0xcb/0x160
      ? sched_cfs_slack_timer+0xd0/0xd0
      __hrtimer_run_queues+0xfb/0x270
      hrtimer_interrupt+0x122/0x270
      smp_apic_timer_interrupt+0x6a/0x140
      apic_timer_interrupt+0xf/0x20
      </IRQ>
    
    To prevent this we add protection to the loop that detects when the loop has run
    too many times and scales the period and quota up, proportionally, so that the timer
    can complete before then next period expires.  This preserves the relative runtime
    quota while preventing the hard lockup.
    
    A warning is issued reporting this state and the new values.
    
    Signed-off-by: Phil Auld <pauld@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Anton Blanchard <anton@ozlabs.org>
    Cc: Ben Segall <bsegall@google.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lkml.kernel.org/r/20190319130005.25492-1-pauld@redhat.com
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2429fcf06d3cb962693868ab0a927c9038f12a2d
Author: Aurelien Aptel <aaptel@suse.com>
Date:   Fri Mar 29 10:49:12 2019 +0100

    CIFS: keep FileInfo handle live during oplock break
    
    commit b98749cac4a695f084a5ff076f4510b23e353ecd upstream.
    
    In the oplock break handler, writing pending changes from pages puts
    the FileInfo handle. If the refcount reaches zero it closes the handle
    and waits for any oplock break handler to return, thus causing a deadlock.
    
    To prevent this situation:
    
    * We add a wait flag to cifsFileInfo_put() to decide whether we should
      wait for running/pending oplock break handlers
    
    * We keep an additionnal reference of the SMB FileInfo handle so that
      for the rest of the handler putting the handle won't close it.
      - The ref is bumped everytime we queue the handler via the
        cifs_queue_oplock_break() helper.
      - The ref is decremented at the end of the handler
    
    This bug was triggered by xfstest 464.
    
    Also important fix to address the various reports of
    oops in smb2_push_mandatory_locks
    
    Signed-off-by: Aurelien Aptel <aaptel@suse.com>
    Signed-off-by: Steve French <stfrench@microsoft.com>
    Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3a1cc3e8b75aff56176677050460402941cf3194
Author: Ronnie Sahlberg <lsahlber@redhat.com>
Date:   Wed Apr 10 07:47:22 2019 +1000

    cifs: fix handle leak in smb2_query_symlink()
    
    commit e6d0fb7b34f264f72c33053558a360a6a734905e upstream.
    
    If we enter smb2_query_symlink() for something that is not a symlink
    and where the SMB2_open() would succeed we would never end up
    closing this handle and would thus leak a handle on the server.
    
    Fix this by immediately calling SMB2_close() on successfull open.
    
    Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
    Signed-off-by: Steve French <stfrench@microsoft.com>
    Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fa3c9f4e709eac1a5a66afdf043fc581b36cd2d3
Author: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Date:   Tue Apr 9 11:15:29 2019 +0200

    tools lib traceevent: Fix missing equality check for strcmp
    
    commit f32c2877bcb068a718bb70094cd59ccc29d4d082 upstream.
    
    There was a missing comparison with 0 when checking if type is "s64" or
    "u64". Therefore, the body of the if-statement was entered if "type" was
    "u64" or not "s64", which made the first strcmp() redundant since if
    type is "u64", it's not "s64".
    
    If type is "s64", the body of the if-statement is not entered but since
    the remainder of the function consists of if-statements which will not
    be entered if type is "s64", we will just return "val", which is
    correct, albeit at the cost of a few more calls to strcmp(), i.e., it
    will behave just as if the if-statement was entered.
    
    If type is neither "s64" or "u64", the body of the if-statement will be
    entered incorrectly and "val" returned. This means that any type that is
    checked after "s64" and "u64" is handled the same way as "s64" and
    "u64", i.e., the limiting of "val" to fit in for example "s8" is never
    reached.
    
    This was introduced in the kernel tree when the sources were copied from
    trace-cmd in commit f7d82350e597 ("tools/events: Add files to create
    libtraceevent.a"), and in the trace-cmd repo in 1cdbae6035cei
    ("Implement typecasting in parser") when the function was introduced,
    i.e., it has always behaved the wrong way.
    
    Detected by cppcheck.
    
    Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
    Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
    Fixes: f7d82350e597 ("tools/events: Add files to create libtraceevent.a")
    Link: http://lkml.kernel.org/r/20190409091529.2686-1-rikard.falkeborn@gmail.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3849fe35584d1c936603d1a357f87ef95df5ec55
Author: Ben Gardon <bgardon@google.com>
Date:   Mon Apr 8 11:07:30 2019 -0700

    kvm: mmu: Fix overflow on kvm mmu page limit calculation
    
    commit bc8a3d8925a8fa09fa550e0da115d95851ce33c6 upstream.
    
    KVM bases its memory usage limits on the total number of guest pages
    across all memslots. However, those limits, and the calculations to
    produce them, use 32 bit unsigned integers. This can result in overflow
    if a VM has more guest pages that can be represented by a u32. As a
    result of this overflow, KVM can use a low limit on the number of MMU
    pages it will allocate. This makes KVM unable to map all of guest memory
    at once, prompting spurious faults.
    
    Tested: Ran all kvm-unit-tests on an Intel Haswell machine. This patch
            introduced no new failures.
    
    Signed-off-by: Ben Gardon <bgardon@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a5c377c984958c34fe6d7a833bc439dbd6c06db3
Author: Ian Abbott <abbotti@mev.co.uk>
Date:   Mon Apr 15 12:52:30 2019 +0100

    staging: comedi: vmk80xx: Fix possible double-free of ->usb_rx_buf
    
    commit 663d294b4768bfd89e529e069bffa544a830b5bf upstream.
    
    `vmk80xx_alloc_usb_buffers()` is called from `vmk80xx_auto_attach()` to
    allocate RX and TX buffers for USB transfers.  It allocates
    `devpriv->usb_rx_buf` followed by `devpriv->usb_tx_buf`.  If the
    allocation of `devpriv->usb_tx_buf` fails, it frees
    `devpriv->usb_rx_buf`,  leaving the pointer set dangling, and returns an
    error.  Later, `vmk80xx_detach()` will be called from the core comedi
    module code to clean up.  `vmk80xx_detach()` also frees both
    `devpriv->usb_rx_buf` and `devpriv->usb_tx_buf`, but
    `devpriv->usb_rx_buf` may have already been freed, leading to a
    double-free error.  Fix it by removing the call to
    `kfree(devpriv->usb_rx_buf)` from `vmk80xx_alloc_usb_buffers()`, relying
    on `vmk80xx_detach()` to free the memory.
    
    Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3fbee2f3b3f4048cf7a1c09acb59319223b7b1b8
Author: Ian Abbott <abbotti@mev.co.uk>
Date:   Mon Apr 15 12:10:14 2019 +0100

    staging: comedi: vmk80xx: Fix use of uninitialized semaphore
    
    commit 08b7c2f9208f0e2a32159e4e7a4831b7adb10a3e upstream.
    
    If `vmk80xx_auto_attach()` returns an error, the core comedi module code
    will call `vmk80xx_detach()` to clean up.  If `vmk80xx_auto_attach()`
    successfully allocated the comedi device private data,
    `vmk80xx_detach()` assumes that a `struct semaphore limit_sem` contained
    in the private data has been initialized and uses it.  Unfortunately,
    there are a couple of places where `vmk80xx_auto_attach()` can return an
    error after allocating the device private data but before initializing
    the semaphore, so this assumption is invalid.  Fix it by initializing
    the semaphore just after allocating the private data in
    `vmk80xx_auto_attach()` before any other errors can be returned.
    
    I believe this was the cause of the following syzbot crash report
    <https://syzkaller.appspot.com/bug?extid=54c2f58f15fe6876b6ad>:
    
    usb 1-1: config 0 has no interface number 0
    usb 1-1: New USB device found, idVendor=10cf, idProduct=8068, bcdDevice=e6.8d
    usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
    usb 1-1: config 0 descriptor??
    vmk80xx 1-1:0.117: driver 'vmk80xx' failed to auto-configure device.
    INFO: trying to register non-static key.
    the code is fine but needs lockdep annotation.
    turning off the locking correctness validator.
    CPU: 0 PID: 12 Comm: kworker/0:1 Not tainted 5.1.0-rc4-319354-g9a33b36 #3
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Workqueue: usb_hub_wq hub_event
    Call Trace:
     __dump_stack lib/dump_stack.c:77 [inline]
     dump_stack+0xe8/0x16e lib/dump_stack.c:113
     assign_lock_key kernel/locking/lockdep.c:786 [inline]
     register_lock_class+0x11b8/0x1250 kernel/locking/lockdep.c:1095
     __lock_acquire+0xfb/0x37c0 kernel/locking/lockdep.c:3582
     lock_acquire+0x10d/0x2f0 kernel/locking/lockdep.c:4211
     __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
     _raw_spin_lock_irqsave+0x44/0x60 kernel/locking/spinlock.c:152
     down+0x12/0x80 kernel/locking/semaphore.c:58
     vmk80xx_detach+0x59/0x100 drivers/staging/comedi/drivers/vmk80xx.c:829
     comedi_device_detach+0xed/0x800 drivers/staging/comedi/drivers.c:204
     comedi_device_cleanup.part.0+0x68/0x140 drivers/staging/comedi/comedi_fops.c:156
     comedi_device_cleanup drivers/staging/comedi/comedi_fops.c:187 [inline]
     comedi_free_board_dev.part.0+0x16/0x90 drivers/staging/comedi/comedi_fops.c:190
     comedi_free_board_dev drivers/staging/comedi/comedi_fops.c:189 [inline]
     comedi_release_hardware_device+0x111/0x140 drivers/staging/comedi/comedi_fops.c:2880
     comedi_auto_config.cold+0x124/0x1b0 drivers/staging/comedi/drivers.c:1068
     usb_probe_interface+0x31d/0x820 drivers/usb/core/driver.c:361
     really_probe+0x2da/0xb10 drivers/base/dd.c:509
     driver_probe_device+0x21d/0x350 drivers/base/dd.c:671
     __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778
     bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454
     __device_attach+0x223/0x3a0 drivers/base/dd.c:844
     bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514
     device_add+0xad2/0x16e0 drivers/base/core.c:2106
     usb_set_configuration+0xdf7/0x1740 drivers/usb/core/message.c:2021
     generic_probe+0xa2/0xda drivers/usb/core/generic.c:210
     usb_probe_device+0xc0/0x150 drivers/usb/core/driver.c:266
     really_probe+0x2da/0xb10 drivers/base/dd.c:509
     driver_probe_device+0x21d/0x350 drivers/base/dd.c:671
     __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778
     bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454
     __device_attach+0x223/0x3a0 drivers/base/dd.c:844
     bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514
     device_add+0xad2/0x16e0 drivers/base/core.c:2106
     usb_new_device.cold+0x537/0xccf drivers/usb/core/hub.c:2534
     hub_port_connect drivers/usb/core/hub.c:5089 [inline]
     hub_port_connect_change drivers/usb/core/hub.c:5204 [inline]
     port_event drivers/usb/core/hub.c:5350 [inline]
     hub_event+0x138e/0x3b00 drivers/usb/core/hub.c:5432
     process_one_work+0x90f/0x1580 kernel/workqueue.c:2269
     worker_thread+0x9b/0xe20 kernel/workqueue.c:2415
     kthread+0x313/0x420 kernel/kthread.c:253
     ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
    
    Reported-by: syzbot+54c2f58f15fe6876b6ad@syzkaller.appspotmail.com
    Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 9dcc2e7b9f998e5cb3c1ca1a71bfd69ce68c057f
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Mon Apr 15 11:51:38 2019 -0400

    USB: core: Fix unterminated string returned by usb_string()
    
    commit c01c348ecdc66085e44912c97368809612231520 upstream.
    
    Some drivers (such as the vub300 MMC driver) expect usb_string() to
    return a properly NUL-terminated string, even when an error occurs.
    (In fact, vub300's probe routine doesn't bother to check the return
    code from usb_string().)  When the driver goes on to use an
    unterminated string, it leads to kernel errors such as
    stack-out-of-bounds, as found by the syzkaller USB fuzzer.
    
    An out-of-range string index argument is not at all unlikely, given
    that some devices don't provide string descriptors and therefore list
    0 as the value for their string indexes.  This patch makes
    usb_string() return a properly terminated empty string along with the
    -EINVAL error code when an out-of-range index is encountered.
    
    And since a USB string index is a single-byte value, indexes >= 256
    are just as invalid as values of 0 or below.
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Reported-by: syzbot+b75b85111c10b8d680f1@syzkaller.appspotmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e7fd68a7a81a50807c43081a6ac12f63b7701612
Author: Aurelien Jarno <aurelien@aurel32.net>
Date:   Tue Apr 9 16:53:55 2019 +0200

    MIPS: scall64-o32: Fix indirect syscall number load
    
    commit 79b4a9cf0e2ea8203ce777c8d5cfa86c71eae86e upstream.
    
    Commit 4c21b8fd8f14 (MIPS: seccomp: Handle indirect system calls (o32))
    added indirect syscall detection for O32 processes running on MIPS64,
    but it did not work correctly for big endian kernel/processes. The
    reason is that the syscall number is loaded from ARG1 using the lw
    instruction while this is a 64-bit value, so zero is loaded instead of
    the syscall number.
    
    Fix the code by using the ld instruction instead. When running a 32-bit
    processes on a 64 bit CPU, the values are properly sign-extended, so it
    ensures the value passed to syscall_trace_enter is correct.
    
    Recent systemd versions with seccomp enabled whitelist the getpid
    syscall for their internal  processes (e.g. systemd-journald), but call
    it through syscall(SYS_getpid). This fix therefore allows O32 big endian
    systems with a 64-bit kernel to run recent systemd versions.
    
    Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
    Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
    Signed-off-by: Paul Burton <paul.burton@mips.com>
    Cc: Ralf Baechle <ralf@linux-mips.org>
    Cc: James Hogan <jhogan@kernel.org>
    Cc: linux-mips@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 13ff2d8cc7e51d7fd9bca13db88020fc5425180c
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun Apr 14 19:51:06 2019 +0200

    x86/speculation: Prevent deadlock on ssb_state::lock
    
    commit 2f5fb19341883bb6e37da351bc3700489d8506a7 upstream.
    
    Mikhail reported a lockdep splat related to the AMD specific ssb_state
    lock:
    
      CPU0                       CPU1
      lock(&st->lock);
                                 local_irq_disable();
                                 lock(&(&sighand->siglock)->rlock);
                                 lock(&st->lock);
      <Interrupt>
         lock(&(&sighand->siglock)->rlock);
    
      *** DEADLOCK ***
    
    The connection between sighand->siglock and st->lock comes through seccomp,
    which takes st->lock while holding sighand->siglock.
    
    Make sure interrupts are disabled when __speculation_ctrl_update() is
    invoked via prctl() -> speculation_ctrl_update(). Add a lockdep assert to
    catch future offenders.
    
    Fixes: 1f50ddb4f418 ("x86/speculation: Handle HT correctly on AMD")
    Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
    Cc: Thomas Lendacky <thomas.lendacky@amd.com>
    Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1904141948200.4917@nanos.tec.linutronix.de
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 399df2ddfb1021f5c3b79f7bd449bad63100a853
Author: Frederic Weisbecker <frederic@kernel.org>
Date:   Mon Nov 6 16:01:17 2017 +0100

    locking/lockdep: Add IRQs disabled/enabled assertion APIs: lockdep_assert_irqs_enabled()/disabled()
    
    commit f54bb2ec02c839f6bfe3e8d438cd93d30b4809dd upstream.
    
    Checking whether IRQs are enabled or disabled is a very common sanity
    check, however not free of overhead especially on fastpath where such
    assertion is very common.
    
    Lockdep is a good host for such concurrency correctness check and it
    even already tracks down IRQs disablement state. Just reuse its
    machinery. This will allow us to get rid of the flags pop and check
    overhead from fast path when kernel is built for production.
    
    Suggested-by: Peter Zijlstra <peterz@infradead.org>
    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: David S . Miller <davem@davemloft.net>
    Cc: Lai Jiangshan <jiangshanlai@gmail.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: Tejun Heo <tj@kernel.org>
    Link: http://lkml.kernel.org/r/1509980490-4285-2-git-send-email-frederic@kernel.org
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e10ea2d722a7acb063736c549b072e4297c020a0
Author: Colin Ian King <colin.king@canonical.com>
Date:   Fri Apr 12 14:45:12 2019 +0100

    vxge: fix return of a free'd memblock on a failed dma mapping
    
    commit 0a2c34f18c94b596562bf3d019fceab998b8b584 upstream.
    
    Currently if a pci dma mapping failure is detected a free'd
    memblock address is returned rather than a NULL (that indicates
    an error). Fix this by ensuring NULL is returned on this error case.
    
    Addresses-Coverity: ("Use after free")
    Fixes: 528f727279ae ("vxge: code cleanup and reorganization")
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 8fe41e807bec8adf1a218c9f8113e23af2acb4c4
Author: Vijayakumar Durai <vijayakumar.durai1@vivint.com>
Date:   Wed Mar 27 11:03:17 2019 +0100

    rt2x00: do not increment sequence number while re-transmitting
    
    commit 746ba11f170603bf1eaade817553a6c2e9135bbe upstream.
    
    Currently rt2x00 devices retransmit the management frames with
    incremented sequence number if hardware is assigning the sequence.
    
    This is HW bug fixed already for non-QOS data frames, but it should
    be fixed for management frames except beacon.
    
    Without fix retransmitted frames have wrong SN:
    
     AlphaNet_e8:fb:36 Vivotek_52:31:51 Authentication, SN=1648, FN=0, Flags=........C Frame is not being retransmitted 1648 1
     AlphaNet_e8:fb:36 Vivotek_52:31:51 Authentication, SN=1649, FN=0, Flags=....R...C Frame is being retransmitted 1649 1
     AlphaNet_e8:fb:36 Vivotek_52:31:51 Authentication, SN=1650, FN=0, Flags=....R...C Frame is being retransmitted 1650 1
    
    With the fix SN stays correctly the same:
    
     88:6a:e3:e8:f9:a2 8c:f5:a3:88:76:87 Authentication, SN=1450, FN=0, Flags=........C
     88:6a:e3:e8:f9:a2 8c:f5:a3:88:76:87 Authentication, SN=1450, FN=0, Flags=....R...C
     88:6a:e3:e8:f9:a2 8c:f5:a3:88:76:87 Authentication, SN=1450, FN=0, Flags=....R...C
    
    Signed-off-by: Vijayakumar Durai <vijayakumar.durai1@vivint.com>
    [sgruszka: simplify code, change comments and changelog]
    Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
    Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
    [bwh: Backported to 3.16: adjust filenames, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a11a987c17af6af4591fcfc54a04e1d204ce6f0e
Author: Joerg Roedel <jroedel@suse.de>
Date:   Fri Apr 12 12:50:31 2019 +0200

    iommu/amd: Set exclusion range correctly
    
    commit 3c677d206210f53a4be972211066c0f1cd47fe12 upstream.
    
    The exlcusion range limit register needs to contain the
    base-address of the last page that is part of the range, as
    bits 0-11 of this register are treated as 0xfff by the
    hardware for comparisons.
    
    So correctly set the exclusion range in the hardware to the
    last page which is _in_ the range.
    
    Fixes: b2026aa2dce44 ('x86, AMD IOMMU: add functions for programming IOMMU MMIO space')
    Signed-off-by: Joerg Roedel <jroedel@suse.de>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 83a138f5176cc8ca9e1d5c970e86fba926f76fc2
Author: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Date:   Thu Apr 11 15:08:25 2019 +0300

    net: bridge: multicast: use rcu to access port list from br_multicast_start_querier
    
    commit c5b493ce192bd7a4e7bd073b5685aad121eeef82 upstream.
    
    br_multicast_start_querier() walks over the port list but it can be
    called from a timer with only multicast_lock held which doesn't protect
    the port list, so use RCU to walk over it.
    
    Fixes: c83b8fab06fc ("bridge: Restart queries when last querier expires")
    Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 06b4ee3a744ff3193d5fc172e6300c3917a734d8
Author: Jérôme Glisse <jglisse@redhat.com>
Date:   Wed Apr 10 16:27:51 2019 -0400

    block: do not leak memory in bio_copy_user_iov()
    
    commit a3761c3c91209b58b6f33bf69dd8bb8ec0c9d925 upstream.
    
    When bio_add_pc_page() fails in bio_copy_user_iov() we should free
    the page we just allocated otherwise we are leaking it.
    
    Cc: linux-block@vger.kernel.org
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
    Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 7773a7089760cf745552a0e0ead180e64ca1b7dc
Author: Erik Schmauss <erik.schmauss@intel.com>
Date:   Mon Apr 8 13:42:26 2019 -0700

    ACPICA: Namespace: remove address node from global list after method termination
    
    commit c5781ffbbd4f742a58263458145fe7f0ac01d9e0 upstream.
    
    ACPICA commit b233720031a480abd438f2e9c643080929d144c3
    
    ASL operation_regions declare a range of addresses that it uses. In a
    perfect world, the range of addresses should be used exclusively by
    the AML interpreter. The OS can use this information to decide which
    drivers to load so that the AML interpreter and device drivers use
    different regions of memory.
    
    During table load, the address information is added to a global
    address range list. Each node in this list contains an address range
    as well as a namespace node of the operation_region. This list is
    deleted at ACPI shutdown.
    
    Unfortunately, ASL operation_regions can be declared inside of control
    methods. Although this is not recommended, modern firmware contains
    such code. New module level code changes unintentionally removed the
    functionality of adding and removing nodes to the global address
    range list.
    
    A few months ago, support for adding addresses has been re-
    implemented. However, the removal of the address range list was
    missed and resulted in some systems to crash due to the address list
    containing bogus namespace nodes from operation_regions declared in
    control methods. In order to fix the crash, this change removes
    dynamic operation_regions after control method termination.
    
    Link: https://github.com/acpica/acpica/commit/b2337200
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=202475
    Fixes: 4abb951b73ff ("ACPICA: AML interpreter: add region addresses in global list during initialization")
    Reported-by: Michael J Gruber <mjg@fedoraproject.org>
    Signed-off-by: Erik Schmauss <erik.schmauss@intel.com>
    Signed-off-by: Bob Moore <robert.moore@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fbcab84bd885b79125be32bddb88c5432dbd282b
Author: Christophe Leroy <christophe.leroy@c-s.fr>
Date:   Thu Apr 4 12:20:05 2019 +0000

    powerpc/vdso32: fix CLOCK_MONOTONIC on PPC64
    
    commit dd9a994fc68d196a052b73747e3366c57d14a09e upstream.
    
    Commit b5b4453e7912 ("powerpc/vdso64: Fix CLOCK_MONOTONIC
    inconsistencies across Y2038") changed the type of wtom_clock_sec
    to s64 on PPC64. Therefore, VDSO32 needs to read it with a 4 bytes
    shift in order to retrieve the lower part of it.
    
    Fixes: b5b4453e7912 ("powerpc/vdso64: Fix CLOCK_MONOTONIC inconsistencies across Y2038")
    Reported-by: Christian Zigotzky <chzigotzky@xenosoft.de>
    Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 30e591c61a4801318b82875c7aa84ee61a0e59a6
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Tue Feb 19 08:49:56 2019 -0800

    xsysace: Fix error handling in ace_setup
    
    commit 47b16820c490149c2923e8474048f2c6e7557cab upstream.
    
    If xace hardware reports a bad version number, the error handling code
    in ace_setup() calls put_disk(), followed by queue cleanup. However, since
    the disk data structure has the queue pointer set, put_disk() also
    cleans and releases the queue. This results in blk_cleanup_queue()
    accessing an already released data structure, which in turn may result
    in a crash such as the following.
    
    [   10.681671] BUG: Kernel NULL pointer dereference at 0x00000040
    [   10.681826] Faulting instruction address: 0xc0431480
    [   10.682072] Oops: Kernel access of bad area, sig: 11 [#1]
    [   10.682251] BE PAGE_SIZE=4K PREEMPT Xilinx Virtex440
    [   10.682387] Modules linked in:
    [   10.682528] CPU: 0 PID: 1 Comm: swapper Tainted: G        W         5.0.0-rc6-next-20190218+ #2
    [   10.682733] NIP:  c0431480 LR: c043147c CTR: c0422ad8
    [   10.682863] REGS: cf82fbe0 TRAP: 0300   Tainted: G        W          (5.0.0-rc6-next-20190218+)
    [   10.683065] MSR:  00029000 <CE,EE,ME>  CR: 22000222  XER: 00000000
    [   10.683236] DEAR: 00000040 ESR: 00000000
    [   10.683236] GPR00: c043147c cf82fc90 cf82ccc0 00000000 00000000 00000000 00000002 00000000
    [   10.683236] GPR08: 00000000 00000000 c04310bc 00000000 22000222 00000000 c0002c54 00000000
    [   10.683236] GPR16: 00000000 00000001 c09aa39c c09021b0 c09021dc 00000007 c0a68c08 00000000
    [   10.683236] GPR24: 00000001 ced6d400 ced6dcf0 c0815d9c 00000000 00000000 00000000 cedf0800
    [   10.684331] NIP [c0431480] blk_mq_run_hw_queue+0x28/0x114
    [   10.684473] LR [c043147c] blk_mq_run_hw_queue+0x24/0x114
    [   10.684602] Call Trace:
    [   10.684671] [cf82fc90] [c043147c] blk_mq_run_hw_queue+0x24/0x114 (unreliable)
    [   10.684854] [cf82fcc0] [c04315bc] blk_mq_run_hw_queues+0x50/0x7c
    [   10.685002] [cf82fce0] [c0422b24] blk_set_queue_dying+0x30/0x68
    [   10.685154] [cf82fcf0] [c0423ec0] blk_cleanup_queue+0x34/0x14c
    [   10.685306] [cf82fd10] [c054d73c] ace_probe+0x3dc/0x508
    [   10.685445] [cf82fd50] [c052d740] platform_drv_probe+0x4c/0xb8
    [   10.685592] [cf82fd70] [c052abb0] really_probe+0x20c/0x32c
    [   10.685728] [cf82fda0] [c052ae58] driver_probe_device+0x68/0x464
    [   10.685877] [cf82fdc0] [c052b500] device_driver_attach+0xb4/0xe4
    [   10.686024] [cf82fde0] [c052b5dc] __driver_attach+0xac/0xfc
    [   10.686161] [cf82fe00] [c0528428] bus_for_each_dev+0x80/0xc0
    [   10.686314] [cf82fe30] [c0529b3c] bus_add_driver+0x144/0x234
    [   10.686457] [cf82fe50] [c052c46c] driver_register+0x88/0x15c
    [   10.686610] [cf82fe60] [c09de288] ace_init+0x4c/0xac
    [   10.686742] [cf82fe80] [c0002730] do_one_initcall+0xac/0x330
    [   10.686888] [cf82fee0] [c09aafd0] kernel_init_freeable+0x34c/0x478
    [   10.687043] [cf82ff30] [c0002c6c] kernel_init+0x18/0x114
    [   10.687188] [cf82ff40] [c000f2f0] ret_from_kernel_thread+0x14/0x1c
    [   10.687349] Instruction dump:
    [   10.687435] 3863ffd4 4bfffd70 9421ffd0 7c0802a6 93c10028 7c9e2378 93e1002c 38810008
    [   10.687637] 7c7f1b78 90010034 4bfffc25 813f008c <81290040> 75290100 4182002c 80810008
    [   10.688056] ---[ end trace 13c9ff51d41b9d40 ]---
    
    Fix the problem by setting the disk queue pointer to NULL before calling
    put_disk(). A more comprehensive fix might be to rearrange the code
    to check the hardware version before initializing data structures,
    but I don't know if this would have undesirable side effects, and
    it would increase the complexity of backporting the fix to older kernels.
    
    Fixes: 74489a91dd43a ("Add support for Xilinx SystemACE CompactFlash interface")
    Acked-by: Michal Simek <michal.simek@xilinx.com>
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a9c46cb2fceb1320f0435f0388a31d196f23e60f
Author: Nick Desaulniers <ndesaulniers@google.com>
Date:   Fri Apr 5 18:38:45 2019 -0700

    lib/string.c: implement a basic bcmp
    
    commit 5f074f3e192f10c9fade898b9b3b8812e3d83342 upstream.
    
    A recent optimization in Clang (r355672) lowers comparisons of the
    return value of memcmp against zero to comparisons of the return value
    of bcmp against zero.  This helps some platforms that implement bcmp
    more efficiently than memcmp.  glibc simply aliases bcmp to memcmp, but
    an optimized implementation is in the works.
    
    This results in linkage failures for all targets with Clang due to the
    undefined symbol.  For now, just implement bcmp as a tailcail to memcmp
    to unbreak the build.  This routine can be further optimized in the
    future.
    
    Other ideas discussed:
    
     * A weak alias was discussed, but breaks for architectures that define
       their own implementations of memcmp since aliases to declarations are
       not permitted (only definitions). Arch-specific memcmp
       implementations typically declare memcmp in C headers, but implement
       them in assembly.
    
     * -ffreestanding also is used sporadically throughout the kernel.
    
     * -fno-builtin-bcmp doesn't work when doing LTO.
    
    Link: https://bugs.llvm.org/show_bug.cgi?id=41035
    Link: https://code.woboq.org/userspace/glibc/string/memcmp.c.html#bcmp
    Link: https://github.com/llvm/llvm-project/commit/8e16d73346f8091461319a7dfc4ddd18eedcff13
    Link: https://github.com/ClangBuiltLinux/linux/issues/416
    Link: http://lkml.kernel.org/r/20190313211335.165605-1-ndesaulniers@google.com
    Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
    Reported-by: Nathan Chancellor <natechancellor@gmail.com>
    Reported-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
    Suggested-by: Arnd Bergmann <arnd@arndb.de>
    Suggested-by: James Y Knight <jyknight@google.com>
    Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
    Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
    Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
    Tested-by: Nathan Chancellor <natechancellor@gmail.com>
    Reviewed-by: Masahiro Yamada <yamada.masahiro@socionext.com>
    Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: David Laight <David.Laight@ACULAB.COM>
    Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit cf0eea870d8371e0142c1b8c4acbb013b7cb917f
Author: NeilBrown <neilb@suse.com>
Date:   Fri Apr 5 11:34:40 2019 +1100

    sunrpc: don't mark uninitialised items as VALID.
    
    commit d58431eacb226222430940134d97bfd72f292fcd upstream.
    
    A recent commit added a call to cache_fresh_locked()
    when an expired item was found.
    The call sets the CACHE_VALID flag, so it is important
    that the item actually is valid.
    There are two ways it could be valid:
    1/ If ->update has been called to fill in relevant content
    2/ if CACHE_NEGATIVE is set, to say that content doesn't exist.
    
    An expired item that is waiting for an update will be neither.
    Setting CACHE_VALID will mean that a subsequent call to cache_put()
    will be likely to dereference uninitialised pointers.
    
    So we must make sure the item is valid, and we already have code to do
    that in try_to_negate_entry().  This takes the hash lock and so cannot
    be used directly, so take out the two lines that we need and use them.
    
    Now cache_fresh_locked() is certain to be called only on
    a valid item.
    
    Fixes: 4ecd55ea0742 ("sunrpc: fix cache_head leak due to queued request")
    Signed-off-by: NeilBrown <neilb@suse.com>
    Signed-off-by: J. Bruce Fields <bfields@redhat.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 1a850ccf3acbd7c2eb5c6b50e0554736c2b9b9b3
Author: Andre Przywara <andre.przywara@arm.com>
Date:   Fri Apr 5 16:20:47 2019 +0100

    PCI: Add function 1 DMA alias quirk for Marvell 9170 SATA controller
    
    commit 9cde402a59770a0669d895399c13407f63d7d209 upstream.
    
    There is a Marvell 88SE9170 PCIe SATA controller I found on a board here.
    Some quick testing with the ARM SMMU enabled reveals that it suffers from
    the same requester ID mixup problems as the other Marvell chips listed
    already.
    
    Add the PCI vendor/device ID to the list of chips which need the
    workaround.
    
    Signed-off-by: Andre Przywara <andre.przywara@arm.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5717589a3e9c56040d4596eff74d42598b3ac645
Author: Zubin Mithra <zsm@chromium.org>
Date:   Thu Apr 4 14:33:55 2019 -0700

    ALSA: seq: Fix OOB-reads from strlcpy
    
    commit 212ac181c158c09038c474ba68068be49caecebb upstream.
    
    When ioctl calls are made with non-null-terminated userspace strings,
    strlcpy causes an OOB-read from within strlen. Fix by changing to use
    strscpy instead.
    
    Signed-off-by: Zubin Mithra <zsm@chromium.org>
    Reviewed-by: Guenter Roeck <groeck@chromium.org>
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e3c039e390523242d50961e6f97d21cab13b589f
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Apr 4 18:12:17 2019 +0300

    xen: Prevent buffer overflow in privcmd ioctl
    
    commit 42d8644bd77dd2d747e004e367cb0c895a606f39 upstream.
    
    The "call" variable comes from the user in privcmd_ioctl_hypercall().
    It's an offset into the hypercall_page[] which has (PAGE_SIZE / 32)
    elements.  We need to put an upper bound on it to prevent an out of
    bounds access.
    
    Fixes: 1246ae0bb992 ("xen: add variable hypercall caller")
    Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
    Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit f4ee4821f98966482707acca74e5f3a1cf034437
Author: Liu Jian <liujian56@huawei.com>
Date:   Sun Mar 3 15:04:18 2019 +0800

    mtd: cfi: fix deadloop in cfi_cmdset_0002.c do_write_buffer
    
    commit d9b8a67b3b95a5c5aae6422b8113adc1c2485f2b upstream.
    
    In function do_write_buffer(), in the for loop, there is a case
    chip_ready() returns 1 while chip_good() returns 0, so it never
    break the loop.
    To fix this, chip_good() is enough and it should timeout if it stay
    bad for a while.
    
    Fixes: dfeae1073583("mtd: cfi_cmdset_0002: Change write buffer to check correct value")
    Signed-off-by: Yi Huaijie <yihuaijie@huawei.com>
    Signed-off-by: Liu Jian <liujian56@huawei.com>
    Reviewed-by: Tokunori Ikegami <ikegami_to@yahoo.co.jp>
    Signed-off-by: Richard Weinberger <richard@nod.at>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 33a7884bb0f8392245bc9a347138d7f320b7fa27
Author: Mike Snitzer <snitzer@redhat.com>
Date:   Wed Apr 3 12:23:11 2019 -0400

    dm: disable DISCARD if the underlying storage no longer supports it
    
    commit bcb44433bba5eaff293888ef22ffa07f1f0347d6 upstream.
    
    Storage devices which report supporting discard commands like
    WRITE_SAME_16 with unmap, but reject discard commands sent to the
    storage device.  This is a clear storage firmware bug but it doesn't
    change the fact that should a program cause discards to be sent to a
    multipath device layered on this buggy storage, all paths can end up
    failed at the same time from the discards, causing possible I/O loss.
    
    The first discard to a path will fail with Illegal Request, Invalid
    field in cdb, e.g.:
     kernel: sd 8:0:8:19: [sdfn] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
     kernel: sd 8:0:8:19: [sdfn] tag#0 Sense Key : Illegal Request [current]
     kernel: sd 8:0:8:19: [sdfn] tag#0 Add. Sense: Invalid field in cdb
     kernel: sd 8:0:8:19: [sdfn] tag#0 CDB: Write same(16) 93 08 00 00 00 00 00 a0 08 00 00 00 80 00 00 00
     kernel: blk_update_request: critical target error, dev sdfn, sector 10487808
    
    The SCSI layer converts this to the BLK_STS_TARGET error number, the sd
    device disables its support for discard on this path, and because of the
    BLK_STS_TARGET error multipath fails the discard without failing any
    path or retrying down a different path.  But subsequent discards can
    cause path failures.  Any discards sent to the path which already failed
    a discard ends up failing with EIO from blk_cloned_rq_check_limits with
    an "over max size limit" error since the discard limit was set to 0 by
    the sd driver for the path.  As the error is EIO, this now fails the
    path and multipath tries to send the discard down the next path.  This
    cycle continues as discards are sent until all paths fail.
    
    Fix this by training DM core to disable DISCARD if the underlying
    storage already did so.
    
    Also, fix branching in dm_done() and clone_endio() to reflect the
    mutually exclussive nature of the IO operations in question.
    
    Reported-by: David Jeffery <djeffery@redhat.com>
    Signed-off-by: Mike Snitzer <snitzer@redhat.com>
    [bwh: Backported to 3.16:
     - Keep using op & flag to check operation type
     - Keep using bdev_get_queue() to find queue in clone_endio()
     - WRITE_ZEROES is not handled
     - Use queue_flag_clear() instead of blk_queue_flag_clear()
     - Adjust filenames, context
     - Declare disable_discard() static as its only user is in the same
       source file]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 53fcf3e09f69055e76d84addb8d8a9231eb30f20
Author: Max Filippov <jcmvbkbc@gmail.com>
Date:   Thu Apr 4 11:08:40 2019 -0700

    xtensa: fix return_address
    
    commit ada770b1e74a77fff2d5f539bf6c42c25f4784db upstream.
    
    return_address returns the address that is one level higher in the call
    stack than requested in its argument, because level 0 corresponds to its
    caller's return address. Use requested level as the number of stack
    frames to skip.
    
    This fixes the address reported by might_sleep and friends.
    
    Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a1f324f0916bf89cbd63faa078b4a48a97ff1074
Author: Johannes Thumshirn <jthumshirn@suse.de>
Date:   Thu Jun 6 12:07:15 2019 +0200

    btrfs: correctly validate compression type
    
    commit aa53e3bfac7205fb3a8815ac1c937fd6ed01b41e upstream.
    
    Nikolay reported the following KASAN splat when running btrfs/048:
    
    [ 1843.470920] ==================================================================
    [ 1843.471971] BUG: KASAN: slab-out-of-bounds in strncmp+0x66/0xb0
    [ 1843.472775] Read of size 1 at addr ffff888111e369e2 by task btrfs/3979
    
    [ 1843.473904] CPU: 3 PID: 3979 Comm: btrfs Not tainted 5.2.0-rc3-default #536
    [ 1843.475009] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
    [ 1843.476322] Call Trace:
    [ 1843.476674]  dump_stack+0x7c/0xbb
    [ 1843.477132]  ? strncmp+0x66/0xb0
    [ 1843.477587]  print_address_description+0x114/0x320
    [ 1843.478256]  ? strncmp+0x66/0xb0
    [ 1843.478740]  ? strncmp+0x66/0xb0
    [ 1843.479185]  __kasan_report+0x14e/0x192
    [ 1843.479759]  ? strncmp+0x66/0xb0
    [ 1843.480209]  kasan_report+0xe/0x20
    [ 1843.480679]  strncmp+0x66/0xb0
    [ 1843.481105]  prop_compression_validate+0x24/0x70
    [ 1843.481798]  btrfs_xattr_handler_set_prop+0x65/0x160
    [ 1843.482509]  __vfs_setxattr+0x71/0x90
    [ 1843.483012]  __vfs_setxattr_noperm+0x84/0x130
    [ 1843.483606]  vfs_setxattr+0xac/0xb0
    [ 1843.484085]  setxattr+0x18c/0x230
    [ 1843.484546]  ? vfs_setxattr+0xb0/0xb0
    [ 1843.485048]  ? __mod_node_page_state+0x1f/0xa0
    [ 1843.485672]  ? _raw_spin_unlock+0x24/0x40
    [ 1843.486233]  ? __handle_mm_fault+0x988/0x1290
    [ 1843.486823]  ? lock_acquire+0xb4/0x1e0
    [ 1843.487330]  ? lock_acquire+0xb4/0x1e0
    [ 1843.487842]  ? mnt_want_write_file+0x3c/0x80
    [ 1843.488442]  ? debug_lockdep_rcu_enabled+0x22/0x40
    [ 1843.489089]  ? rcu_sync_lockdep_assert+0xe/0x70
    [ 1843.489707]  ? __sb_start_write+0x158/0x200
    [ 1843.490278]  ? mnt_want_write_file+0x3c/0x80
    [ 1843.490855]  ? __mnt_want_write+0x98/0xe0
    [ 1843.491397]  __x64_sys_fsetxattr+0xba/0xe0
    [ 1843.492201]  ? trace_hardirqs_off_thunk+0x1a/0x1c
    [ 1843.493201]  do_syscall_64+0x6c/0x230
    [ 1843.493988]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [ 1843.495041] RIP: 0033:0x7fa7a8a7707a
    [ 1843.495819] Code: 48 8b 0d 21 de 2b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 49 89 ca b8 be 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d ee dd 2b 00 f7 d8 64 89 01 48
    [ 1843.499203] RSP: 002b:00007ffcb73bca38 EFLAGS: 00000202 ORIG_RAX: 00000000000000be
    [ 1843.500210] RAX: ffffffffffffffda RBX: 00007ffcb73bda9d RCX: 00007fa7a8a7707a
    [ 1843.501170] RDX: 00007ffcb73bda9d RSI: 00000000006dc050 RDI: 0000000000000003
    [ 1843.502152] RBP: 00000000006dc050 R08: 0000000000000000 R09: 0000000000000000
    [ 1843.503109] R10: 0000000000000002 R11: 0000000000000202 R12: 00007ffcb73bda91
    [ 1843.504055] R13: 0000000000000003 R14: 00007ffcb73bda82 R15: ffffffffffffffff
    
    [ 1843.505268] Allocated by task 3979:
    [ 1843.505771]  save_stack+0x19/0x80
    [ 1843.506211]  __kasan_kmalloc.constprop.5+0xa0/0xd0
    [ 1843.506836]  setxattr+0xeb/0x230
    [ 1843.507264]  __x64_sys_fsetxattr+0xba/0xe0
    [ 1843.507886]  do_syscall_64+0x6c/0x230
    [ 1843.508429]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
    
    [ 1843.509558] Freed by task 0:
    [ 1843.510188] (stack is not available)
    
    [ 1843.511309] The buggy address belongs to the object at ffff888111e369e0
                    which belongs to the cache kmalloc-8 of size 8
    [ 1843.514095] The buggy address is located 2 bytes inside of
                    8-byte region [ffff888111e369e0, ffff888111e369e8)
    [ 1843.516524] The buggy address belongs to the page:
    [ 1843.517561] page:ffff88813f478d80 refcount:1 mapcount:0 mapping:ffff88811940c300 index:0xffff888111e373b8 compound_mapcount: 0
    [ 1843.519993] flags: 0x4404000010200(slab|head)
    [ 1843.520951] raw: 0004404000010200 ffff88813f48b008 ffff888119403d50 ffff88811940c300
    [ 1843.522616] raw: ffff888111e373b8 000000000016000f 00000001ffffffff 0000000000000000
    [ 1843.524281] page dumped because: kasan: bad access detected
    
    [ 1843.525936] Memory state around the buggy address:
    [ 1843.526975]  ffff888111e36880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [ 1843.528479]  ffff888111e36900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [ 1843.530138] >ffff888111e36980: fc fc fc fc fc fc fc fc fc fc fc fc 02 fc fc fc
    [ 1843.531877]                                                        ^
    [ 1843.533287]  ffff888111e36a00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [ 1843.534874]  ffff888111e36a80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    [ 1843.536468] ==================================================================
    
    This is caused by supplying a too short compression value ('lz') in the
    test-case and comparing it to 'lzo' with strncmp() and a length of 3.
    strncmp() read past the 'lz' when looking for the 'o' and thus caused an
    out-of-bounds read.
    
    Introduce a new check 'btrfs_compress_is_valid_type()' which not only
    checks the user-supplied value against known compression types, but also
    employs checks for too short values.
    
    Reported-by: Nikolay Borisov <nborisov@suse.com>
    Fixes: 272e5326c783 ("btrfs: prop: fix vanished compression property after failed set")
    Reviewed-by: Nikolay Borisov <nborisov@suse.com>
    Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
    Reviewed-by: David Sterba <dsterba@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    [bwh: Backported to 3.16:
     - "zstd" is not supported
     - Add definition of btrfs_compression_types[]
     - Include compression.h in props.c
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 7eaca00e59130c05df132e06a7a45752c2cd55f6
Author: Anand Jain <anand.jain@oracle.com>
Date:   Tue Apr 2 18:07:40 2019 +0800

    btrfs: prop: fix vanished compression property after failed set
    
    commit 272e5326c7837697882ce3162029ba893059b616 upstream.
    
    The compression property resets to NULL, instead of the old value if we
    fail to set the new compression parameter.
    
      $ btrfs prop get /btrfs compression
        compression=lzo
      $ btrfs prop set /btrfs compression zli
        ERROR: failed to set compression for /btrfs: Invalid argument
      $ btrfs prop get /btrfs compression
    
    This is because the compression property ->validate() is successful for
    'zli' as the strncmp() used the length passed from the userspace.
    
    Fix it by using the expected string length in strncmp().
    
    Fixes: 63541927c8d1 ("Btrfs: add support for inode properties")
    Fixes: 5c1aab1dd544 ("btrfs: Add zstd support")
    Reviewed-by: Nikolay Borisov <nborisov@suse.com>
    Signed-off-by: Anand Jain <anand.jain@oracle.com>
    Reviewed-by: David Sterba <dsterba@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    [bwh: Backported to 3.16: "zstd" is not supported]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit bc05cf847507f322d9a656cfd46b598e51cb6bd8
Author: Mel Gorman <mgorman@techsingularity.net>
Date:   Tue Mar 19 12:36:10 2019 +0000

    sched/fair: Do not re-read ->h_load_next during hierarchical load calculation
    
    commit 0e9f02450da07fc7b1346c8c32c771555173e397 upstream.
    
    A NULL pointer dereference bug was reported on a distribution kernel but
    the same issue should be present on mainline kernel. It occured on s390
    but should not be arch-specific.  A partial oops looks like:
    
      Unable to handle kernel pointer dereference in virtual kernel address space
      ...
      Call Trace:
        ...
        try_to_wake_up+0xfc/0x450
        vhost_poll_wakeup+0x3a/0x50 [vhost]
        __wake_up_common+0xbc/0x178
        __wake_up_common_lock+0x9e/0x160
        __wake_up_sync_key+0x4e/0x60
        sock_def_readable+0x5e/0x98
    
    The bug hits any time between 1 hour to 3 days. The dereference occurs
    in update_cfs_rq_h_load when accumulating h_load. The problem is that
    cfq_rq->h_load_next is not protected by any locking and can be updated
    by parallel calls to task_h_load. Depending on the compiler, code may be
    generated that re-reads cfq_rq->h_load_next after the check for NULL and
    then oops when reading se->avg.load_avg. The dissassembly showed that it
    was possible to reread h_load_next after the check for NULL.
    
    While this does not appear to be an issue for later compilers, it's still
    an accident if the correct code is generated. Full locking in this path
    would have high overhead so this patch uses READ_ONCE to read h_load_next
    only once and check for NULL before dereferencing. It was confirmed that
    there were no further oops after 10 days of testing.
    
    As Peter pointed out, it is also necessary to use WRITE_ONCE() to avoid any
    potential problems with store tearing.
    
    Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mike Galbraith <efault@gmx.de>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Fixes: 685207963be9 ("sched: Move h_load calculation to task_h_load()")
    Link: https://lkml.kernel.org/r/20190319123610.nsivgf3mjbjjesxb@techsingularity.net
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    [bwh: Backported to 3.16: use ACCESS_ONCE()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit c3877029d2374d70aa35961c596555f14b798f62
Author: Steffen Klassert <steffen.klassert@secunet.com>
Date:   Tue Feb 26 07:04:50 2019 +0100

    xfrm4: Fix uninitialized memory read in _decode_session4
    
    commit 8742dc86d0c7a9628117a989c11f04a9b6b898f3 upstream.
    
    We currently don't reload pointers pointing into skb header
    after doing pskb_may_pull() in _decode_session4(). So in case
    pskb_may_pull() changed the pointers, we read from random
    memory. Fix this by putting all the needed infos on the
    stack, so that we don't need to access the header pointers
    after doing pskb_may_pull().
    
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 8e9ba7fbb8088e798390b7e39b7eb282325be7c9
Author: Steffen Klassert <steffen.klassert@secunet.com>
Date:   Fri Oct 23 07:32:39 2015 +0200

    xfrm4: Reload skb header pointers after calling pskb_may_pull.
    
    commit ea673a4d3a337184f3c314dcc6300bf02f39e077 upstream.
    
    A call to pskb_may_pull may change the pointers into the packet,
    so reload the pointers after the call.
    
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e31193e134e4c614e61df99c6fe5461dc4abf9b5
Author: Steffen Klassert <steffen.klassert@secunet.com>
Date:   Fri Oct 23 07:31:23 2015 +0200

    xfrm4: Fix header checks in _decode_session4.
    
    commit 1a14f1e5550a341f76e5c8f596e9b5f8a886dfbc upstream.
    
    We skip the header informations if the data pointer points
    already behind the header in question for some protocols.
    This is because we call pskb_may_pull with a negative value
    converted to unsigened int from pskb_may_pull in this case.
    Skipping the header informations can lead to incorrect policy
    lookups, so fix it by a check of the data pointer position
    before we call pskb_may_pull.
    
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 6f5a5f7e229e3ec71d729f3fd4479a11a0a21fd8
Author: YueHaibing <yuehaibing@huawei.com>
Date:   Mon Apr 1 09:35:54 2019 +0800

    dccp: Fix memleak in __feat_register_sp
    
    commit 1d3ff0950e2b40dc861b1739029649d03f591820 upstream.
    
    If dccp_feat_push_change fails, we forget free the mem
    which is alloced by kmemdup in dccp_feat_clone_sp_val.
    
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Fixes: e8ef967a54f4 ("dccp: Registration routines for changing feature values")
    Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
    Signed-off-by: YueHaibing <yuehaibing@huawei.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2f62bb9249b9ba450fd52afb586461f929fae870
Author: Ilya Dryomov <idryomov@gmail.com>
Date:   Tue Mar 26 20:20:58 2019 +0100

    dm table: propagate BDI_CAP_STABLE_WRITES to fix sporadic checksum errors
    
    commit eb40c0acdc342b815d4d03ae6abb09e80c0f2988 upstream.
    
    Some devices don't use blk_integrity but still want stable pages
    because they do their own checksumming.  Examples include rbd and iSCSI
    when data digests are negotiated.  Stacking DM (and thus LVM) on top of
    these devices results in sporadic checksum errors.
    
    Set BDI_CAP_STABLE_WRITES if any underlying device has it set.
    
    Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
    Signed-off-by: Mike Snitzer <snitzer@redhat.com>
    [bwh: Backported to 3.16: request_queue::backing_dev_info is a struct
     not a pointer]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 246ead036a9ed8cfb0d4fe118d7695b1de31a389
Author: Fabrice Gasnier <fabrice.gasnier@st.com>
Date:   Mon Mar 25 14:01:23 2019 +0100

    iio: core: fix a possible circular locking dependency
    
    commit 7f75591fc5a123929a29636834d1bcb8b5c9fee3 upstream.
    
    This fixes a possible circular locking dependency detected warning seen
    with:
    - CONFIG_PROVE_LOCKING=y
    - consumer/provider IIO devices (ex: "voltage-divider" consumer of "adc")
    
    When using the IIO consumer interface, e.g. iio_channel_get(), the consumer
    device will likely call iio_read_channel_raw() or similar that rely on
    'info_exist_lock' mutex.
    
    typically:
    ...
            mutex_lock(&chan->indio_dev->info_exist_lock);
            if (chan->indio_dev->info == NULL) {
                    ret = -ENODEV;
                    goto err_unlock;
            }
            ret = do_some_ops()
    err_unlock:
            mutex_unlock(&chan->indio_dev->info_exist_lock);
            return ret;
    ...
    
    Same mutex is also hold in iio_device_unregister().
    
    The following deadlock warning happens when:
    - the consumer device has called an API like iio_read_channel_raw()
      at least once.
    - the consumer driver is unregistered, removed (unbind from sysfs)
    
    ======================================================
    WARNING: possible circular locking dependency detected
    4.19.24 #577 Not tainted
    ------------------------------------------------------
    sh/372 is trying to acquire lock:
    (kn->count#30){++++}, at: kernfs_remove_by_name_ns+0x3c/0x84
    
    but task is already holding lock:
    (&dev->info_exist_lock){+.+.}, at: iio_device_unregister+0x18/0x60
    
    which lock already depends on the new lock.
    
    the existing dependency chain (in reverse order) is:
    
    -> #1 (&dev->info_exist_lock){+.+.}:
           __mutex_lock+0x70/0xa3c
           mutex_lock_nested+0x1c/0x24
           iio_read_channel_raw+0x1c/0x60
           iio_read_channel_info+0xa8/0xb0
           dev_attr_show+0x1c/0x48
           sysfs_kf_seq_show+0x84/0xec
           seq_read+0x154/0x528
           __vfs_read+0x2c/0x15c
           vfs_read+0x8c/0x110
           ksys_read+0x4c/0xac
           ret_fast_syscall+0x0/0x28
           0xbedefb60
    
    -> #0 (kn->count#30){++++}:
           lock_acquire+0xd8/0x268
           __kernfs_remove+0x288/0x374
           kernfs_remove_by_name_ns+0x3c/0x84
           remove_files+0x34/0x78
           sysfs_remove_group+0x40/0x9c
           sysfs_remove_groups+0x24/0x34
           device_remove_attrs+0x38/0x64
           device_del+0x11c/0x360
           cdev_device_del+0x14/0x2c
           iio_device_unregister+0x24/0x60
           release_nodes+0x1bc/0x200
           device_release_driver_internal+0x1a0/0x230
           unbind_store+0x80/0x130
           kernfs_fop_write+0x100/0x1e4
           __vfs_write+0x2c/0x160
           vfs_write+0xa4/0x17c
           ksys_write+0x4c/0xac
           ret_fast_syscall+0x0/0x28
           0xbe906840
    
    other info that might help us debug this:
    
     Possible unsafe locking scenario:
    
           CPU0                    CPU1
           ----                    ----
      lock(&dev->info_exist_lock);
                                   lock(kn->count#30);
                                   lock(&dev->info_exist_lock);
      lock(kn->count#30);
    
     *** DEADLOCK ***
    ...
    
    cdev_device_del() can be called without holding the lock. It should be safe
    as info_exist_lock prevents kernelspace consumers to use the exported
    routines during/after provider removal. cdev_device_del() is for userspace.
    
    Help to reproduce:
    See example: Documentation/devicetree/bindings/iio/afe/voltage-divider.txt
    sysv {
            compatible = "voltage-divider";
            io-channels = <&adc 0>;
            output-ohms = <22>;
            full-ohms = <222>;
    };
    
    First, go to iio:deviceX for the "voltage-divider", do one read:
    $ cd /sys/bus/iio/devices/iio:deviceX
    $ cat in_voltage0_raw
    
    Then, unbind the consumer driver. It triggers above deadlock warning.
    $ cd /sys/bus/platform/drivers/iio-rescale/
    $ echo sysv > unbind
    
    Note I don't actually expect stable will pick this up all the
    way back into IIO being in staging, but if's probably valid that
    far back.
    
    Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
    Fixes: ac917a81117c ("staging:iio:core set the iio_dev.info pointer to null on unregister")
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 79c7d53c4e3df6bc0c41b62adb0aefe10d28a888
Author: YueHaibing <yuehaibing@huawei.com>
Date:   Thu Mar 28 20:44:40 2019 -0700

    fs/proc/proc_sysctl.c: fix NULL pointer dereference in put_links
    
    commit 23da9588037ecdd4901db76a5b79a42b529c4ec3 upstream.
    
    Syzkaller reports:
    
    kasan: GPF could be caused by NULL-ptr deref or user memory access
    general protection fault: 0000 [#1] SMP KASAN PTI
    CPU: 1 PID: 5373 Comm: syz-executor.0 Not tainted 5.0.0-rc8+ #3
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
    RIP: 0010:put_links+0x101/0x440 fs/proc/proc_sysctl.c:1599
    Code: 00 0f 85 3a 03 00 00 48 8b 43 38 48 89 44 24 20 48 83 c0 38 48 89 c2 48 89 44 24 28 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 <80> 3c 02 00 0f 85 fe 02 00 00 48 8b 74 24 20 48 c7 c7 60 2a 9d 91
    RSP: 0018:ffff8881d828f238 EFLAGS: 00010202
    RAX: dffffc0000000000 RBX: ffff8881e01b1140 RCX: ffffffff8ee98267
    RDX: 0000000000000007 RSI: ffffc90001479000 RDI: ffff8881e01b1178
    RBP: dffffc0000000000 R08: ffffed103ee27259 R09: ffffed103ee27259
    R10: 0000000000000001 R11: ffffed103ee27258 R12: fffffffffffffff4
    R13: 0000000000000006 R14: ffff8881f59838c0 R15: dffffc0000000000
    FS:  00007f072254f700(0000) GS:ffff8881f7100000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007fff8b286668 CR3: 00000001f0542002 CR4: 00000000007606e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    PKRU: 55555554
    Call Trace:
     drop_sysctl_table+0x152/0x9f0 fs/proc/proc_sysctl.c:1629
     get_subdir fs/proc/proc_sysctl.c:1022 [inline]
     __register_sysctl_table+0xd65/0x1090 fs/proc/proc_sysctl.c:1335
     br_netfilter_init+0xbc/0x1000 [br_netfilter]
     do_one_initcall+0xfa/0x5ca init/main.c:887
     do_init_module+0x204/0x5f6 kernel/module.c:3460
     load_module+0x66b2/0x8570 kernel/module.c:3808
     __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
     do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
     entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x462e99
    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 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
    RSP: 002b:00007f072254ec58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
    RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
    RDX: 0000000000000000 RSI: 0000000020000280 RDI: 0000000000000003
    RBP: 00007f072254ec70 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 00007f072254f6bc
    R13: 00000000004bcefa R14: 00000000006f6fb0 R15: 0000000000000004
    Modules linked in: br_netfilter(+) dvb_usb_dibusb_mc_common dib3000mc dibx000_common dvb_usb_dibusb_common dvb_usb_dw2102 dvb_usb classmate_laptop palmas_regulator cn videobuf2_v4l2 v4l2_common snd_soc_bd28623 mptbase snd_usb_usx2y snd_usbmidi_lib snd_rawmidi wmi libnvdimm lockd sunrpc grace rc_kworld_pc150u rc_core rtc_da9063 sha1_ssse3 i2c_cros_ec_tunnel adxl34x_spi adxl34x nfnetlink lib80211 i5500_temp dvb_as102 dvb_core videobuf2_common videodev media videobuf2_vmalloc videobuf2_memops udc_core lnbp22 leds_lp3952 hid_roccat_ryos s1d13xxxfb mtd vport_geneve openvswitch nf_conncount nf_nat_ipv6 nsh geneve udp_tunnel ip6_udp_tunnel snd_soc_mt6351 sis_agp phylink snd_soc_adau1761_spi snd_soc_adau1761 snd_soc_adau17x1 snd_soc_core snd_pcm_dmaengine ac97_bus snd_compress snd_soc_adau_utils snd_soc_sigmadsp_regmap snd_soc_sigmadsp raid_class hid_roccat_konepure hid_roccat_common hid_roccat c2port_duramar2150 core mdio_bcm_unimac iptable_security iptable_raw iptable_mangle
     iptable_nat nf_nat_ipv4 nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_filter bpfilter ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel hsr veth netdevsim devlink vxcan batman_adv cfg80211 rfkill chnl_net caif nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel joydev mousedev ide_pci_generic piix aesni_intel aes_x86_64 ide_core crypto_simd atkbd cryptd glue_helper serio_raw ata_generic pata_acpi i2c_piix4 floppy sch_fq_codel ip_tables x_tables ipv6 [last unloaded: lm73]
    Dumping ftrace buffer:
       (ftrace buffer empty)
    ---[ end trace 770020de38961fd0 ]---
    
    A new dir entry can be created in get_subdir and its 'header->parent' is
    set to NULL.  Only after insert_header success, it will be set to 'dir',
    otherwise 'header->parent' is set to NULL and drop_sysctl_table is called.
    However in err handling path of get_subdir, drop_sysctl_table also be
    called on 'new->header' regardless its value of parent pointer.  Then
    put_links is called, which triggers NULL-ptr deref when access member of
    header->parent.
    
    In fact we have multiple error paths which call drop_sysctl_table() there,
    upon failure on insert_links() we also call drop_sysctl_table().And even
    in the successful case on __register_sysctl_table() we still always call
    drop_sysctl_table().This patch fix it.
    
    Link: http://lkml.kernel.org/r/20190314085527.13244-1-yuehaibing@huawei.com
    Fixes: 0e47c99d7fe25 ("sysctl: Replace root_list with links between sysctl_table_sets")
    Signed-off-by: YueHaibing <yuehaibing@huawei.com>
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Acked-by: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Eric W. Biederman <ebiederm@xmission.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 25f144c9799d974445d683ccd9569e45417ea643
Author: Sean Christopherson <sean.j.christopherson@intel.com>
Date:   Thu Mar 7 15:43:02 2019 -0800

    KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts
    
    commit 0cf9135b773bf32fba9dd8e6699c1b331ee4b749 upstream.
    
    The CPUID flag ARCH_CAPABILITIES is unconditioinally exposed to host
    userspace for all x86 hosts, i.e. KVM advertises ARCH_CAPABILITIES
    regardless of hardware support under the pretense that KVM fully
    emulates MSR_IA32_ARCH_CAPABILITIES.  Unfortunately, only VMX hosts
    handle accesses to MSR_IA32_ARCH_CAPABILITIES (despite KVM_GET_MSRS
    also reporting MSR_IA32_ARCH_CAPABILITIES for all hosts).
    
    Move the MSR_IA32_ARCH_CAPABILITIES handling to common x86 code so
    that it's emulated on AMD hosts.
    
    Fixes: 1eaafe91a0df4 ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported")
    Reported-by: Xiaoyao Li <xiaoyao.li@linux.intel.com>
    Cc: Jim Mattson <jmattson@google.com>
    Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    [bwh: Backported to 3.16:
     - Keep using guest_cpuid_has_arch_capabilities() to check the CPUID
     - Keep using rdmsrl() to get the initial value of IA32_ARCH_CAPABILITIES
     - Adjust filenames, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 0824675ce7b01210b2e35b6f10b690c3f6ca0d93
Author: Jim Mattson <jmattson@google.com>
Date:   Wed May 9 14:29:35 2018 -0700

    kvm: x86: IA32_ARCH_CAPABILITIES is always supported
    
    commit 1eaafe91a0df4157521b6417b3dd8430bf5f52f0 upstream.
    
    If there is a possibility that a VM may migrate to a Skylake host,
    then the hypervisor should report IA32_ARCH_CAPABILITIES.RSBA[bit 2]
    as being set (future work, of course). This implies that
    CPUID.(EAX=7,ECX=0):EDX.ARCH_CAPABILITIES[bit 29] should be
    set. Therefore, kvm should report this CPUID bit as being supported
    whether or not the host supports it.  Userspace is still free to clear
    the bit if it chooses.
    
    For more information on RSBA, see Intel's white paper, "Retpoline: A
    Branch Target Injection Mitigation" (Document Number 337131-001),
    currently available at https://bugzilla.kernel.org/show_bug.cgi?id=199511.
    
    Since the IA32_ARCH_CAPABILITIES MSR is emulated in kvm, there is no
    dependency on hardware support for this feature.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
    Fixes: 28c1c9fabf48 ("KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES")
    Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit e62b3b79691dc02ebf32b2326f0d9509c7702365
Author: Sean Christopherson <sean.j.christopherson@intel.com>
Date:   Fri Feb 15 12:48:39 2019 -0800

    KVM: Reject device ioctls from processes other than the VM's creator
    
    commit ddba91801aeb5c160b660caed1800eb3aef403f8 upstream.
    
    KVM's API requires thats ioctls must be issued from the same process
    that created the VM.  In other words, userspace can play games with a
    VM's file descriptors, e.g. fork(), SCM_RIGHTS, etc..., but only the
    creator can do anything useful.  Explicitly reject device ioctls that
    are issued by a process other than the VM's creator, and update KVM's
    API documentation to extend its requirements to device ioctls.
    
    Fixes: 852b6d57dc7f ("kvm: add device control API")
    Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 4f7aaeafd908e4b36236c4516db2ee80a4bf2705
Author: David Howells <dhowells@redhat.com>
Date:   Wed Mar 27 22:48:02 2019 +0000

    afs: Fix StoreData op marshalling
    
    commit 8c7ae38d1ce12a0eaeba655df8562552b3596c7f upstream.
    
    The marshalling of AFS.StoreData, AFS.StoreData64 and YFS.StoreData64 calls
    generated by ->setattr() ops for the purpose of expanding a file is
    incorrect due to older documentation incorrectly describing the way the RPC
    'FileLength' parameter is meant to work.
    
    The older documentation says that this is the length the file is meant to
    end up at the end of the operation; however, it was never implemented this
    way in any of the servers, but rather the file is truncated down to this
    before the write operation is effected, and never expanded to it (and,
    indeed, it was renamed to 'TruncPos' in 2014).
    
    Fix this by setting the position parameter to the new file length and doing
    a zero-lengh write there.
    
    The bug causes Xwayland to SIGBUS due to unexpected non-expansion of a file
    it then mmaps.  This can be tested by giving the following test program a
    filename in an AFS directory:
    
            #include <stdio.h>
            #include <stdlib.h>
            #include <unistd.h>
            #include <fcntl.h>
            #include <sys/mman.h>
            int main(int argc, char *argv[])
            {
                    char *p;
                    int fd;
                    if (argc != 2) {
                            fprintf(stderr,
                                    "Format: test-trunc-mmap <file>\n");
                            exit(2);
                    }
                    fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC);
                    if (fd < 0) {
                            perror(argv[1]);
                            exit(1);
                    }
                    if (ftruncate(fd, 0x140008) == -1) {
                            perror("ftruncate");
                            exit(1);
                    }
                    p = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
                             MAP_SHARED, fd, 0);
                    if (p == MAP_FAILED) {
                            perror("mmap");
                            exit(1);
                    }
                    p[0] = 'a';
                    if (munmap(p, 4096) < 0) {
                            perror("munmap");
                            exit(1);
                    }
                    if (close(fd) < 0) {
                            perror("close");
                            exit(1);
                    }
                    exit(0);
            }
    
    Fixes: 31143d5d515e ("AFS: implement basic file write support")
    Reported-by: Jonathan Billings <jsbillin@umich.edu>
    Tested-by: Jonathan Billings <jsbillin@umich.edu>
    Signed-off-by: David Howells <dhowells@redhat.com>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.16: drop change in yfsclient.c]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 647f8e5ee1b2a8553797c4be45d9350d85d55cb6
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Mar 27 10:11:14 2019 +0900

    USB: serial: cp210x: add new device id
    
    commit a595ecdd5f60b2d93863cebb07eec7f935839b54 upstream.
    
    Lorenz Messtechnik has a device that is controlled by the cp210x driver,
    so add the device id to the driver.  The device id was provided by
    Silicon-Labs for the devices from this vendor.
    
    Reported-by: Uli <t9cpu@web.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 722163784a4cbf24c88465ccd82cf85fcd66a512
Author: Steffen Maier <maier@linux.ibm.com>
Date:   Tue Mar 26 14:36:59 2019 +0100

    scsi: zfcp: fix scsi_eh host reset with port_forced ERP for non-NPIV FCP devices
    
    commit 242ec1455151267fe35a0834aa9038e4c4670884 upstream.
    
    Suppose more than one non-NPIV FCP device is active on the same channel.
    Send I/O to storage and have some of the pending I/O run into a SCSI
    command timeout, e.g. due to bit errors on the fibre. Now the error
    situation stops. However, we saw FCP requests continue to timeout in the
    channel. The abort will be successful, but the subsequent TUR fails.
    Scsi_eh starts. The LUN reset fails. The target reset fails.  The host
    reset only did an FCP device recovery. However, for non-NPIV FCP devices,
    this does not close and reopen ports on the SAN-side if other non-NPIV FCP
    device(s) share the same open ports.
    
    In order to resolve the continuing FCP request timeouts, we need to
    explicitly close and reopen ports on the SAN-side.
    
    This was missing since the beginning of zfcp in v2.6.0 history commit
    ea127f975424 ("[PATCH] s390 (7/7): zfcp host adapter.").
    
    Note: The FSF requests for forced port reopen could run into FSF request
    timeouts due to other reasons. This would trigger an internal FCP device
    recovery. Pending forced port reopen recoveries would get dismissed. So
    some ports might not get fully reopened during this host reset handler.
    However, subsequent I/O would trigger the above described escalation and
    eventually all ports would be forced reopen to resolve any continuing FCP
    request timeouts due to earlier bit errors.
    
    Signed-off-by: Steffen Maier <maier@linux.ibm.com>
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Reviewed-by: Jens Remus <jremus@linux.ibm.com>
    Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 506aba4f1fdf7e57d12b17a130abac97f87ebd73
Author: Steffen Maier <maier@linux.ibm.com>
Date:   Tue Mar 26 14:36:58 2019 +0100

    scsi: zfcp: fix rport unblock if deleted SCSI devices on Scsi_Host
    
    commit fe67888fc007a76b81e37da23ce5bd8fb95890b0 upstream.
    
    An already deleted SCSI device can exist on the Scsi_Host and remain there
    because something still holds a reference.  A new SCSI device with the same
    H:C:T:L and FCP device, target port WWPN, and FCP LUN can be created.  When
    we try to unblock an rport, we still find the deleted SCSI device and
    return early because the zfcp_scsi_dev of that SCSI device is not
    ZFCP_STATUS_COMMON_UNBLOCKED. Hence we miss to unblock the rport, even if
    the new proper SCSI device would be in good state.
    
    Therefore, skip deleted SCSI devices when iterating the sdevs of the shost.
    [cf. __scsi_device_lookup{_by_target}() or scsi_device_get()]
    
    The following abbreviated trace sequence can indicate such problem:
    
    Area           : REC
    Tag            : ersfs_3
    LUN            : 0x4045400300000000
    WWPN           : 0x50050763031bd327
    LUN status     : 0x40000000     not ZFCP_STATUS_COMMON_UNBLOCKED
    Ready count    : n              not incremented yet
    Running count  : 0x00000000
    ERP want       : 0x01
    ERP need       : 0xc1           ZFCP_ERP_ACTION_NONE
    
    Area           : REC
    Tag            : ersfs_3
    LUN            : 0x4045400300000000
    WWPN           : 0x50050763031bd327
    LUN status     : 0x41000000
    Ready count    : n+1
    Running count  : 0x00000000
    ERP want       : 0x01
    ERP need       : 0x01
    
    ...
    
    Area           : REC
    Level          : 4              only with increased trace level
    Tag            : ertru_l
    LUN            : 0x4045400300000000
    WWPN           : 0x50050763031bd327
    LUN status     : 0x40000000
    Request ID     : 0x0000000000000000
    ERP status     : 0x01800000
    ERP step       : 0x1000
    ERP action     : 0x01
    ERP count      : 0x00
    
    NOT followed by a trace record with tag "scpaddy"
    for WWPN 0x50050763031bd327.
    
    Signed-off-by: Steffen Maier <maier@linux.ibm.com>
    Fixes: 6f2ce1c6af37 ("scsi: zfcp: fix rport unblock race with LUN recovery")
    Reviewed-by: Jens Remus <jremus@linux.ibm.com>
    Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 521ee6fbb7336a04ef50a613b42a6e99b5251b55
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Fri Mar 22 20:00:20 2019 +0100

    net: phy: don't clear BMCR in genphy_soft_reset
    
    commit d29f5aa0bc0c321e1b9e4658a2a7e08e885da52a upstream.
    
    So far we effectively clear the BMCR register. Some PHY's can deal
    with this (e.g. because they reset BMCR to a default as part of a
    soft-reset) whilst on others this causes issues because e.g. the
    autoneg bit is cleared. Marvell is an example, see also thread [0].
    So let's be a little bit more gentle and leave all bits we're not
    interested in as-is. This change is needed for PHY drivers to
    properly deal with the original patch.
    
    [0] https://marc.info/?t=155264050700001&r=1&w=2
    
    Fixes: 6e2d85ec0559 ("net: phy: Stop with excessive soft reset")
    Tested-by: Phil Reid <preid@electromag.com.au>
    Tested-by: liweihang <liweihang@hisilicon.com>
    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: open-code phy_set_bits()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit c304704b4d6bec7863071995b205832083e6c38d
Author: Takashi Iwai <tiwai@suse.de>
Date:   Mon Mar 25 10:38:58 2019 +0100

    ALSA: pcm: Don't suspend stream in unrecoverable PCM state
    
    commit 113ce08109f8e3b091399e7cc32486df1cff48e7 upstream.
    
    Currently PCM core sets each opened stream forcibly to SUSPENDED state
    via snd_pcm_suspend_all() call, and the user-space is responsible for
    re-triggering the resume manually either via snd_pcm_resume() or
    prepare call.  The scheme works fine usually, but there are corner
    cases where the stream can't be resumed by that call: the streams
    still in OPEN state before finishing hw_params.  When they are
    suspended, user-space cannot perform resume or prepare because they
    haven't been set up yet.  The only possible recovery is to re-open the
    device, which isn't nice at all.  Similarly, when a stream is in
    DISCONNECTED state, it makes no sense to change it to SUSPENDED
    state.  Ditto for in SETUP state; which you can re-prepare directly.
    
    So, this patch addresses these issues by filtering the PCM streams to
    be suspended by checking the PCM state.  When a stream is in either
    OPEN, SETUP or DISCONNECTED as well as already SUSPENDED, the suspend
    action is skipped.
    
    To be noted, this problem was originally reported for the PCM runtime
    PM on HD-audio.  And, the runtime PM problem itself was already
    addressed (although not intended) by the code refactoring commits
    3d21ef0b49f8 ("ALSA: pcm: Suspend streams globally via device type PM
    ops") and 17bc4815de58 ("ALSA: pci: Remove superfluous
    snd_pcm_suspend*() calls").  These commits eliminated the
    snd_pcm_suspend*() calls from the runtime PM suspend callback code
    path, hence the racy OPEN state won't appear while runtime PM.
    (FWIW, the race window is between snd_pcm_open_substream() and the
    first power up in azx_pcm_open().)
    
    Although the runtime PM issue was already "fixed", the same problem is
    still present for the system PM, hence this patch is still needed.
    And for stable trees, this patch alone should suffice for fixing the
    runtime PM problem, too.
    
    Reported-and-tested-by: Jon Hunter <jonathanh@nvidia.com>
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 6aa8ab0ef393702780afb5b3a03e0f66fa8e3f87
Author: Sven Eckelmann <sven@narfation.org>
Date:   Sat Feb 23 14:27:10 2019 +0100

    batman-adv: Reduce tt_global hash refcnt only for removed entry
    
    commit f131a56880d10932931e74773fb8702894a94a75 upstream.
    
    The batadv_hash_remove is a function which searches the hashtable for an
    entry using a needle, a hashtable bucket selection function and a compare
    function. It will lock the bucket list and delete an entry when the compare
    function matches it with the needle. It returns the pointer to the
    hlist_node which matches or NULL when no entry matches the needle.
    
    The batadv_tt_global_free is not itself protected in anyway to avoid that
    any other function is modifying the hashtable between the search for the
    entry and the call to batadv_hash_remove. It can therefore happen that the
    entry either doesn't exist anymore or an entry was deleted which is not the
    same object as the needle. In such an situation, the reference counter (for
    the reference stored in the hashtable) must not be reduced for the needle.
    Instead the reference counter of the actually removed entry has to be
    reduced.
    
    Otherwise the reference counter will underflow and the object might be
    freed before all its references were dropped. The kref helpers reported
    this problem as:
    
      refcount_t: underflow; use-after-free.
    
    Fixes: 7683fdc1e886 ("batman-adv: protect the local and the global trans-tables with rcu")
    Reported-by: Martin Weinelt <martin@linuxlounge.net>
    Signed-off-by: Sven Eckelmann <sven@narfation.org>
    Acked-by: Antonio Quartulli <a@unstable.cc>
    Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 9197085ff131a3571b57a043333aa42f8bf84f5b
Author: Sven Eckelmann <sven@narfation.org>
Date:   Sat Feb 23 14:27:10 2019 +0100

    batman-adv: Reduce tt_local hash refcnt only for removed entry
    
    commit 3d65b9accab4a7ed5038f6df403fbd5e298398c7 upstream.
    
    The batadv_hash_remove is a function which searches the hashtable for an
    entry using a needle, a hashtable bucket selection function and a compare
    function. It will lock the bucket list and delete an entry when the compare
    function matches it with the needle. It returns the pointer to the
    hlist_node which matches or NULL when no entry matches the needle.
    
    The batadv_tt_local_remove is not itself protected in anyway to avoid that
    any other function is modifying the hashtable between the search for the
    entry and the call to batadv_hash_remove. It can therefore happen that the
    entry either doesn't exist anymore or an entry was deleted which is not the
    same object as the needle. In such an situation, the reference counter (for
    the reference stored in the hashtable) must not be reduced for the needle.
    Instead the reference counter of the actually removed entry has to be
    reduced.
    
    Otherwise the reference counter will underflow and the object might be
    freed before all its references were dropped. The kref helpers reported
    this problem as:
    
      refcount_t: underflow; use-after-free.
    
    Fixes: ef72706a0543 ("batman-adv: protect tt_local_entry from concurrent delete events")
    Signed-off-by: Sven Eckelmann <sven@narfation.org>
    Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit da1efb82607392b6b289954f8527fdd005aaa89a
Author: Sven Eckelmann <sven@narfation.org>
Date:   Sat Feb 23 14:27:10 2019 +0100

    batman-adv: Reduce claim hash refcnt only for removed entry
    
    commit 4ba104f468bbfc27362c393815d03aa18fb7a20f upstream.
    
    The batadv_hash_remove is a function which searches the hashtable for an
    entry using a needle, a hashtable bucket selection function and a compare
    function. It will lock the bucket list and delete an entry when the compare
    function matches it with the needle. It returns the pointer to the
    hlist_node which matches or NULL when no entry matches the needle.
    
    The batadv_bla_del_claim is not itself protected in anyway to avoid that
    any other function is modifying the hashtable between the search for the
    entry and the call to batadv_hash_remove. It can therefore happen that the
    entry either doesn't exist anymore or an entry was deleted which is not the
    same object as the needle. In such an situation, the reference counter (for
    the reference stored in the hashtable) must not be reduced for the needle.
    Instead the reference counter of the actually removed entry has to be
    reduced.
    
    Otherwise the reference counter will underflow and the object might be
    freed before all its references were dropped. The kref helpers reported
    this problem as:
    
      refcount_t: underflow; use-after-free.
    
    Fixes: 23721387c409 ("batman-adv: add basic bridge loop avoidance code")
    Signed-off-by: Sven Eckelmann <sven@narfation.org>
    Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
    [bwh: Backported to 3.16: keep using batadv_claim_free_ref()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 48960a368b76a39cd112ba0417f8c5b21231d5f5
Author: Dragos Bogdan <dragos.bogdan@analog.com>
Date:   Tue Mar 19 12:47:00 2019 +0200

    iio: ad_sigma_delta: select channel when reading register
    
    commit fccfb9ce70ed4ea7a145f77b86de62e38178517f upstream.
    
    The desired channel has to be selected in order to correctly fill the
    buffer with the corresponding data.
    The `ad_sd_write_reg()` already does this, but for the
    `ad_sd_read_reg_raw()` this was omitted.
    
    Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
    Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
    Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a3a3b6c71ed63aa3e6dc56b1922d273a77585cb1
Author: Mathias Nyman <mathias.nyman@linux.intel.com>
Date:   Fri Mar 22 17:50:17 2019 +0200

    xhci: Don't let USB3 ports stuck in polling state prevent suspend
    
    commit d92f2c59cc2cbca6bfb2cc54882b58ba76b15fd4 upstream.
    
    Commit 2f31a67f01a8 ("usb: xhci: Prevent bus suspend if a port connect
    change or polling state is detected") was intended to prevent ports that
    were still link training from being forced to U3 suspend state mid
    enumeration.
    This solved enumeration issues for devices with slow link training.
    
    Turns out some devices are stuck in the link training/polling state,
    and thus that patch will prevent suspend completely for these devices.
    This is seen with USB3 card readers in some MacBooks.
    
    Instead of preventing suspend, give some time to complete the link
    training. On successful training the port will end up as connected
    and enabled.
    If port instead is stuck in link training the bus suspend will continue
    suspending after 360ms (10 * 36ms) timeout (tPollingLFPSTimeout).
    
    Original patch was sent to stable, this one should go there as well
    
    Fixes: 2f31a67f01a8 ("usb: xhci: Prevent bus suspend if a port connect change or polling state is detected")
    Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit b101a36d34c90451cb0a450d82bbc1c33f4e4986
Author: Axel Lin <axel.lin@ingics.com>
Date:   Mon Mar 11 21:29:37 2019 +0800

    gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input
    
    commit c5bc6e526d3f217ed2cc3681d256dc4a2af4cc2b upstream.
    
    Current code test wrong value so it does not verify if the written
    data is correctly read back. Fix it.
    Also make it return -EPERM if read value does not match written bit,
    just like it done for adnp_gpio_direction_output().
    
    Fixes: 5e969a401a01 ("gpio: Add Avionic Design N-bit GPIO expander support")
    Signed-off-by: Axel Lin <axel.lin@ingics.com>
    Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
    Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a537bdc096389aaff41166e4f3be7fb91067c786
Author: Takashi Iwai <tiwai@suse.de>
Date:   Fri Mar 22 16:00:54 2019 +0100

    ALSA: pcm: Fix possible OOB access in PCM oss plugins
    
    commit ca0214ee2802dd47239a4e39fb21c5b00ef61b22 upstream.
    
    The PCM OSS emulation converts and transfers the data on the fly via
    "plugins".  The data is converted over the dynamically allocated
    buffer for each plugin, and recently syzkaller caught OOB in this
    flow.
    
    Although the bisection by syzbot pointed out to the commit
    65766ee0bf7f ("ALSA: oss: Use kvzalloc() for local buffer
    allocations"), this is merely a commit to replace vmalloc() with
    kvmalloc(), hence it can't be the cause.  The further debug action
    revealed that this happens in the case where a slave PCM doesn't
    support only the stereo channels while the OSS stream is set up for a
    mono channel.  Below is a brief explanation:
    
    At each OSS parameter change, the driver sets up the PCM hw_params
    again in snd_pcm_oss_change_params_lock().  This is also the place
    where plugins are created and local buffers are allocated.  The
    problem is that the plugins are created before the final hw_params is
    determined.  Namely, two snd_pcm_hw_param_near() calls for setting the
    period size and periods may influence on the final result of channels,
    rates, etc, too, while the current code has already created plugins
    beforehand with the premature values.  So, the plugin believes that
    channels=1, while the actual I/O is with channels=2, which makes the
    driver reading/writing over the allocated buffer size.
    
    The fix is simply to move the plugin allocation code after the final
    hw_params call.
    
    Reported-by: syzbot+d4503ae45b65c5bc1194@syzkaller.appspotmail.com
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit c5f75dd9f7d58789b96d5118e93eddff395b68d9
Author: Chen Jie <chenjie6@huawei.com>
Date:   Fri Mar 15 03:44:38 2019 +0000

    futex: Ensure that futex address is aligned in handle_futex_death()
    
    commit 5a07168d8d89b00fe1760120714378175b3ef992 upstream.
    
    The futex code requires that the user space addresses of futexes are 32bit
    aligned. sys_futex() checks this in futex_get_keys() but the robust list
    code has no alignment check in place.
    
    As a consequence the kernel crashes on architectures with strict alignment
    requirements in handle_futex_death() when trying to cmpxchg() on an
    unaligned futex address which was retrieved from the robust list.
    
    [ tglx: Rewrote changelog, proper sizeof() based alignement check and add
            comment ]
    
    Fixes: 0771dfefc9e5 ("[PATCH] lightweight robust futexes: core")
    Signed-off-by: Chen Jie <chenjie6@huawei.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: <dvhart@infradead.org>
    Cc: <peterz@infradead.org>
    Cc: <zengweilin@huawei.com>
    Link: https://lkml.kernel.org/r/1552621478-119787-1-git-send-email-chenjie6@huawei.com
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit b17048c53c903a698609a71bb19cb535eab49894
Author: Lu Baolu <baolu.lu@linux.intel.com>
Date:   Wed Mar 20 09:58:33 2019 +0800

    iommu/vt-d: Check capability before disabling protected memory
    
    commit 5bb71fc790a88d063507dc5d445ab8b14e845591 upstream.
    
    The spec states in 10.4.16 that the Protected Memory Enable
    Register should be treated as read-only for implementations
    not supporting protected memory regions (PLMR and PHMR fields
    reported as Clear in the Capability register).
    
    Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
    Cc: mark gross <mgross@intel.com>
    Suggested-by: Ashok Raj <ashok.raj@intel.com>
    Fixes: f8bab73515ca5 ("intel-iommu: PMEN support")
    Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
    Signed-off-by: Joerg Roedel <jroedel@suse.de>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 09e3abfd0c817264b82f85c5ca9d8634d3c19d18
Author: Gustavo A. R. Silva <gustavo@embeddedor.com>
Date:   Wed Mar 20 18:42:01 2019 -0500

    ALSA: seq: oss: Fix Spectre v1 vulnerability
    
    commit c709f14f0616482b67f9fbcb965e1493a03ff30b upstream.
    
    dev is indirectly controlled by user-space, hence leading to
    a potential exploitation of the Spectre variant 1 vulnerability.
    
    This issue was detected with the help of Smatch:
    
    sound/core/seq/oss/seq_oss_synth.c:626 snd_seq_oss_synth_make_info() warn: potential spectre issue 'dp->synths' [w] (local cap)
    
    Fix this by sanitizing dev before using it to index dp->synths.
    
    Notice that given that speculation windows are large, the policy is
    to kill the speculation on the first load and not worry if it can be
    completed with a dependent load/store [1].
    
    [1] https://lore.kernel.org/lkml/20180423164740.GY17484@dhcp22.suse.cz/
    
    Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 748cfcf4db34f23c2d681c9427f2de6730718341
Author: Gustavo A. R. Silva <gustavo@embeddedor.com>
Date:   Wed Mar 20 16:15:24 2019 -0500

    ALSA: rawmidi: Fix potential Spectre v1 vulnerability
    
    commit 2b1d9c8f87235f593826b9cf46ec10247741fff9 upstream.
    
    info->stream is indirectly controlled by user-space, hence leading to
    a potential exploitation of the Spectre variant 1 vulnerability.
    
    This issue was detected with the help of Smatch:
    
    sound/core/rawmidi.c:604 __snd_rawmidi_info_select() warn: potential spectre issue 'rmidi->streams' [r] (local cap)
    
    Fix this by sanitizing info->stream before using it to index
    rmidi->streams.
    
    Notice that given that speculation windows are large, the policy is
    to kill the speculation on the first load and not worry if it can be
    completed with a dependent load/store [1].
    
    [1] https://lore.kernel.org/lkml/20180423164740.GY17484@dhcp22.suse.cz/
    
    Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 1d6f09cbd4d7734f4966c7c51d60a28f16b6400f
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Mar 21 09:26:38 2019 +0300

    staging: rtl8712: uninitialized memory in read_bbreg_hdl()
    
    commit 22c971db7dd4b0ad8dd88e99c407f7a1f4231a2e upstream.
    
    Colin King reported a bug in read_bbreg_hdl():
    
            memcpy(pcmd->rsp, (u8 *)&val, pcmd->rspsz);
    
    The problem is that "val" is uninitialized.
    
    This code is obviously not useful, but so far as I can tell
    "pcmd->cmdcode" is never GEN_CMD_CODE(_Read_BBREG) so it's not harmful
    either.  For now the easiest fix is to just call r8712_free_cmd_obj()
    and return.
    
    Fixes: 2865d42c78a9 ("staging: r8712u: Add the new driver to the mainline kernel")
    Reported-by: Colin Ian King <colin.king@canonical.com>
    Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 83ffc8b8e4e2713c929c356e76446bda0e9f50e2
Author: Lin Yi <teroincn@163.com>
Date:   Wed Mar 20 19:04:56 2019 +0800

    USB: serial: mos7720: fix mos_parport refcount imbalance on error path
    
    commit 2908b076f5198d231de62713cb2b633a3a4b95ac upstream.
    
    The write_parport_reg_nonblock() helper takes a reference to the struct
    mos_parport, but failed to release it in a couple of error paths after
    allocation failures, leading to a memory leak.
    
    Johan said that move the kref_get() and mos_parport assignment to the
    end of urbtrack initialisation is a better way, so move it. and
    mos_parport do not used until urbtrack initialisation.
    
    Signed-off-by: Lin Yi <teroincn@163.com>
    Fixes: b69578df7e98 ("USB: usbserial: mos7720: add support for parallel port on moschip 7715")
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 919f4897748208d3f111e022bf23ce89e6088599
Author: Marco Felsch <m.felsch@pengutronix.de>
Date:   Mon Mar 4 11:49:40 2019 +0100

    ARM: dts: pfla02: increase phy reset duration
    
    commit 032f85c9360fb1a08385c584c2c4ed114b33c260 upstream.
    
    Increase the reset duration to ensure correct phy functionality. The
    reset duration is taken from barebox commit 52fdd510de ("ARM: dts:
    pfla02: use long enough reset for ethernet phy"):
    
      Use a longer reset time for ethernet phy Micrel KSZ9031RNX. Otherwise a
      small percentage of modules have 'transmission timeouts' errors like
    
      barebox@Phytec phyFLEX-i.MX6 Quad Carrier-Board:/ ifup eth0
      warning: No MAC address set. Using random address 7e:94:4d:02:f8:f3
      eth0: 1000Mbps full duplex link detected
      eth0: transmission timeout
      T eth0: transmission timeout
      T eth0: transmission timeout
      T eth0: transmission timeout
      T eth0: transmission timeout
    
    Cc: Stefan Christ <s.christ@phytec.de>
    Cc: Christian Hemp <c.hemp@phytec.de>
    Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
    Fixes: 3180f956668e ("ARM: dts: Phytec imx6q pfla02 and pbab01 support")
    Signed-off-by: Shawn Guo <shawnguo@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 89acc242459316bea3e69b0a1da5b9c62be0d425
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Tue Mar 19 22:15:58 2019 +0100

    3c515: fix integer overflow warning
    
    commit fb6fafbc7de4a813bb5364358bbe27f71e62b24a upstream.
    
    clang points out a harmless signed integer overflow:
    
    drivers/net/ethernet/3com/3c515.c:1530:66: error: implicit conversion from 'int' to 'short' changes value from 32783 to -32753 [-Werror,-Wconstant-conversion]
                    new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm;
                             ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
    drivers/net/ethernet/3com/3c515.c:1532:52: error: implicit conversion from 'int' to 'short' changes value from 32775 to -32761 [-Werror,-Wconstant-conversion]
                    new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast;
                             ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    drivers/net/ethernet/3com/3c515.c:1534:38: error: implicit conversion from 'int' to 'short' changes value from 32773 to -32763 [-Werror,-Wconstant-conversion]
                    new_mode = SetRxFilter | RxStation | RxBroadcast;
                             ~ ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    
    Make the variable unsigned to avoid the overflow.
    
    Fixes: Linux-2.1.128pre1
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit a9bf2079f179a04c0b0d2fcbd6069c1713eeee6d
Author: Eric Dumazet <edumazet@google.com>
Date:   Tue Mar 19 05:46:18 2019 -0700

    dccp: do not use ipv6 header for ipv4 flow
    
    commit e0aa67709f89d08c8d8e5bdd9e0b649df61d0090 upstream.
    
    When a dual stack dccp listener accepts an ipv4 flow,
    it should not attempt to use an ipv6 header or
    inet6_iif() helper.
    
    Fixes: 3df80d9320bc ("[DCCP]: Introduce DCCPv6")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 169b154649e29d455b0677ec43fb874d18794802
Author: Eric Dumazet <edumazet@google.com>
Date:   Tue Mar 19 05:45:35 2019 -0700

    tcp: do not use ipv6 header for ipv4 flow
    
    commit 89e4130939a20304f4059ab72179da81f5347528 upstream.
    
    When a dual stack tcp listener accepts an ipv4 flow,
    it should not attempt to use an ipv6 header or tcp_v6_iif() helper.
    
    Fixes: 1397ed35f22d ("ipv6: add flowinfo for tcp6 pkt_options for all cases")
    Fixes: df3687ffc665 ("ipv6: add the IPV6_FL_F_REFLECT flag to IPV6_FL_A_GET")
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 1b75034a1bb506abcabb2c2f9d7360020a7e2c42
Author: YueHaibing <yuehaibing@huawei.com>
Date:   Tue Mar 19 10:16:53 2019 +0800

    net-sysfs: call dev_hold if kobject_init_and_add success
    
    commit a3e23f719f5c4a38ffb3d30c8d7632a4ed8ccd9e upstream.
    
    In netdev_queue_add_kobject and rx_queue_add_kobject,
    if sysfs_create_group failed, kobject_put will call
    netdev_queue_release to decrease dev refcont, however
    dev_hold has not be called. So we will see this while
    unregistering dev:
    
    unregister_netdevice: waiting for bcsh0 to become free. Usage count = -1
    
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Fixes: d0d668371679 ("net: don't decrement kobj reference count on init failure")
    Signed-off-by: YueHaibing <yuehaibing@huawei.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 15e268e9e1c32a1558b6849a8edebeeba5d88d67
Author: Changbin Du <changbin.du@gmail.com>
Date:   Sat Mar 16 16:05:56 2019 +0800

    perf tests: Fix a memory leak in test__perf_evsel__tp_sched_test()
    
    commit d982b33133284fa7efa0e52ae06b88f9be3ea764 upstream.
    
      =================================================================
      ==20875==ERROR: LeakSanitizer: detected memory leaks
    
      Direct leak of 1160 byte(s) in 1 object(s) allocated from:
          #0 0x7f1b6fc84138 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xee138)
          #1 0x55bd50005599 in zalloc util/util.h:23
          #2 0x55bd500068f5 in perf_evsel__newtp_idx util/evsel.c:327
          #3 0x55bd4ff810fc in perf_evsel__newtp /home/work/linux/tools/perf/util/evsel.h:216
          #4 0x55bd4ff81608 in test__perf_evsel__tp_sched_test tests/evsel-tp-sched.c:69
          #5 0x55bd4ff528e6 in run_test tests/builtin-test.c:358
          #6 0x55bd4ff52baf in test_and_print tests/builtin-test.c:388
          #7 0x55bd4ff543fe in __cmd_test tests/builtin-test.c:583
          #8 0x55bd4ff5572f in cmd_test tests/builtin-test.c:722
          #9 0x55bd4ffc4087 in run_builtin /home/changbin/work/linux/tools/perf/perf.c:302
          #10 0x55bd4ffc45c6 in handle_internal_command /home/changbin/work/linux/tools/perf/perf.c:354
          #11 0x55bd4ffc49ca in run_argv /home/changbin/work/linux/tools/perf/perf.c:398
          #12 0x55bd4ffc5138 in main /home/changbin/work/linux/tools/perf/perf.c:520
          #13 0x7f1b6e34809a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
    
      Indirect leak of 19 byte(s) in 1 object(s) allocated from:
          #0 0x7f1b6fc83f30 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xedf30)
          #1 0x7f1b6e3ac30f in vasprintf (/lib/x86_64-linux-gnu/libc.so.6+0x8830f)
    
    Signed-off-by: Changbin Du <changbin.du@gmail.com>
    Reviewed-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Fixes: 6a6cd11d4e57 ("perf test: Add test for the sched tracepoint format fields")
    Link: http://lkml.kernel.org/r/20190316080556.3075-17-changbin.du@gmail.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 198f512652c375a22744e86dda97b46b5854e04f
Author: Jann Horn <jannh@google.com>
Date:   Tue Mar 19 02:36:59 2019 +0100

    device_cgroup: fix RCU imbalance in error case
    
    commit 0fcc4c8c044e117ac126ab6df4138ea9a67fa2a9 upstream.
    
    When dev_exception_add() returns an error (due to a failed memory
    allocation), make sure that we move the RCU preemption count back to where
    it was before we were called. We dropped the RCU read lock inside the loop
    body, so we can't just "break".
    
    sparse complains about this, too:
    
    $ make -s C=2 security/device_cgroup.o
    ./include/linux/rcupdate.h:647:9: warning: context imbalance in
    'propagate_exception' - unexpected unlock
    
    Fixes: d591fb56618f ("device_cgroup: simplify cgroup tree walk in propagate_exception()")
    Signed-off-by: Jann Horn <jannh@google.com>
    Acked-by: Michal Hocko <mhocko@suse.com>
    Signed-off-by: Tejun Heo <tj@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fe9f6d5757be34c153f3c167843a53547d238c6c
Author: Hoan Nguyen An <na-hoan@jinso.co.jp>
Date:   Mon Mar 18 18:26:32 2019 +0900

    serial: sh-sci: Fix setting SCSCR_TIE while transferring data
    
    commit 93bcefd4c6bad4c69dbc4edcd3fbf774b24d930d upstream.
    
    We disable transmission interrupt (clear SCSCR_TIE) after all data has been transmitted
    (if uart_circ_empty(xmit)). While transmitting, if the data is still in the tty buffer,
    re-enable the SCSCR_TIE bit, which was done at sci_start_tx().
    This is unnecessary processing, wasting CPU operation if the data transmission length is large.
    And further, transmit end, FIFO empty bits disabling have also been performed in the step above.
    
    Signed-off-by: Hoan Nguyen An <na-hoan@jinso.co.jp>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 9169957cdf06f2ff96f13d9719741c7528f37818
Author: Kangjie Lu <kjlu@umn.edu>
Date:   Thu Mar 14 02:21:51 2019 -0500

    tty: mxs-auart: fix a potential NULL pointer dereference
    
    commit 6734330654dac550f12e932996b868c6d0dcb421 upstream.
    
    In case ioremap fails, the fix returns -ENOMEM to avoid NULL
    pointer dereferences.
    Multiple places use port.membase.
    
    Signed-off-by: Kangjie Lu <kjlu@umn.edu>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: There is no out_disable_clks label, so goto
     out_free_clk on error]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit cf592ae629558dba003094192c667c74f4cc670c
Author: Kangjie Lu <kjlu@umn.edu>
Date:   Fri Mar 15 12:16:06 2019 -0500

    tty: atmel_serial: fix a potential NULL pointer dereference
    
    commit c85be041065c0be8bc48eda4c45e0319caf1d0e5 upstream.
    
    In case dmaengine_prep_dma_cyclic fails, the fix returns a proper
    error code to avoid NULL pointer dereference.
    
    Signed-off-by: Kangjie Lu <kjlu@umn.edu>
    Fixes: 34df42f59a60 ("serial: at91: add rx dma support")
    Acked-by: Richard Genoud <richard.genoud@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 22230045cf8128435150a12d0b4ee4c41311600d
Author: Aditya Pakki <pakki001@umn.edu>
Date:   Mon Mar 18 18:44:14 2019 -0500

    serial: max310x: Fix to avoid potential NULL pointer dereference
    
    commit 3a10e3dd52e80b9a97a3346020024d17b2c272d6 upstream.
    
    of_match_device can return a NULL pointer when matching device is not
    found. This patch avoids a scenario causing NULL pointer derefernce.
    
    Signed-off-by: Aditya Pakki <pakki001@umn.edu>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit d05b1e8c07ee6e7878b239bd14c8f031436fc976
Author: George McCollister <george.mccollister@gmail.com>
Date:   Tue Mar 5 16:05:03 2019 -0600

    USB: serial: ftdi_sio: add additional NovaTech products
    
    commit 422c2537ba9d42320f8ab6573940269f87095320 upstream.
    
    Add PIDs for the NovaTech OrionLX+ and Orion I/O so they can be
    automatically detected.
    
    Signed-off-by: George McCollister <george.mccollister@gmail.com>
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 6eef8f1ef10c1501b5856dd1e62172cabc0a5286
Author: Kohji Okuno <okuno.kohji@jp.panasonic.com>
Date:   Tue Feb 26 11:34:13 2019 +0900

    ARM: imx6q: cpuidle: fix bug that CPU might not wake up at expected time
    
    commit 91740fc8242b4f260cfa4d4536d8551804777fae upstream.
    
    In the current cpuidle implementation for i.MX6q, the CPU that sets
    'WAIT_UNCLOCKED' and the CPU that returns to 'WAIT_CLOCKED' are always
    the same. While the CPU that sets 'WAIT_UNCLOCKED' is in IDLE state of
    "WAIT", if the other CPU wakes up and enters IDLE state of "WFI"
    istead of "WAIT", this CPU can not wake up at expired time.
     Because, in the case of "WFI", the CPU must be waked up by the local
    timer interrupt. But, while 'WAIT_UNCLOCKED' is set, the local timer
    is stopped, when all CPUs execute "wfi" instruction. As a result, the
    local timer interrupt is not fired.
     In this situation, this CPU will wake up by IRQ different from local
    timer. (e.g. broacast timer)
    
    So, this fix changes CPU to return to 'WAIT_CLOCKED'.
    
    Signed-off-by: Kohji Okuno <okuno.kohji@jp.panasonic.com>
    Fixes: e5f9dec8ff5f ("ARM: imx6q: support WAIT mode using cpuidle")
    Signed-off-by: Shawn Guo <shawnguo@kernel.org>
    [bwh: Backported to 3.16: use imx6q_set_lpm() instead of imx6_set_lpm()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 761e3db3dde4cf06c4dfb764e5bb8541e412741b
Author: NeilBrown <neilb@suse.com>
Date:   Tue Mar 19 11:33:24 2019 +1100

    NFS: fix mount/umount race in nlmclnt.
    
    commit 4a9be28c45bf02fa0436808bb6c0baeba30e120e upstream.
    
    If the last NFSv3 unmount from a given host races with a mount from the
    same host, we can destroy an nlm_host that is still in use.
    
    Specifically nlmclnt_lookup_host() can increment h_count on
    an nlm_host that nlmclnt_release_host() has just successfully called
    refcount_dec_and_test() on.
    Once nlmclnt_lookup_host() drops the mutex, nlm_destroy_host_lock()
    will be called to destroy the nlmclnt which is now in use again.
    
    The cause of the problem is that the dec_and_test happens outside the
    locked region.  This is easily fixed by using
    refcount_dec_and_mutex_lock().
    
    Fixes: 8ea6ecc8b075 ("lockd: Create client-side nlm_host cache")
    Signed-off-by: NeilBrown <neilb@suse.com>
    Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
    [bwh: Backported to 3.16: use atomic instead of refcount API]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3ef66b61b37b5e28dad11f3c3937f8be647e0e07
Author: Xin Long <lucien.xin@gmail.com>
Date:   Mon Mar 18 19:47:00 2019 +0800

    sctp: get sctphdr by offset in sctp_compute_cksum
    
    commit 273160ffc6b993c7c91627f5a84799c66dfe4dee upstream.
    
    sctp_hdr(skb) only works when skb->transport_header is set properly.
    
    But in Netfilter, skb->transport_header for ipv6 is not guaranteed
    to be right value for sctphdr. It would cause to fail to check the
    checksum for sctp packets.
    
    So fix it by using offset, which is always right in all places.
    
    v1->v2:
      - Fix the changelog.
    
    Fixes: e6d8b64b34aa ("net: sctp: fix and consolidate SCTP checksumming code")
    Reported-by: Li Shuang <shuali@redhat.com>
    Signed-off-by: Xin Long <lucien.xin@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 7e8343060fc2f97a50bd64dd373fbe27939ba5bb
Author: Finn Thain <fthain@telegraphics.com.au>
Date:   Sat Mar 16 14:21:19 2019 +1100

    mac8390: Fix mmio access size probe
    
    commit bb9e5c5bcd76f4474eac3baf643d7a39f7bac7bb upstream.
    
    The bug that Stan reported is as follows. After a restart, a 16-bit NIC
    may be incorrectly identified as a 32-bit NIC and stop working.
    
    mac8390 slot.E: Memory length resource not found, probing
    mac8390 slot.E: Farallon EtherMac II-C (type farallon)
    mac8390 slot.E: MAC 00:00:c5:30:c2:99, IRQ 61, 32 KB shared memory at 0xfeed0000, 32-bit access.
    
    The bug never arises after a cold start and only intermittently after a
    warm start. (I didn't investigate why the bug is intermittent.)
    
    It turns out that memcpy_toio() is deprecated and memcmp_withio() also
    has issues. Replacing these calls with mmio accessors fixes the problem.
    
    Reported-and-tested-by: Stan Johnson <userm57@yahoo.com>
    Fixes: 2964db0f5904 ("m68k: Mac DP8390 update")
    Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 129429a20b249f3c5dd76b88fa9f207e63e9922f
Author: Geert Uytterhoeven <geert@linux-m68k.org>
Date:   Tue Jun 26 20:32:22 2018 +0200

    net: mac8390: Use standard memcpy_{from,to}io()
    
    commit 4042cd756e193f49469d31a23d5b85c4dca2a3b6 upstream.
    
    The mac8390 driver defines its own variants of memcpy_fromio() and
    memcpy_toio(), using similar implementations, but different function
    signatures.
    
    Remove the custom definitions of memcpy_fromio() and memcpy_toio(), and
    adjust all callers to the standard signatures.
    
    Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
    Acked-by: David S. Miller <davem@davemloft.net>
    Acked-by: Greg Ungerer <gerg@linux-m68k.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5c2dbe3435aa74e47790720fa69308aa21ab4615
Author: Jan Kara <jack@suse.cz>
Date:   Mon Mar 11 15:04:18 2019 +0100

    udf: Fix crash on IO error during truncate
    
    commit d3ca4651d05c0ff7259d087d8c949bcf3e14fb46 upstream.
    
    When truncate(2) hits IO error when reading indirect extent block the
    code just bugs with:
    
    kernel BUG at linux-4.15.0/fs/udf/truncate.c:249!
    ...
    
    Fix the problem by bailing out cleanly in case of IO error.
    
    Reported-by: jean-luc malet <jeanluc.malet@gmail.com>
    Signed-off-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 5d17c80f28dc9041b57aaa527057c5ad7b68cc41
Author: Xin Long <lucien.xin@gmail.com>
Date:   Wed Mar 13 16:33:29 2019 +0800

    netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING
    
    commit e166e4fdaced850bee3d5ee12a5740258fb30587 upstream.
    
    Since Commit 21d1196a35f5 ("ipv4: set transport header earlier"),
    skb->transport_header has been always set before entering INET
    netfilter. This patch is to set skb->transport_header for bridge
    before entering INET netfilter by bridge-nf-call-iptables.
    
    It also fixes an issue that sctp_error() couldn't compute a right
    csum due to unset skb->transport_header.
    
    Fixes: e6d8b64b34aa ("net: sctp: fix and consolidate SCTP checksumming code")
    Reported-by: Li Shuang <shuali@redhat.com>
    Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: Xin Long <lucien.xin@gmail.com>
    Acked-by: Neil Horman <nhorman@tuxdriver.com>
    Acked-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    [bwh: Backported to 3.16: adjust filenames, context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit bb693bc07a915f22f93f4a67c09764bfbe356cd0
Author: Michael Ellerman <mpe@ellerman.id.au>
Date:   Thu Mar 14 00:14:38 2019 +1100

    powerpc/vdso64: Fix CLOCK_MONOTONIC inconsistencies across Y2038
    
    commit b5b4453e7912f056da1ca7572574cada32ecb60c upstream.
    
    Jakub Drnec reported:
      Setting the realtime clock can sometimes make the monotonic clock go
      back by over a hundred years. Decreasing the realtime clock across
      the y2k38 threshold is one reliable way to reproduce. Allegedly this
      can also happen just by running ntpd, I have not managed to
      reproduce that other than booting with rtc at >2038 and then running
      ntp. When this happens, anything with timers (e.g. openjdk) breaks
      rather badly.
    
    And included a test case (slightly edited for brevity):
      #define _POSIX_C_SOURCE 199309L
      #include <stdio.h>
      #include <time.h>
      #include <stdlib.h>
      #include <unistd.h>
    
      long get_time(void) {
        struct timespec tp;
        clock_gettime(CLOCK_MONOTONIC, &tp);
        return tp.tv_sec + tp.tv_nsec / 1000000000;
      }
    
      int main(void) {
        long last = get_time();
        while(1) {
          long now = get_time();
          if (now < last) {
            printf("clock went backwards by %ld seconds!\n", last - now);
          }
          last = now;
          sleep(1);
        }
        return 0;
      }
    
    Which when run concurrently with:
     # date -s 2040-1-1
     # date -s 2037-1-1
    
    Will detect the clock going backward.
    
    The root cause is that wtom_clock_sec in struct vdso_data is only a
    32-bit signed value, even though we set its value to be equal to
    tk->wall_to_monotonic.tv_sec which is 64-bits.
    
    Because the monotonic clock starts at zero when the system boots the
    wall_to_montonic.tv_sec offset is negative for current and future
    dates. Currently on a freshly booted system the offset will be in the
    vicinity of negative 1.5 billion seconds.
    
    However if the wall clock is set past the Y2038 boundary, the offset
    from wall to monotonic becomes less than negative 2^31, and no longer
    fits in 32-bits. When that value is assigned to wtom_clock_sec it is
    truncated and becomes positive, causing the VDSO assembly code to
    calculate CLOCK_MONOTONIC incorrectly.
    
    That causes CLOCK_MONOTONIC to jump ahead by ~4 billion seconds which
    it is not meant to do. Worse, if the time is then set back before the
    Y2038 boundary CLOCK_MONOTONIC will jump backward.
    
    We can fix it simply by storing the full 64-bit offset in the
    vdso_data, and using that in the VDSO assembly code. We also shuffle
    some of the fields in vdso_data to avoid creating a hole.
    
    The original commit that added the CLOCK_MONOTONIC support to the VDSO
    did actually use a 64-bit value for wtom_clock_sec, see commit
    a7f290dad32e ("[PATCH] powerpc: Merge vdso's and add vdso support to
    32 bits kernel") (Nov 2005). However just 3 days later it was
    converted to 32-bits in commit 0c37ec2aa88b ("[PATCH] powerpc: vdso
    fixes (take #2)"), and the bug has existed since then AFAICS.
    
    Fixes: 0c37ec2aa88b ("[PATCH] powerpc: vdso fixes (take #2)")
    Link: http://lkml.kernel.org/r/HaC.ZfES.62bwlnvAvMP.1STMMj@seznam.cz
    Reported-by: Jakub Drnec <jaydee@email.cz>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    [bwh: Backported to 3.16: CLOCK_MONOTONIC_COARSE is not handled by
     this vDSO]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2dc2961f8efc6d013e88cc42244afc0ff558a2b4
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Mar 7 23:06:57 2019 +0100

    staging: speakup_soft: Fix alternate speech with other synths
    
    commit 45ac7b31bc6c4af885cc5b5d6c534c15bcbe7643 upstream.
    
    When switching from speakup_soft to another synth, speakup_soft would
    keep calling synth_buffer_getc() from softsynthx_read.
    
    Let's thus make synth.c export the knowledge of the current synth, so
    that speakup_soft can determine whether it should be running.
    
    speakup_soft also needs to set itself alive, otherwise the switch would
    let it remain silent.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    [bwh: Backported to 3.16:
     - There's no Unicode support
     - Adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 507ed215f534a30043dac35a08ccf137166d6020
Author: Jack Morgenstein <jackm@dev.mellanox.co.il>
Date:   Wed Mar 6 19:17:56 2019 +0200

    IB/mlx4: Fix race condition between catas error reset and aliasguid flows
    
    commit 587443e7773e150ae29e643ee8f41a1eed226565 upstream.
    
    Code review revealed a race condition which could allow the catas error
    flow to interrupt the alias guid query post mechanism at random points.
    Thiis is fixed by doing cancel_delayed_work_sync() instead of
    cancel_delayed_work() during the alias guid mechanism destroy flow.
    
    Fixes: a0c64a17aba8 ("mlx4: Add alias_guid mechanism")
    Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
    Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
    Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 64b2f2b04918e7e05f5286166e819238fc12a626
Author: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Date:   Wed Mar 6 15:56:06 2019 -0500

    iio: dac: mcp4725: add missing powerdown bits in store eeprom
    
    commit 06003531502d06bc89d32528f6ec96bf978790f9 upstream.
    
    When issuing the write DAC register and write eeprom command, the two
    powerdown bits (PD0 and PD1) are assumed by the chip to be present in
    the bytes sent. Leaving them at 0 implies "powerdown disabled" which is
    a different state that the current one. By adding the current state of
    the powerdown in the i2c write, the chip will correctly power-on exactly
    like as it is at the moment of store_eeprom call.
    
    This is documented in MCP4725's datasheet, FIGURE 6-2: "Write Commands
    for DAC Input Register and EEPROM" and MCP4726's datasheet, FIGURE 6-3:
    "Write All Memory Command".
    
    Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
    Acked-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 520f412b3694a260bd9a75a7146895ff150054e9
Author: Su Yanjun <suyj.fnst@cn.fujitsu.com>
Date:   Thu Mar 14 14:59:42 2019 +0800

    xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module
    
    commit 6ee02a54ef990a71bf542b6f0a4e3321de9d9c66 upstream.
    
    When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly
    frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the
    xfrm6_tunnel_spi, so need to wait it.
    
    Fixes: 91cc3bb0b04ff("xfrm6_tunnel: RCU conversion")
    Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
    Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 742015130eee098b966e1f5b2a4b3f8395089d53
Author: Lukas Czerner <lczerner@redhat.com>
Date:   Fri Mar 15 00:15:32 2019 -0400

    ext4: add missing brelse() in add_new_gdb_meta_bg()
    
    commit d64264d6218e6892edd832dc3a5a5857c2856c53 upstream.
    
    Currently in add_new_gdb_meta_bg() there is a missing brelse of gdb_bh
    in case ext4_journal_get_write_access() fails.
    Additionally kvfree() is missing in the same error path. Fix it by
    moving the ext4_journal_get_write_access() before the ext4 sb update as
    Ted suggested and release n_group_desc and gdb_bh in case it fails.
    
    Fixes: 61a9c11e5e7a ("ext4: add missing brelse() add_new_gdb_meta_bg()'s error path")
    Signed-off-by: Lukas Czerner <lczerner@redhat.com>
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 3668fd2619fed84326bc449a79ee4ad9e270f229
Author: Lukas Czerner <lczerner@redhat.com>
Date:   Thu Mar 14 23:20:25 2019 -0400

    ext4: fix data corruption caused by unaligned direct AIO
    
    commit 372a03e01853f860560eade508794dd274e9b390 upstream.
    
    Ext4 needs to serialize unaligned direct AIO because the zeroing of
    partial blocks of two competing unaligned AIOs can result in data
    corruption.
    
    However it decides not to serialize if the potentially unaligned aio is
    past i_size with the rationale that no pending writes are possible past
    i_size. Unfortunately if the i_size is not block aligned and the second
    unaligned write lands past i_size, but still into the same block, it has
    the potential of corrupting the previous unaligned write to the same
    block.
    
    This is (very simplified) reproducer from Frank
    
        // 41472 = (10 * 4096) + 512
        // 37376 = 41472 - 4096
    
        ftruncate(fd, 41472);
        io_prep_pwrite(iocbs[0], fd, buf[0], 4096, 37376);
        io_prep_pwrite(iocbs[1], fd, buf[1], 4096, 41472);
    
        io_submit(io_ctx, 1, &iocbs[1]);
        io_submit(io_ctx, 1, &iocbs[2]);
    
        io_getevents(io_ctx, 2, 2, events, NULL);
    
    Without this patch the 512B range from 40960 up to the start of the
    second unaligned write (41472) is going to be zeroed overwriting the data
    written by the first write. This is a data corruption.
    
    00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
    *
    00009200  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30
    *
    0000a000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
    *
    0000a200  31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31
    
    With this patch the data corruption is avoided because we will recognize
    the unaligned_aio and wait for the unwritten extent conversion.
    
    00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
    *
    00009200  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30
    *
    0000a200  31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31
    *
    0000b200
    
    Reported-by: Frank Sorenson <fsorenso@redhat.com>
    Signed-off-by: Lukas Czerner <lczerner@redhat.com>
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
    Fixes: e9e3bcecf44c ("ext4: serialize unaligned asynchronous DIO")
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit fcd707df873c72acecb1db496bbf9384df6d9da4
Author: Stephane Eranian <eranian@google.com>
Date:   Thu Mar 7 10:52:33 2019 -0800

    perf/core: Restore mmap record type correctly
    
    commit d9c1bb2f6a2157b38e8eb63af437cb22701d31ee upstream.
    
    On mmap(), perf_events generates a RECORD_MMAP record and then checks
    which events are interested in this record. There are currently 2
    versions of mmap records: RECORD_MMAP and RECORD_MMAP2. MMAP2 is larger.
    The event configuration controls which version the user level tool
    accepts.
    
    If the event->attr.mmap2=1 field then MMAP2 record is returned.  The
    perf_event_mmap_output() takes care of this. It checks attr->mmap2 and
    corrects the record fields before putting it in the sampling buffer of
    the event.  At the end the function restores the modified MMAP record
    fields.
    
    The problem is that the function restores the size but not the type.
    Thus, if a subsequent event only accepts MMAP type, then it would
    instead receive an MMAP2 record with a size of MMAP record.
    
    This patch fixes the problem by restoring the record type on exit.
    
    Signed-off-by: Stephane Eranian <eranian@google.com>
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Fixes: 13d7a2410fa6 ("perf: Add attr->mmap2 attribute to an event")
    Link: http://lkml.kernel.org/r/20190307185233.225521-1-eranian@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 82bbd92e6fde8d2722f3bd2206ac20a25ef90fbd
Author: Georg Ottinger <g.ottinger@abatec.at>
Date:   Wed Jan 30 14:42:02 2019 +0100

    iio: adc: at91: disable adc channel interrupt in timeout case
    
    commit 09c6bdee51183a575bf7546890c8c137a75a2b44 upstream.
    
    Having a brief look at at91_adc_read_raw() it is obvious that in the case
    of a timeout the setting of AT91_ADC_CHDR and AT91_ADC_IDR registers is
    omitted. If 2 different channels are queried we can end up with a
    situation where two interrupts are enabled, but only one interrupt is
    cleared in the interrupt handler. Resulting in a interrupt loop and a
    system hang.
    
    Signed-off-by: Georg Ottinger <g.ottinger@abatec.at>
    Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit f7803d78f87877529bb5c4f0304ca90fb23aa9b1
Author: Lars-Peter Clausen <lars@metafoo.de>
Date:   Wed Feb 20 17:11:32 2019 +0200

    iio: Fix scan mask selection
    
    commit 20ea39ef9f2f911bd01c69519e7d69cfec79fde3 upstream.
    
    The trialmask is expected to have all bits set to 0 after allocation.
    Currently kmalloc_array() is used which does not zero the memory and so
    random bits are set. This results in random channels being enabled when
    they shouldn't. Replace kmalloc_array() with kcalloc() which has the same
    interface but zeros the memory.
    
    Note the fix is actually required earlier than the below fixes tag, but
    will require a manual backport due to move from kmalloc to kmalloc_array.
    
    Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
    Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
    Fixes commit 057ac1acdfc4 ("iio: Use kmalloc_array() in iio_scan_mask_set()").
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 326b6adda0340f9de6da470906a5c262e2d738ff
Author: Markus Elfring <elfring@users.sourceforge.net>
Date:   Fri Sep 23 22:30:32 2016 +0200

    iio: Use kmalloc_array() in iio_scan_mask_set()
    
    commit 057ac1acdfc4743f066fcefe359385cad00549eb upstream.
    
    A multiplication for the size determination of a memory allocation
    indicated that an array data structure should be processed.
    Thus use the corresponding function "kmalloc_array".
    
    This issue was detected by using the Coccinelle software.
    
    Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
    Signed-off-by: Jonathan Cameron <jic23@kernel.org>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit b8da660f62ed905b3afc953488abfacf359d2d79
Author: Leonard Pollak <leonardp@tr-host.de>
Date:   Wed Feb 13 11:19:52 2019 +0100

    Staging: iio: meter: fixed typo
    
    commit 0a8a29be499cbb67df79370aaf5109085509feb8 upstream.
    
    This patch fixes an obvious typo, which will cause erroneously returning the Peak
    Voltage instead of the Peak Current.
    
    Signed-off-by: Leonard Pollak <leonardp@tr-host.de>
    Acked-by: Michael Hennerich <michael.hennerich@analog.com>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 056bd2ff271dd62e52efb09c96399a7ef9d68455
Author: YueHaibing <yuehaibing@huawei.com>
Date:   Thu Feb 28 15:18:59 2019 +0800

    xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink
    
    commit b805d78d300bcf2c83d6df7da0c818b0fee41427 upstream.
    
    UBSAN report this:
    
    UBSAN: Undefined behaviour in net/xfrm/xfrm_policy.c:1289:24
    index 6 is out of range for type 'unsigned int [6]'
    CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.4.162-514.55.6.9.x86_64+ #13
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
     0000000000000000 1466cf39b41b23c9 ffff8801f6b07a58 ffffffff81cb35f4
     0000000041b58ab3 ffffffff83230f9c ffffffff81cb34e0 ffff8801f6b07a80
     ffff8801f6b07a20 1466cf39b41b23c9 ffffffff851706e0 ffff8801f6b07ae8
    Call Trace:
     <IRQ>  [<ffffffff81cb35f4>] __dump_stack lib/dump_stack.c:15 [inline]
     <IRQ>  [<ffffffff81cb35f4>] dump_stack+0x114/0x1a0 lib/dump_stack.c:51
     [<ffffffff81d94225>] ubsan_epilogue+0x12/0x8f lib/ubsan.c:164
     [<ffffffff81d954db>] __ubsan_handle_out_of_bounds+0x16e/0x1b2 lib/ubsan.c:382
     [<ffffffff82a25acd>] __xfrm_policy_unlink+0x3dd/0x5b0 net/xfrm/xfrm_policy.c:1289
     [<ffffffff82a2e572>] xfrm_policy_delete+0x52/0xb0 net/xfrm/xfrm_policy.c:1309
     [<ffffffff82a3319b>] xfrm_policy_timer+0x30b/0x590 net/xfrm/xfrm_policy.c:243
     [<ffffffff813d3927>] call_timer_fn+0x237/0x990 kernel/time/timer.c:1144
     [<ffffffff813d8e7e>] __run_timers kernel/time/timer.c:1218 [inline]
     [<ffffffff813d8e7e>] run_timer_softirq+0x6ce/0xb80 kernel/time/timer.c:1401
     [<ffffffff8120d6f9>] __do_softirq+0x299/0xe10 kernel/softirq.c:273
     [<ffffffff8120e676>] invoke_softirq kernel/softirq.c:350 [inline]
     [<ffffffff8120e676>] irq_exit+0x216/0x2c0 kernel/softirq.c:391
     [<ffffffff82c5edab>] exiting_irq arch/x86/include/asm/apic.h:652 [inline]
     [<ffffffff82c5edab>] smp_apic_timer_interrupt+0x8b/0xc0 arch/x86/kernel/apic/apic.c:926
     [<ffffffff82c5c985>] apic_timer_interrupt+0xa5/0xb0 arch/x86/entry/entry_64.S:735
     <EOI>  [<ffffffff81188096>] ? native_safe_halt+0x6/0x10 arch/x86/include/asm/irqflags.h:52
     [<ffffffff810834d7>] arch_safe_halt arch/x86/include/asm/paravirt.h:111 [inline]
     [<ffffffff810834d7>] default_idle+0x27/0x430 arch/x86/kernel/process.c:446
     [<ffffffff81085f05>] arch_cpu_idle+0x15/0x20 arch/x86/kernel/process.c:437
     [<ffffffff8132abc3>] default_idle_call+0x53/0x90 kernel/sched/idle.c:92
     [<ffffffff8132b32d>] cpuidle_idle_call kernel/sched/idle.c:156 [inline]
     [<ffffffff8132b32d>] cpu_idle_loop kernel/sched/idle.c:251 [inline]
     [<ffffffff8132b32d>] cpu_startup_entry+0x60d/0x9a0 kernel/sched/idle.c:299
     [<ffffffff8113e119>] start_secondary+0x3c9/0x560 arch/x86/kernel/smpboot.c:245
    
    The issue is triggered as this:
    
    xfrm_add_policy
        -->verify_newpolicy_info  //check the index provided by user with XFRM_POLICY_MAX
                                  //In my case, the index is 0x6E6BB6, so it pass the check.
        -->xfrm_policy_construct  //copy the user's policy and set xfrm_policy_timer
        -->xfrm_policy_insert
            --> __xfrm_policy_link //use the orgin dir, in my case is 2
            --> xfrm_gen_index   //generate policy index, there is 0x6E6BB6
    
    then xfrm_policy_timer be fired
    
    xfrm_policy_timer
       --> xfrm_policy_id2dir  //get dir from (policy index & 7), in my case is 6
       --> xfrm_policy_delete
          --> __xfrm_policy_unlink //access policy_count[dir], trigger out of range access
    
    Add xfrm_policy_id2dir check in verify_newpolicy_info, make sure the computed dir is
    valid, to fix the issue.
    
    Reported-by: Hulk Robot <hulkci@huawei.com>
    Fixes: e682adf021be ("xfrm: Try to honor policy index if it's supplied by user")
    Signed-off-by: YueHaibing <yuehaibing@huawei.com>
    Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

commit 2b8d63b97d78835d3cd75b0ee344d21489df4edc
Author: Xin Long <lucien.xin@gmail.com>
Date:   Fri Feb 24 16:29:06 2017 +0800

    ipv6: check sk sk_type and protocol early in ip_mroute_set/getsockopt
    
    commit 99253eb750fda6a644d5188fb26c43bad8d5a745 upstream.
    
    Commit 5e1859fbcc3c ("ipv4: ipmr: various fixes and cleanups") fixed
    the issue for ipv4 ipmr:
    
      ip_mroute_setsockopt() & ip_mroute_getsockopt() should not
      access/set raw_sk(sk)->ipmr_table before making sure the socket
      is a raw socket, and protocol is IGMP
    
    The same fix should be done for ipv6 ipmr as well.
    
    This patch can fix the panic caused by overwriting the same offset
    as ipmr_table as in raw_sk(sk) when accessing other type's socket
    by ip_mroute_setsockopt().
    
    Signed-off-by: Xin Long <lucien.xin@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>