drm/msm/gem: A couple VM_BIND fixes
Rob Clark
maintainercover drm/msm/gem: A couple VM_BIND fixes
Fix possible overflow in range check, and disallow passing BOs table to GEM_SUBMIT for VM_BIND contexts.
Rob Clark (2):
drm/msm/gem: Fix VM_BIND range check drm/msm/gem: Disallow nr_bos for VM_BIND contexts
drivers/gpu/drm/msm/msm_gem_submit.c | 5 ++++- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.56.0
Rob Clark
maintainerPATCH 1/2 drm/msm/gem: Fix VM_BIND range check
Use size_add() to guard against overflow.
--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_gem_vma.c +1 -1
@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++; -if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) { ret =UERR (EINVAL , dev,"invalid range: %016llx + %016llx > %016zx\n" , op->range, op->obj_offset, obj->size); goto out_unlock;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/msm: 64-to-32-bit truncation in size_add() in vm_bind_job_lookup_ops() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/msm: 64-to-32-bit truncation in size_add() in vm_bind_job_lookup_ops() --
commit 0bb1fc19abe2c004d338802c56cd54e0621aa9a6
Author: Rob Clark <[email protected]>
drm/msm/gem: Fix VM_BIND range check
This commit replaces the addition of op->range and op->obj_offset with size_add() in vm_bind_job_lookup_ops() to guard against integer overflow when validating the range against obj->size.
drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 10 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++; -if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {
[Severity: Medium]
On 32-bit builds, does passing op->range and op->obj_offset to size_add() truncate the upper 32 bits of both 64-bit operands before checking for overflow?
In struct msm_vm_bind_op, obj_offset and range are 64-bit values:
drivers/gpu/drm/msm/msm_gem_vma.c:
struct msm_vm_bind_op {
...
uint64_t obj_offset;
uint64_t iova;
uint64_t range;
...
};However, size_add() in include/linux/overflow.h takes size_t arguments:
static __always_inline size_t __must_check size_add(size_t addend1, size_t addend2)
Earlier in lookup_op(), op->obj_offset is only checked with invalid_alignment(op->obj_offset), which does not reject non-zero upper 32 bits. On 32-bit architectures where size_t is 32 bits wide, an offset such as 0x100000000ULL is truncated to 0 when passed to size_add(), allowing an out-of-bounds 64-bit op->obj_offset or op->range to bypass the obj->size check in vm_bind_job_lookup_ops() and be stored into vma->gem.offset.
Would check_add_overflow() with a uint64_t sum (or range_overflows_t(u64, op->obj_offset, op->range, obj->size)) avoid narrowing the operands on 32-bit targets?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
In reply to Rob ClarkQuoted 14 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gem_vma.c +0
-0
drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 5 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++; -if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {
GPT and Sashiko are unhappy about what this does on 32b
Konrad
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
Quoted 18 lines · Konrad Dybcio
Quoted 17 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gem_vma.c +0
-0@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++;
Quoted 4 lines
drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 2 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1-if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {GPT and Sashiko are unhappy about what this does on 32b
I'd somewhat doubt that we would ever need VM_BIND on arm32 platforms. a2xx isn't Vulkan-compatible, a3xx is questionable.
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
In reply to Konrad DybcioQuoted 19 lines · Konrad Dybcio
Quoted 17 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gem_vma.c +0
-0@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++;
Quoted 4 lines
drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 2 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1-if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {GPT and Sashiko are unhappy about what this does on 32b
Considering that we can't have >4gb BOs on 32b, I think the concerns are probably unwarranted. But yes, I do look at Sashiko's reports
BR,
-R
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
Quoted 22 lines · Rob Clark
Quoted 19 lines · Konrad Dybcio
Quoted 17 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gem_vma.c +0
-0@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++;
Quoted 7 lines
Quoted 4 lines
drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 2 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1-if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {GPT and Sashiko are unhappy about what this does on 32b
Considering that we can't have >4gb BOs on 32b, I think the concerns are probably unwarranted. But yes, I do look at Sashiko's reports
Probably we should add checks that obj_offset/range are not more than SIZE_MAX?
BR,
-R
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
Quoted 28 lines · Rob Clark
Quoted 27 lines · Rob Clark
Quoted 23 lines · Konrad Dybcio
Quoted 14 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gem_vma.c +0
-0drivers/gpu/drm/msm/msm_gem_vma.c vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args · line 1121
Quoted 5 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1
-1@@ -1118,7 +1118,7 @@ vm_bind_job_lookup_ops(struct msm_vm_bind_job *job, struct drm_msm_vm_bind *args op->obj = obj; cnt++; -if ((op->range + op->obj_offset) > obj->size) { +if (size_add (op->range, op->obj_offset) > obj->size) {GPT and Sashiko are unhappy about what this does on 32b
Quoted 4 lines
Quoted 2 lines
Considering that we can't have >4gb BOs on 32b, I think the concerns are probably unwarranted. But yes, I do look at Sashiko's reports
Probably we should add checks that obj_offset/range are not more than
SIZE_MAX?
Wouldn't hurt
Konrad
Re: [PATCH 1/2] drm/msm/gem: Fix VM_BIND range check
In reply to Rob ClarkQuoted 9 lines · Rob Clark
Use
size_add()to guard against overflow.Reported-by Konrad Dybcio <[email protected]>Fixes 3a3bef68a6c1 ("drm/msm: Fix missing VM_BIND offset/range validation")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
With best wishes Dmitry
Rob Clark
maintainerPATCH 2/2 drm/msm/gem: Disallow nr_bos for VM_BIND contexts
In reply to Rob ClarkIf using VM_BIND, it is invalid to attach BOs to a GEM_SUBMIT ioctl. Only the VM_BIND ioctl should be used for binding objects.
--- drivers/gpu/drm/msm/msm_gem_submit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_gem_submit.c +4 -1
@@ -272,7 +272,7 @@ static int submit_lock_objects_vmbind(struct msm_gem_submit *submit)struct drm_exec *exec = &submit->exec;int ret =0 ; -drm_exec_init (&submit->exec, flags, submit->nr_bos); +drm_exec_init (&submit->exec, flags,0 ); submit->has_exec = true; drm_exec_until_all_locked (&submit->exec) {
@@ -589,6 +589,9 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,return -EINVAL ; } +if (msm_context_is_vmbind (ctx) && args->nr_bos) +return UERR (EINVAL , dev,"invalid nr_bos, must be zero for VM_BIND contexts" ); + queue =msm_submitqueue_get (ctx, args->queueid);if (!queue)return -ENOENT ;
Signature · 1 line
2.56.0
Re: [PATCH 2/2] drm/msm/gem: Disallow nr_bos for VM_BIND contexts
Quoted 9 lines · Rob Clark
If using
VM_BIND, it is invalid to attach BOs to aGEM_SUBMITioctl. Only theVM_BINDioctl should be used for binding objects.Fixes 2e6a8a1fe2b2 ("drm/msm: Add VM_BIND ioctl")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_gem_submit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 2 lines
With best wishes Dmitry