Skip to contentSkip to conversation

drm/amdkfd: Add bounds check for AMDKFD_IOC_WAIT_EVENTS

PATCH In review Sunday Clement 2 participants 3 messages May 19 – May 27

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

PATCH 1/1 drm/amdkfd: Add bounds check for AMDKFD_IOC_WAIT_EVENTS

The kfd_wait_on_events ioctl passes a user-supplied num_events parameter directly to alloc_event_waiters() which calls kcalloc() without validation. This allows unprivileged users with /dev/kfd access to trigger large kernel memory allocations, potentially causing memory exhaustion and denial of service via the OOM killer.

Add a check to reject num_events values exceeding KFD_SIGNAL_EVENT_LIMIT (4096), which is the maximum number of events a single process can create.

---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
index e9be798c0a2b..83edc4af77b5 100644
@@ -799,7 +799,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events)
 {
 	struct kfd_event_waiter *event_waiters;
 	uint32_t i;
-
+	if (num_events > KFD_SIGNAL_EVENT_LIMIT)
+		return NULL;
 	event_waiters = kcalloc(num_events, sizeof(struct kfd_event_waiter),
 				GFP_KERNEL);
 	if (!event_waiters)
Signature · 1 line
2.43.0
#1 lore raw

AMD General

ping

Quoted 42 lines

-----Original Message-----
From: Clement, Sunday <[email protected]>
Sent: Tuesday, May 19, 2026 10:18 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Clement, Sunday <[email protected]>
Subject: [PATCH] drm/amdkfd: Add bounds check for AMDKFD_IOC_WAIT_EVENTS

The kfd_wait_on_events ioctl passes a user-supplied num_events parameter directly to alloc_event_waiters() which calls kcalloc() without validation. This allows unprivileged users with /dev/kfd access to trigger large kernel memory allocations, potentially causing memory exhaustion and denial of service via the OOM killer.

Add a check to reject num_events values exceeding KFD_SIGNAL_EVENT_LIMIT (4096), which is the maximum number of events a single process can create.

---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -2
index e9be798c0a2b..83edc4af77b5 100644
@@ -799,7 +799,8 @@ static struct kfd_event_waiter
 *alloc_event_waiters(uint32_t num_events)  {
      struct kfd_event_waiter *event_waiters;
      uint32_t i;
-
+     if (num_events > KFD_SIGNAL_EVENT_LIMIT)
+             return NULL;
      event_waiters = kcalloc(num_events, sizeof(struct kfd_event_waiter),
                              GFP_KERNEL);
      if (!event_waiters)
--

2.43.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Sunday Clement

AMD General

________________________________
From: Clement, Sunday <[email protected]>
Sent: Tuesday, May 19, 2026 10:18 AM
To: [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Clement, Sunday <[email protected]>
Subject: [PATCH] drm/amdkfd: Add bounds check for AMDKFD_IOC_WAIT_EVENTS

The kfd_wait_on_events ioctl passes a user-supplied num_events parameter directly to alloc_event_waiters() which calls kcalloc() without validation. This allows unprivileged users with /dev/kfd access to trigger large kernel memory allocations, potentially causing memory exhaustion and denial of service via the OOM killer.

Add a check to reject num_events values exceeding KFD_SIGNAL_EVENT_LIMIT (4096), which is the maximum number of events a single process can create.

---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
index e9be798c0a2b..83edc4af77b5 100644
@@ -799,7 +799,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events)
 {
         struct kfd_event_waiter *event_waiters;
         uint32_t i;
-
+       if (num_events > KFD_SIGNAL_EVENT_LIMIT)
+               return NULL;
         event_waiters = kcalloc(num_events, sizeof(struct kfd_event_waiter),
                                 GFP_KERNEL);
         if (!event_waiters)

--
2.43.0