]> git.baikalelectronics.ru Git - kernel.git/commitdiff
habanalabs: prevent possible out-of-bounds array access
authorOded Gabbay <oded.gabbay@gmail.com>
Sun, 12 Jul 2020 20:34:57 +0000 (23:34 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Sun, 19 Jul 2020 05:15:36 +0000 (08:15 +0300)
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 <oded.gabbay@gmail.com>
Reviewed-by: Tomer Tayar <ttayar@habana.ai>
drivers/misc/habanalabs/command_submission.c

index b0f62cbbdc878d945827ffd4063aa956dc2d56a1..f3a8f113865d2b06fc1e587c06da7212756c9000 100644 (file)
@@ -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;
        }