lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a9fe9bc4-b6b2-444d-2a6b-500637c96906@amd.com>
Date:   Wed, 24 May 2023 20:27:33 +0200
From:   Christian König <christian.koenig@....com>
To:     Chia-I Wu <olvaffe@...il.com>, dri-devel@...ts.freedesktop.org
Cc:     Alex Deucher <alexander.deucher@....com>,
        "Pan, Xinhui" <Xinhui.Pan@....com>,
        David Airlie <airlied@...il.com>,
        Daniel Vetter <daniel@...ll.ch>,
        Felix Kuehling <Felix.Kuehling@....com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Marek Olšák <marek.olsak@....com>,
        Yang Li <yang.lee@...ux.alibaba.com>,
        Kefeng Wang <wangkefeng.wang@...wei.com>,
        Suren Baghdasaryan <surenb@...gle.com>,
        Philip Yang <Philip.Yang@....com>,
        Luben Tuikov <luben.tuikov@....com>,
        Mukul Joshi <mukul.joshi@....com>,
        Danijel Slivka <danijel.slivka@....com>,
        Jammy Zhou <Jammy.Zhou@....com>, amd-gfx@...ts.freedesktop.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] amdgpu: validate drm_amdgpu_gem_va addrs

Am 24.05.23 um 00:53 schrieb Chia-I Wu:
> Validate drm_amdgpu_gem_va addrs in amdgpu_gem_va_ioctl.
> amdgpu_vm_bo_replace_map no longer needs to validate (and its
> validations were insufficient either).  amdgpu_vm_bo_map has internal
> users and its validations are kept.

No, please keep all validation inside amdgpu_vm.c code.

See the offset is unused or might have a different meaning for some use 
cases, so validating it here is actually not correct.

Christian.

>
> This is motivated by OOB access in amdgpu_vm_update_range when
> offset_in_bo+map_size overflows.
>
> Userspace (radeonsi and radv) seems fine as well.
>
> v2: keep the validations in amdgpu_vm_bo_map
>
> Fixes: 9f7eb5367d00 ("drm/amdgpu: actually use the VM map parameters")
> Signed-off-by: Chia-I Wu <olvaffe@...il.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 15 +++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  |  8 +-------
>   2 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index d8e683688daab..36d5adfdf0f69 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -681,6 +681,21 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
>   	uint64_t vm_size;
>   	int r = 0;
>   
> +	if (args->va_address & ~PAGE_MASK || args->offset_in_bo & ~PAGE_MASK ||
> +	    args->map_size & ~PAGE_MASK) {
> +		dev_dbg(dev->dev, "unaligned va_address 0x%LX, offset_in_bo 0x%LX, or map_size 0x%LX\n",
> +			args->va_address, args->offset_in_bo, args->map_size);
> +		return -EINVAL;
> +	}
> +
> +	if (args->map_size == 0 ||
> +	    args->va_address + args->map_size < args->va_address ||
> +	    args->offset_in_bo + args->map_size < args->offset_in_bo) {
> +		dev_dbg(dev->dev, "invalid map_size 0x%LX (va_address 0x%LX, offset_in_bo 0x%LX)\n",
> +			args->map_size, args->va_address, args->offset_in_bo);
> +		return -EINVAL;
> +	}
> +
>   	if (args->va_address < AMDGPU_VA_RESERVED_SIZE) {
>   		dev_dbg(dev->dev,
>   			"va_address 0x%LX is in reserved area 0x%LX\n",
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index b9441ab457ea7..6307baaa136cf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1501,15 +1501,9 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
>   	uint64_t eaddr;
>   	int r;
>   
> -	/* validate the parameters */
> -	if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK ||
> -	    size == 0 || size & ~PAGE_MASK)
> -		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;
>   

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ