[PATCH] drm/amd/display: fix HDCP workqueue use-after-free on destroy

From: Fan Wu

Date: Mon Jul 06 2026 - 05:48:10 EST


hdcp_destroy() cancels callback_dwork, watchdog_timer_dwork and
property_validate_dwork, but leaves cpirq_work and property_update_work
queued. These works are queued with schedule_work(), recover struct
hdcp_workqueue through container_of(), and dereference it. If either work
runs after hdcp_destroy() frees hdcp_work, it can trigger a
use-after-free.

The HDCP callbacks also call process_output(), which can requeue the HDCP
works: it always queues property_validate_dwork and may queue
callback_dwork or watchdog_timer_dwork depending on the state-machine
output. A simple cancel sequence can therefore miss work requeued by
another callback.

Set a teardown flag under hdcp_work->mutex before draining the works.
The callbacks already hold this mutex while calling process_output(), so
once teardown is set they can no longer requeue work. Then cancel
cpirq_work, the delayed works, and property_update_work before freeing
hdcp_work.

This bug was found by static analysis.

Fixes: a193ed2094ba ("drm/amd/display: Create amdgpu_dm_hdcp")
Fixes: da3fd7ac0bcf ("drm/amd/display: Update CP property based on HW query")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Fan Wu <fanwu01@xxxxxxxxxx>
---
.../drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c | 15 +++++++++++++++
.../drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h | 2 ++
2 files changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c
index 4c164ae4a4f9..2be763049b9e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c
@@ -164,6 +164,9 @@ void process_output(struct hdcp_workqueue *hdcp_work)
{
struct mod_hdcp_output output = hdcp_work->output;

+ if (hdcp_work->teardown)
+ return;
+
if (output.callback_stop)
cancel_delayed_work(&hdcp_work->callback_dwork);

@@ -487,9 +490,21 @@ void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
int i = 0;

for (i = 0; i < hdcp_work->max_link; i++) {
+ /*
+ * process_output() can requeue the HDCP works. Set teardown
+ * under the callback mutex first so no callback can requeue
+ * work after destroy starts, then drain any work already
+ * queued.
+ */
+ mutex_lock(&hdcp_work[i].mutex);
+ hdcp_work[i].teardown = true;
+ mutex_unlock(&hdcp_work[i].mutex);
+
+ cancel_work_sync(&hdcp_work[i].cpirq_work);
cancel_delayed_work_sync(&hdcp_work[i].callback_dwork);
cancel_delayed_work_sync(&hdcp_work[i].watchdog_timer_dwork);
cancel_delayed_work_sync(&hdcp_work[i].property_validate_dwork);
+ cancel_work_sync(&hdcp_work[i].property_update_work);
}

sysfs_remove_bin_file(kobj, &hdcp_work[0].attr);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h
index 90b18c450ca6..2313434b57c0 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h
@@ -54,6 +54,8 @@ struct hdcp_workqueue {
struct amdgpu_dm_connector *aconnector[AMDGPU_DM_MAX_DISPLAY_INDEX];
struct mutex mutex;

+ bool teardown;
+
struct mod_hdcp hdcp;
struct mod_hdcp_output output;
struct mod_hdcp_display display;
--
2.34.1