Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp444973pxb; Thu, 9 Sep 2021 04:45:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl9Sw9lKES8gEvHG9/JGWEyjsVc1vWpQ94HhTlw5Y9mwsJSXT8niD20RADniLR0L9o+ugj X-Received: by 2002:a92:dd88:: with SMTP id g8mr61375iln.306.1631187944025; Thu, 09 Sep 2021 04:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631187944; cv=none; d=google.com; s=arc-20160816; b=x7J3emIwAF4SDv39Wc5wLw4tW1SZzvosjbmojVCeWHoFjG2Mwn/qfxjg9wpF7i2k/u 1L63RxmzE+JYQE+OkiZls51s9XRT1pBfRqOhxWo64jIc0egSU5lYJKcZiEyvbM0a0wf8 ROS4lOfoGFzNMYVFRznsw5t7LmPgWPHQU7GyNo2CNZELspymYhEpXw0pF2+P02TVgSZf hpP1gwD9qm80y5Kq22g4ZApkXNEQZaqCckVsv8d4qRzyQ25ZyL15GCllM2T2IPdOMJ6V GJe9YAS/VaXRCZFvPST75OYMQTPSboBDPAMjRvDNTNI8g7N5QABZ5yR/DPm87xWxYDdB fGJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=309tNI+unOEw2R8dKKbDgrjlvnkzZIyJDaz/qobBRnc=; b=Ax4rUENb99t0xpd2gvqmclOY0wArCFmR8w2H6/qYtuUyWfqS/qg7lFd+DudmOQSikh qToen5/wDmXLNnQe13y1g9XF68Sn6SfsTe7T/xl2wP9h0qUxUts6R38DSDBb/ugtSioA 45D8rpQiGACMsHqEXCoQuwZ2v+0P//R3kGTsPk1bb60nzOIWNAwdNbVZdKASwcVLxsC1 Zwc0VtoS8ylwVABvwnnR3TyYde8mcqpU7mGnRz1MWNj+tBG1ap9PT1+ni7pygSzJzA21 DuJ4KQZOH0v6Ixd9z+c0f7JkBDpB6cWvwmKJi+X1VPcq6KNxrM4lhdRr9BabP/PElpAO cMfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rhd6EXTF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 20si1364406ioz.25.2021.09.09.04.45.32; Thu, 09 Sep 2021 04:45:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rhd6EXTF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238416AbhIILpH (ORCPT + 99 others); Thu, 9 Sep 2021 07:45:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237468AbhIILnF (ORCPT ); Thu, 9 Sep 2021 07:43:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F22D661205; Thu, 9 Sep 2021 11:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187715; bh=VIATtPJ0D92dbWg+eENiigWc7KCEyc/ZyJO/wyvcxVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rhd6EXTFNGu66ve6n60xiwHOPAFHZXb4AfAKbvH4qqUYQqR1joA6YYSLawJ0TFcRN f+l3lUybcyHenNfaDZMXxtZVGvIA12s4VFpYrIla8zNLa61d0it47F/otE/xwJplyJ OpZ4FQPlMjApVSLfpjgmpqIYurdA1MHs3EYCLRcWFUfNoLrYvXPRrF6YgrDGX7mzjp xRTk2XY+DKoLXXnaADEMDCn6xPyc8eH6fumK4Djhaw7YGvhpFB1DFVI2+aKrqrlL99 I4Lt1QS9Sk+q3IQuoeY1yJgldgaIT/NWl8ARRz+OMDS07B5YntjWxvB3KqhyDt5cPd BjEp23so8w51A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sasha Neftin , Aleksandr Loktionov , Dvora Fuxbrumer , Tony Nguyen , Sasha Levin , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 038/252] igc: Check if num of q_vectors is smaller than max before array access Date: Thu, 9 Sep 2021 07:37:32 -0400 Message-Id: <20210909114106.141462-38-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sasha Neftin [ Upstream commit 373e2829e7c2e1e606503cdb5c97749f512a4be9 ] Ensure that the adapter->q_vector[MAX_Q_VECTORS] array isn't accessed beyond its size. It was fixed by using a local variable num_q_vectors as a limit for loop index, and ensure that num_q_vectors is not bigger than MAX_Q_VECTORS. Suggested-by: Aleksandr Loktionov Signed-off-by: Sasha Neftin Tested-by: Dvora Fuxbrumer Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igc/igc_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index ed2d66bc2d6c..f62982c4d933 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -4817,6 +4817,7 @@ static irqreturn_t igc_msix_ring(int irq, void *data) */ static int igc_request_msix(struct igc_adapter *adapter) { + unsigned int num_q_vectors = adapter->num_q_vectors; int i = 0, err = 0, vector = 0, free_vector = 0; struct net_device *netdev = adapter->netdev; @@ -4825,7 +4826,13 @@ static int igc_request_msix(struct igc_adapter *adapter) if (err) goto err_out; - for (i = 0; i < adapter->num_q_vectors; i++) { + if (num_q_vectors > MAX_Q_VECTORS) { + num_q_vectors = MAX_Q_VECTORS; + dev_warn(&adapter->pdev->dev, + "The number of queue vectors (%d) is higher than max allowed (%d)\n", + adapter->num_q_vectors, MAX_Q_VECTORS); + } + for (i = 0; i < num_q_vectors; i++) { struct igc_q_vector *q_vector = adapter->q_vector[i]; vector++; -- 2.30.2