From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24B993B47CD; Wed, 30 Sep 2026 16:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790786397; cv=none; b=arrJ0RCL7kDD1WX6KA+0VXCG37Yfh702vDYufqHSAe3244Z7VzKTyAifKBoZ3kZ9JXecUi3Eq022D/clwuCQeMdAhQ78dFPiThiU/k72KHlWBzIi25/P/egwZF5Q2iEp5atqSNbgMPjob7ynVuTPDOfUzqKKax/IBn7G/UPQNw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790786397; c=relaxed/simple; bh=F3Is6jOjatTF+10OMHY2l9c0uyzRpNetkOTiDCjt+D8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q5SpfNuvP+zTVwrHwjU9Aud9Z7qfpFiMaOclgFqT3zmqkGJnD7UdcY7vTiAc6E3RLfR5XdJtUtTeK235LwOmhbK46nZCBZ2ylIDux/pTnMvgX54gHwzE0ecsl3i8pJG0K+Z8orP7R0+NQOuAlhaUNVxMOyzeLkFAfcZnb6FeMJs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CuCsvB4q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CuCsvB4q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E72F1F000FF; Wed, 30 Sep 2026 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790786395; bh=lTAvr3G+RYG1UA1lPFV0GU7VeOIy+doK2De/fNv+cJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CuCsvB4qLJ2k5kGTN+AYBczgHZMKCFkuQhHOSNv4kLk+5TdIW7vkIwUFP7kotXyfU nO+lR4PRXdOL+LuW20uJ5SLYmWraiuOMjgNln8HfD9Zw8l2e0e1230kqQiGJEBADXU LMxkU8UXV/3SMKQRLpZHXH6lUiK0I6hGHZbrZcgE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuhao Jiang , Junrui Luo , Dmitry Osipenko , Sasha Levin Subject: [PATCH 6.1 848/982] drm/virtio: fix object leak when drm_gem_handle_create() fails Date: Wed, 30 Sep 2026 17:26:24 +0200 Message-ID: <20260930152434.963597330@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152416.775402466@linuxfoundation.org> References: <20260930152416.775402466@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Junrui Luo [ Upstream commit 36570ef2244cc4d7563b1f0157bc0f032498638c ] virtio_gpu_gem_create() owns the reference taken by virtio_gpu_object_create(). On the drm_gem_handle_create() error path it calls drm_gem_object_release() instead of dropping that reference. drm_gem_object_release() is the inverse of drm_gem_object_init() and does not touch the reference count or call obj->funcs->free(), so it is only correct as the last step of a destructor, as in virtio_gpu_cleanup_object(). Using it here leaves the bo at refcount 1 with no remaining reference, so virtio_gpu_free_object() never runs and the shmem pages, sg table and virtio_gpu_object are leaked. Since virtio_gpu_object_create() has already set bo->created, VIRTIO_GPU_CMD_RESOURCE_UNREF is not queued either, leaking the host-side resource and the resource id. drm_gem_handle_create_tail() drops the handle reference on all of its internal error paths, so the caller only has to drop its own. Use drm_gem_object_put(), matching the success path below. Fixes: dc5698e80cf7 ("Add virtio gpu driver.") Reported-by: Yuhao Jiang Assisted-by: Claude:claude-opus-5 Signed-off-by: Junrui Luo Signed-off-by: Dmitry Osipenko Link: https://patch.msgid.link/20260915-fixes-v2-1-a0d799e4db66@outlook.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/virtio/virtgpu_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c index 2e75cdeb49b3d..0233a1c3181c5 100644 --- a/drivers/gpu/drm/virtio/virtgpu_gem.c +++ b/drivers/gpu/drm/virtio/virtgpu_gem.c @@ -45,7 +45,7 @@ static int virtio_gpu_gem_create(struct drm_file *file, ret = drm_gem_handle_create(file, &obj->base.base, &handle); if (ret) { - drm_gem_object_release(&obj->base.base); + drm_gem_object_put(&obj->base.base); return ret; } -- 2.53.0