Skip to contentSkip to conversation

drm/amdkfd: Check bounds on allocate_doorbell

PATCH In review David Francis 2 participants 4 messages May 12 – May 13

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

PATCH 1/2 drm/amdkfd: Check bounds on allocate_doorbell

allocated_doorbell has an option to set the doorbell id to a specific value (used by CRIU). This value was not bounds checked.

Check to confirm it's less than KFD_MAX_NUM_OF_QUEUES_PER_PROCESS.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -0
index 2e6923528342..b4cc74138f1e 100644
@@ -612,6 +612,9 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 	} else {
 		/* For CP queues on SOC15 */
 		if (restore_id) {
+			if (*restore_id >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
+				return -EINVAL;
+
 			/* make sure that ID is free  */
 			if (__test_and_set_bit(*restore_id, qpd->doorbell_bitmap))
 				return -EINVAL;
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

allocate_sdma_queue has an option where the sdma queue id can be specified (used by CRIU). We weren't bounds-checking that value.

Confirm it's less than the maximum number of queues.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
index b4cc74138f1e..ddbc4bd8ab10 100644
@@ -1727,6 +1727,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
 		}
 
 		if (restore_sdma_id) {
+			if (restore_sdma_id >= get_num_sdma_queues(dqm))
+				return -EINVAL;
+
 			/* Re-use existing sdma_id */
 			if (!test_bit(*restore_sdma_id, dqm->sdma_bitmap)) {
 				dev_err(dev, "SDMA queue already in use\n");
@@ -1753,6 +1756,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
 			return -ENOMEM;
 		}
 		if (restore_sdma_id) {
+			if (restore_sdma_id >= get_num_xgmi_sdma_queues(dqm))
+				return -EINVAL;
+
 			/* Re-use existing sdma_id */
 			if (!test_bit(*restore_sdma_id, dqm->xgmi_sdma_bitmap)) {
 				dev_err(dev, "SDMA queue already in use\n");
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

AMD General

This series Reviewed-by: Harish Kasiviswanathan <[email protected]>
________________________________
From: amd-gfx <[email protected]> on behalf of David Francis <[email protected]>
Sent: Tuesday, May 12, 2026 3:28 PM
To: [email protected] <[email protected]>
Cc: Francis, David <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

allocate_sdma_queue has an option where the sdma queue id can be specified (used by CRIU). We weren't bounds-checking that value.

Confirm it's less than the maximum number of queues.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
index b4cc74138f1e..ddbc4bd8ab10 100644
@@ -1727,6 +1727,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
                 }
 
                 if (restore_sdma_id) {
+                       if (restore_sdma_id >= get_num_sdma_queues(dqm))
+                               return -EINVAL;
+
                         /* Re-use existing sdma_id */
                         if (!test_bit(*restore_sdma_id, dqm->sdma_bitmap)) {
                                 dev_err(dev, "SDMA queue already in use\n");
@@ -1753,6 +1756,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
                         return -ENOMEM;
                 }
                 if (restore_sdma_id) {
+                       if (restore_sdma_id >= get_num_xgmi_sdma_queues(dqm))
+                               return -EINVAL;
+
                         /* Re-use existing sdma_id */
                         if (!test_bit(*restore_sdma_id, dqm->xgmi_sdma_bitmap)) {
                                 dev_err(dev, "SDMA queue already in use\n");

--
2.34.1

#3 lore raw

Re: [PATCH 2/2] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

Quoted 1 line

+ if (restore_sdma_id >= get_num_sdma_queues(dqm))

Just realized that an amend didn't go through; this should be *restore_sdma_id because restore_sdma_id is a pointer. (and similarly for the other changed line)

David Francis

________________________________________
From: Kasiviswanathan, Harish <[email protected]>
Sent: Tuesday, May 12, 2026 5:25 PM
To: Francis, David; [email protected]
Subject: Re: [PATCH 2/2] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

AMD General

This series Reviewed-by: Harish Kasiviswanathan <[email protected]>
________________________________
From: amd-gfx <[email protected]> on behalf of David Francis <[email protected]>
Sent: Tuesday, May 12, 2026 3:28 PM
To: [email protected] <[email protected]>
Cc: Francis, David <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id

allocate_sdma_queue has an option where the sdma queue id can be specified (used by CRIU). We weren't bounds-checking that value.

Confirm it's less than the maximum number of queues.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
index b4cc74138f1e..ddbc4bd8ab10 100644
@@ -1727,6 +1727,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
                 }
 
                 if (restore_sdma_id) {
+                       if (restore_sdma_id >= get_num_sdma_queues(dqm))
+                               return -EINVAL;
+
                         /* Re-use existing sdma_id */
                         if (!test_bit(*restore_sdma_id, dqm->sdma_bitmap)) {
                                 dev_err(dev, "SDMA queue already in use\n");
@@ -1753,6 +1756,9 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
                         return -ENOMEM;
                 }
                 if (restore_sdma_id) {
+                       if (restore_sdma_id >= get_num_xgmi_sdma_queues(dqm))
+                               return -EINVAL;
+
                         /* Re-use existing sdma_id */
                         if (!test_bit(*restore_sdma_id, dqm->xgmi_sdma_bitmap)) {
                                 dev_err(dev, "SDMA queue already in use\n");

--
2.34.1