Skip to contentSkip to conversation

habanalabs: prevent possible out-of-bounds array access

PATCH In review Oded Gabbay 2 participants 2 messages Jul 12, 2020 – Jul 13, 2020 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 habanalabs: prevent possible out-of-bounds array access

Queue index is received from the user. Therefore, we must validate it before using it to access the queue props array.

---
 drivers/misc/habanalabs/command_submission.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/command_submission.c +11 -3
index b0f62cbbdc87..f3a8f113865d 100644
@@ -499,11 +499,19 @@ static int validate_queue_index(struct hl_device *hdev,
 	struct asic_fixed_properties *asic = &hdev->asic_prop;
 	struct hw_queue_properties *hw_queue_prop;
 
+	/* This must be checked here to prevent out-of-bounds access to
+	 * hw_queues_props array
+	 */
+	if (chunk->queue_index >= HL_MAX_QUEUES) {
+		dev_err(hdev->dev, "Queue index %d is invalid\n",
+			chunk->queue_index);
+		return -EINVAL;
+	}
+
 	hw_queue_prop = &asic->hw_queues_props[chunk->queue_index];
 
-	if ((chunk->queue_index >= HL_MAX_QUEUES) ||
-			(hw_queue_prop->type == QUEUE_TYPE_NA)) {
-		dev_err(hdev->dev, "Queue index %d is invalid\n",
+	if (hw_queue_prop->type == QUEUE_TYPE_NA) {
+		dev_err(hdev->dev, "Queue index %d is not applicable\n",
 			chunk->queue_index);
 		return -EINVAL;
 	}
Signature · 1 line
2.17.1