Skip to content

Commit 1987253

Browse files
committed
drm/msm: fix cmdstream size check
Need to check size+offset against bo size (duh!).. now we have a test case to make sure I've done it right: https://github.com/freedreno/msmtest/blob/master/submittest.c Also, use DRM_ERROR() for error case traces, which makes debugging userspace easier when enabling debug traces is too much. Signed-off-by: Rob Clark <[email protected]>
1 parent 26791c4 commit 1987253

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

drivers/gpu/drm/msm/msm_gem_submit.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int submit_lookup_objects(struct msm_gem_submit *submit,
7878
}
7979

8080
if (submit_bo.flags & BO_INVALID_FLAGS) {
81-
DBG("invalid flags: %x", submit_bo.flags);
81+
DRM_ERROR("invalid flags: %x\n", submit_bo.flags);
8282
ret = -EINVAL;
8383
goto out_unlock;
8484
}
@@ -92,15 +92,15 @@ static int submit_lookup_objects(struct msm_gem_submit *submit,
9292
*/
9393
obj = idr_find(&file->object_idr, submit_bo.handle);
9494
if (!obj) {
95-
DBG("invalid handle %u at index %u", submit_bo.handle, i);
95+
DRM_ERROR("invalid handle %u at index %u\n", submit_bo.handle, i);
9696
ret = -EINVAL;
9797
goto out_unlock;
9898
}
9999

100100
msm_obj = to_msm_bo(obj);
101101

102102
if (!list_empty(&msm_obj->submit_entry)) {
103-
DBG("handle %u at index %u already on submit list",
103+
DRM_ERROR("handle %u at index %u already on submit list\n",
104104
submit_bo.handle, i);
105105
ret = -EINVAL;
106106
goto out_unlock;
@@ -216,8 +216,9 @@ static int submit_bo(struct msm_gem_submit *submit, uint32_t idx,
216216
struct msm_gem_object **obj, uint32_t *iova, bool *valid)
217217
{
218218
if (idx >= submit->nr_bos) {
219-
DBG("invalid buffer index: %u (out of %u)", idx, submit->nr_bos);
220-
return EINVAL;
219+
DRM_ERROR("invalid buffer index: %u (out of %u)\n",
220+
idx, submit->nr_bos);
221+
return -EINVAL;
221222
}
222223

223224
if (obj)
@@ -239,7 +240,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
239240
int ret;
240241

241242
if (offset % 4) {
242-
DBG("non-aligned cmdstream buffer: %u", offset);
243+
DRM_ERROR("non-aligned cmdstream buffer: %u\n", offset);
243244
return -EINVAL;
244245
}
245246

@@ -266,7 +267,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
266267
return -EFAULT;
267268

268269
if (submit_reloc.submit_offset % 4) {
269-
DBG("non-aligned reloc offset: %u",
270+
DRM_ERROR("non-aligned reloc offset: %u\n",
270271
submit_reloc.submit_offset);
271272
return -EINVAL;
272273
}
@@ -276,7 +277,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
276277

277278
if ((off >= (obj->base.size / 4)) ||
278279
(off < last_offset)) {
279-
DBG("invalid offset %u at reloc %u", off, i);
280+
DRM_ERROR("invalid offset %u at reloc %u\n", off, i);
280281
return -EINVAL;
281282
}
282283

@@ -374,14 +375,15 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
374375
goto out;
375376

376377
if (submit_cmd.size % 4) {
377-
DBG("non-aligned cmdstream buffer size: %u",
378+
DRM_ERROR("non-aligned cmdstream buffer size: %u\n",
378379
submit_cmd.size);
379380
ret = -EINVAL;
380381
goto out;
381382
}
382383

383-
if (submit_cmd.size >= msm_obj->base.size) {
384-
DBG("invalid cmdstream size: %u", submit_cmd.size);
384+
if ((submit_cmd.size + submit_cmd.submit_offset) >=
385+
msm_obj->base.size) {
386+
DRM_ERROR("invalid cmdstream size: %u\n", submit_cmd.size);
385387
ret = -EINVAL;
386388
goto out;
387389
}

0 commit comments

Comments
 (0)