* [PATCH v3] amdgpu: validate offset_in_bo of drm_amdgpu_gem_va
@ 2023-06-01 22:44 Chia-I Wu
2023-06-02 11:43 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Chia-I Wu @ 2023-06-01 22:44 UTC (permalink / raw)
To: dri-devel
Cc: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
Daniel Vetter, Felix Kuehling, Philip Yang, Hawking Zhang,
Mukul Joshi, Danijel Slivka, Lang Yu, Marek Olšák,
Jammy Zhou, amd-gfx, linux-kernel
This is motivated by OOB access in amdgpu_vm_update_range when
offset_in_bo+map_size overflows.
v2: keep the validations in amdgpu_vm_bo_map
v3: add the validations to amdgpu_vm_bo_map/amdgpu_vm_bo_replace_map
rather than to amdgpu_gem_va_ioctl
Fixes: 9f7eb5367d00 ("drm/amdgpu: actually use the VM map parameters")
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 22f9a65ca0fc7..76d57bc7ac620 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1434,14 +1434,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
uint64_t eaddr;
/* validate the parameters */
- if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
- size == 0 || size & ~PAGE_MASK)
+ if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
+ return -EINVAL;
+ if (saddr + size <= saddr || offset + size <= offset)
return -EINVAL;
/* make sure object fit at this offset */
eaddr = saddr + size - 1;
- if (saddr >= eaddr ||
- (bo && offset + size > amdgpu_bo_size(bo)) ||
+ if ((bo && offset + size > amdgpu_bo_size(bo)) ||
(eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
return -EINVAL;
@@ -1500,14 +1500,14 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
int r;
/* validate the parameters */
- if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
- size == 0 || size & ~PAGE_MASK)
+ if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
+ return -EINVAL;
+ if (saddr + size <= saddr || offset + size <= offset)
return -EINVAL;
/* make sure object fit at this offset */
eaddr = saddr + size - 1;
- if (saddr >= eaddr ||
- (bo && offset + size > amdgpu_bo_size(bo)) ||
+ if ((bo && offset + size > amdgpu_bo_size(bo)) ||
(eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
return -EINVAL;
--
2.41.0.rc0.172.g3f132b7071-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] amdgpu: validate offset_in_bo of drm_amdgpu_gem_va
2023-06-01 22:44 [PATCH v3] amdgpu: validate offset_in_bo of drm_amdgpu_gem_va Chia-I Wu
@ 2023-06-02 11:43 ` Christian König
2023-06-02 18:22 ` Alex Deucher
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2023-06-02 11:43 UTC (permalink / raw)
To: Chia-I Wu, dri-devel
Cc: Alex Deucher, Pan, Xinhui, David Airlie, Daniel Vetter,
Felix Kuehling, Philip Yang, Hawking Zhang, Mukul Joshi,
Danijel Slivka, Lang Yu, Marek Olšák, Jammy Zhou,
amd-gfx, linux-kernel
Am 02.06.23 um 00:44 schrieb Chia-I Wu:
> This is motivated by OOB access in amdgpu_vm_update_range when
> offset_in_bo+map_size overflows.
>
> v2: keep the validations in amdgpu_vm_bo_map
> v3: add the validations to amdgpu_vm_bo_map/amdgpu_vm_bo_replace_map
> rather than to amdgpu_gem_va_ioctl
>
> Fixes: 9f7eb5367d00 ("drm/amdgpu: actually use the VM map parameters")
> Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 22f9a65ca0fc7..76d57bc7ac620 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1434,14 +1434,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
> uint64_t eaddr;
>
> /* validate the parameters */
> - if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
> - size == 0 || size & ~PAGE_MASK)
> + if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
> + return -EINVAL;
> + if (saddr + size <= saddr || offset + size <= offset)
> return -EINVAL;
>
> /* make sure object fit at this offset */
> eaddr = saddr + size - 1;
> - if (saddr >= eaddr ||
> - (bo && offset + size > amdgpu_bo_size(bo)) ||
> + if ((bo && offset + size > amdgpu_bo_size(bo)) ||
> (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
> return -EINVAL;
>
> @@ -1500,14 +1500,14 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
> int r;
>
> /* validate the parameters */
> - if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
> - size == 0 || size & ~PAGE_MASK)
> + if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
> + return -EINVAL;
> + if (saddr + size <= saddr || offset + size <= offset)
> return -EINVAL;
>
> /* make sure object fit at this offset */
> eaddr = saddr + size - 1;
> - if (saddr >= eaddr ||
> - (bo && offset + size > amdgpu_bo_size(bo)) ||
> + if ((bo && offset + size > amdgpu_bo_size(bo)) ||
> (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
> return -EINVAL;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] amdgpu: validate offset_in_bo of drm_amdgpu_gem_va
2023-06-02 11:43 ` Christian König
@ 2023-06-02 18:22 ` Alex Deucher
0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2023-06-02 18:22 UTC (permalink / raw)
To: Christian König
Cc: Chia-I Wu, dri-devel, Philip Yang, Jammy Zhou, Mukul Joshi,
Lang Yu, Felix Kuehling, Pan, Xinhui, linux-kernel, amd-gfx,
Marek Olšák, Daniel Vetter, Alex Deucher, David Airlie,
Danijel Slivka, Hawking Zhang
Applied. Thanks!
Alex
On Fri, Jun 2, 2023 at 7:43 AM Christian König <christian.koenig@amd.com> wrote:
>
> Am 02.06.23 um 00:44 schrieb Chia-I Wu:
> > This is motivated by OOB access in amdgpu_vm_update_range when
> > offset_in_bo+map_size overflows.
> >
> > v2: keep the validations in amdgpu_vm_bo_map
> > v3: add the validations to amdgpu_vm_bo_map/amdgpu_vm_bo_replace_map
> > rather than to amdgpu_gem_va_ioctl
> >
> > Fixes: 9f7eb5367d00 ("drm/amdgpu: actually use the VM map parameters")
> > Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++--------
> > 1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > index 22f9a65ca0fc7..76d57bc7ac620 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > @@ -1434,14 +1434,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
> > uint64_t eaddr;
> >
> > /* validate the parameters */
> > - if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
> > - size == 0 || size & ~PAGE_MASK)
> > + if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
> > + return -EINVAL;
> > + if (saddr + size <= saddr || offset + size <= offset)
> > return -EINVAL;
> >
> > /* make sure object fit at this offset */
> > eaddr = saddr + size - 1;
> > - if (saddr >= eaddr ||
> > - (bo && offset + size > amdgpu_bo_size(bo)) ||
> > + if ((bo && offset + size > amdgpu_bo_size(bo)) ||
> > (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
> > return -EINVAL;
> >
> > @@ -1500,14 +1500,14 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
> > int r;
> >
> > /* validate the parameters */
> > - if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
> > - size == 0 || size & ~PAGE_MASK)
> > + if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
> > + return -EINVAL;
> > + if (saddr + size <= saddr || offset + size <= offset)
> > return -EINVAL;
> >
> > /* make sure object fit at this offset */
> > eaddr = saddr + size - 1;
> > - if (saddr >= eaddr ||
> > - (bo && offset + size > amdgpu_bo_size(bo)) ||
> > + if ((bo && offset + size > amdgpu_bo_size(bo)) ||
> > (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
> > return -EINVAL;
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-02 18:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-01 22:44 [PATCH v3] amdgpu: validate offset_in_bo of drm_amdgpu_gem_va Chia-I Wu
2023-06-02 11:43 ` Christian König
2023-06-02 18:22 ` Alex Deucher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox