1. 16 Feb, 2018 40 commits
    • Peter Rosin's avatar
      pinctrl: sx150x: Register pinctrl before adding the gpiochip · 5219eedf
      Peter Rosin authored
      commit 1a1d39e1 upstream.
      
      Various gpiolib activity depend on the pinctrl to be up and kicking.
      Therefore, register the pinctrl before adding a gpiochip.
      Suggested-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5219eedf
    • Peter Rosin's avatar
      pinctrl: sx150x: Unregister the pinctrl on release · 89cad3fa
      Peter Rosin authored
      commit 0657cb50 upstream.
      
      There is no matching call to pinctrl_unregister, so switch to the
      managed devm_pinctrl_register to clean up properly when done.
      
      Fixes: 9e80f906 ("pinctrl: Add SX150X GPIO Extender Pinctrl Driver")
      Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89cad3fa
    • Dmitry Mastykin's avatar
      pinctrl: mcp23s08: fix irq setup order · 688d1b8c
      Dmitry Mastykin authored
      commit 02e389e6 upstream.
      
      When using mcp23s08 module with gpio-keys, often (50% of boots)
      it fails to get irq numbers with message:
      "gpio-keys keys: Unable to get irq number for GPIO 0, error -6".
      Seems that irqs must be setup before devm_gpiochip_add_data().
      Signed-off-by: default avatarDmitry Mastykin <mastichi@gmail.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      688d1b8c
    • Mika Westerberg's avatar
      pinctrl: intel: Initialize GPIO properly when used through irqchip · 05c9297f
      Mika Westerberg authored
      commit f5a26acf upstream.
      
      When a GPIO is requested using gpiod_get_* APIs the intel pinctrl driver
      switches the pin to GPIO mode and makes sure interrupts are routed to
      the GPIO hardware instead of IOAPIC. However, if the GPIO is used
      directly through irqchip, as is the case with many I2C-HID devices where
      I2C core automatically configures interrupt for the device, the pin is
      not initialized as GPIO. Instead we rely that the BIOS configures the
      pin accordingly which seems not to be the case at least in Asus X540NA
      SKU3 with Focaltech touchpad.
      
      When the pin is not properly configured it might result weird behaviour
      like interrupts suddenly stop firing completely and the touchpad stops
      responding to user input.
      
      Fix this by properly initializing the pin to GPIO mode also when it is
      used directly through irqchip.
      
      Fixes: 7981c001 ("pinctrl: intel: Add Intel Sunrisepoint pin controller and GPIO support")
      Reported-by: default avatarDaniel Drake <drake@endlessm.com>
      Reported-and-tested-by: default avatarChris Chiu <chiu@endlessm.com>
      Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05c9297f
    • James Hogan's avatar
      EDAC, octeon: Fix an uninitialized variable warning · bed938ba
      James Hogan authored
      commit 544e9258 upstream.
      
      Fix an uninitialized variable warning in the Octeon EDAC driver, as seen
      in MIPS cavium_octeon_defconfig builds since v4.14 with Codescape GNU
      Tools 2016.05-03:
      
        drivers/edac/octeon_edac-lmc.c In function ‘octeon_lmc_edac_poll_o2’:
        drivers/edac/octeon_edac-lmc.c:87:24: warning: ‘((long unsigned int*)&int_reg)[1]’ may \
          be used uninitialized in this function [-Wmaybe-uninitialized]
          if (int_reg.s.sec_err || int_reg.s.ded_err) {
                              ^
      Iinitialise the whole int_reg variable to zero before the conditional
      assignments in the error injection case.
      Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Acked-by: default avatarDavid Daney <david.daney@cavium.com>
      Cc: linux-edac <linux-edac@vger.kernel.org>
      Cc: linux-mips@linux-mips.org
      Fixes: 1bc021e8 ("EDAC: Octeon: Add error injection support")
      Link: http://lkml.kernel.org/r/20171113161206.20990-1-james.hogan@mips.comSigned-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bed938ba
    • Max Filippov's avatar
      xtensa: fix futex_atomic_cmpxchg_inatomic · e68d638e
      Max Filippov authored
      commit ca474809 upstream.
      
      Return 0 if the operation was successful, not the userspace memory
      value. Check that userspace value equals passed oldval, not itself.
      Don't update *uval if the value wasn't read from userspace memory.
      
      This fixes process hang due to infinite loop in futex_lock_pi.
      It also fixes a bunch of glibc tests nptl/tst-mutexpi*.
      Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e68d638e
    • Mikulas Patocka's avatar
      alpha: fix formating of stack content · 12ab9e1e
      Mikulas Patocka authored
      commit 4b01abdb upstream.
      
      Since version 4.9, the kernel automatically breaks printk calls into
      multiple newlines unless pr_cont is used. Fix the alpha stacktrace code,
      so that it prints stack trace in four columns, as it was initially
      intended.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMatt Turner <mattst88@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12ab9e1e
    • Mikulas Patocka's avatar
      alpha: fix reboot on Avanti platform · bef0563f
      Mikulas Patocka authored
      commit 55fc633c upstream.
      
      We need to define NEED_SRM_SAVE_RESTORE on the Avanti, otherwise we get
      machine check exception when attempting to reboot the machine.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMatt Turner <mattst88@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bef0563f
    • Michael Cree's avatar
      alpha: Fix mixed up args in EXC macro in futex operations · 371c5ada
      Michael Cree authored
      commit 84e45536 upstream.
      
      Fix the typo (mixed up arguments) in the EXC macro in the futex
      definitions introduced by commit ca282f69 (alpha: add a
      helper for emitting exception table entries).
      Signed-off-by: default avatarMichael Cree <mcree@orcon.net.nz>
      Signed-off-by: default avatarMatt Turner <mattst88@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      371c5ada
    • Arnd Bergmann's avatar
      alpha: osf_sys.c: fix put_tv32 regression · 90d17505
      Arnd Bergmann authored
      commit 47669fb6 upstream.
      
      There was a typo in the new version of put_tv32() that caused an unguarded
      access of a user space pointer, and failed to return the correct result in
      gettimeofday(), wait4(), usleep_thread() and old_adjtimex().
      
      This fixes it to give the correct behavior again.
      
      Fixes: 1cc6c463 ("osf_sys.c: switch handling of timeval32/itimerval32 to copy_{to,from}_user()")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      90d17505
    • Mikulas Patocka's avatar
      alpha: fix crash if pthread_create races with signal delivery · 632a537b
      Mikulas Patocka authored
      commit 21ffceda upstream.
      
      On alpha, a process will crash if it attempts to start a thread and a
      signal is delivered at the same time. The crash can be reproduced with
      this program: https://cygwin.com/ml/cygwin/2014-11/msg00473.html
      
      The reason for the crash is this:
      * we call the clone syscall
      * we go to the function copy_process
      * copy process calls copy_thread_tls, it is a wrapper around copy_thread
      * copy_thread sets the tls pointer: childti->pcb.unique = regs->r20
      * copy_thread sets regs->r20 to zero
      * we go back to copy_process
      * copy process checks "if (signal_pending(current))" and returns
        -ERESTARTNOINTR
      * the clone syscall is restarted, but this time, regs->r20 is zero, so
        the new thread is created with zero tls pointer
      * the new thread crashes in start_thread when attempting to access tls
      
      The comment in the code says that setting the register r20 is some
      compatibility with OSF/1. But OSF/1 doesn't use the CLONE_SETTLS flag, so
      we don't have to zero r20 if CLONE_SETTLS is set. This patch fixes the bug
      by zeroing regs->r20 only if CLONE_SETTLS is not set.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMatt Turner <mattst88@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      632a537b
    • Eric W. Biederman's avatar
      signal/sh: Ensure si_signo is initialized in do_divide_error · 16256f26
      Eric W. Biederman authored
      commit 0e88bb00 upstream.
      
      Set si_signo.
      
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Paul Mundt <lethal@linux-sh.org>
      Cc: linux-sh@vger.kernel.org
      Fixes: 0983b318 ("sh: Wire up division and address error exceptions on SH-2A.")
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16256f26
    • Eric W. Biederman's avatar
      signal/openrisc: Fix do_unaligned_access to send the proper signal · 34ad5909
      Eric W. Biederman authored
      commit 500d5830 upstream.
      
      While reviewing the signal sending on openrisc the do_unaligned_access
      function stood out because it is obviously wrong.  A comment about an
      si_code set above when actually si_code is never set.  Leading to a
      random si_code being sent to userspace in the event of an unaligned
      access.
      
      Looking further SIGBUS BUS_ADRALN is the proper pair of signal and
      si_code to send for an unaligned access. That is what other
      architectures do and what is required by posix.
      
      Given that do_unaligned_access is broken in a way that no one can be
      relying on it on openrisc fix the code to just do the right thing.
      
      Fixes: 769a8a96 ("OpenRISC: Traps")
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
      Cc: Stafford Horne <shorne@gmail.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: openrisc@lists.librecores.org
      Acked-by: default avatarStafford Horne <shorne@gmail.com>
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      34ad5909
    • John Garry's avatar
      ipmi: use dynamic memory for DMI driver override · 765ae618
      John Garry authored
      commit 5516e21a upstream.
      
      Currently a crash can be seen if we reach the "err"
      label in dmi_add_platform_ipmi(), calling
      platform_device_put(), like here:
      [    7.270584]  (null): ipmi:dmi: Unable to add resources: -16
      [    7.330229] ------------[ cut here ]------------
      [    7.334889] kernel BUG at mm/slub.c:3894!
      [    7.338936] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
      [    7.344475] Modules linked in:
      [    7.347556] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc2-00004-gbe9cb7b-dirty #114
      [    7.355907] Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT17 Nemo 2.0 RC0 11/29/2017
      [    7.365137] task: 00000000c211f6d3 task.stack: 00000000f276e9af
      [    7.371116] pstate: 60000005 (nZCv daif -PAN -UAO)
      [    7.375957] pc : kfree+0x194/0x1b4
      [    7.379389] lr : platform_device_release+0xcc/0xd8
      [    7.384225] sp : ffff0000092dba90
      [    7.387567] x29: ffff0000092dba90 x28: ffff000008a83000
      [    7.392933] x27: ffff0000092dbc10 x26: 00000000000000e6
      [    7.398297] x25: 0000000000000003 x24: ffff0000085b51e8
      [    7.403662] x23: 0000000000000100 x22: ffff7e0000234cc0
      [    7.409027] x21: ffff000008af3660 x20: ffff8017d21acc10
      [    7.414392] x19: ffff8017d21acc00 x18: 0000000000000002
      [    7.419757] x17: 0000000000000001 x16: 0000000000000008
      [    7.425121] x15: 0000000000000001 x14: 6666666678303d65
      [    7.430486] x13: 6469727265766f5f x12: 7265766972642e76
      [    7.435850] x11: 6564703e2d617020 x10: 6530326435373638
      [    7.441215] x9 : 3030303030303030 x8 : 3d76656420657361
      [    7.446580] x7 : ffff000008f59df8 x6 : ffff8017fbe0ea50
      [    7.451945] x5 : 0000000000000000 x4 : 0000000000000000
      [    7.457309] x3 : ffffffffffffffff x2 : 0000000000000000
      [    7.462674] x1 : 0fffc00000000800 x0 : ffff7e0000234ce0
      [    7.468039] Process swapper/0 (pid: 1, stack limit = 0x00000000f276e9af)
      [    7.474809] Call trace:
      [    7.477272]  kfree+0x194/0x1b4
      [    7.480351]  platform_device_release+0xcc/0xd8
      [    7.484837]  device_release+0x34/0x90
      [    7.488531]  kobject_put+0x70/0xcc
      [    7.491961]  put_device+0x14/0x1c
      [    7.495304]  platform_device_put+0x14/0x1c
      [    7.499439]  dmi_add_platform_ipmi+0x348/0x3ac
      [    7.503923]  scan_for_dmi_ipmi+0xfc/0x10c
      [    7.507970]  do_one_initcall+0x38/0x124
      [    7.511840]  kernel_init_freeable+0x188/0x228
      [    7.516238]  kernel_init+0x10/0x100
      [    7.519756]  ret_from_fork+0x10/0x18
      [    7.523362] Code: f94002c0 37780080 f94012c0 37000040 (d4210000)
      [    7.529552] ---[ end trace 11750e4787deef9e ]---
      [    7.534228] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
      [    7.534228]
      
      This is because when the device is released in
      platform_device_release(), we try to free
      pdev.driver_override. This is a const string, hence
      the crash.
      Fix by using dynamic memory for pdev->driver_override.
      Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
      [Removed the free of driver_override from ipmi_si_remove_by_dev().  The
       free is done in platform_device_release(), and would result in a double
       free, and ipmi_si_remove_by_dev() is called by non-platform devices.]
      Signed-off-by: default avatarCorey Minyard <cminyard@mvista.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      765ae618
    • Hans de Goede's avatar
      Bluetooth: btusb: Restore QCA Rome suspend/resume fix with a "rewritten" version · fed016a7
      Hans de Goede authored
      commit 61f5acea upstream.
      
      Commit 7d06d589 ("Revert "Bluetooth: btusb: fix QCA...suspend/resume"")
      removed the setting of the BTUSB_RESET_RESUME quirk for QCA Rome devices,
      instead favoring adding USB_QUIRK_RESET_RESUME quirks in usb/core/quirks.c.
      
      This was done because the DIY BTUSB_RESET_RESUME reset-resume handling
      has several issues (see the original commit message). An added advantage
      of moving over to the USB-core reset-resume handling is that it also
      disables autosuspend for these devices, which is similarly broken on these.
      
      But there are 2 issues with this approach:
      1) It leaves the broken DIY BTUSB_RESET_RESUME code in place for Realtek
         devices.
      2) Sofar only 2 of the 10 QCA devices known to the btusb code have been
         added to usb/core/quirks.c and if we fix the Realtek case the same way
         we need to add an additional 14 entries. So in essence we need to
         duplicate a large part of the usb_device_id table in btusb.c in
         usb/core/quirks.c and manually keep them in sync.
      
      This commit instead restores setting a reset-resume quirk for QCA devices
      in the btusb.c code, avoiding the duplicate usb_device_id table problem.
      
      This commit avoids the problems with the original DIY BTUSB_RESET_RESUME
      code by simply setting the USB_QUIRK_RESET_RESUME quirk directly on the
      usb_device.
      
      This commit also moves the BTUSB_REALTEK case over to directly setting the
      USB_QUIRK_RESET_RESUME on the usb_device and removes the now unused
      BTUSB_RESET_RESUME code.
      
      BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1514836
      Fixes: 7d06d589 ("Revert "Bluetooth: btusb: fix QCA...suspend/resume"")
      Cc: Leif Liddy <leif.linux@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Brian Norris <briannorris@chromium.org>
      Cc: Daniel Drake <drake@endlessm.com>
      Cc: Kai-Heng Feng <kai.heng.feng@canonical.com>
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fed016a7
    • Kai-Heng Feng's avatar
      Revert "Bluetooth: btusb: fix QCA Rome suspend/resume" · 2a2ee0c1
      Kai-Heng Feng authored
      commit 7d06d589 upstream.
      
      This reverts commit fd865802.
      
      This commit causes a regression on some QCA ROME chips. The USB device
      reset happens in btusb_open(), hence firmware loading gets interrupted.
      
      Furthermore, this commit stops working after commit
      ("a0085f25 Bluetooth: btusb: driver to
      enable the usb-wakeup feature"). Reset-resume quirk only gets enabled in
      btusb_suspend() when it's not a wakeup source.
      
      If we really want to reset the USB device, we need to do it before
      btusb_open(). Let's handle it in drivers/usb/core/quirks.c.
      
      Cc: Leif Liddy <leif.linux@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Brian Norris <briannorris@chromium.org>
      Cc: Daniel Drake <drake@endlessm.com>
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Reviewed-by: default avatarBrian Norris <briannorris@chromium.org>
      Tested-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2a2ee0c1
    • Hans de Goede's avatar
      Bluetooth: btsdio: Do not bind to non-removable BCM43341 · ed72fcf6
      Hans de Goede authored
      commit b4cdaba2 upstream.
      
      BCM43341 devices soldered onto the PCB (non-removable) always (AFAICT)
      use an UART connection for bluetooth. But they also advertise btsdio
      support on their 3th sdio function, this causes 2 problems:
      
      1) A non functioning BT HCI getting registered
      
      2) Since the btsdio driver does not have suspend/resume callbacks,
      mmc_sdio_pre_suspend will return -ENOSYS, causing mmc_pm_notify()
      to react as if the SDIO-card is removed and since the slot is
      marked as non-removable it will never get detected as inserted again.
      Which results in wifi no longer working after a suspend/resume.
      
      This commit fixes both by making btsdio ignore BCM43341 devices
      when connected to a slot which is marked non-removable.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ed72fcf6
    • Hans de Goede's avatar
      HID: quirks: Fix keyboard + touchpad on Toshiba Click Mini not working · 0e4ac4ae
      Hans de Goede authored
      commit edfc3722 upstream.
      
      The Toshiba Click Mini uses an i2c attached keyboard/touchpad combo
      (single i2c_hid device for both) which has a vid:pid of 04F3:0401,
      which is also used by a bunch of Elan touchpads which are handled by the
      drivers/input/mouse/elan_i2c driver, but that driver deals with pure
      touchpads and does not work for a combo device such as the one on the
      Toshiba Click Mini.
      
      The combo on the Mini has an ACPI id of ELAN0800, which is not claimed
      by the elan_i2c driver, so check for that and if it is found do not ignore
      the device. This fixes the keyboard/touchpad combo on the Mini not working
      (although with the touchpad in mouse emulation mode).
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0e4ac4ae
    • Eric Biggers's avatar
      pipe: fix off-by-one error when checking buffer limits · 703b37d8
      Eric Biggers authored
      commit 9903a91c upstream.
      
      With pipe-user-pages-hard set to 'N', users were actually only allowed up
      to 'N - 1' buffers; and likewise for pipe-user-pages-soft.
      
      Fix this to allow up to 'N' buffers, as would be expected.
      
      Link: http://lkml.kernel.org/r/20180111052902.14409-5-ebiggers3@gmail.com
      Fixes: b0b91d18 ("pipe: fix limit checking in pipe_set_size()")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Acked-by: default avatarWilly Tarreau <w@1wt.eu>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarJoe Lawrence <joe.lawrence@redhat.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: "Luis R . Rodriguez" <mcgrof@kernel.org>
      Cc: Michael Kerrisk <mtk.manpages@gmail.com>
      Cc: Mikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      703b37d8
    • Eric Biggers's avatar
      pipe: actually allow root to exceed the pipe buffer limits · a125e9a4
      Eric Biggers authored
      commit 85c2dd54 upstream.
      
      pipe-user-pages-hard and pipe-user-pages-soft are only supposed to apply
      to unprivileged users, as documented in both Documentation/sysctl/fs.txt
      and the pipe(7) man page.
      
      However, the capabilities are actually only checked when increasing a
      pipe's size using F_SETPIPE_SZ, not when creating a new pipe.  Therefore,
      if pipe-user-pages-hard has been set, the root user can run into it and be
      unable to create pipes.  Similarly, if pipe-user-pages-soft has been set,
      the root user can run into it and have their pipes limited to 1 page each.
      
      Fix this by allowing the privileged override in both cases.
      
      Link: http://lkml.kernel.org/r/20180111052902.14409-4-ebiggers3@gmail.com
      Fixes: 759c0114 ("pipe: limit the per-user amount of pages allocated in pipes")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarJoe Lawrence <joe.lawrence@redhat.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: "Luis R . Rodriguez" <mcgrof@kernel.org>
      Cc: Michael Kerrisk <mtk.manpages@gmail.com>
      Cc: Mikulas Patocka <mpatocka@redhat.com>
      Cc: Willy Tarreau <w@1wt.eu>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a125e9a4
    • Eric Biggers's avatar
      kernel/relay.c: revert "kernel/relay.c: fix potential memory leak" · 75526a9b
      Eric Biggers authored
      commit a1be1f39 upstream.
      
      This reverts commit ba62bafe ("kernel/relay.c: fix potential memory leak").
      
      This commit introduced a double free bug, because 'chan' is already
      freed by the line:
      
          kref_put(&chan->kref, relay_destroy_channel);
      
      This bug was found by syzkaller, using the BLKTRACESETUP ioctl.
      
      Link: http://lkml.kernel.org/r/20180127004759.101823-1-ebiggers3@gmail.com
      Fixes: ba62bafe ("kernel/relay.c: fix potential memory leak")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: Zhouyi Zhou <yizhouzhou@ict.ac.cn>
      Cc: Jens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75526a9b
    • Rasmus Villemoes's avatar
      kernel/async.c: revert "async: simplify lowest_in_progress()" · 838f9cc9
      Rasmus Villemoes authored
      commit 4f7e988e upstream.
      
      This reverts commit 92266d6e ("async: simplify lowest_in_progress()")
      which was simply wrong: In the case where domain is NULL, we now use the
      wrong offsetof() in the list_first_entry macro, so we don't actually
      fetch the ->cookie value, but rather the eight bytes located
      sizeof(struct list_head) further into the struct async_entry.
      
      On 64 bit, that's the data member, while on 32 bit, that's a u64 built
      from func and data in some order.
      
      I think the bug happens to be harmless in practice: It obviously only
      affects callers which pass a NULL domain, and AFAICT the only such
      caller is
      
        async_synchronize_full() ->
        async_synchronize_full_domain(NULL) ->
        async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, NULL)
      
      and the ASYNC_COOKIE_MAX means that in practice we end up waiting for
      the async_global_pending list to be empty - but it would break if
      somebody happened to pass (void*)-1 as the data element to
      async_schedule, and of course also if somebody ever does a
      async_synchronize_cookie_domain(, NULL) with a "finite" cookie value.
      
      Maybe the "harmless in practice" means this isn't -stable material.  But
      I'm not completely confident my quick git grep'ing is enough, and there
      might be affected code in one of the earlier kernels that has since been
      removed, so I'll leave the decision to the stable guys.
      
      Link: http://lkml.kernel.org/r/20171128104938.3921-1-linux@rasmusvillemoes.dk
      Fixes: 92266d6e "async: simplify lowest_in_progress()"
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Arjan van de Ven <arjan@linux.intel.com>
      Cc: Adam Wallis <awallis@codeaurora.org>
      Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      838f9cc9
    • Heiko Carstens's avatar
      fs/proc/kcore.c: use probe_kernel_read() instead of memcpy() · 7e54b582
      Heiko Carstens authored
      commit d0290bc2 upstream.
      
      Commit df04abfd ("fs/proc/kcore.c: Add bounce buffer for ktext
      data") added a bounce buffer to avoid hardened usercopy checks.  Copying
      to the bounce buffer was implemented with a simple memcpy() assuming
      that it is always valid to read from kernel memory iff the
      kern_addr_valid() check passed.
      
      A simple, but pointless, test case like "dd if=/proc/kcore of=/dev/null"
      now can easily crash the kernel, since the former execption handling on
      invalid kernel addresses now doesn't work anymore.
      
      Also adding a kern_addr_valid() implementation wouldn't help here.  Most
      architectures simply return 1 here, while a couple implemented a page
      table walk to figure out if something is mapped at the address in
      question.
      
      With DEBUG_PAGEALLOC active mappings are established and removed all the
      time, so that relying on the result of kern_addr_valid() before
      executing the memcpy() also doesn't work.
      
      Therefore simply use probe_kernel_read() to copy to the bounce buffer.
      This also allows to simplify read_kcore().
      
      At least on s390 this fixes the observed crashes and doesn't introduce
      warnings that were removed with df04abfd ("fs/proc/kcore.c: Add
      bounce buffer for ktext data"), even though the generic
      probe_kernel_read() implementation uses uaccess functions.
      
      While looking into this I'm also wondering if kern_addr_valid() could be
      completely removed...(?)
      
      Link: http://lkml.kernel.org/r/20171202132739.99971-1-heiko.carstens@de.ibm.com
      Fixes: df04abfd ("fs/proc/kcore.c: Add bounce buffer for ktext data")
      Fixes: f5509cc1 ("mm: Hardened usercopy")
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Al Viro <viro@ZenIV.linux.org.uk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7e54b582
    • Mauro Carvalho Chehab's avatar
      media: cxusb, dib0700: ignore XC2028_I2C_FLUSH · ebe2ba53
      Mauro Carvalho Chehab authored
      commit 9893b905 upstream.
      
      The XC2028_I2C_FLUSH only needs to be implemented on a few
      devices. Others can safely ignore it.
      
      That prevents filling the dmesg with lots of messages like:
      
      	dib0700: stk7700ph_xc3028_callback: unknown command 2, arg 0
      
      Fixes: 4d37ece7 ("[media] tuner/xc2028: Add I2C flush callback")
      Reported-by: default avatarEnrico Mioso <mrkiko.rs@gmail.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ebe2ba53
    • Mauro Carvalho Chehab's avatar
      media: ts2020: avoid integer overflows on 32 bit machines · 7a401e25
      Mauro Carvalho Chehab authored
      commit 81742be1 upstream.
      
      Before this patch, when compiled for arm32, the signal strength
      were reported as:
      
      Lock   (0x1f) Signal= 4294908.66dBm C/N= 12.79dB
      
      Because of a 32 bit integer overflow. After it, it is properly
      reported as:
      
      	Lock   (0x1f) Signal= -58.64dBm C/N= 12.79dB
      
      Fixes: 0f91c9d6 ("[media] TS2020: Calculate tuner gain correctly")
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7a401e25
    • Arnd Bergmann's avatar
      media: dvb-frontends: fix i2c access helpers for KASAN · ad91b2e3
      Arnd Bergmann authored
      commit 3cd890db upstream.
      
      A typical code fragment was copied across many dvb-frontend drivers and
      causes large stack frames when built with with CONFIG_KASAN on gcc-5/6/7:
      
      drivers/media/dvb-frontends/cxd2841er.c:3225:1: error: the frame size of 3992 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
      drivers/media/dvb-frontends/cxd2841er.c:3404:1: error: the frame size of 3136 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
      drivers/media/dvb-frontends/stv0367.c:3143:1: error: the frame size of 4016 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
      drivers/media/dvb-frontends/stv090x.c:3430:1: error: the frame size of 5312 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
      drivers/media/dvb-frontends/stv090x.c:4248:1: error: the frame size of 4872 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
      
      gcc-8 now solves this by consolidating the stack slots for the argument
      variables, but on older compilers we can get the same behavior by taking
      the pointer of a local variable rather than the inline function argument.
      
      Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ad91b2e3
    • Arnd Bergmann's avatar
      kasan: rework Kconfig settings · 062cd346
      Arnd Bergmann authored
      commit e7c52b84 upstream.
      
      We get a lot of very large stack frames using gcc-7.0.1 with the default
      -fsanitize-address-use-after-scope --param asan-stack=1 options, which can
      easily cause an overflow of the kernel stack, e.g.
      
        drivers/gpu/drm/i915/gvt/handlers.c:2434:1: warning: the frame size of 46176 bytes is larger than 3072 bytes
        drivers/net/wireless/ralink/rt2x00/rt2800lib.c:5650:1: warning: the frame size of 23632 bytes is larger than 3072 bytes
        lib/atomic64_test.c:250:1: warning: the frame size of 11200 bytes is larger than 3072 bytes
        drivers/gpu/drm/i915/gvt/handlers.c:2621:1: warning: the frame size of 9208 bytes is larger than 3072 bytes
        drivers/media/dvb-frontends/stv090x.c:3431:1: warning: the frame size of 6816 bytes is larger than 3072 bytes
        fs/fscache/stats.c:287:1: warning: the frame size of 6536 bytes is larger than 3072 bytes
      
      To reduce this risk, -fsanitize-address-use-after-scope is now split out
      into a separate CONFIG_KASAN_EXTRA Kconfig option, leading to stack
      frames that are smaller than 2 kilobytes most of the time on x86_64.  An
      earlier version of this patch also prevented combining KASAN_EXTRA with
      KASAN_INLINE, but that is no longer necessary with gcc-7.0.1.
      
      All patches to get the frame size below 2048 bytes with CONFIG_KASAN=y
      and CONFIG_KASAN_EXTRA=n have been merged by maintainers now, so we can
      bring back that default now.  KASAN_EXTRA=y still causes lots of
      warnings but now defaults to !COMPILE_TEST to disable it in
      allmodconfig, and it remains disabled in all other defconfigs since it
      is a new option.  I arbitrarily raise the warning limit for KASAN_EXTRA
      to 3072 to reduce the noise, but an allmodconfig kernel still has around
      50 warnings on gcc-7.
      
      I experimented a bit more with smaller stack frames and have another
      follow-up series that reduces the warning limit for 64-bit architectures
      to 1280 bytes (without CONFIG_KASAN).
      
      With earlier versions of this patch series, I also had patches to address
      the warnings we get with KASAN and/or KASAN_EXTRA, using a
      "noinline_if_stackbloat" annotation.
      
      That annotation now got replaced with a gcc-8 bugfix (see
      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715) and a workaround for
      older compilers, which means that KASAN_EXTRA is now just as bad as
      before and will lead to an instant stack overflow in a few extreme
      cases.
      
      This reverts parts of commit 3f181b4d ("lib/Kconfig.debug: disable
      -Wframe-larger-than warnings with KASAN=y").  Two patches in linux-next
      should be merged first to avoid introducing warnings in an allmodconfig
      build:
        3cd890db ("media: dvb-frontends: fix i2c access helpers for KASAN")
        16c3ada8 ("media: r820t: fix r820t_write_reg for KASAN")
      
      Do we really need to backport this?
      
      I think we do: without this patch, enabling KASAN will lead to
      unavoidable kernel stack overflow in certain device drivers when built
      with gcc-7 or higher on linux-4.10+ or any version that contains a
      backport of commit c5caf21a.  Most people are probably still on
      older compilers, but it will get worse over time as they upgrade their
      distros.
      
      The warnings we get on kernels older than this should all be for code
      that uses dangerously large stack frames, though most of them do not
      cause an actual stack overflow by themselves.The asan-stack option was
      added in linux-4.0, and commit 3f181b4d ("lib/Kconfig.debug:
      disable -Wframe-larger-than warnings with KASAN=y") effectively turned
      off the warning for allmodconfig kernels, so I would like to see this
      fix backported to any kernels later than 4.0.
      
      I have done dozens of fixes for individual functions with stack frames
      larger than 2048 bytes with asan-stack, and I plan to make sure that
      all those fixes make it into the stable kernels as well (most are
      already there).
      
      Part of the complication here is that asan-stack (from 4.0) was
      originally assumed to always require much larger stacks, but that
      turned out to be a combination of multiple gcc bugs that we have now
      worked around and fixed, but sanitize-address-use-after-scope (from
      v4.10) has a much higher inherent stack usage and also suffers from at
      least three other problems that we have analyzed but not yet fixed
      upstream, each of them makes the stack usage more severe than it should
      be.
      
      Link: http://lkml.kernel.org/r/20171221134744.2295529-1-arnd@arndb.deSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      062cd346
    • Andrey Konovalov's avatar
      kasan: don't emit builtin calls when sanitization is off · e186d8bf
      Andrey Konovalov authored
      commit 0e410e15 upstream.
      
      With KASAN enabled the kernel has two different memset() functions, one
      with KASAN checks (memset) and one without (__memset).  KASAN uses some
      macro tricks to use the proper version where required.  For example
      memset() calls in mm/slub.c are without KASAN checks, since they operate
      on poisoned slab object metadata.
      
      The issue is that clang emits memset() calls even when there is no
      memset() in the source code.  They get linked with improper memset()
      implementation and the kernel fails to boot due to a huge amount of KASAN
      reports during early boot stages.
      
      The solution is to add -fno-builtin flag for files with KASAN_SANITIZE :=
      n marker.
      
      Link: http://lkml.kernel.org/r/8ffecfffe04088c52c42b92739c2bd8a0bcb3f5e.1516384594.git.andreyknvl@google.comSigned-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Michal Marek <michal.lkml@markovi.net>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e186d8bf
    • Liu Bo's avatar
      Btrfs: raid56: iterate raid56 internal bio with bio_for_each_segment_all · d16919a3
      Liu Bo authored
      commit 0198e5b7 upstream.
      
      Bio iterated by set_bio_pages_uptodate() is raid56 internal one, so it
      will never be a BIO_CLONED bio, and since this is called by end_io
      functions, bio->bi_iter.bi_size is zero, we mustn't use
      bio_for_each_segment() as that is a no-op if bi_size is zero.
      
      Fixes: 6592e58c ("Btrfs: fix write corruption due to bio cloning on raid5/6")
      Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d16919a3
    • Martin Kaiser's avatar
      watchdog: imx2_wdt: restore previous timeout after suspend+resume · e06f7b68
      Martin Kaiser authored
      commit 0be26725 upstream.
      
      When the watchdog device is suspended, its timeout is set to the maximum
      value. During resume, the previously set timeout should be restored.
      This does not work at the moment.
      
      The suspend function calls
      
      imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
      
      and resume reverts this by calling
      
      imx2_wdt_set_timeout(wdog, wdog->timeout);
      
      However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
      wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
      function.
      
      Fix this by adding a new function __imx2_wdt_set_timeout() which
      only updates the hardware settings. imx2_wdt_set_timeout() now calls
      __imx2_wdt_set_timeout() and then saves the new timeout to
      wdog->timeout.
      
      During suspend, we call __imx2_wdt_set_timeout() directly so that
      wdog->timeout won't be updated and we can restore the previous value
      during resume. This approach makes wdog->timeout different from the
      actual setting in the hardware which is usually not a good thing.
      However, the two differ only while we're suspended and no kernel code is
      running, so it should be ok in this case.
      Signed-off-by: default avatarMartin Kaiser <martin@kaiser.cx>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e06f7b68
    • Takashi Iwai's avatar
      ASoC: skl: Fix kernel warning due to zero NHTL entry · b897f1dc
      Takashi Iwai authored
      commit 20a1ea22 upstream.
      
      I got the following kernel warning when loading snd-soc-skl module on
      Dell Latitude 7270 laptop:
       memremap attempted on mixed range 0x0000000000000000 size: 0x0
       WARNING: CPU: 0 PID: 484 at kernel/memremap.c:98 memremap+0x8a/0x180
       Call Trace:
        skl_nhlt_init+0x82/0xf0 [snd_soc_skl]
        skl_probe+0x2ee/0x7c0 [snd_soc_skl]
        ....
      
      It seems that the machine doesn't support the SKL DSP gives the empty
      NHLT entry, and it triggers the warning.  For avoiding it, let do the
      zero check before calling memremap().
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b897f1dc
    • John Keeping's avatar
      ASoC: rockchip: i2s: fix playback after runtime resume · 4562bfde
      John Keeping authored
      commit c66234cf upstream.
      
      When restoring registers during runtime resume, we must not write to
      I2S_TXDR which is the transmit FIFO as this queues up a sample to be
      output and pushes all of the output channels down by one.
      
      This can be demonstrated with the speaker-test utility:
      
      	for i in a b c; do speaker-test -c 2 -s 1; done
      
      which should play a test through the left speaker three times but if the
      I2S hardware starts runtime suspended the first sample will be played
      through the right speaker.
      
      Fix this by marking I2S_TXDR as volatile (which also requires marking it
      as readble, even though it technically isn't).  This seems to be the
      most robust fix, the alternative of giving I2S_TXDR a default value is
      more fragile since it does not prevent regcache writing to the register
      in all circumstances.
      
      While here, also fix the configuration of I2S_RXDR and I2S_FIFOLR; these
      are not writable so they do not suffer from the same problem as I2S_TXDR
      but reading from I2S_RXDR does suffer from a similar problem.
      
      Fixes: f0447f6c ("ASoC: rockchip: i2s: restore register during runtime_suspend/resume cycle", 2016-09-07)
      Signed-off-by: default avatarJohn Keeping <john@metanate.com>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4562bfde
    • Ulf Magnusson's avatar
      KVM: PPC: Book3S PR: Fix broken select due to misspelling · e747a02d
      Ulf Magnusson authored
      commit 57ea5f16 upstream.
      
      Commit 76d837a4 ("KVM: PPC: Book3S PR: Don't include SPAPR TCE code
      on non-pseries platforms") added a reference to the globally undefined
      symbol PPC_SERIES. Looking at the rest of the commit, PPC_PSERIES was
      probably intended.
      
      Change PPC_SERIES to PPC_PSERIES.
      
      Discovered with the
      https://github.com/ulfalizer/Kconfiglib/blob/master/examples/list_undefined.py
      script.
      
      Fixes: 76d837a4 ("KVM: PPC: Book3S PR: Don't include SPAPR TCE code on non-pseries platforms")
      Signed-off-by: default avatarUlf Magnusson <ulfalizer@gmail.com>
      Signed-off-by: default avatarPaul Mackerras <paulus@ozlabs.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e747a02d
    • James Morse's avatar
      KVM: arm/arm64: Handle CPU_PM_ENTER_FAILED · 985bf399
      James Morse authored
      commit 58d6b15e upstream.
      
      cpu_pm_enter() calls the pm notifier chain with CPU_PM_ENTER, then if
      there is a failure: CPU_PM_ENTER_FAILED.
      
      When KVM receives CPU_PM_ENTER it calls cpu_hyp_reset() which will
      return us to the hyp-stub. If we subsequently get a CPU_PM_ENTER_FAILED,
      KVM does nothing, leaving the CPU running with the hyp-stub, at odds
      with kvm_arm_hardware_enabled.
      
      Add CPU_PM_ENTER_FAILED as a fallthrough for CPU_PM_EXIT, this reloads
      KVM based on kvm_arm_hardware_enabled. This is safe even if CPU_PM_ENTER
      never gets as far as KVM, as cpu_hyp_reinit() calls cpu_hyp_reset()
      to make sure the hyp-stub is loaded before reloading KVM.
      
      Fixes: 67f69197 ("arm64: kvm: allows kvm cpu hotplug")
      CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: default avatarJames Morse <james.morse@arm.com>
      Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      985bf399
    • Paul Mackerras's avatar
      KVM: PPC: Book3S HV: Drop locks before reading guest memory · be54d79b
      Paul Mackerras authored
      commit 36ee41d1 upstream.
      
      Running with CONFIG_DEBUG_ATOMIC_SLEEP reveals that HV KVM tries to
      read guest memory, in order to emulate guest instructions, while
      preempt is disabled and a vcore lock is held.  This occurs in
      kvmppc_handle_exit_hv(), called from post_guest_process(), when
      emulating guest doorbell instructions on POWER9 systems, and also
      when checking whether we have hit a hypervisor breakpoint.
      Reading guest memory can cause a page fault and thus cause the
      task to sleep, so we need to avoid reading guest memory while
      holding a spinlock or when preempt is disabled.
      
      To fix this, we move the preempt_enable() in kvmppc_run_core() to
      before the loop that calls post_guest_process() for each vcore that
      has just run, and we drop and re-take the vcore lock around the calls
      to kvmppc_emulate_debug_inst() and kvmppc_emulate_doorbell_instr().
      
      Dropping the lock is safe with respect to the iteration over the
      runnable vcpus in post_guest_process(); for_each_runnable_thread
      is actually safe to use locklessly.  It is possible for a vcpu
      to become runnable and add itself to the runnable_threads array
      (code near the beginning of kvmppc_run_vcpu()) and then get included
      in the iteration in post_guest_process despite the fact that it
      has not just run.  This is benign because vcpu->arch.trap and
      vcpu->arch.ceded will be zero.
      
      Fixes: 57900694 ("KVM: PPC: Book3S HV: Virtualize doorbell facility on POWER9")
      Signed-off-by: default avatarPaul Mackerras <paulus@ozlabs.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      be54d79b
    • Paul Mackerras's avatar
      KVM: PPC: Book3S HV: Make sure we don't re-enter guest without XIVE loaded · 88b64450
      Paul Mackerras authored
      commit 43ff3f65 upstream.
      
      This fixes a bug where it is possible to enter a guest on a POWER9
      system without having the XIVE (interrupt controller) context loaded.
      This can happen because we unload the XIVE context from the CPU
      before doing the real-mode handling for machine checks.  After the
      real-mode handler runs, it is possible that we re-enter the guest
      via a fast path which does not load the XIVE context.
      
      To fix this, we move the unloading of the XIVE context to come after
      the real-mode machine check handler is called.
      
      Fixes: 5af50993 ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller")
      Signed-off-by: default avatarPaul Mackerras <paulus@ozlabs.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88b64450
    • Liran Alon's avatar
      KVM: nVMX: Fix bug of injecting L2 exception into L1 · fe90a3a6
      Liran Alon authored
      commit 5c7d4f9a upstream.
      
      kvm_clear_exception_queue() should clear pending exception.
      This also includes exceptions which were only marked pending but not
      yet injected. This is because exception.pending is used for both L1
      and L2 to determine if an exception should be raised to guest.
      Note that an exception which is pending but not yet injected will
      be raised again once the guest will be resumed.
      
      Consider the following scenario:
      1) L0 KVM with ignore_msrs=false.
      2) L1 prepare vmcs12 with the following:
          a) No intercepts on MSR (MSR_BITMAP exist and is filled with 0).
          b) No intercept for #GP.
          c) vmx-preemption-timer is configured.
      3) L1 enters into L2.
      4) L2 reads an unhandled MSR that exists in MSR_BITMAP
      (such as 0x1fff).
      
      L2 RDMSR could be handled as described below:
      1) L2 exits to L0 on RDMSR and calls handle_rdmsr().
      2) handle_rdmsr() calls kvm_inject_gp() which sets
      KVM_REQ_EVENT, exception.pending=true and exception.injected=false.
      3) vcpu_enter_guest() consumes KVM_REQ_EVENT and calls
      inject_pending_event() which calls vmx_check_nested_events()
      which sees that exception.pending=true but
      nested_vmx_check_exception() returns 0 and therefore does nothing at
      this point. However let's assume it later sees vmx-preemption-timer
      expired and therefore exits from L2 to L1 by calling
      nested_vmx_vmexit().
      4) nested_vmx_vmexit() calls prepare_vmcs12()
      which calls vmcs12_save_pending_event() but it does nothing as
      exception.injected is false. Also prepare_vmcs12() calls
      kvm_clear_exception_queue() which does nothing as
      exception.injected is already false.
      5) We now return from vmx_check_nested_events() with 0 while still
      having exception.pending=true!
      6) Therefore inject_pending_event() continues
      and we inject L2 exception to L1!...
      
      This commit will fix above issue by changing step (4) to
      clear exception.pending in kvm_clear_exception_queue().
      
      Fixes: 664f8e26 ("KVM: X86: Fix loss of exception which has not yet been injected")
      Signed-off-by: default avatarLiran Alon <liran.alon@oracle.com>
      Reviewed-by: default avatarNikita Leshenko <nikita.leshchenko@oracle.com>
      Reviewed-by: default avatarKrish Sadhukhan <krish.sadhukhan@oracle.com>
      Signed-off-by: default avatarKrish Sadhukhan <krish.sadhukhan@oracle.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe90a3a6
    • Liran Alon's avatar
      KVM: nVMX: Fix races when sending nested PI while dest enters/leaves L2 · 6bad5116
      Liran Alon authored
      commit 6b697711 upstream.
      
      Consider the following scenario:
      1. CPU A calls vmx_deliver_nested_posted_interrupt() to send an IPI
      to CPU B via virtual posted-interrupt mechanism.
      2. CPU B is currently executing L2 guest.
      3. vmx_deliver_nested_posted_interrupt() calls
      kvm_vcpu_trigger_posted_interrupt() which will note that
      vcpu->mode == IN_GUEST_MODE.
      4. Assume that before CPU A sends the physical POSTED_INTR_NESTED_VECTOR
      IPI, CPU B exits from L2 to L0 during event-delivery
      (valid IDT-vectoring-info).
      5. CPU A now sends the physical IPI. The IPI is received in host and
      it's handler (smp_kvm_posted_intr_nested_ipi()) does nothing.
      6. Assume that before CPU A sets pi_pending=true and KVM_REQ_EVENT,
      CPU B continues to run in L0 and reach vcpu_enter_guest(). As
      KVM_REQ_EVENT is not set yet, vcpu_enter_guest() will continue and resume
      L2 guest.
      7. At this point, CPU A sets pi_pending=true and KVM_REQ_EVENT but
      it's too late! CPU B already entered L2 and KVM_REQ_EVENT will only be
      consumed at next L2 entry!
      
      Another scenario to consider:
      1. CPU A calls vmx_deliver_nested_posted_interrupt() to send an IPI
      to CPU B via virtual posted-interrupt mechanism.
      2. Assume that before CPU A calls kvm_vcpu_trigger_posted_interrupt(),
      CPU B is at L0 and is about to resume into L2. Further assume that it is
      in vcpu_enter_guest() after check for KVM_REQ_EVENT.
      3. At this point, CPU A calls kvm_vcpu_trigger_posted_interrupt() which
      will note that vcpu->mode != IN_GUEST_MODE. Therefore, do nothing and
      return false. Then, will set pi_pending=true and KVM_REQ_EVENT.
      4. Now CPU B continue and resumes into L2 guest without processing
      the posted-interrupt until next L2 entry!
      
      To fix both issues, we just need to change
      vmx_deliver_nested_posted_interrupt() to set pi_pending=true and
      KVM_REQ_EVENT before calling kvm_vcpu_trigger_posted_interrupt().
      
      It will fix the first scenario by chaging step (6) to note that
      KVM_REQ_EVENT and pi_pending=true and therefore process
      nested posted-interrupt.
      
      It will fix the second scenario by two possible ways:
      1. If kvm_vcpu_trigger_posted_interrupt() is called while CPU B has changed
      vcpu->mode to IN_GUEST_MODE, physical IPI will be sent and will be received
      when CPU resumes into L2.
      2. If kvm_vcpu_trigger_posted_interrupt() is called while CPU B hasn't yet
      changed vcpu->mode to IN_GUEST_MODE, then after CPU B will change
      vcpu->mode it will call kvm_request_pending() which will return true and
      therefore force another round of vcpu_enter_guest() which will note that
      KVM_REQ_EVENT and pi_pending=true and therefore process nested
      posted-interrupt.
      
      Fixes: 705699a1 ("KVM: nVMX: Enable nested posted interrupt processing")
      Signed-off-by: default avatarLiran Alon <liran.alon@oracle.com>
      Reviewed-by: default avatarNikita Leshenko <nikita.leshchenko@oracle.com>
      Reviewed-by: default avatarKrish Sadhukhan <krish.sadhukhan@oracle.com>
      [Add kvm_vcpu_kick to also handle the case where L1 doesn't intercept L2 HLT
       and L2 executes HLT instruction. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6bad5116
    • Marc Zyngier's avatar
      arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls · 7dffdb31
      Marc Zyngier authored
      commit 20e8175d upstream.
      
      KVM doesn't follow the SMCCC when it comes to unimplemented calls,
      and inject an UNDEF instead of returning an error. Since firmware
      calls are now used for security mitigation, they are becoming more
      common, and the undef is counter productive.
      
      Instead, let's follow the SMCCC which states that -1 must be returned
      to the caller when getting an unknown function number.
      Tested-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7dffdb31
    • Eric Biggers's avatar
      crypto: sha512-mb - initialize pending lengths correctly · f37a798e
      Eric Biggers authored
      commit eff84b37 upstream.
      
      The SHA-512 multibuffer code keeps track of the number of blocks pending
      in each lane.  The minimum of these values is used to identify the next
      lane that will be completed.  Unused lanes are set to a large number
      (0xFFFFFFFF) so that they don't affect this calculation.
      
      However, it was forgotten to set the lengths to this value in the
      initial state, where all lanes are unused.  As a result it was possible
      for sha512_mb_mgr_get_comp_job_avx2() to select an unused lane, causing
      a NULL pointer dereference.  Specifically this could happen in the case
      where ->update() was passed fewer than SHA512_BLOCK_SIZE bytes of data,
      so it then called sha_complete_job() without having actually submitted
      any blocks to the multi-buffer code.  This hit a NULL pointer
      dereference if another task happened to have submitted blocks
      concurrently to the same CPU and the flush timer had not yet expired.
      
      Fix this by initializing sha512_mb_mgr->lens correctly.
      
      As usual, this bug was found by syzkaller.
      
      Fixes: 45691e2d ("crypto: sha512-mb - submit/flush routines for AVX2")
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f37a798e