All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/qxl: Handle failure to reference the surface release buffer
@ 2026-11-13 11:06 Alex Kazinsky
  2026-11-13 11:16 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Kazinsky @ 2026-11-13 11:06 UTC (permalink / raw)
  To: Dave Airlie
  Cc: Alex Kazinsky, Gerd Hoffmann, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, virtualization,
	spice-devel, dri-devel, linux-kernel, lvc-project, stable

When allocating a surface destroy release, qxl_release_list_add()
takes a reference to the buffer shared with the create release.
If allocation of the list entry fails, the error is ignored and
the destroy command is submitted without holding that reference.

Once the current release buffer has changed and the create release
has been freed, the buffer may be freed while the destroy release
still points to it. Garbage collection can then access the freed
buffer through qxl_release_map().

Check the return value, free the new release and propagate the error
before submitting the command. Increment release_count after successful
release allocation to balance the decrement in qxl_release_free() on
both the error and normal completion paths.

Found by Linux Verification Center (linuxtesting.org) with SVACE static
analysis tool.

Fixes: 8002db6336dd ("qxl: convert qxl driver to proper use for reservations")
Cc: stable@vger.kernel.org
Signed-off-by: Alex Kazinsky <a.kazinsky@ideco.ru>
---
 drivers/gpu/drm/qxl/qxl_release.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c
index 06979d0e8a9f..342c3600d425 100644
--- a/drivers/gpu/drm/qxl/qxl_release.c
+++ b/drivers/gpu/drm/qxl/qxl_release.c
@@ -262,6 +262,7 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev,
 {
 	if (surface_cmd_type == QXL_SURFACE_CMD_DESTROY && create_rel) {
 		int idr_ret;
+		int ret;
 		struct qxl_bo *bo;
 		union qxl_release_info *info;
 
@@ -269,12 +270,17 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev,
 		idr_ret = qxl_release_alloc(qdev, QXL_RELEASE_SURFACE_CMD, release);
 		if (idr_ret < 0)
 			return idr_ret;
+		atomic_inc(&qdev->release_count);
 		bo = create_rel->release_bo;
 
 		(*release)->release_bo = bo;
 		(*release)->release_offset = create_rel->release_offset + 64;
 
-		qxl_release_list_add(*release, bo);
+		ret = qxl_release_list_add(*release, bo);
+		if (ret) {
+			qxl_release_free(qdev, *release);
+			return ret;
+		}
 
 		info = qxl_release_map(qdev, *release);
 		info->id = idr_ret;
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-13 11:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 11:06 [PATCH] drm/qxl: Handle failure to reference the surface release buffer Alex Kazinsky
2026-11-13 11:16 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.