OSDN Git Service

drm/amdkfd: potential crash in kfd_create_indirect_link_prop()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 12 Aug 2022 06:20:58 +0000 (09:20 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 16 Aug 2022 22:06:29 +0000 (18:06 -0400)
commit7d50b92d588d1e7bdcf38f523200b7b113b46c14
treeb0bcc45ccc579e2e9b88afbce8af51a233ff166f
parente48e6a131d34de54ce6852149e4c97c2208f45cc
drm/amdkfd: potential crash in kfd_create_indirect_link_prop()

This code has two bugs.  If kfd_topology_device_by_proximity_domain()
failed on the first iteration through the loop then "cpu_link" is
uninitialized and should not be dereferenced.

The second bug is that we cannot dereference a list iterator when it
points to the list head.  In other words, if we exit the
list_for_each_entry() loop exits without hitting a break then "cpu_link"
is not a valid pointer and should not be dereferenced.

Fix both of these problems by setting "cpu_link" to NULL when it is invalid
and non-NULL when it is valid.  That makes it easier to test for
valid vs invalid.

Fixes: 0f28cca87e9a ("drm/amdkfd: Extend KFD device topology to surface peer-to-peer links")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_topology.c