linux-stable/drivers/usb/host
Sriharsha Allenki c6a1ce81b4 usb: xhci: Fix NULL pointer dereference when enqueuing trbs from urb sg list
commit 3c6f8cb92c upstream.

On platforms with IOMMU enabled, multiple SGs can be coalesced into one
by the IOMMU driver. In that case the SG list processing as part of the
completion of a urb on a bulk endpoint can result into a NULL pointer
dereference with the below stack dump.

<6> Unable to handle kernel NULL pointer dereference at virtual address 0000000c
<6> pgd = c0004000
<6> [0000000c] *pgd=00000000
<6> Internal error: Oops: 5 [#1] PREEMPT SMP ARM
<2> PC is at xhci_queue_bulk_tx+0x454/0x80c
<2> LR is at xhci_queue_bulk_tx+0x44c/0x80c
<2> pc : [<c08907c4>]    lr : [<c08907bc>]    psr: 000000d3
<2> sp : ca337c80  ip : 00000000  fp : ffffffff
<2> r10: 00000000  r9 : 50037000  r8 : 00004000
<2> r7 : 00000000  r6 : 00004000  r5 : 00000000  r4 : 00000000
<2> r3 : 00000000  r2 : 00000082  r1 : c2c1a200  r0 : 00000000
<2> Flags: nzcv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment none
<2> Control: 10c0383d  Table: b412c06a  DAC: 00000051
<6> Process usb-storage (pid: 5961, stack limit = 0xca336210)
<snip>
<2> [<c08907c4>] (xhci_queue_bulk_tx)
<2> [<c0881b3c>] (xhci_urb_enqueue)
<2> [<c0831068>] (usb_hcd_submit_urb)
<2> [<c08350b4>] (usb_sg_wait)
<2> [<c089f384>] (usb_stor_bulk_transfer_sglist)
<2> [<c089f2c0>] (usb_stor_bulk_srb)
<2> [<c089fe38>] (usb_stor_Bulk_transport)
<2> [<c089f468>] (usb_stor_invoke_transport)
<2> [<c08a11b4>] (usb_stor_control_thread)
<2> [<c014a534>] (kthread)

The above NULL pointer dereference is the result of block_len and the
sent_len set to zero after the first SG of the list when IOMMU driver
is enabled. Because of this the loop of processing the SGs has run
more than num_sgs which resulted in a sg_next on the last SG of the
list which has SG_END set.

Fix this by check for the sg before any attributes of the sg are
accessed.

[modified reason for null pointer dereference in commit message subject -Mathias]
Fixes: f9c589e142 ("xhci: TD-fragment, align the unsplittable case with a bounce buffer")
Cc: stable@vger.kernel.org
Signed-off-by: Sriharsha Allenki <sallenki@codeaurora.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20200514110432.25564-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-20 08:20:32 +02:00
..
bcma-hcd.c
ehci-atmel.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ehci-dbg.c
ehci-exynos.c usb: exynos: add support for getting PHYs from the standard dt array 2019-07-30 13:00:37 +02:00
ehci-fsl.c usb: host: Stops USB controller init if PLL fails to lock 2019-07-03 18:52:20 +02:00
ehci-fsl.h usb: phy: Workaround for USB erratum-A005728 2019-07-03 18:52:20 +02:00
ehci-grlib.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-hub.c
ehci-mem.c
ehci-mv.c USB: EHCI: ehci-mv: add MODULE_DEVICE_TABLE 2019-01-18 10:07:05 +01:00
ehci-mxc.c
ehci-npcm7xx.c
ehci-omap.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ehci-orion.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ehci-pci.c usb: pci-quirks: Minor cleanup for AMD PLL quirk 2019-07-25 10:40:02 +02:00
ehci-platform.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ehci-pmcmsp.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-ppc-of.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-ps3.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-q.c USB: EHCI: Do not return -EPIPE when hub is disconnected 2019-12-31 16:46:07 +01:00
ehci-sched.c
ehci-sh.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci-spear.c
ehci-st.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ehci-sysfs.c
ehci-tegra.c
ehci-timer.c
ehci-xilinx-of.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ehci.h
fhci-dbg.c
fhci-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
fhci-hub.c
fhci-mem.c
fhci-q.c
fhci-sched.c usb: host: use usb_endpoint_maxp instead of usb_maxpacket 2019-04-19 14:23:34 +02:00
fhci-tds.c
fhci.h
fotg210-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
fotg210.h
fsl-mph-dr-of.c usb :fsl: Change string format for errata property 2019-07-03 18:52:20 +02:00
imx21-dbg.c
imx21-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
imx21-hcd.h
isp116x-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
isp116x.h
isp1362-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
isp1362.h usb: isp1362: Spelling s/eclusive/exclusive/ 2019-06-18 08:51:28 +02:00
Kconfig USB changes for 5.4-rc1 2019-09-18 10:33:46 -07:00
Makefile usb: remove ehci-w90x900 driver 2019-08-10 09:28:28 +02:00
max3421-hcd.c usb/max3421: remove the dummy {un,}map_urb_for_dma methods 2019-08-21 10:07:25 -07:00
ohci-at91.c
ohci-da8xx.c usb: ohci-da8xx: ensure error return on variable error is set 2020-01-14 20:08:29 +01:00
ohci-dbg.c
ohci-exynos.c usb: exynos: add support for getting PHYs from the standard dt array 2019-07-30 13:00:37 +02:00
ohci-hcd.c Merge 5.3-rc7 into usb-next 2019-09-02 19:31:18 +02:00
ohci-hub.c
ohci-mem.c usb: host: Fix excessive alignment restriction for local memory allocations 2019-06-28 07:57:07 +02:00
ohci-nxp.c usb: ohci-nxp: enable compile-testing 2019-08-15 21:32:56 +02:00
ohci-omap.c
ohci-pci.c usb: pci-quirks: Minor cleanup for AMD PLL quirk 2019-07-25 10:40:02 +02:00
ohci-platform.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ohci-ppc-of.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ohci-ps3.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ohci-pxa27x.c usb: host: ohci-pxa27x: Fix and & vs | typo 2019-08-21 09:59:30 -07:00
ohci-q.c
ohci-s3c2410.c usb: ohci-s3c2410: Remove set but not used variable 'hcd' 2019-06-03 15:21:57 +02:00
ohci-sa1111.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
ohci-sm501.c usb/ohci-sm501: remove the HCD_DMA flag 2019-09-03 15:25:52 +02:00
ohci-spear.c USB: ohci-spear: Remove set but not used variable 'ohci' 2019-06-03 15:21:57 +02:00
ohci-st.c usb: Remove dev_err() usage after platform_get_irq() 2019-07-30 20:29:18 +02:00
ohci-tmio.c usb/ohci-tmio: remove the HCD_DMA flag 2019-09-03 15:26:05 +02:00
ohci.h USB: use genalloc for USB HCs with local memory 2019-06-03 16:00:07 +02:00
oxu210hp-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
pci-quirks.c usb: pci-quirks: Minor cleanup for AMD PLL quirk 2019-07-25 10:40:02 +02:00
pci-quirks.h usb: pci-quirks: Minor cleanup for AMD PLL quirk 2019-07-25 10:40:02 +02:00
r8a66597-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
r8a66597.h
sl811-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
sl811.h
sl811_cs.c
ssb-hcd.c
u132-hcd.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
uhci-debug.c
uhci-grlib.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
uhci-hcd.c USB: drop HCD_LOCAL_MEM flag 2019-06-03 16:00:08 +02:00
uhci-hcd.h
uhci-hub.c
uhci-pci.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
uhci-platform.c usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
uhci-q.c
xhci-dbg.c
xhci-dbgcap.c usb: host: Remove call to memset after dma_alloc_coherent 2019-07-25 11:10:54 +02:00
xhci-dbgcap.h
xhci-dbgtty.c usb: xhci: dbc: Use GFP_KERNEL instead of GFP_ATOMIC in 'xhci_dbc_alloc_requests()' 2019-09-03 15:49:11 +02:00
xhci-debugfs.c usb: xhci: fix __le32/__le64 accessors in debugfs code 2019-10-28 17:47:08 +01:00
xhci-debugfs.h usb: xhci: remove unused member 'parent' in xhci_regset struct 2019-02-20 20:18:23 +01:00
xhci-ext-caps.c xhci-ext-caps.c: Add missing platform_device_put() on error in xhci_create_intel_xhci_sw_pdev() 2019-10-04 14:37:53 +02:00
xhci-ext-caps.h
xhci-histb.c
xhci-hub.c xhci: prevent bus suspend if a roothub port detected a over-current condition 2020-04-29 16:33:23 +02:00
xhci-mem.c xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0 2020-04-29 16:33:03 +02:00
xhci-mtk-sch.c
xhci-mtk.c usb: xhci-mtk: add an optional xhci_ck clock 2019-08-28 22:50:25 +02:00
xhci-mtk.h usb: xhci-mtk: add an optional xhci_ck clock 2019-08-28 22:50:25 +02:00
xhci-mvebu.c usb: host: xhci: mvebu: add reset on resume quirk 2019-01-30 09:22:35 +01:00
xhci-mvebu.h usb: host: xhci: mvebu: add reset on resume quirk 2019-01-30 09:22:35 +01:00
xhci-pci.c usb: xhci: apply XHCI_SUSPEND_DELAY to AMD XHCI controller 1022:145c 2020-03-25 08:25:51 +01:00
xhci-plat.c usb: host: xhci-plat: keep runtime active when removing host 2020-05-20 08:20:31 +02:00
xhci-plat.h usb: host: xhci-plat: add quirks member into struct xhci_plat_priv 2019-09-03 15:53:11 +02:00
xhci-rcar.c usb: host: xhci-rcar: Use xhci_plat_priv.quirks instead of code settings 2019-09-03 15:53:27 +02:00
xhci-rcar.h usb: host: xhci-rcar: Use xhci_plat_priv.quirks instead of code settings 2019-09-03 15:53:27 +02:00
xhci-ring.c usb: xhci: Fix NULL pointer dereference when enqueuing trbs from urb sg list 2020-05-20 08:20:32 +02:00
xhci-tegra.c usb: host: xhci-tegra: set MODULE_FIRMWARE for tegra186 2020-02-01 09:34:31 +00:00
xhci-trace.c
xhci-trace.h xhci: Do not open code __print_symbolic() in xhci trace events 2020-03-25 08:25:56 +01:00
xhci.c xhci: Fix handling halted endpoint even if endpoint ring appears empty 2020-04-29 16:33:23 +02:00
xhci.h xhci: Fix handling halted endpoint even if endpoint ring appears empty 2020-04-29 16:33:23 +02:00