mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/gem: fix warning in idr_alloc due to unvalidated user handle
@ 2026-04-22 11:42 Mingyu Wang
  2026-06-05  3:06 ` 王明煜
  0 siblings, 1 reply; 5+ messages in thread
From: Mingyu Wang @ 2026-04-22 11:42 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, simona
  Cc: dri-devel, linux-kernel, Mingyu Wang

During fuzzing, a warning was triggered in idr_alloc() when handling
the DRM_IOCTL_GEM_CHANGE_HANDLE (or similar) ioctl.

The function drm_gem_change_handle_ioctl() currently only checks if
args->new_handle is strictly greater than INT_MAX. However, it fails
to check for negative values. If a userpace application passes a
negative handle, it bypasses the upper-bound check and is passed
directly to idr_alloc() as the 'start' parameter, triggering the
WARN_ON_ONCE(start < 0) inside idr_alloc().

Fix this by explicitly validating that the user-provided handle is
strictly positive and within the valid IDR range.

Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
---
 drivers/gpu/drm/drm_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index d6424267260b..3d84d4f1c3e0 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1026,7 +1026,7 @@ int drm_gem_change_handle_ioctl(struct drm_device *dev, void *data,
 		return -EOPNOTSUPP;
 
 	/* idr_alloc() limitation. */
-	if (args->new_handle > INT_MAX)
+	if (args->new_handle <= 0 || args->new_handle > INT_MAX)
 		return -EINVAL;
 	handle = args->new_handle;
 
-- 
2.34.1


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

end of thread, other threads:[~2026-06-05 14:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-22 11:42 [PATCH] drm/gem: fix warning in idr_alloc due to unvalidated user handle Mingyu Wang
2026-06-05  3:06 ` 王明煜
2026-06-05  8:02   ` Thomas Zimmermann
2026-06-05 13:38     ` 王明煜
2026-06-05 14:15       ` 王明煜

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®