mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm: drm_bufs: Error out if 'dev->agp' is a null pointer
@ 2022-03-11  7:23 Zheyu Ma
  2022-03-17 10:49 ` Daniel Vetter
  0 siblings, 1 reply; 5+ messages in thread
From: Zheyu Ma @ 2022-03-11  7:23 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel, Zheyu Ma

The user program can control the 'drm_buf_desc::flags' via ioctl system
call and enter the function drm_legacy_addbufs_agp(). If the driver
doesn't initialize the agp resources, the driver will cause a null
pointer dereference.

The following log reveals it:
    general protection fault, probably for non-canonical address
    0xdffffc000000000f: 0000 [#1] PREEMPT SMP KASAN PTI
    KASAN: null-ptr-deref in range [0x0000000000000078-0x000000000000007f]
    Call Trace:
     <TASK>
     drm_ioctl_kernel+0x342/0x450 drivers/gpu/drm/drm_ioctl.c:785
     drm_ioctl+0x592/0x940 drivers/gpu/drm/drm_ioctl.c:885
     vfs_ioctl fs/ioctl.c:51 [inline]
     __do_sys_ioctl fs/ioctl.c:874 [inline]
     __se_sys_ioctl+0xaa/0xf0 fs/ioctl.c:860
     do_syscall_x64 arch/x86/entry/common.c:50 [inline]
     do_syscall_64+0x43/0x90 arch/x86/entry/common.c:80
     entry_SYSCALL_64_after_hwframe+0x44/0xae

Fix this bug by adding a check.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
 drivers/gpu/drm/drm_bufs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index fcca21e8efac..4fe2363b1e34 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -734,7 +734,7 @@ int drm_legacy_addbufs_agp(struct drm_device *dev,
 	int i, valid;
 	struct drm_buf **temp_buflist;
 
-	if (!dma)
+	if (!dma || !dev->agp)
 		return -EINVAL;
 
 	count = request->count;
-- 
2.25.1


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

end of thread, other threads:[~2022-03-23  1:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11  7:23 [PATCH] drm: drm_bufs: Error out if 'dev->agp' is a null pointer Zheyu Ma
2022-03-17 10:49 ` Daniel Vetter
2022-03-21 13:02   ` Zheyu Ma
2022-03-22 14:27     ` Daniel Vetter
2022-03-23  1:39       ` Zheyu Ma

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®