Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] amdgpu: out-of-bounds array access due to flawed KFD SVM bounds check
--

commit f15cd1b71660722b40bc92fadadb46cc7210b7fd
Author: Daniel Huang <[email protected]>
Date:   Fri Oct 16 14:51:29 2026 +0000

    drm/amdkfd: disable SVM when the GPUVM cannot cover CPU addresses
    
    KFD SVM maps memory in GPUVM at the same virtual address used by
    the CPU. However, svm_range_map_to_gpu() passes the corresponding
    PFNs to amdgpu_vm_update_range() without checking them against
    vm_manager.max_pfn.

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h 
> b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
> index c7d7adae4476b..6235ce0f988ea 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
> @@ -203,11 +203,25 @@ struct kfd_process_device *
>  svm_range_get_pdd_by_node(struct svm_range *prange, struct kfd_node *node);
>  void svm_range_list_lock_and_flush_work(struct svm_range_list *svms, struct 
> mm_struct *mm);
>  
> +/*
> + * SVM uses CPU virtual addresses for GPU mappings. Disable SVM if the GPUVM
> + * address range cannot cover the required CPU address range.
> + *
> + * The parameter must be named adev since AMDGPU_GMC_HOLE_START references
> + * adev->vm_manager.max_level.
> + */
> +static inline bool kfd_svm_vm_covers_user_va(struct amdgpu_device *adev)
> +{
> +     return (adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT) >=
> +             AMDGPU_GMC_HOLE_START;

[Severity: High]
Does this check erroneously rely on the GPU-dependent hole start instead of
the CPU's actual maximum user virtual address?

AMDGPU_GMC_HOLE_START is defined based on the GPU's capabilities:

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h:
#define AMDGPU_GMC_HOLE_START   (adev->vm_manager.max_level == 4 ?\
                                0x0100000000000000ULL : 0x0000800000000000ULL)

On a system with a 57-bit (5-level) CPU and a 48-bit (4-level) GPU, this
comparison evaluates to true, keeping SVM enabled. A malicious userspace
program could then map a valid CPU address above 48 bits and pass it to
KFD SVM.

This would result in svm_range_validate_and_map() passing the unvalidated
address to amdgpu_vm_update_range(), leading to an out-of-bounds access in
amdgpu_vm_pt_descendant():

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c:amdgpu_vm_pt_descendant() {
    ...
        idx = (cursor->pfn >> shift) & mask;
        cursor->parent = cursor->entry;
        cursor->entry = &to_amdgpu_bo_vm(cursor->entry->bo)->entries[idx];
    ...
}

Should this check use a CPU-specific limit like TASK_SIZE_MAX to ensure SVM
is safely disabled when the GPU cannot cover the CPU's address space?

> +}
> +

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to