Subject: CVE-2024-49876: drm/xe: fix UAF around queue destruction

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

drm/xe: fix UAF around queue destruction

We currently do stuff like queuing the final destruction step on a
random system wq, which will outlive the driver instance. With bad
timing we can teardown the driver with one or more work workqueue still
being alive leading to various UAF splats. Add a fini step to ensure
user queues are properly torn down. At this point GuC should already be
nuked so queue itself should no longer be referenced from hw pov.

v2 (Matt B)
 - Looks much safer to use a waitqueue and then just wait for the
   xa_array to become empty before triggering the drain.

(cherry picked from commit 861108666cc0e999cffeab6aff17b662e68774e3)

The Linux kernel CVE team has assigned CVE-2024-49876 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 6.8 with commit dd08ebf6c352 and fixed in 6.10.14 with commit 272b0e788745
	Issue introduced in 6.8 with commit dd08ebf6c352 and fixed in 6.11.3 with commit 421c74670b0f
	Issue introduced in 6.8 with commit dd08ebf6c352 and fixed in 6.12-rc2 with commit 2d2be279f1ca

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-49876
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/gpu/drm/xe/xe_device.c
	drivers/gpu/drm/xe/xe_device_types.h
	drivers/gpu/drm/xe/xe_guc_submit.c
	drivers/gpu/drm/xe/xe_guc_types.h

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/272b0e78874586d6ccae04079d75b27b47705544
	https://git.kernel.org/stable/c/421c74670b0f9d5c007f1276d3647aa58f407fde
	https://git.kernel.org/stable/c/2d2be279f1ca9e7288282d4214f16eea8a727cdb