From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C54D30B500 for ; Mon, 29 Sep 2025 14:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759156734; cv=none; b=V67c23ZCZ4912VmqpcX0doVJNUKIvZSTbArmwAsILvOYKkMY8logvokkkyEYOUgYBSTots98VN2qljVcyggwc6orAnlavwwiKF0Nq7EQXL+sg/oOyatSBhuncQ3Cz/ZnfSPWypn3Ma4Ek+qjIbYG8ACE0PEGIHFtq8pFNeaHhKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759156734; c=relaxed/simple; bh=ZsO7vwKm1jXuVZmumm15qa170vzbnsQVChSUZXC6rAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QGA4o5RQ+LxwJ6HGQEUC6erfDlBttjTJKm2nfZxTmwUjqg/l8IdwQshKHWSFjVAclIzE1cA+zt860fVEJfbMvwOI4eXyTPafeLPsccRSfPBDfGRetFH0DUVq5TwMdM8KVTojeIjY9HHhBt6gDN+kkMRWn1g19NE6Hg9uvm3zniU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XZg2YxzE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XZg2YxzE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11431C116C6; Mon, 29 Sep 2025 14:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759156733; bh=ZsO7vwKm1jXuVZmumm15qa170vzbnsQVChSUZXC6rAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZg2YxzEOFHOvjSSEilASNtc5z4OK7x7ejfxiu2P2uHPS+tNIlyxW9Lj52p7xdzyK I15dL3IyN0xDOkj+zI8XcPtWZyADsvDJ5rtBJ2k9B3q4vBPsF/vvzyuDqwrGlonux7 X19h7MkMBmRa71k6Y1HRvk4F5VRShlquy6Ck15Zqijnms1t3Ix3pz0SU8xpbOA00dR GWI3WOZdSc9/JvnIjd6k1zmhAGsEV45tzzSzjkz+yZmShJ1Ca/cuR7dLRP/qlMFM0i CwHd+BiUc6puSI41ji8+ZYT1HJRLenbV8N+F9uwvp1VBVFjNQlXcCHi6TtKEfKRyC+ mvVZOvxxOJYXQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Lukasz Czapnik , Aleksandr Loktionov , Przemek Kitszel , Simon Horman , Rafal Romanowski , Tony Nguyen , Sasha Levin Subject: [PATCH 5.15.y 2/2] i40e: add validation for ring_len param Date: Mon, 29 Sep 2025 10:38:50 -0400 Message-ID: <20250929143850.92375-2-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250929143850.92375-1-sashal@kernel.org> References: <2025092935-hatred-salutary-8769@gregkh> <20250929143850.92375-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lukasz Czapnik [ Upstream commit 55d225670def06b01af2e7a5e0446fbe946289e8 ] The `ring_len` parameter provided by the virtual function (VF) is assigned directly to the hardware memory context (HMC) without any validation. To address this, introduce an upper boundary check for both Tx and Rx queue lengths. The maximum number of descriptors supported by the hardware is 8k-32. Additionally, enforce alignment constraints: Tx rings must be a multiple of 8, and Rx rings must be a multiple of 32. Fixes: 5c3c48ac6bf5 ("i40e: implement virtual device interface") Cc: stable@vger.kernel.org Signed-off-by: Lukasz Czapnik Reviewed-by: Aleksandr Loktionov Signed-off-by: Przemek Kitszel Reviewed-by: Simon Horman Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index 7673ce2be1c02..bc79c6057e9e7 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -653,6 +653,13 @@ static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id, /* only set the required fields */ tx_ctx.base = info->dma_ring_addr / 128; + + /* ring_len has to be multiple of 8 */ + if (!IS_ALIGNED(info->ring_len, 8) || + info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) { + ret = -EINVAL; + goto error_context; + } tx_ctx.qlen = info->ring_len; tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]); tx_ctx.rdylist_act = 0; @@ -718,6 +725,13 @@ static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id, /* only set the required fields */ rx_ctx.base = info->dma_ring_addr / 128; + + /* ring_len has to be multiple of 32 */ + if (!IS_ALIGNED(info->ring_len, 32) || + info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) { + ret = -EINVAL; + goto error_param; + } rx_ctx.qlen = info->ring_len; if (info->splithdr_enabled) { -- 2.51.0