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 C4EF5149E03; Tue, 25 Jun 2024 09:43:14 +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=1719308594; cv=none; b=WDJONyxqCyAurxefhel3XFMZ2DwxYmEqhymUqAYh1yJ91coln7qI/nGBLoWSqv3RknDFH7tYmznvoBIhw/D/R2Uu+CSuBbcQU7dSkEKCDG9s2X8t7Ow3rGe2gwARzDQvNi+jmb+p7txcHTK/MBSwE56zh1gpZmM6SeApsJPgbxQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719308594; c=relaxed/simple; bh=ylIDHTLw9sifm/FJVBWF76PD3kjDcPhVxlQzwhH2ZiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c/UmSS/BojdQdUUCYq8xDTUmQ3bJduSe2X6+iLJBwwVF0t/UFuc+59cSRnKO6Ys5rBnqTZok8wjqEcC27WJwF/hUkGpTY9ozwUmzAd/O49y6d27NAN6lD17Xgvoy8+h2yalS3OrCGchVxUyi7CigWkZRF6JcoXWTHUbnWSNWkas= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cTCLvqvU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cTCLvqvU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43A09C32781; Tue, 25 Jun 2024 09:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1719308594; bh=ylIDHTLw9sifm/FJVBWF76PD3kjDcPhVxlQzwhH2ZiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cTCLvqvU9JmClnXQanHaxcdANOW0ueY82j08hZsNtUdc6VDSdini7VyYoy7iiidcD 5ysHrkxUlLIo5ikD/7qdXRBChsxhJDoGJNEPl2C8zeRnxZADEvtx93YWJ4tA6pr2Ft cgbO4f+hapVPcLXQ1z6Tg+v/cP2+9JtYVlIW/5+c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Patrisious Haddad , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.9 175/250] RDMA/mlx5: Add check for srq max_sge attribute Date: Tue, 25 Jun 2024 11:32:13 +0200 Message-ID: <20240625085554.768520475@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240625085548.033507125@linuxfoundation.org> References: <20240625085548.033507125@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Patrisious Haddad [ Upstream commit 36ab7ada64caf08f10ee5a114d39964d1f91e81d ] max_sge attribute is passed by the user, and is inserted and used unchecked, so verify that the value doesn't exceed maximum allowed value before using it. Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Patrisious Haddad Link: https://lore.kernel.org/r/277ccc29e8d57bfd53ddeb2ac633f2760cf8cdd0.1716900410.git.leon@kernel.org Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx5/srq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c index a056ea835da54..84be0c3d56995 100644 --- a/drivers/infiniband/hw/mlx5/srq.c +++ b/drivers/infiniband/hw/mlx5/srq.c @@ -199,17 +199,20 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq, int err; struct mlx5_srq_attr in = {}; __u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); + __u32 max_sge_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq) / + sizeof(struct mlx5_wqe_data_seg); if (init_attr->srq_type != IB_SRQT_BASIC && init_attr->srq_type != IB_SRQT_XRC && init_attr->srq_type != IB_SRQT_TM) return -EOPNOTSUPP; - /* Sanity check SRQ size before proceeding */ - if (init_attr->attr.max_wr >= max_srq_wqes) { - mlx5_ib_dbg(dev, "max_wr %d, cap %d\n", - init_attr->attr.max_wr, - max_srq_wqes); + /* Sanity check SRQ and sge size before proceeding */ + if (init_attr->attr.max_wr >= max_srq_wqes || + init_attr->attr.max_sge > max_sge_sz) { + mlx5_ib_dbg(dev, "max_wr %d,wr_cap %d,max_sge %d, sge_cap:%d\n", + init_attr->attr.max_wr, max_srq_wqes, + init_attr->attr.max_sge, max_sge_sz); return -EINVAL; } -- 2.43.0