linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Oded Gabbay <oded.gabbay@gmail.com>,
	Tomer Tayar <ttayar@habana.ai>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 5.4 05/17] habanalabs: prevent possible out-of-bounds array access
Date: Mon, 27 Jul 2020 19:24:08 -0400	[thread overview]
Message-ID: <20200727232420.717684-5-sashal@kernel.org> (raw)
In-Reply-To: <20200727232420.717684-1-sashal@kernel.org>

From: Oded Gabbay <oded.gabbay@gmail.com>

[ Upstream commit cea7a0449ea3fa4883bf5dc8397f000d6b67d6cd ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/misc/habanalabs/command_submission.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/habanalabs/command_submission.c b/drivers/misc/habanalabs/command_submission.c
index 447f307ef4d6f..ef95ee33cea40 100644
--- a/drivers/misc/habanalabs/command_submission.c
+++ b/drivers/misc/habanalabs/command_submission.c
@@ -400,15 +400,23 @@ static struct hl_cb *validate_queue_index(struct hl_device *hdev,
 	/* Assume external queue */
 	*ext_queue = true;
 
-	hw_queue_prop = &asic->hw_queues_props[chunk->queue_index];
-
-	if ((chunk->queue_index >= HL_MAX_QUEUES) ||
-			(hw_queue_prop->type == QUEUE_TYPE_NA)) {
+	/* 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 NULL;
 	}
 
+	hw_queue_prop = &asic->hw_queues_props[chunk->queue_index];
+
+	if (hw_queue_prop->type == QUEUE_TYPE_NA) {
+		dev_err(hdev->dev, "Queue index %d is not applicable\n",
+			chunk->queue_index);
+		return -EINVAL;
+	}
+
 	if (hw_queue_prop->driver_only) {
 		dev_err(hdev->dev,
 			"Queue index %d is restricted for the kernel driver\n",
-- 
2.25.1


  parent reply	other threads:[~2020-07-27 23:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 23:24 [PATCH AUTOSEL 5.4 01/17] usb: hso: Fix debug compile warning on sparc32 Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 02/17] selftests: fib_nexthop_multiprefix: fix cleanup() netns deletion Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 03/17] qed: Disable "MFW indication via attention" SPAM every 5 minutes Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 04/17] selftests: net: ip_defrag: modprobe missing nf_defrag_ipv6 support Sasha Levin
2020-07-27 23:24 ` Sasha Levin [this message]
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 06/17] nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 07/17] scsi: core: Run queue in case of I/O resource contention failure Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 08/17] parisc: add support for cmpxchg on u8 pointers Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 09/17] net: ethernet: ravb: exit if re-initialization fails in tx timeout Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 10/17] drivers/net/wan/x25_asy: Fix to make it work Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 11/17] Revert "i2c: cadence: Fix the hold bit setting" Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 12/17] x86/unwind/orc: Fix ORC for newly forked tasks Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 13/17] x86/stacktrace: Fix reliable check for empty user task stacks Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 14/17] cxgb4: add missing release on skb in uld_send() Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 15/17] xen-netfront: fix potential deadlock in xennet_remove() Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 16/17] RISC-V: Set maximum number of mapped pages correctly Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 17/17] drivers/net/wan: lapb: Corrected the usage of skb_cow Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200727232420.717684-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oded.gabbay@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=ttayar@habana.ai \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).