Skip to content

Commit 4a8093c

Browse files
amd-alysaliugregkh
authored andcommitted
drm/amdkfd: Add upper bound check for num_of_nodes
commit 74b73fa upstream. 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 98ff46a) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1db4313 commit 4a8093c

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp,
784784
goto out_unlock;
785785
}
786786

787+
if (args->num_of_nodes > kfd_topology_get_num_devices())
788+
return -EINVAL;
789+
787790
/* Fill in process-aperture information for all available
788791
* nodes, but not more than args->num_of_nodes as that is
789792
* the amount of memory allocated by user

drivers/gpu/drm/amd/amdkfd/kfd_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ static inline struct kfd_node *kfd_node_by_irq_ids(struct amdgpu_device *adev,
11451145
return NULL;
11461146
}
11471147
int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_node **kdev);
1148+
uint32_t kfd_topology_get_num_devices(void);
11481149
int kfd_numa_node_to_apic_id(int numa_node_id);
11491150

11501151
/* Interrupts */

drivers/gpu/drm/amd/amdkfd/kfd_topology.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,17 @@ int kfd_topology_remove_device(struct kfd_node *gpu)
21772177
return res;
21782178
}
21792179

2180+
uint32_t kfd_topology_get_num_devices(void)
2181+
{
2182+
uint32_t num_devices;
2183+
2184+
down_read(&topology_lock);
2185+
num_devices = sys_props.num_devices;
2186+
up_read(&topology_lock);
2187+
2188+
return num_devices;
2189+
}
2190+
21802191
/* kfd_topology_enum_kfd_devices - Enumerate through all devices in KFD
21812192
* topology. If GPU device is found @idx, then valid kfd_dev pointer is
21822193
* returned through @kdev

0 commit comments

Comments
 (0)