Bug 2297511 (CVE-2024-40927) - CVE-2024-40927 kernel: xhci: Handle TD clearing for multiple streams case
Summary: CVE-2024-40927 kernel: xhci: Handle TD clearing for multiple streams case
Keywords:
Status: NEW
Alias: CVE-2024-40927
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Product Security DevOps Team
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-07-12 13:33 UTC by OSIDB Bzimport
Modified: 2024-09-12 14:28 UTC (History)
4 users (show)

Fixed In Version: kernel 5.15.162, kernel 6.1.95, kernel 6.6.35, kernel 6.9.6, kernel 6.10-rc4
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2024:5117 0 None None None 2024-08-08 08:35:49 UTC
Red Hat Product Errata RHBA-2024:5207 0 None None None 2024-08-12 07:54:55 UTC
Red Hat Product Errata RHBA-2024:5208 0 None None None 2024-08-12 08:34:15 UTC
Red Hat Product Errata RHBA-2024:5233 0 None None None 2024-08-12 13:53:39 UTC
Red Hat Product Errata RHBA-2024:5235 0 None None None 2024-08-12 14:26:25 UTC
Red Hat Product Errata RHBA-2024:5236 0 None None None 2024-08-12 14:42:34 UTC
Red Hat Product Errata RHBA-2024:5237 0 None None None 2024-08-12 14:45:53 UTC
Red Hat Product Errata RHBA-2024:5386 0 None None None 2024-08-14 10:50:13 UTC
Red Hat Product Errata RHBA-2024:5866 0 None None None 2024-08-26 14:40:52 UTC
Red Hat Product Errata RHBA-2024:6650 0 None None None 2024-09-12 14:28:37 UTC
Red Hat Product Errata RHSA-2024:5101 0 None None None 2024-08-08 04:59:07 UTC
Red Hat Product Errata RHSA-2024:5102 0 None None None 2024-08-08 04:46:30 UTC
Red Hat Product Errata RHSA-2024:6567 0 None None None 2024-09-11 00:57:53 UTC

Description OSIDB Bzimport 2024-07-12 13:33:53 UTC
In the Linux kernel, the following vulnerability has been resolved:

xhci: Handle TD clearing for multiple streams case

When multiple streams are in use, multiple TDs might be in flight when
an endpoint is stopped. We need to issue a Set TR Dequeue Pointer for
each, to ensure everything is reset properly and the caches cleared.
Change the logic so that any N>1 TDs found active for different streams
are deferred until after the first one is processed, calling
xhci_invalidate_cancelled_tds() again from xhci_handle_cmd_set_deq() to
queue another command until we are done with all of them. Also change
the error/"should never happen" paths to ensure we at least clear any
affected TDs, even if we can't issue a command to clear the hardware
cache, and complain loudly with an xhci_warn() if this ever happens.

This problem case dates back to commit e9df17eb1408 ("USB: xhci: Correct
assumptions about number of rings per endpoint.") early on in the XHCI
driver's life, when stream support was first added.
It was then identified but not fixed nor made into a warning in commit
674f8438c121 ("xhci: split handling halted endpoints into two steps"),
which added a FIXME comment for the problem case (without materially
changing the behavior as far as I can tell, though the new logic made
the problem more obvious).

Then later, in commit 94f339147fc3 ("xhci: Fix failure to give back some
cached cancelled URBs."), it was acknowledged again.

[Mathias: commit 94f339147fc3 ("xhci: Fix failure to give back some cached
cancelled URBs.") was a targeted regression fix to the previously mentioned
patch. Users reported issues with usb stuck after unmounting/disconnecting
UAS devices. This rolled back the TD clearing of multiple streams to its
original state.]

Apparently the commit author was aware of the problem (yet still chose
to submit it): It was still mentioned as a FIXME, an xhci_dbg() was
added to log the problem condition, and the remaining issue was mentioned
in the commit description. The choice of making the log type xhci_dbg()
for what is, at this point, a completely unhandled and known broken
condition is puzzling and unfortunate, as it guarantees that no actual
users would see the log in production, thereby making it nigh
undebuggable (indeed, even if you turn on DEBUG, the message doesn't
really hint at there being a problem at all).

It took me *months* of random xHC crashes to finally find a reliable
repro and be able to do a deep dive debug session, which could all have
been avoided had this unhandled, broken condition been actually reported
with a warning, as it should have been as a bug intentionally left in
unfixed (never mind that it shouldn't have been left in at all).

> Another fix to solve clearing the caches of all stream rings with
> cancelled TDs is needed, but not as urgent.

3 years after that statement and 14 years after the original bug was
introduced, I think it's finally time to fix it. And maybe next time
let's not leave bugs unfixed (that are actually worse than the original
bug), and let's actually get people to review kernel commits please.

Fixes xHC crashes and IOMMU faults with UAS devices when handling
errors/faults. Easiest repro is to use `hdparm` to mark an early sector
(e.g. 1024) on a disk as bad, then `cat /dev/sdX > /dev/null` in a loop.
At least in the case of JMicron controllers, the read errors end up
having to cancel two TDs (for two queued requests to different streams)
and the one that didn't get cleared properly ends up faulting the xHC
entirely when it tries to access DMA pages that have since been unmapped,
referred to by the stale TDs. This normally happens quickly (after two
or three loops). After this fix, I left the `cat` in a loop running
overnight and experienced no xHC failures, with all read errors
recovered properly. Repro'd and tested on an Apple M1 Mac Mini
(dwc3 host).

On systems without an IOMMU, this bug would instead silently corrupt
freed memory, making this a
---truncated---

Comment 11 errata-xmlrpc 2024-08-08 04:46:29 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2024:5102 https://access.redhat.com/errata/RHSA-2024:5102

Comment 12 errata-xmlrpc 2024-08-08 04:59:06 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2024:5101 https://access.redhat.com/errata/RHSA-2024:5101

Comment 13 errata-xmlrpc 2024-09-11 00:57:52 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2024:6567 https://access.redhat.com/errata/RHSA-2024:6567


Note You need to log in before you can comment on or make changes to this bug.