1. 17 Oct, 2019 40 commits
    • Johan Hovold's avatar
      USB: serial: keyspan: fix NULL-derefs on open() and write() · c45a69ce
      Johan Hovold authored
      commit 7d7e21fa upstream.
      
      Fix NULL-pointer dereferences on open() and write() which can be
      triggered by a malicious USB device.
      
      The current URB allocation helper would fail to initialise the newly
      allocated URB if the device has unexpected endpoint descriptors,
      something which could lead NULL-pointer dereferences in a number of
      open() and write() paths when accessing the URB. For example:
      
      	BUG: kernel NULL pointer dereference, address: 0000000000000000
      	...
      	RIP: 0010:usb_clear_halt+0x11/0xc0
      	...
      	Call Trace:
      	 ? tty_port_open+0x4d/0xd0
      	 keyspan_open+0x70/0x160 [keyspan]
      	 serial_port_activate+0x5b/0x80 [usbserial]
      	 tty_port_open+0x7b/0xd0
      	 ? check_tty_count+0x43/0xa0
      	 tty_open+0xf1/0x490
      
      	BUG: kernel NULL pointer dereference, address: 0000000000000000
      	...
      	RIP: 0010:keyspan_write+0x14e/0x1f3 [keyspan]
      	...
      	Call Trace:
      	 serial_write+0x43/0xa0 [usbserial]
      	 n_tty_write+0x1af/0x4f0
      	 ? do_wait_intr_irq+0x80/0x80
      	 ? process_echoes+0x60/0x60
      	 tty_write+0x13f/0x2f0
      
      	BUG: kernel NULL pointer dereference, address: 0000000000000000
      	...
      	RIP: 0010:keyspan_usa26_send_setup+0x298/0x305 [keyspan]
      	...
      	Call Trace:
      	 keyspan_open+0x10f/0x160 [keyspan]
      	 serial_port_activate+0x5b/0x80 [usbserial]
      	 tty_port_open+0x7b/0xd0
      	 ? check_tty_count+0x43/0xa0
      	 tty_open+0xf1/0x490
      
      Fixes: fdcba53e ("fix for bugzilla #7544 (keyspan USB-to-serial converter)")
      Cc: stable <stable@vger.kernel.org>	# 2.6.21
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c45a69ce
    • Randy Dunlap's avatar
      serial: uartlite: fix exit path null pointer · 091c0f11
      Randy Dunlap authored
      commit a553add0 upstream.
      
      Call uart_unregister_driver() conditionally instead of
      unconditionally, only if it has been previously registered.
      
      This uses driver.state, just as the sh-sci.c driver does.
      
      Fixes this null pointer dereference in tty_unregister_driver(),
      since the 'driver' argument is null:
      
        general protection fault: 0000 [#1] PREEMPT SMP KASAN PTI
        RIP: 0010:tty_unregister_driver+0x25/0x1d0
      
      Fixes: 238b8721 ("[PATCH] serial uartlite driver")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: stable <stable@vger.kernel.org>
      Cc: Peter Korsgaard <jacmet@sunsite.dk>
      Link: https://lore.kernel.org/r/9c8e6581-6fcc-a595-0897-4d90f5d710df@infradead.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      091c0f11
    • Johan Hovold's avatar
      USB: ldusb: fix NULL-derefs on driver unbind · f56ae521
      Johan Hovold authored
      commit 58ecf131 upstream.
      
      The driver was using its struct usb_interface pointer as an inverted
      disconnected flag, but was setting it to NULL before making sure all
      completion handlers had run. This could lead to a NULL-pointer
      dereference in a number of dev_dbg, dev_warn and dev_err statements in
      the completion handlers which relies on said pointer.
      
      Fix this by unconditionally stopping all I/O and preventing
      resubmissions by poisoning the interrupt URBs at disconnect and using a
      dedicated disconnected flag.
      
      This also makes sure that all I/O has completed by the time the
      disconnect callback returns.
      
      Fixes: 2824bd25 ("[PATCH] USB: add ldusb driver")
      Cc: stable <stable@vger.kernel.org>     # 2.6.13
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009153848.8664-4-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f56ae521
    • Johan Hovold's avatar
      USB: chaoskey: fix use-after-free on release · 697bd634
      Johan Hovold authored
      commit 93ddb1f5 upstream.
      
      The driver was accessing its struct usb_interface in its release()
      callback without holding a reference. This would lead to a
      use-after-free whenever the device was disconnected while the character
      device was still open.
      
      Fixes: 66e3e591 ("usb: Add driver for Altus Metrum ChaosKey device (v2)")
      Cc: stable <stable@vger.kernel.org>     # 4.1
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009153848.8664-3-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      697bd634
    • Johan Hovold's avatar
      USB: usblp: fix runtime PM after driver unbind · 25184b86
      Johan Hovold authored
      commit 9a315358 upstream.
      
      Since commit c2b71462 ("USB: core: Fix bug caused by duplicate
      interface PM usage counter") USB drivers must always balance their
      runtime PM gets and puts, including when the driver has already been
      unbound from the interface.
      
      Leaving the interface with a positive PM usage counter would prevent a
      later bound driver from suspending the device.
      
      Fixes: c2b71462 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191001084908.2003-3-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25184b86
    • Johan Hovold's avatar
      USB: iowarrior: fix use-after-free after driver unbind · 685546c8
      Johan Hovold authored
      commit b5f8d468 upstream.
      
      Make sure to stop also the asynchronous write URBs on disconnect() to
      avoid use-after-free in the completion handler after driver unbind.
      
      Fixes: 946b960d ("USB: add driver for iowarrior devices.")
      Cc: stable <stable@vger.kernel.org>	# 2.6.21: 51a2f077 ("USB: introduce usb_anchor")
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009104846.5925-4-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      685546c8
    • Johan Hovold's avatar
      USB: iowarrior: fix use-after-free on release · d8180d42
      Johan Hovold authored
      commit 80cd5479 upstream.
      
      The driver was accessing its struct usb_interface from its release()
      callback without holding a reference. This would lead to a
      use-after-free whenever debugging was enabled and the device was
      disconnected while its character device was open.
      
      Fixes: 549e8350 ("USB: iowarrior: Convert local dbg macro to dev_dbg")
      Cc: stable <stable@vger.kernel.org>     # 3.16
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009104846.5925-3-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d8180d42
    • Johan Hovold's avatar
      USB: iowarrior: fix use-after-free on disconnect · 323f425a
      Johan Hovold authored
      commit edc4746f upstream.
      
      A recent fix addressing a deadlock on disconnect introduced a new bug
      by moving the present flag out of the critical section protected by the
      driver-data mutex. This could lead to a racing release() freeing the
      driver data before disconnect() is done with it.
      
      Due to insufficient locking a related use-after-free could be triggered
      also before the above mentioned commit. Specifically, the driver needs
      to hold the driver-data mutex also while checking the opened flag at
      disconnect().
      
      Fixes: c468a8aa ("usb: iowarrior: fix deadlock on disconnect")
      Fixes: 946b960d ("USB: add driver for iowarrior devices.")
      Cc: stable <stable@vger.kernel.org>	# 2.6.21
      Reported-by: syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009104846.5925-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      323f425a
    • Johan Hovold's avatar
      USB: adutux: fix use-after-free on release · 1e3c57e0
      Johan Hovold authored
      commit 123a0f12 upstream.
      
      The driver was accessing its struct usb_device in its release()
      callback without holding a reference. This would lead to a
      use-after-free whenever the device was disconnected while the character
      device was still open.
      
      Fixes: 66d4bc30 ("USB: adutux: remove custom debug macro")
      Cc: stable <stable@vger.kernel.org>     # 3.12
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009153848.8664-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e3c57e0
    • Johan Hovold's avatar
      USB: adutux: fix NULL-derefs on disconnect · 139d8d9f
      Johan Hovold authored
      commit b2fa7bae upstream.
      
      The driver was using its struct usb_device pointer as an inverted
      disconnected flag, but was setting it to NULL before making sure all
      completion handlers had run. This could lead to a NULL-pointer
      dereference in a number of dev_dbg statements in the completion handlers
      which relies on said pointer.
      
      The pointer was also dereferenced unconditionally in a dev_dbg statement
      release() something which would lead to a NULL-deref whenever a device
      was disconnected before the final character-device close if debugging
      was enabled.
      
      Fix this by unconditionally stopping all I/O and preventing
      resubmissions by poisoning the interrupt URBs at disconnect and using a
      dedicated disconnected flag.
      
      This also makes sure that all I/O has completed by the time the
      disconnect callback returns.
      
      Fixes: 1ef37c60 ("USB: adutux: remove custom debug macro and module parameter")
      Fixes: 66d4bc30 ("USB: adutux: remove custom debug macro")
      Cc: stable <stable@vger.kernel.org>     # 3.12
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20190925092913.8608-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      139d8d9f
    • Johan Hovold's avatar
      USB: adutux: fix use-after-free on disconnect · aa1b499d
      Johan Hovold authored
      commit 44efc269 upstream.
      
      The driver was clearing its struct usb_device pointer, which it used as
      an inverted disconnected flag, before deregistering the character device
      and without serialising against racing release().
      
      This could lead to a use-after-free if a racing release() callback
      observes the cleared pointer and frees the driver data before
      disconnect() is finished with it.
      
      This could also lead to NULL-pointer dereferences in a racing open().
      
      Fixes: f08812d5 ("USB: FIx locks and urb->status in adutux (updated)")
      Cc: stable <stable@vger.kernel.org>     # 2.6.24
      Reported-by: syzbot+0243cb250a51eeefb8cc@syzkaller.appspotmail.com
      Tested-by: syzbot+0243cb250a51eeefb8cc@syzkaller.appspotmail.com
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20190925092913.8608-1-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa1b499d
    • Colin Ian King's avatar
      USB: adutux: remove redundant variable minor · 89121c71
      Colin Ian King authored
      commit 8444efc4 upstream.
      
      Variable minor is being assigned but never read, hence it is redundant
      and can be removed. Cleans up clang warning:
      
      drivers/usb/misc/adutux.c:770:2: warning: Value stored to 'minor' is
      never read
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89121c71
    • Kai-Heng Feng's avatar
      xhci: Increase STS_SAVE timeout in xhci_suspend() · a656cabb
      Kai-Heng Feng authored
      commit ac343366 upstream.
      
      After commit f7fac17c ("xhci: Convert xhci_handshake() to use
      readl_poll_timeout_atomic()"), ASMedia xHCI may fail to suspend.
      
      Although the algorithms are essentially the same, the old max timeout is
      (usec + usec * time of doing readl()), and the new max timeout is just
      usec, which is much less than the old one.
      
      Increase the timeout to make ASMedia xHCI able to suspend again.
      
      BugLink: https://bugs.launchpad.net/bugs/1844021
      Fixes: f7fac17c ("xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()")
      Cc: <stable@vger.kernel.org> # v5.2+
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/1570190373-30684-8-git-send-email-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a656cabb
    • Rick Tseng's avatar
      usb: xhci: wait for CNR controller not ready bit in xhci resume · 4b0f198b
      Rick Tseng authored
      commit a70bcbc3 upstream.
      
      NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold.
      Thus we need to wait for CNR bit to clear in xhci resume, just as in
      xhci init.
      
      [Minor changes to comment and commit message -Mathias]
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarRick Tseng <rtseng@nvidia.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/1570190373-30684-6-git-send-email-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4b0f198b
    • Jan Schmidt's avatar
      xhci: Check all endpoints for LPM timeout · 6e29e092
      Jan Schmidt authored
      commit d500c63f upstream.
      
      If an endpoint is encountered that returns USB3_LPM_DEVICE_INITIATED, keep
      checking further endpoints, as there might be periodic endpoints later
      that return USB3_LPM_DISABLED due to shorter service intervals.
      
      Without this, the code can set too high a maximum-exit-latency and
      prevent the use of multiple USB3 cameras that should be able to work.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarJan Schmidt <jan@centricular.com>
      Tested-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/1570190373-30684-4-git-send-email-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e29e092
    • Mathias Nyman's avatar
      xhci: Prevent device initiated U1/U2 link pm if exit latency is too long · 0ccae303
      Mathias Nyman authored
      commit cd9d9491 upstream.
      
      If host/hub initiated link pm is prevented by a driver flag we still must
      ensure that periodic endpoints have longer service intervals than link pm
      exit latency before allowing device initiated link pm.
      
      Fix this by continue walking and checking endpoint service interval if
      xhci_get_timeout_no_hub_lpm() returns anything else than USB3_LPM_DISABLED
      
      While at it fix the split line error message
      Tested-by: default avatarJan Schmidt <jan@centricular.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/1570190373-30684-3-git-send-email-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0ccae303
    • Mathias Nyman's avatar
      xhci: Fix false warning message about wrong bounce buffer write length · 1817e62b
      Mathias Nyman authored
      commit c03101ff upstream.
      
      The check printing out the "WARN Wrong bounce buffer write length:"
      uses incorrect values when comparing bytes written from scatterlist
      to bounce buffer. Actual copied lengths are fine.
      
      The used seg->bounce_len will be set to equal new_buf_len a few lines later
      in the code, but is incorrect when doing the comparison.
      
      The patch which added this false warning was backported to 4.8+ kernels
      so this should be backported as far as well.
      
      Cc: <stable@vger.kernel.org> # v4.8+
      Fixes: 597c56e3 ("xhci: update bounce buffer with correct sg num")
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/1570190373-30684-2-git-send-email-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1817e62b
    • Johan Hovold's avatar
      USB: usb-skeleton: fix NULL-deref on disconnect · 46b9de8b
      Johan Hovold authored
      commit bed5ef23 upstream.
      
      The driver was using its struct usb_interface pointer as an inverted
      disconnected flag and was setting it to NULL before making sure all
      completion handlers had run. This could lead to NULL-pointer
      dereferences in the dev_err() statements in the completion handlers
      which relies on said pointer.
      
      Fix this by using a dedicated disconnected flag.
      
      Note that this is also addresses a NULL-pointer dereference at release()
      and a struct usb_interface reference leak introduced by a recent runtime
      PM fix, which depends on and should have been submitted together with
      this patch.
      
      Fixes: 4212cd74 ("USB: usb-skeleton.c: remove err() usage")
      Fixes: 5c290a5e ("USB: usb-skeleton: fix runtime PM after driver unbind")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009170944.30057-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46b9de8b
    • Johan Hovold's avatar
      USB: usb-skeleton: fix runtime PM after driver unbind · 6bddbe73
      Johan Hovold authored
      commit 5c290a5e upstream.
      
      Since commit c2b71462 ("USB: core: Fix bug caused by duplicate
      interface PM usage counter") USB drivers must always balance their
      runtime PM gets and puts, including when the driver has already been
      unbound from the interface.
      
      Leaving the interface with a positive PM usage counter would prevent a
      later bound driver from suspending the device.
      
      Fixes: c2b71462 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191001084908.2003-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6bddbe73
    • Johan Hovold's avatar
      USB: yurex: fix NULL-derefs on disconnect · 15362762
      Johan Hovold authored
      commit aafb00a9 upstream.
      
      The driver was using its struct usb_interface pointer as an inverted
      disconnected flag, but was setting it to NULL without making sure all
      code paths that used it were done with it.
      
      Before commit ef61eb43 ("USB: yurex: Fix protection fault after
      device removal") this included the interrupt-in completion handler, but
      there are further accesses in dev_err and dev_dbg statements in
      yurex_write() and the driver-data destructor (sic!).
      
      Fix this by unconditionally stopping also the control URB at disconnect
      and by using a dedicated disconnected flag.
      
      Note that we need to take a reference to the struct usb_interface to
      avoid a use-after-free in the destructor whenever the device was
      disconnected while the character device was still open.
      
      Fixes: aadd6472 ("USB: yurex.c: remove dbg() usage")
      Fixes: 45714104 ("USB: yurex.c: remove err() usage")
      Cc: stable <stable@vger.kernel.org>     # 3.5: ef61eb43Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20191009153848.8664-6-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      15362762
    • Alan Stern's avatar
      USB: yurex: Don't retry on unexpected errors · 9c3fd29b
      Alan Stern authored
      commit 32a0721c upstream.
      
      According to Greg KH, it has been generally agreed that when a USB
      driver encounters an unknown error (or one it can't handle directly),
      it should just give up instead of going into a potentially infinite
      retry loop.
      
      The three codes -EPROTO, -EILSEQ, and -ETIME fall into this category.
      They can be caused by bus errors such as packet loss or corruption,
      attempting to communicate with a disconnected device, or by malicious
      firmware.  Nowadays the extent of packet loss or corruption is
      negligible, so it should be safe for a driver to give up whenever one
      of these errors occurs.
      
      Although the yurex driver handles -EILSEQ errors in this way, it
      doesn't do the same for -EPROTO (as discovered by the syzbot fuzzer)
      or other unrecognized errors.  This patch adjusts the driver so that
      it doesn't log an error message for -EPROTO or -ETIME, and it doesn't
      retry after any errors.
      
      Reported-and-tested-by: syzbot+b24d736f18a1541ad550@syzkaller.appspotmail.com
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      CC: Tomoki Sekiyama <tomoki.sekiyama@gmail.com>
      CC: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.1909171245410.1590-100000@iolanthe.rowland.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9c3fd29b
    • Bastien Nocera's avatar
      USB: rio500: Remove Rio 500 kernel driver · 04d063d2
      Bastien Nocera authored
      commit 015664d1 upstream.
      
      The Rio500 kernel driver has not been used by Rio500 owners since 2001
      not long after the rio500 project added support for a user-space USB stack
      through the very first versions of usbdevfs and then libusb.
      
      Support for the kernel driver was removed from the upstream utilities
      in 2008:
      https://gitlab.freedesktop.org/hadess/rio500/commit/943f624ab721eb8281c287650fcc9e2026f6f5db
      
      Cc: Cesar Miquel <miquel@df.uba.ar>
      Signed-off-by: default avatarBastien Nocera <hadess@hadess.net>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/6251c17584d220472ce882a3d9c199c401a51a71.camel@hadess.netSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04d063d2
    • Will Deacon's avatar
      panic: ensure preemption is disabled during panic() · 9489b435
      Will Deacon authored
      commit 20bb759a upstream.
      
      Calling 'panic()' on a kernel with CONFIG_PREEMPT=y can leave the
      calling CPU in an infinite loop, but with interrupts and preemption
      enabled.  From this state, userspace can continue to be scheduled,
      despite the system being "dead" as far as the kernel is concerned.
      
      This is easily reproducible on arm64 when booting with "nosmp" on the
      command line; a couple of shell scripts print out a periodic "Ping"
      message whilst another triggers a crash by writing to
      /proc/sysrq-trigger:
      
        | sysrq: Trigger a crash
        | Kernel panic - not syncing: sysrq triggered crash
        | CPU: 0 PID: 1 Comm: init Not tainted 5.2.15 #1
        | Hardware name: linux,dummy-virt (DT)
        | Call trace:
        |  dump_backtrace+0x0/0x148
        |  show_stack+0x14/0x20
        |  dump_stack+0xa0/0xc4
        |  panic+0x140/0x32c
        |  sysrq_handle_reboot+0x0/0x20
        |  __handle_sysrq+0x124/0x190
        |  write_sysrq_trigger+0x64/0x88
        |  proc_reg_write+0x60/0xa8
        |  __vfs_write+0x18/0x40
        |  vfs_write+0xa4/0x1b8
        |  ksys_write+0x64/0xf0
        |  __arm64_sys_write+0x14/0x20
        |  el0_svc_common.constprop.0+0xb0/0x168
        |  el0_svc_handler+0x28/0x78
        |  el0_svc+0x8/0xc
        | Kernel Offset: disabled
        | CPU features: 0x0002,24002004
        | Memory Limit: none
        | ---[ end Kernel panic - not syncing: sysrq triggered crash ]---
        |  Ping 2!
        |  Ping 1!
        |  Ping 1!
        |  Ping 2!
      
      The issue can also be triggered on x86 kernels if CONFIG_SMP=n,
      otherwise local interrupts are disabled in 'smp_send_stop()'.
      
      Disable preemption in 'panic()' before re-enabling interrupts.
      
      Link: http://lkml.kernel.org/r/20191002123538.22609-1-will@kernel.org
      Link: https://lore.kernel.org/r/BX1W47JXPMR8.58IYW53H6M5N@dragonstoneSigned-off-by: default avatarWill Deacon <will@kernel.org>
      Reported-by: default avatarXogium <contact@xogium.me>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: <stable@vger.kernel.org>
      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>
      9489b435
    • Oleksandr Suvorov's avatar
      ASoC: sgtl5000: Improve VAG power and mute control · b05f0d9e
      Oleksandr Suvorov authored
      [ Upstream commit b1f373a1 ]
      
      VAG power control is improved to fit the manual [1]. This patch fixes as
      minimum one bug: if customer muxes Headphone to Line-In right after boot,
      the VAG power remains off that leads to poor sound quality from line-in.
      
      I.e. after boot:
        - Connect sound source to Line-In jack;
        - Connect headphone to HP jack;
        - Run following commands:
        $ amixer set 'Headphone' 80%
        $ amixer set 'Headphone Mux' LINE_IN
      
      Change VAG power on/off control according to the following algorithm:
        - turn VAG power ON on the 1st incoming event.
        - keep it ON if there is any active VAG consumer (ADC/DAC/HP/Line-In).
        - turn VAG power OFF when there is the latest consumer's pre-down event
          come.
        - always delay after VAG power OFF to avoid pop.
        - delay after VAG power ON if the initiative consumer is Line-In, this
          prevents pop during line-in muxing.
      
      According to the data sheet [1], to avoid any pops/clicks,
      the outputs should be muted during input/output
      routing changes.
      
      [1] https://www.nxp.com/docs/en/data-sheet/SGTL5000.pdf
      
      Cc: stable@vger.kernel.org
      Fixes: 9b34e6cc ("ASoC: Add Freescale SGTL5000 codec support")
      Signed-off-by: default avatarOleksandr Suvorov <oleksandr.suvorov@toradex.com>
      Reviewed-by: default avatarMarcel Ziswiler <marcel.ziswiler@toradex.com>
      Reviewed-by: default avatarFabio Estevam <festevam@gmail.com>
      Reviewed-by: default avatarCezary Rojewski <cezary.rojewski@intel.com>
      Link: https://lore.kernel.org/r/20190719100524.23300-3-oleksandr.suvorov@toradex.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b05f0d9e
    • Johannes Berg's avatar
      nl80211: validate beacon head · a873afd7
      Johannes Berg authored
      commit f88eb7c0 upstream.
      
      We currently don't validate the beacon head, i.e. the header,
      fixed part and elements that are to go in front of the TIM
      element. This means that the variable elements there can be
      malformed, e.g. have a length exceeding the buffer size, but
      most downstream code from this assumes that this has already
      been checked.
      
      Add the necessary checks to the netlink policy.
      
      Cc: stable@vger.kernel.org
      Fixes: ed1b6cc7 ("cfg80211/nl80211: add beacon settings")
      Link: https://lore.kernel.org/r/1569009255-I7ac7fbe9436e9d8733439eab8acbbd35e55c74ef@changeidSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a873afd7
    • Jouni Malinen's avatar
      cfg80211: Use const more consistently in for_each_element macros · fbc012a1
      Jouni Malinen authored
      commit 7388afe0 upstream.
      
      Enforce the first argument to be a correct type of a pointer to struct
      element and avoid unnecessary typecasts from const to non-const pointers
      (the change in validate_ie_attr() is needed to make this part work). In
      addition, avoid signed/unsigned comparison within for_each_element() and
      mark struct element packed just in case.
      Signed-off-by: default avatarJouni Malinen <j@w1.fi>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fbc012a1
    • Johannes Berg's avatar
      cfg80211: add and use strongly typed element iteration macros · c48986ff
      Johannes Berg authored
      commit 0f3b07f0 upstream.
      
      Rather than always iterating elements from frames with pure
      u8 pointers, add a type "struct element" that encapsulates
      the id/datalen/data format of them.
      
      Then, add the element iteration macros
       * for_each_element
       * for_each_element_id
       * for_each_element_extid
      
      which take, as their first 'argument', such a structure and
      iterate through a given u8 array interpreting it as elements.
      
      While at it and since we'll need it, also add
       * for_each_subelement
       * for_each_subelement_id
       * for_each_subelement_extid
      
      which instead of taking data/length just take an outer element
      and use its data/datalen.
      
      Also add for_each_element_completed() to determine if any of
      the loops above completed, i.e. it was able to parse all of
      the elements successfully and no data remained.
      
      Use for_each_element_id() in cfg80211_find_ie_match() as the
      first user of this.
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c48986ff
    • Andrew Murray's avatar
      coresight: etm4x: Use explicit barriers on enable/disable · 8f68571b
      Andrew Murray authored
      commit 1004ce4c upstream.
      
      Synchronization is recommended before disabling the trace registers
      to prevent any start or stop points being speculative at the point
      of disabling the unit (section 7.3.77 of ARM IHI 0064D).
      
      Synchronization is also recommended after programming the trace
      registers to ensure all updates are committed prior to normal code
      resuming (section 4.3.7 of ARM IHI 0064D).
      
      Let's ensure these syncronization points are present in the code
      and clearly commented.
      
      Note that we could rely on the barriers in CS_LOCK and
      coresight_disclaim_device_unlocked or the context switch to user
      space - however coresight may be of use in the kernel.
      
      On armv8 the mb macro is defined as dsb(sy) - Given that the etm4x is
      only used on armv8 let's directly use dsb(sy) instead of mb(). This
      removes some ambiguity and makes it easier to correlate the code with
      the TRM.
      Signed-off-by: default avatarAndrew Murray <andrew.murray@arm.com>
      Reviewed-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      [Fixed capital letter for "use" in title]
      Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
      Link: https://lore.kernel.org/r/20190829202842.580-11-mathieu.poirier@linaro.org
      Cc: stable@vger.kernel.org # 4.9+
      Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8f68571b
    • Horia Geantă's avatar
      crypto: caam - fix concurrency issue in givencrypt descriptor · 99f1f6b3
      Horia Geantă authored
      commit 48f89d2a upstream.
      
      IV transfer from ofifo to class2 (set up at [29][30]) is not guaranteed
      to be scheduled before the data transfer from ofifo to external memory
      (set up at [38]:
      
      [29] 10FA0004           ld: ind-nfifo (len=4) imm
      [30] 81F00010               <nfifo_entry: ofifo->class2 type=msg len=16>
      [31] 14820004           ld: ccb2-datasz len=4 offs=0 imm
      [32] 00000010               data:0x00000010
      [33] 8210010D    operation: cls1-op aes cbc init-final enc
      [34] A8080B04         math: (seqin + math0)->vseqout len=4
      [35] 28000010    seqfifold: skip len=16
      [36] A8080A04         math: (seqin + math0)->vseqin len=4
      [37] 2F1E0000    seqfifold: both msg1->2-last2-last1 len=vseqinsz
      [38] 69300000   seqfifostr: msg len=vseqoutsz
      [39] 5C20000C      seqstr: ccb2 ctx len=12 offs=0
      
      If ofifo -> external memory transfer happens first, DECO will hang
      (issuing a Watchdog Timeout error, if WDOG is enabled) waiting for
      data availability in ofifo for the ofifo -> c2 ififo transfer.
      
      Make sure IV transfer happens first by waiting for all CAAM internal
      transfers to end before starting payload transfer.
      
      New descriptor with jump command inserted at [37]:
      
      [..]
      [36] A8080A04         math: (seqin + math0)->vseqin len=4
      [37] A1000401         jump: jsl1 all-match[!nfifopend] offset=[01] local->[38]
      [38] 2F1E0000    seqfifold: both msg1->2-last2-last1 len=vseqinsz
      [39] 69300000   seqfifostr: msg len=vseqoutsz
      [40] 5C20000C      seqstr: ccb2 ctx len=12 offs=0
      
      [Note: the issue is present in the descriptor from the very beginning
      (cf. Fixes tag). However I've marked it v4.19+ since it's the oldest
      maintained kernel that the patch applies clean against.]
      
      Cc: <stable@vger.kernel.org> # v4.19+
      Fixes: 1acebad3 ("crypto: caam - faster aead implementation")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      [Horia: backport to v4.4, v4.9]
      Signed-off-by: default avatarHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      99f1f6b3
    • Srikar Dronamraju's avatar
      perf stat: Reset previous counts on repeat with interval · 375cf9ab
      Srikar Dronamraju authored
      [ Upstream commit b63fd11c ]
      
      When using 'perf stat' with repeat and interval option, it shows wrong
      values for events.
      
      The wrong values will be shown for the first interval on the second and
      subsequent repetitions.
      
      Without the fix:
      
        # perf stat -r 3 -I 2000 -e faults -e sched:sched_switch -a sleep 5
      
           2.000282489                 53      faults
           2.000282489                513      sched:sched_switch
           4.005478208              3,721      faults
           4.005478208              2,666      sched:sched_switch
           5.025470933                395      faults
           5.025470933              1,307      sched:sched_switch
           2.009602825 1,84,46,74,40,73,70,95,47,520      faults 		<------
           2.009602825 1,84,46,74,40,73,70,95,49,568      sched:sched_switch  <------
           4.019612206              4,730      faults
           4.019612206              2,746      sched:sched_switch
           5.039615484              3,953      faults
           5.039615484              1,496      sched:sched_switch
           2.000274620 1,84,46,74,40,73,70,95,47,520      faults		<------
           2.000274620 1,84,46,74,40,73,70,95,47,520      sched:sched_switch	<------
           4.000480342              4,282      faults
           4.000480342              2,303      sched:sched_switch
           5.000916811              1,322      faults
           5.000916811              1,064      sched:sched_switch
        #
      
      prev_raw_counts is allocated when using intervals. This is used when
      calculating the difference in the counts of events when using interval.
      
      The current counts are stored in prev_raw_counts to calculate the
      differences in the next iteration.
      
      On the first interval of the second and subsequent repetitions,
      prev_raw_counts would be the values stored in the last interval of the
      previous repetitions, while the current counts will only be for the
      first interval of the current repetition.
      
      Hence there is a possibility of events showing up as big number.
      
      Fix this by resetting prev_raw_counts whenever perf stat repeats the
      command.
      
      With the fix:
      
        # perf stat -r 3 -I 2000 -e faults -e sched:sched_switch -a sleep 5
      
           2.019349347              2,597      faults
           2.019349347              2,753      sched:sched_switch
           4.019577372              3,098      faults
           4.019577372              2,532      sched:sched_switch
           5.019415481              1,879      faults
           5.019415481              1,356      sched:sched_switch
           2.000178813              8,468      faults
           2.000178813              2,254      sched:sched_switch
           4.000404621              7,440      faults
           4.000404621              1,266      sched:sched_switch
           5.040196079              2,458      faults
           5.040196079                556      sched:sched_switch
           2.000191939              6,870      faults
           2.000191939              1,170      sched:sched_switch
           4.000414103                541      faults
           4.000414103                902      sched:sched_switch
           5.000809863                450      faults
           5.000809863                364      sched:sched_switch
        #
      
      Committer notes:
      
      This was broken since the cset introducing the --interval feature, i.e.
      --repeat + --interval wasn't tested at that point, add the Fixes tag so
      that automatic scripts can pick this up.
      
      Fixes: 13370a9b ("perf stat: Add interval printing")
      Signed-off-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: stable@vger.kernel.org # v3.9+
      Link: http://lore.kernel.org/lkml/20190904094738.9558-2-srikar@linux.vnet.ibm.com
      [ Fixed up conflicts with libperf, i.e. some perf_{evsel,evlist} lost the 'perf' prefix ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      375cf9ab
    • Srikar Dronamraju's avatar
      perf stat: Fix a segmentation fault when using repeat forever · 94505b62
      Srikar Dronamraju authored
      [ Upstream commit 443f2d5b ]
      
      Observe a segmentation fault when 'perf stat' is asked to repeat forever
      with the interval option.
      
      Without fix:
      
        # perf stat -r 0 -I 5000 -e cycles -a sleep 10
        #           time             counts unit events
             5.000211692  3,13,89,82,34,157      cycles
            10.000380119  1,53,98,52,22,294      cycles
            10.040467280       17,16,79,265      cycles
        Segmentation fault
      
      This problem was only observed when we use forever option aka -r 0 and
      works with limited repeats. Calling print_counter with ts being set to
      NULL, is not a correct option when interval is set. Hence avoid
      print_counter(NULL,..)  if interval is set.
      
      With fix:
      
        # perf stat -r 0 -I 5000 -e cycles -a sleep 10
         #           time             counts unit events
             5.019866622  3,15,14,43,08,697      cycles
            10.039865756  3,15,16,31,95,261      cycles
            10.059950628     1,26,05,47,158      cycles
             5.009902655  3,14,52,62,33,932      cycles
            10.019880228  3,14,52,22,89,154      cycles
            10.030543876       66,90,18,333      cycles
             5.009848281  3,14,51,98,25,437      cycles
            10.029854402  3,15,14,93,04,918      cycles
             5.009834177  3,14,51,95,92,316      cycles
      
      Committer notes:
      
      Did the 'git bisect' to find the cset introducing the problem to add the
      Fixes tag below, and at that time the problem reproduced as:
      
        (gdb) run stat -r0 -I500 sleep 1
        <SNIP>
        Program received signal SIGSEGV, Segmentation fault.
        print_interval (prefix=prefix@entry=0x7fffffffc8d0 "", ts=ts@entry=0x0) at builtin-stat.c:866
        866		sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
        (gdb) bt
        #0  print_interval (prefix=prefix@entry=0x7fffffffc8d0 "", ts=ts@entry=0x0) at builtin-stat.c:866
        #1  0x000000000041860a in print_counters (ts=ts@entry=0x0, argc=argc@entry=2, argv=argv@entry=0x7fffffffd640) at builtin-stat.c:938
        #2  0x0000000000419a7f in cmd_stat (argc=2, argv=0x7fffffffd640, prefix=<optimized out>) at builtin-stat.c:1411
        #3  0x000000000045c65a in run_builtin (p=p@entry=0x6291b8 <commands+216>, argc=argc@entry=5, argv=argv@entry=0x7fffffffd640) at perf.c:370
        #4  0x000000000045c893 in handle_internal_command (argc=5, argv=0x7fffffffd640) at perf.c:429
        #5  0x000000000045c8f1 in run_argv (argcp=argcp@entry=0x7fffffffd4ac, argv=argv@entry=0x7fffffffd4a0) at perf.c:473
        #6  0x000000000045cac9 in main (argc=<optimized out>, argv=<optimized out>) at perf.c:588
        (gdb)
      
      Mostly the same as just before this patch:
      
        Program received signal SIGSEGV, Segmentation fault.
        0x00000000005874a7 in print_interval (config=0xa1f2a0 <stat_config>, evlist=0xbc9b90, prefix=0x7fffffffd1c0 "`", ts=0x0) at util/stat-display.c:964
        964		sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
        (gdb) bt
        #0  0x00000000005874a7 in print_interval (config=0xa1f2a0 <stat_config>, evlist=0xbc9b90, prefix=0x7fffffffd1c0 "`", ts=0x0) at util/stat-display.c:964
        #1  0x0000000000588047 in perf_evlist__print_counters (evlist=0xbc9b90, config=0xa1f2a0 <stat_config>, _target=0xa1f0c0 <target>, ts=0x0, argc=2, argv=0x7fffffffd670)
            at util/stat-display.c:1172
        #2  0x000000000045390f in print_counters (ts=0x0, argc=2, argv=0x7fffffffd670) at builtin-stat.c:656
        #3  0x0000000000456bb5 in cmd_stat (argc=2, argv=0x7fffffffd670) at builtin-stat.c:1960
        #4  0x00000000004dd2e0 in run_builtin (p=0xa30e00 <commands+288>, argc=5, argv=0x7fffffffd670) at perf.c:310
        #5  0x00000000004dd54d in handle_internal_command (argc=5, argv=0x7fffffffd670) at perf.c:362
        #6  0x00000000004dd694 in run_argv (argcp=0x7fffffffd4cc, argv=0x7fffffffd4c0) at perf.c:406
        #7  0x00000000004dda11 in main (argc=5, argv=0x7fffffffd670) at perf.c:531
        (gdb)
      
      Fixes: d4f63a47 ("perf stat: Introduce print_counters function")
      Signed-off-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: stable@vger.kernel.org # v4.2+
      Link: http://lore.kernel.org/lkml/20190904094738.9558-3-srikar@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      94505b62
    • Jiri Olsa's avatar
      perf tools: Fix segfault in cpu_cache_level__read() · 8530a7e9
      Jiri Olsa authored
      [ Upstream commit 0216234c ]
      
      We release wrong pointer on error path in cpu_cache_level__read
      function, leading to segfault:
      
        (gdb) r record ls
        Starting program: /root/perf/tools/perf/perf record ls
        ...
        [ perf record: Woken up 1 times to write data ]
        double free or corruption (out)
      
        Thread 1 "perf" received signal SIGABRT, Aborted.
        0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
        (gdb) bt
        #0  0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
        #1  0x00007ffff7443bac in abort () from /lib64/power9/libc.so.6
        #2  0x00007ffff74af8bc in __libc_message () from /lib64/power9/libc.so.6
        #3  0x00007ffff74b92b8 in malloc_printerr () from /lib64/power9/libc.so.6
        #4  0x00007ffff74bb874 in _int_free () from /lib64/power9/libc.so.6
        #5  0x0000000010271260 in __zfree (ptr=0x7fffffffa0b0) at ../../lib/zalloc..
        #6  0x0000000010139340 in cpu_cache_level__read (cache=0x7fffffffa090, cac..
        #7  0x0000000010143c90 in build_caches (cntp=0x7fffffffa118, size=<optimiz..
        ...
      
      Releasing the proper pointer.
      
      Fixes: 720e98b5 ("perf tools: Add perf data cache feature")
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org: # v4.6+
      Link: http://lore.kernel.org/lkml/20190912105235.10689-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8530a7e9
    • Steven Rostedt (VMware)'s avatar
      tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure · 06585534
      Steven Rostedt (VMware) authored
      [ Upstream commit e0d2615856b2046c2e8d5bfd6933f37f69703b0b ]
      
      If the re-allocation of tep->cmdlines succeeds, then the previous
      allocation of tep->cmdlines will be freed. If we later fail in
      add_new_comm(), we must not free cmdlines, and also should assign
      tep->cmdlines to the new allocation. Otherwise when freeing tep, the
      tep->cmdlines will be pointing to garbage.
      
      Fixes: a6d2a61a ("tools lib traceevent: Remove some die() calls")
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: linux-trace-devel@vger.kernel.org
      Cc: stable@vger.kernel.org
      Link: http://lkml.kernel.org/r/20190828191819.970121417@goodmis.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      06585534
    • Valdis Kletnieks's avatar
      kernel/elfcore.c: include proper prototypes · d3d96472
      Valdis Kletnieks authored
      [ Upstream commit 0f749140 ]
      
      When building with W=1, gcc properly complains that there's no prototypes:
      
        CC      kernel/elfcore.o
      kernel/elfcore.c:7:17: warning: no previous prototype for 'elf_core_extra_phdrs' [-Wmissing-prototypes]
          7 | Elf_Half __weak elf_core_extra_phdrs(void)
            |                 ^~~~~~~~~~~~~~~~~~~~
      kernel/elfcore.c:12:12: warning: no previous prototype for 'elf_core_write_extra_phdrs' [-Wmissing-prototypes]
         12 | int __weak elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
            |            ^~~~~~~~~~~~~~~~~~~~~~~~~~
      kernel/elfcore.c:17:12: warning: no previous prototype for 'elf_core_write_extra_data' [-Wmissing-prototypes]
         17 | int __weak elf_core_write_extra_data(struct coredump_params *cprm)
            |            ^~~~~~~~~~~~~~~~~~~~~~~~~
      kernel/elfcore.c:22:15: warning: no previous prototype for 'elf_core_extra_data_size' [-Wmissing-prototypes]
         22 | size_t __weak elf_core_extra_data_size(void)
            |               ^~~~~~~~~~~~~~~~~~~~~~~~
      
      Provide the include file so gcc is happy, and we don't have potential code drift
      
      Link: http://lkml.kernel.org/r/29875.1565224705@turing-policeSigned-off-by: default avatarValdis Kletnieks <valdis.kletnieks@vt.edu>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d3d96472
    • KeMeng Shi's avatar
      sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() · afed3c5c
      KeMeng Shi authored
      [ Upstream commit 714e501e ]
      
      An oops can be triggered in the scheduler when running qemu on arm64:
      
       Unable to handle kernel paging request at virtual address ffff000008effe40
       Internal error: Oops: 96000007 [#1] SMP
       Process migration/0 (pid: 12, stack limit = 0x00000000084e3736)
       pstate: 20000085 (nzCv daIf -PAN -UAO)
       pc : __ll_sc___cmpxchg_case_acq_4+0x4/0x20
       lr : move_queued_task.isra.21+0x124/0x298
       ...
       Call trace:
        __ll_sc___cmpxchg_case_acq_4+0x4/0x20
        __migrate_task+0xc8/0xe0
        migration_cpu_stop+0x170/0x180
        cpu_stopper_thread+0xec/0x178
        smpboot_thread_fn+0x1ac/0x1e8
        kthread+0x134/0x138
        ret_from_fork+0x10/0x18
      
      __set_cpus_allowed_ptr() will choose an active dest_cpu in affinity mask to
      migrage the process if process is not currently running on any one of the
      CPUs specified in affinity mask. __set_cpus_allowed_ptr() will choose an
      invalid dest_cpu (dest_cpu >= nr_cpu_ids, 1024 in my virtual machine) if
      CPUS in an affinity mask are deactived by cpu_down after cpumask_intersects
      check. cpumask_test_cpu() of dest_cpu afterwards is overflown and may pass if
      corresponding bit is coincidentally set. As a consequence, kernel will
      access an invalid rq address associate with the invalid CPU in
      migration_cpu_stop->__migrate_task->move_queued_task and the Oops occurs.
      
      The reproduce the crash:
      
        1) A process repeatedly binds itself to cpu0 and cpu1 in turn by calling
        sched_setaffinity.
      
        2) A shell script repeatedly does "echo 0 > /sys/devices/system/cpu/cpu1/online"
        and "echo 1 > /sys/devices/system/cpu/cpu1/online" in turn.
      
        3) Oops appears if the invalid CPU is set in memory after tested cpumask.
      Signed-off-by: default avatarKeMeng Shi <shikemeng@huawei.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Reviewed-by: default avatarValentin Schneider <valentin.schneider@arm.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/1568616808-16808-1-git-send-email-shikemeng@huawei.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      afed3c5c
    • zhengbin's avatar
      fuse: fix memleak in cuse_channel_open · 80a84d6c
      zhengbin authored
      [ Upstream commit 9ad09b19 ]
      
      If cuse_send_init fails, need to fuse_conn_put cc->fc.
      
      cuse_channel_open->fuse_conn_init->refcount_set(&fc->count, 1)
                       ->fuse_dev_alloc->fuse_conn_get
                       ->fuse_dev_free->fuse_conn_put
      
      Fixes: cc080e9e ("fuse: introduce per-instance fuse_dev structure")
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarzhengbin <zhengbin13@huawei.com>
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      80a84d6c
    • Ido Schimmel's avatar
      thermal: Fix use-after-free when unregistering thermal zone device · 3e5043ad
      Ido Schimmel authored
      [ Upstream commit 1851799e ]
      
      thermal_zone_device_unregister() cancels the delayed work that polls the
      thermal zone, but it does not wait for it to finish. This is racy with
      respect to the freeing of the thermal zone device, which can result in a
      use-after-free [1].
      
      Fix this by waiting for the delayed work to finish before freeing the
      thermal zone device. Note that thermal_zone_device_set_polling() is
      never invoked from an atomic context, so it is safe to call
      cancel_delayed_work_sync() that can block.
      
      [1]
      [  +0.002221] ==================================================================
      [  +0.000064] BUG: KASAN: use-after-free in __mutex_lock+0x1076/0x11c0
      [  +0.000016] Read of size 8 at addr ffff8881e48e0450 by task kworker/1:0/17
      
      [  +0.000023] CPU: 1 PID: 17 Comm: kworker/1:0 Not tainted 5.2.0-rc6-custom-02495-g8e73ca3be4af #1701
      [  +0.000010] Hardware name: Mellanox Technologies Ltd. MSN2100-CB2FO/SA001017, BIOS 5.6.5 06/07/2016
      [  +0.000016] Workqueue: events_freezable_power_ thermal_zone_device_check
      [  +0.000012] Call Trace:
      [  +0.000021]  dump_stack+0xa9/0x10e
      [  +0.000020]  print_address_description.cold.2+0x9/0x25e
      [  +0.000018]  __kasan_report.cold.3+0x78/0x9d
      [  +0.000016]  kasan_report+0xe/0x20
      [  +0.000016]  __mutex_lock+0x1076/0x11c0
      [  +0.000014]  step_wise_throttle+0x72/0x150
      [  +0.000018]  handle_thermal_trip+0x167/0x760
      [  +0.000019]  thermal_zone_device_update+0x19e/0x5f0
      [  +0.000019]  process_one_work+0x969/0x16f0
      [  +0.000017]  worker_thread+0x91/0xc40
      [  +0.000014]  kthread+0x33d/0x400
      [  +0.000015]  ret_from_fork+0x3a/0x50
      
      [  +0.000020] Allocated by task 1:
      [  +0.000015]  save_stack+0x19/0x80
      [  +0.000015]  __kasan_kmalloc.constprop.4+0xc1/0xd0
      [  +0.000014]  kmem_cache_alloc_trace+0x152/0x320
      [  +0.000015]  thermal_zone_device_register+0x1b4/0x13a0
      [  +0.000015]  mlxsw_thermal_init+0xc92/0x23d0
      [  +0.000014]  __mlxsw_core_bus_device_register+0x659/0x11b0
      [  +0.000013]  mlxsw_core_bus_device_register+0x3d/0x90
      [  +0.000013]  mlxsw_pci_probe+0x355/0x4b0
      [  +0.000014]  local_pci_probe+0xc3/0x150
      [  +0.000013]  pci_device_probe+0x280/0x410
      [  +0.000013]  really_probe+0x26a/0xbb0
      [  +0.000013]  driver_probe_device+0x208/0x2e0
      [  +0.000013]  device_driver_attach+0xfe/0x140
      [  +0.000013]  __driver_attach+0x110/0x310
      [  +0.000013]  bus_for_each_dev+0x14b/0x1d0
      [  +0.000013]  driver_register+0x1c0/0x400
      [  +0.000015]  mlxsw_sp_module_init+0x5d/0xd3
      [  +0.000014]  do_one_initcall+0x239/0x4dd
      [  +0.000013]  kernel_init_freeable+0x42b/0x4e8
      [  +0.000012]  kernel_init+0x11/0x18b
      [  +0.000013]  ret_from_fork+0x3a/0x50
      
      [  +0.000015] Freed by task 581:
      [  +0.000013]  save_stack+0x19/0x80
      [  +0.000014]  __kasan_slab_free+0x125/0x170
      [  +0.000013]  kfree+0xf3/0x310
      [  +0.000013]  thermal_release+0xc7/0xf0
      [  +0.000014]  device_release+0x77/0x200
      [  +0.000014]  kobject_put+0x1a8/0x4c0
      [  +0.000014]  device_unregister+0x38/0xc0
      [  +0.000014]  thermal_zone_device_unregister+0x54e/0x6a0
      [  +0.000014]  mlxsw_thermal_fini+0x184/0x35a
      [  +0.000014]  mlxsw_core_bus_device_unregister+0x10a/0x640
      [  +0.000013]  mlxsw_devlink_core_bus_device_reload+0x92/0x210
      [  +0.000015]  devlink_nl_cmd_reload+0x113/0x1f0
      [  +0.000014]  genl_family_rcv_msg+0x700/0xee0
      [  +0.000013]  genl_rcv_msg+0xca/0x170
      [  +0.000013]  netlink_rcv_skb+0x137/0x3a0
      [  +0.000012]  genl_rcv+0x29/0x40
      [  +0.000013]  netlink_unicast+0x49b/0x660
      [  +0.000013]  netlink_sendmsg+0x755/0xc90
      [  +0.000013]  __sys_sendto+0x3de/0x430
      [  +0.000013]  __x64_sys_sendto+0xe2/0x1b0
      [  +0.000013]  do_syscall_64+0xa4/0x4d0
      [  +0.000013]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      [  +0.000017] The buggy address belongs to the object at ffff8881e48e0008
                     which belongs to the cache kmalloc-2k of size 2048
      [  +0.000012] The buggy address is located 1096 bytes inside of
                     2048-byte region [ffff8881e48e0008, ffff8881e48e0808)
      [  +0.000007] The buggy address belongs to the page:
      [  +0.000012] page:ffffea0007923800 refcount:1 mapcount:0 mapping:ffff88823680d0c0 index:0x0 compound_mapcount: 0
      [  +0.000020] flags: 0x200000000010200(slab|head)
      [  +0.000019] raw: 0200000000010200 ffffea0007682008 ffffea00076ab808 ffff88823680d0c0
      [  +0.000016] raw: 0000000000000000 00000000000d000d 00000001ffffffff 0000000000000000
      [  +0.000007] page dumped because: kasan: bad access detected
      
      [  +0.000012] Memory state around the buggy address:
      [  +0.000012]  ffff8881e48e0300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  +0.000012]  ffff8881e48e0380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  +0.000012] >ffff8881e48e0400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  +0.000008]                                                  ^
      [  +0.000012]  ffff8881e48e0480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  +0.000012]  ffff8881e48e0500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  +0.000007] ==================================================================
      
      Fixes: b1569e99 ("ACPI: move thermal trip handling to generic thermal layer")
      Reported-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3e5043ad
    • Trek's avatar
      drm/amdgpu: Check for valid number of registers to read · 8f2e3c7f
      Trek authored
      [ Upstream commit 73d8e6c7 ]
      
      Do not try to allocate any amount of memory requested by the user.
      Instead limit it to 128 registers. Actually the longest series of
      consecutive allowed registers are 48, mmGB_TILE_MODE0-31 and
      mmGB_MACROTILE_MODE0-15 (0x2644-0x2673).
      
      Bug: https://bugs.freedesktop.org/show_bug.cgi?id=111273Signed-off-by: default avatarTrek <trek00@inbox.ru>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8f2e3c7f
    • Erqi Chen's avatar
      ceph: reconnect connection if session hang in opening state · 60991fef
      Erqi Chen authored
      [ Upstream commit 71a228bc ]
      
      If client mds session is evicted in CEPH_MDS_SESSION_OPENING state,
      mds won't send session msg to client, and delayed_work skip
      CEPH_MDS_SESSION_OPENING state session, the session hang forever.
      
      Allow ceph_con_keepalive to reconnect a session in OPENING to avoid
      session hang. Also, ensure that we skip sessions in RESTARTING and
      REJECTED states since those states can't be resurrected by issuing
      a keepalive.
      
      Link: https://tracker.ceph.com/issues/41551
      Signed-off-by: Erqi Chen chenerqi@gmail.com
      Reviewed-by: default avatar"Yan, Zheng" <zyan@redhat.com>
      Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      60991fef
    • Luis Henriques's avatar
      ceph: fix directories inode i_blkbits initialization · 3f2533b6
      Luis Henriques authored
      [ Upstream commit 75067034 ]
      
      When filling an inode with info from the MDS, i_blkbits is being
      initialized using fl_stripe_unit, which contains the stripe unit in
      bytes.  Unfortunately, this doesn't make sense for directories as they
      have fl_stripe_unit set to '0'.  This means that i_blkbits will be set
      to 0xff, causing an UBSAN undefined behaviour in i_blocksize():
      
        UBSAN: Undefined behaviour in ./include/linux/fs.h:731:12
        shift exponent 255 is too large for 32-bit type 'int'
      
      Fix this by initializing i_blkbits to CEPH_BLOCK_SHIFT if fl_stripe_unit
      is zero.
      Signed-off-by: default avatarLuis Henriques <lhenriques@suse.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3f2533b6