]> 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)
commite9770fc8c8bceec4170276145ec22d07dff0aec5
treeb0bcc45ccc579e2e9b88afbce8af51a233ff166f
parent4f030309e2410751477ed3b1f2f96b294c68caf7
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: e8fc7a6e79c6 ("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