Skip to contentSkip to conversation

drm/amdkfd: lock event_mutex while counting events for CRIU

PATCH New Changyul Lee 1 participant 1 message Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: lock event_mutex while counting events for CRIU

criu_get_process_object_info() holds p->mutex while counting events in p->event_idr. Event creation and destruction use p->event_mutex, so the event IDR can change during the walk. If an event is removed, the walk can access a freed IDR node.

Hold p->event_mutex while counting events. kfd_criu_checkpoint_events() uses the same lock when walking the event IDR. Event creation and destruction do not acquire p->mutex, so taking p->event_mutex while holding p->mutex preserves the lock order.

Fixes 40e8a766a761 ("drm/amdkfd: CRIU checkpoint and restore events")

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus DRM_AMDGPU, HSA_AMD and W=1.

 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
index 3d2136adb62b..20e3bbd073a5 100644
@@ -2234,7 +2234,9 @@ static int criu_get_process_object_info(struct kfd_process *p,
 	if (ret)
 		return ret;
 
+	mutex_lock(&p->event_mutex);
 	num_events = kfd_get_num_events(p);
+	mutex_unlock(&p->event_mutex);
 
 	svm_range_get_info(p, &num_svm_ranges, &svm_priv_data_size);
 

base-commit: 8dd68a79583aaf6df6fe4feea3ee9e9f26b02993

Signature · 1 line
2.43.0