]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdkfd: Add upper bound check for num_of_nodes
authorAlysa Liu <Alysa.Liu@amd.com>
Mon, 30 Mar 2026 14:50:07 +0000 (10:50 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 23 Apr 2026 16:54:45 +0000 (12:54 -0400)
drm/amdkfd: Add upper bound check for num_of_nodes
in kfd_ioctl_get_process_apertures_new.

Reviewed-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Signed-off-by: Alysa Liu <Alysa.Liu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 98ff46a5ea090c14d2cdb4f5b993b05d74f3949f)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_topology.c

index 462a32abf720abef2bf2605027fb0e010a255c54..55ea5145a28accabb81d9321c1b5130809580779 100644 (file)
@@ -776,6 +776,9 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp,
                goto out_unlock;
        }
 
+       if (args->num_of_nodes > kfd_topology_get_num_devices())
+               return -EINVAL;
+
        /* Fill in process-aperture information for all available
         * nodes, but not more than args->num_of_nodes as that is
         * the amount of memory allocated by user
index fa025bea9b4f5df8451b7f4cd20d76c70afedcdb..6e333bfa17d6273eb8aca36bf58ac3770d779be3 100644 (file)
@@ -1191,6 +1191,7 @@ static inline struct kfd_node *kfd_node_by_irq_ids(struct amdgpu_device *adev,
        return NULL;
 }
 int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_node **kdev);
+uint32_t kfd_topology_get_num_devices(void);
 int kfd_numa_node_to_apic_id(int numa_node_id);
 uint32_t kfd_gpu_node_num(void);
 
index 995f2c2528a988462b2f64b42626895b46ff1134..29dee26261ab1fd387707e72da41e6a5e83e1b9d 100644 (file)
@@ -2297,6 +2297,17 @@ int kfd_topology_remove_device(struct kfd_node *gpu)
        return res;
 }
 
+uint32_t kfd_topology_get_num_devices(void)
+{
+       uint32_t num_devices;
+
+       down_read(&topology_lock);
+       num_devices = sys_props.num_devices;
+       up_read(&topology_lock);
+
+       return num_devices;
+}
+
 /* kfd_topology_enum_kfd_devices - Enumerate through all devices in KFD
  *     topology. If GPU device is found @idx, then valid kfd_dev pointer is
  *     returned through @kdev