Skip to content

Commit b62e185

Browse files
committed
Merge tag 'misc-habanalabs-fixes-2020-07-19' of git://people.freedesktop.org/~gabbayo/linux into char-misc-linus
Oded writes: This tag contains a single bug fix for 5.8-rc7: - Check that an index is in valid range before using it to access an array. The index is received from the user. This is to prevent a possible out-of-bounds access error. * tag 'misc-habanalabs-fixes-2020-07-19' of git://people.freedesktop.org/~gabbayo/linux: habanalabs: prevent possible out-of-bounds array access
2 parents 120c8a4 + cea7a04 commit b62e185

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)