[PATCH] drm: drm_bufs: Error out if 'dev->agp' is a null pointer

Daniel Vetter daniel at ffwll.ch
Thu Mar 17 10:49:20 UTC 2022


On Fri, Mar 11, 2022 at 07:23:02AM +0000, Zheyu Ma wrote:
> 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 at gmail.com>

You can only hit this if you enabled a DRIVER_LEGACY drm driver, which
opens you up to tons of other CVEs and issues. What's your .config?
-Daniel

> ---
>  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
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list