]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/xe: Validate user fence during creation
authorMatthew Brost <matthew.brost@intel.com>
Wed, 17 Jul 2024 14:04:28 +0000 (07:04 -0700)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 15 Aug 2024 13:44:21 +0000 (09:44 -0400)
Fail invalid addresses during user fence creation.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240717140429.1396820-1-matthew.brost@intel.com
(cherry picked from commit 0fde907da2d5fd4da68845e96c6842497159c858)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_sync.c

index c4e018aa2982fbc70a062a52bac2873a08d85635..e8d31e0108601981a1ba70434f97e7d80945a342 100644 (file)
@@ -53,14 +53,18 @@ static struct xe_user_fence *user_fence_create(struct xe_device *xe, u64 addr,
                                               u64 value)
 {
        struct xe_user_fence *ufence;
+       u64 __user *ptr = u64_to_user_ptr(addr);
+
+       if (!access_ok(ptr, sizeof(ptr)))
+               return ERR_PTR(-EFAULT);
 
        ufence = kmalloc(sizeof(*ufence), GFP_KERNEL);
        if (!ufence)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        ufence->xe = xe;
        kref_init(&ufence->refcount);
-       ufence->addr = u64_to_user_ptr(addr);
+       ufence->addr = ptr;
        ufence->value = value;
        ufence->mm = current->mm;
        mmgrab(ufence->mm);
@@ -183,8 +187,8 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
                } else {
                        sync->ufence = user_fence_create(xe, sync_in.addr,
                                                         sync_in.timeline_value);
-                       if (XE_IOCTL_DBG(xe, !sync->ufence))
-                               return -ENOMEM;
+                       if (XE_IOCTL_DBG(xe, IS_ERR(sync->ufence)))
+                               return PTR_ERR(sync->ufence);
                }
 
                break;