提交 c8725226 编写于 作者: C Chris Wilson

drm/i915: Protect against drm_gem_object not being the first member

Dave Airlie spotted that we had a potential bug should we ever rearrange
the drm_i915_gem_object so not the base drm_gem_object was not its first
member. He noticed that we often convert the return of
drm_gem_object_lookup() immediately into drm_i915_gem_object and then
check the result for nullity. This is only valid when the base object is
the first member and so the superobject has the same address. Play safe
instead and use the compiler to convert back to the original return
address for sanity testing.
Signed-off-by: NChris Wilson <chris@chris-wilson.co.uk>
上级 548f245b
...@@ -506,7 +506,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, ...@@ -506,7 +506,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -949,7 +949,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, ...@@ -949,7 +949,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -1045,7 +1045,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, ...@@ -1045,7 +1045,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -1088,7 +1088,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data, ...@@ -1088,7 +1088,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -1463,7 +1463,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data, ...@@ -1463,7 +1463,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -3331,7 +3331,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data, ...@@ -3331,7 +3331,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -3382,7 +3382,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data, ...@@ -3382,7 +3382,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -3419,7 +3419,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, ...@@ -3419,7 +3419,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -3497,7 +3497,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data, ...@@ -3497,7 +3497,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle));
if (obj == NULL) { if (&obj->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} }
......
...@@ -677,7 +677,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, ...@@ -677,7 +677,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
obj = to_intel_bo(drm_gem_object_lookup(dev, file, obj = to_intel_bo(drm_gem_object_lookup(dev, file,
exec[i].handle)); exec[i].handle));
if (obj == NULL) { if (&obj->base == NULL) {
DRM_ERROR("Invalid object handle %d at index %d\n", DRM_ERROR("Invalid object handle %d at index %d\n",
exec[i].handle, i); exec[i].handle, i);
ret = -ENOENT; ret = -ENOENT;
...@@ -1087,7 +1087,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, ...@@ -1087,7 +1087,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
obj = to_intel_bo(drm_gem_object_lookup(dev, file, obj = to_intel_bo(drm_gem_object_lookup(dev, file,
exec[i].handle)); exec[i].handle));
if (obj == NULL) { if (&obj->base == NULL) {
DRM_ERROR("Invalid object handle %d at index %d\n", DRM_ERROR("Invalid object handle %d at index %d\n",
exec[i].handle, i); exec[i].handle, i);
/* prevent error path from reading uninitialized data */ /* prevent error path from reading uninitialized data */
......
...@@ -286,7 +286,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, ...@@ -286,7 +286,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) if (&obj->base == NULL)
return -ENOENT; return -ENOENT;
if (!i915_tiling_ok(dev, if (!i915_tiling_ok(dev,
...@@ -366,7 +366,7 @@ i915_gem_get_tiling(struct drm_device *dev, void *data, ...@@ -366,7 +366,7 @@ i915_gem_get_tiling(struct drm_device *dev, void *data,
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
if (obj == NULL) if (&obj->base == NULL)
return -ENOENT; return -ENOENT;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
......
...@@ -5324,7 +5324,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -5324,7 +5324,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
} }
obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
if (!obj) if (&obj->base == NULL)
return -ENOENT; return -ENOENT;
if (obj->base.size < width * height * 4) { if (obj->base.size < width * height * 4) {
...@@ -6563,7 +6563,7 @@ intel_user_framebuffer_create(struct drm_device *dev, ...@@ -6563,7 +6563,7 @@ intel_user_framebuffer_create(struct drm_device *dev,
int ret; int ret;
obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle)); obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
if (!obj) if (&obj->base == NULL)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
......
...@@ -1156,7 +1156,7 @@ int intel_overlay_put_image(struct drm_device *dev, void *data, ...@@ -1156,7 +1156,7 @@ int intel_overlay_put_image(struct drm_device *dev, void *data,
new_bo = to_intel_bo(drm_gem_object_lookup(dev, file_priv, new_bo = to_intel_bo(drm_gem_object_lookup(dev, file_priv,
put_image_rec->bo_handle)); put_image_rec->bo_handle));
if (!new_bo) { if (&new_bo->base == NULL) {
ret = -ENOENT; ret = -ENOENT;
goto out_free; goto out_free;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册