]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commit147ae178e66035b4c2fe0948e9f5de517602859a
treeb0bcc45ccc579e2e9b88afbce8af51a233ff166f
parent12192be1459924ef0ccd7daff70d0662b56722bb
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: a6d4acde0ef2 ("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