Skip to content

Commit 84c4ba5

Browse files
committed
Merge branch 'vmwgfx-fixes-4.11' of git://people.freedesktop.org/~thomash/linux into drm-fixes
Set of vmwgfx fixes * 'vmwgfx-fixes-4.11' of git://people.freedesktop.org/~thomash/linux: drm/vmwgfx: fix integer overflow in vmw_surface_define_ioctl() drm/vmwgfx: Remove getparam error message drm/ttm: Avoid calling drm_ht_remove from atomic context drm/ttm, drm/vmwgfx: Relax permission checking when opening surfaces drm/vmwgfx: avoid calling vzalloc with a 0 size in vmw_get_cap_3d_ioctl() drm/vmwgfx: NULL pointer dereference in vmw_surface_define_ioctl() drm/vmwgfx: Type-check lookups of fence objects
2 parents a71c9a1 + e7e11f9 commit 84c4ba5

File tree

6 files changed

+80
-57
lines changed

6 files changed

+80
-57
lines changed

drivers/gpu/drm/ttm/ttm_object.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
179179
if (unlikely(ret != 0))
180180
goto out_err0;
181181

182-
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL);
182+
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false);
183183
if (unlikely(ret != 0))
184184
goto out_err1;
185185

@@ -318,7 +318,8 @@ EXPORT_SYMBOL(ttm_ref_object_exists);
318318

319319
int ttm_ref_object_add(struct ttm_object_file *tfile,
320320
struct ttm_base_object *base,
321-
enum ttm_ref_type ref_type, bool *existed)
321+
enum ttm_ref_type ref_type, bool *existed,
322+
bool require_existed)
322323
{
323324
struct drm_open_hash *ht = &tfile->ref_hash[ref_type];
324325
struct ttm_ref_object *ref;
@@ -345,6 +346,9 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
345346
}
346347

347348
rcu_read_unlock();
349+
if (require_existed)
350+
return -EPERM;
351+
348352
ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref),
349353
false, false);
350354
if (unlikely(ret != 0))
@@ -449,10 +453,10 @@ void ttm_object_file_release(struct ttm_object_file **p_tfile)
449453
ttm_ref_object_release(&ref->kref);
450454
}
451455

456+
spin_unlock(&tfile->lock);
452457
for (i = 0; i < TTM_REF_NUM; ++i)
453458
drm_ht_remove(&tfile->ref_hash[i]);
454459

455-
spin_unlock(&tfile->lock);
456460
ttm_object_file_unref(&tfile);
457461
}
458462
EXPORT_SYMBOL(ttm_object_file_release);
@@ -529,9 +533,7 @@ void ttm_object_device_release(struct ttm_object_device **p_tdev)
529533

530534
*p_tdev = NULL;
531535

532-
spin_lock(&tdev->object_lock);
533536
drm_ht_remove(&tdev->object_hash);
534-
spin_unlock(&tdev->object_lock);
535537

536538
kfree(tdev);
537539
}
@@ -635,7 +637,7 @@ int ttm_prime_fd_to_handle(struct ttm_object_file *tfile,
635637
prime = (struct ttm_prime_object *) dma_buf->priv;
636638
base = &prime->base;
637639
*handle = base->hash.key;
638-
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL);
640+
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false);
639641

640642
dma_buf_put(dma_buf);
641643

drivers/gpu/drm/vmwgfx/vmwgfx_fence.c

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ int vmw_fence_create(struct vmw_fence_manager *fman,
538538
struct vmw_fence_obj **p_fence)
539539
{
540540
struct vmw_fence_obj *fence;
541-
int ret;
541+
int ret;
542542

543543
fence = kzalloc(sizeof(*fence), GFP_KERNEL);
544544
if (unlikely(fence == NULL))
@@ -701,6 +701,41 @@ void vmw_fence_fifo_up(struct vmw_fence_manager *fman)
701701
}
702702

703703

704+
/**
705+
* vmw_fence_obj_lookup - Look up a user-space fence object
706+
*
707+
* @tfile: A struct ttm_object_file identifying the caller.
708+
* @handle: A handle identifying the fence object.
709+
* @return: A struct vmw_user_fence base ttm object on success or
710+
* an error pointer on failure.
711+
*
712+
* The fence object is looked up and type-checked. The caller needs
713+
* to have opened the fence object first, but since that happens on
714+
* creation and fence objects aren't shareable, that's not an
715+
* issue currently.
716+
*/
717+
static struct ttm_base_object *
718+
vmw_fence_obj_lookup(struct ttm_object_file *tfile, u32 handle)
719+
{
720+
struct ttm_base_object *base = ttm_base_object_lookup(tfile, handle);
721+
722+
if (!base) {
723+
pr_err("Invalid fence object handle 0x%08lx.\n",
724+
(unsigned long)handle);
725+
return ERR_PTR(-EINVAL);
726+
}
727+
728+
if (base->refcount_release != vmw_user_fence_base_release) {
729+
pr_err("Invalid fence object handle 0x%08lx.\n",
730+
(unsigned long)handle);
731+
ttm_base_object_unref(&base);
732+
return ERR_PTR(-EINVAL);
733+
}
734+
735+
return base;
736+
}
737+
738+
704739
int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data,
705740
struct drm_file *file_priv)
706741
{
@@ -726,13 +761,9 @@ int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data,
726761
arg->kernel_cookie = jiffies + wait_timeout;
727762
}
728763

729-
base = ttm_base_object_lookup(tfile, arg->handle);
730-
if (unlikely(base == NULL)) {
731-
printk(KERN_ERR "Wait invalid fence object handle "
732-
"0x%08lx.\n",
733-
(unsigned long)arg->handle);
734-
return -EINVAL;
735-
}
764+
base = vmw_fence_obj_lookup(tfile, arg->handle);
765+
if (IS_ERR(base))
766+
return PTR_ERR(base);
736767

737768
fence = &(container_of(base, struct vmw_user_fence, base)->fence);
738769

@@ -771,13 +802,9 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
771802
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
772803
struct vmw_private *dev_priv = vmw_priv(dev);
773804

774-
base = ttm_base_object_lookup(tfile, arg->handle);
775-
if (unlikely(base == NULL)) {
776-
printk(KERN_ERR "Fence signaled invalid fence object handle "
777-
"0x%08lx.\n",
778-
(unsigned long)arg->handle);
779-
return -EINVAL;
780-
}
805+
base = vmw_fence_obj_lookup(tfile, arg->handle);
806+
if (IS_ERR(base))
807+
return PTR_ERR(base);
781808

782809
fence = &(container_of(base, struct vmw_user_fence, base)->fence);
783810
fman = fman_from_fence(fence);
@@ -1024,6 +1051,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
10241051
(struct drm_vmw_fence_event_arg *) data;
10251052
struct vmw_fence_obj *fence = NULL;
10261053
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
1054+
struct ttm_object_file *tfile = vmw_fp->tfile;
10271055
struct drm_vmw_fence_rep __user *user_fence_rep =
10281056
(struct drm_vmw_fence_rep __user *)(unsigned long)
10291057
arg->fence_rep;
@@ -1037,24 +1065,18 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
10371065
*/
10381066
if (arg->handle) {
10391067
struct ttm_base_object *base =
1040-
ttm_base_object_lookup_for_ref(dev_priv->tdev,
1041-
arg->handle);
1042-
1043-
if (unlikely(base == NULL)) {
1044-
DRM_ERROR("Fence event invalid fence object handle "
1045-
"0x%08lx.\n",
1046-
(unsigned long)arg->handle);
1047-
return -EINVAL;
1048-
}
1068+
vmw_fence_obj_lookup(tfile, arg->handle);
1069+
1070+
if (IS_ERR(base))
1071+
return PTR_ERR(base);
1072+
10491073
fence = &(container_of(base, struct vmw_user_fence,
10501074
base)->fence);
10511075
(void) vmw_fence_obj_reference(fence);
10521076

10531077
if (user_fence_rep != NULL) {
1054-
bool existed;
1055-
10561078
ret = ttm_ref_object_add(vmw_fp->tfile, base,
1057-
TTM_REF_USAGE, &existed);
1079+
TTM_REF_USAGE, NULL, false);
10581080
if (unlikely(ret != 0)) {
10591081
DRM_ERROR("Failed to reference a fence "
10601082
"object.\n");
@@ -1097,8 +1119,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
10971119
return 0;
10981120
out_no_create:
10991121
if (user_fence_rep != NULL)
1100-
ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
1101-
handle, TTM_REF_USAGE);
1122+
ttm_ref_object_base_unref(tfile, handle, TTM_REF_USAGE);
11021123
out_no_ref_obj:
11031124
vmw_fence_obj_unreference(&fence);
11041125
return ret;

drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ int vmw_getparam_ioctl(struct drm_device *dev, void *data,
114114
param->value = dev_priv->has_dx;
115115
break;
116116
default:
117-
DRM_ERROR("Illegal vmwgfx get param request: %d\n",
118-
param->param);
119117
return -EINVAL;
120118
}
121119

@@ -186,7 +184,7 @@ int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
186184
bool gb_objects = !!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS);
187185
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
188186

189-
if (unlikely(arg->pad64 != 0)) {
187+
if (unlikely(arg->pad64 != 0 || arg->max_size == 0)) {
190188
DRM_ERROR("Illegal GET_3D_CAP argument.\n");
191189
return -EINVAL;
192190
}

drivers/gpu/drm/vmwgfx/vmwgfx_resource.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo,
589589
return ret;
590590

591591
ret = ttm_ref_object_add(tfile, &user_bo->prime.base,
592-
TTM_REF_SYNCCPU_WRITE, &existed);
592+
TTM_REF_SYNCCPU_WRITE, &existed, false);
593593
if (ret != 0 || existed)
594594
ttm_bo_synccpu_write_release(&user_bo->dma.base);
595595

@@ -773,7 +773,7 @@ int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
773773

774774
*handle = user_bo->prime.base.hash.key;
775775
return ttm_ref_object_add(tfile, &user_bo->prime.base,
776-
TTM_REF_USAGE, NULL);
776+
TTM_REF_USAGE, NULL, false);
777777
}
778778

779779
/*

drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,14 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
713713
128;
714714

715715
num_sizes = 0;
716-
for (i = 0; i < DRM_VMW_MAX_SURFACE_FACES; ++i)
716+
for (i = 0; i < DRM_VMW_MAX_SURFACE_FACES; ++i) {
717+
if (req->mip_levels[i] > DRM_VMW_MAX_MIP_LEVELS)
718+
return -EINVAL;
717719
num_sizes += req->mip_levels[i];
720+
}
718721

719-
if (num_sizes > DRM_VMW_MAX_SURFACE_FACES *
720-
DRM_VMW_MAX_MIP_LEVELS)
722+
if (num_sizes > DRM_VMW_MAX_SURFACE_FACES * DRM_VMW_MAX_MIP_LEVELS ||
723+
num_sizes == 0)
721724
return -EINVAL;
722725

723726
size = vmw_user_surface_size + 128 +
@@ -891,17 +894,16 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv,
891894
uint32_t handle;
892895
struct ttm_base_object *base;
893896
int ret;
897+
bool require_exist = false;
894898

895899
if (handle_type == DRM_VMW_HANDLE_PRIME) {
896900
ret = ttm_prime_fd_to_handle(tfile, u_handle, &handle);
897901
if (unlikely(ret != 0))
898902
return ret;
899903
} else {
900-
if (unlikely(drm_is_render_client(file_priv))) {
901-
DRM_ERROR("Render client refused legacy "
902-
"surface reference.\n");
903-
return -EACCES;
904-
}
904+
if (unlikely(drm_is_render_client(file_priv)))
905+
require_exist = true;
906+
905907
if (ACCESS_ONCE(vmw_fpriv(file_priv)->locked_master)) {
906908
DRM_ERROR("Locked master refused legacy "
907909
"surface reference.\n");
@@ -929,17 +931,14 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv,
929931

930932
/*
931933
* Make sure the surface creator has the same
932-
* authenticating master.
934+
* authenticating master, or is already registered with us.
933935
*/
934936
if (drm_is_primary_client(file_priv) &&
935-
user_srf->master != file_priv->master) {
936-
DRM_ERROR("Trying to reference surface outside of"
937-
" master domain.\n");
938-
ret = -EACCES;
939-
goto out_bad_resource;
940-
}
937+
user_srf->master != file_priv->master)
938+
require_exist = true;
941939

942-
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL);
940+
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL,
941+
require_exist);
943942
if (unlikely(ret != 0)) {
944943
DRM_ERROR("Could not add a reference to a surface.\n");
945944
goto out_bad_resource;

include/drm/ttm/ttm_object.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ extern void ttm_base_object_unref(struct ttm_base_object **p_base);
229229
* @ref_type: The type of reference.
230230
* @existed: Upon completion, indicates that an identical reference object
231231
* already existed, and the refcount was upped on that object instead.
232+
* @require_existed: Fail with -EPERM if an identical ref object didn't
233+
* already exist.
232234
*
233235
* Checks that the base object is shareable and adds a ref object to it.
234236
*
@@ -243,7 +245,8 @@ extern void ttm_base_object_unref(struct ttm_base_object **p_base);
243245
*/
244246
extern int ttm_ref_object_add(struct ttm_object_file *tfile,
245247
struct ttm_base_object *base,
246-
enum ttm_ref_type ref_type, bool *existed);
248+
enum ttm_ref_type ref_type, bool *existed,
249+
bool require_existed);
247250

248251
extern bool ttm_ref_object_exists(struct ttm_object_file *tfile,
249252
struct ttm_base_object *base);

0 commit comments

Comments
 (0)