drm/amdkfd: fix overflow for the function criu_restore_bos
Subsystems (3)
PATCH 3/8 drm/amdkfd: fix overflow for the function criu_restore_bos
When copying the information from the user fails, it will goto exit. But the variable i remains at 0, and do i-- will overflow.
Signed-off-by Jesse Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -1
@@ -2480,10 +2480,11 @@ static int criu_restore_bos(struct kfd_process *p, ret = -EFAULT ; exit: -while (ret && i--) { +while (ret && i) {if (bo_buckets[i].alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |KFD_IOC_ALLOC_MEM_FLAGS_GTT ))close_fd (bo_buckets[i].dmabuf_fd); + i--; }kvfree (bo_buckets);kvfree (bo_privs);
Signature · 1 line
2.25.1
Felix Kuehling
maintainerQuoted 2 lines · Jesse Zhang
When copying the information from the user fails, it will goto exit. But the variable i remains at 0, and do i-- will overflow.
i-- may underflow, but the loop will still exit. Why is the underflow a problem?
Quoted 11 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_bos(struct kfd_process *p, · line 2487
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2
-1@@ -2480,10 +2480,11 @@ static int criu_restore_bos(struct kfd_process *p, ret = -EFAULT ; exit: -while (ret && i--) { +while (ret && i) {if (bo_buckets[i].alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |KFD_IOC_ALLOC_MEM_FLAGS_GTT ))close_fd (bo_buckets[i].dmabuf_fd); + i--;
This changes the value of i in the loop body. To get the same behaviour you'd need to decrement i at the start of the loop body.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0}kvfree (bo_buckets);kvfree (bo_privs);