Skip to content

Commit cea7a04

Browse files
committed
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. Signed-off-by: Oded Gabbay <[email protected]> Reviewed-by: Tomer Tayar <[email protected]>
1 parent b279b1f commit cea7a04

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

drivers/misc/habanalabs/command_submission.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,19 @@ static int validate_queue_index(struct hl_device *hdev,
499499
struct asic_fixed_properties *asic = &hdev->asic_prop;
500500
struct hw_queue_properties *hw_queue_prop;
501501

502+
/* This must be checked here to prevent out-of-bounds access to
503+
* hw_queues_props array
504+
*/
505+
if (chunk->queue_index >= HL_MAX_QUEUES) {
506+
dev_err(hdev->dev, "Queue index %d is invalid\n",
507+
chunk->queue_index);
508+
return -EINVAL;
509+
}
510+
502511
hw_queue_prop = &asic->hw_queues_props[chunk->queue_index];
503512

504-
if ((chunk->queue_index >= HL_MAX_QUEUES) ||
505-
(hw_queue_prop->type == QUEUE_TYPE_NA)) {
506-
dev_err(hdev->dev, "Queue index %d is invalid\n",
513+
if (hw_queue_prop->type == QUEUE_TYPE_NA) {
514+
dev_err(hdev->dev, "Queue index %d is not applicable\n",
507515
chunk->queue_index);
508516
return -EINVAL;
509517
}

0 commit comments

Comments
 (0)