Article View: linux.kernel.netdev
Article #17005Re: [PATCH V1 rdma-next 22/24] RDMA/mlx5: Clamp log_max_* shifts in query_device and ucontext paths
From: Leon Romanovsky
Date: Mon, 16 Nov 2026 09:06
Date: Mon, 16 Nov 2026 09:06
80 lines
10557 bytes
10557 bytes
On Tue, Nov 10, 2026 at 03:43:18PM +0200, Yishai Hadas wrote: > The device, port and ucontext attributes and the SRQ size limit are > computed as 1 << cap from log_max_* FW capabilities. An untrusted NIC > can report 31 or more, which makes the shift undefined. The same > applies to 1ull << log_pg_sz with a value of 64 or more, and to the > max_tso computed as 1 << max_lso_cap, which can be 31. > > Use MLX5_CAP_GEN_LOGSZ_U32() and MLX5_CAP_GEN_LOGSZ_U64() for these > values, and BIT() for max_tso. As the limits can now reach 2^31, > compute max_qp_wr in 64 bits and saturate the max_res_rd_atom and > max_total_mcast_qp_attach products at U32_MAX. Cap max_cqe at 2^30 - 1, > the largest CQ size the create path accepts. > > The SRQ size limit then lets the rounded up SRQ size overflow the int > srq->msrq.max, and the SRQ buffer size exceed the int passed to > create_srq_user() and create_srq_kernel(). Reject both above INT_MAX, > computing the buffer size with check_mul_overflow(). > > Signed-off-by: Yishai Hadas <yishaih@nvidia.com> > --- > drivers/infiniband/hw/mlx5/mad.c | 2 +- > drivers/infiniband/hw/mlx5/main.c | 65 +++++++++++++++++-------------- > drivers/infiniband/hw/mlx5/srq.c | 14 +++++-- > 3 files changed, 46 insertions(+), 35 deletions(-) <...> > + /* The CQ size is a power of two that fits in an int */ > + props->max_cqe = min_t(u32, MLX5_CAP_GEN_LOGSZ_U32(mdev, log_max_cq_sz), > + rounddown_pow_of_two(INT_MAX)) - 1; <...> > + props->max_res_rd_atom = min_t(u64, (u64)props->max_qp_rd_atom * props->max_qp, > + U32_MAX); Avoid min_t() where possible: it silently casts operands to the specified type instead of checking that their types match. <...> > + props->max_total_mcast_qp_attach = > + min_t(u64, (u64)props->max_mcast_qp_attach * props->max_mcast_grp, > + U32_MAX); <...> > + /* srq->msrq.max is an int */ > + max = roundup_pow_of_two(init_attr->attr.max_wr + 1); > + if (max > INT_MAX) Please fix types instead of doing this check. > + return -EINVAL; > + srq->msrq.max = max; > srq->msrq.max_gs = init_attr->attr.max_sge; > > desc_size = sizeof(struct mlx5_wqe_srq_next_seg) + > @@ -238,8 +243,9 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq, > srq->msrq.max_avail_gather = (desc_size - sizeof(struct mlx5_wqe_srq_next_seg)) / > sizeof(struct mlx5_wqe_data_seg); > srq->msrq.wqe_shift = ilog2(desc_size); > - buf_size = srq->msrq.max * desc_size; > - if (buf_size < desc_size) > + /* create_srq_user() and create_srq_kernel() take an int */ > + if (check_mul_overflow((size_t)srq->msrq.max, desc_size, &buf_size) || > + buf_size > INT_MAX) Same Thanks. > return -EINVAL; > > in.type = init_attr->srq_type; > -- > 2.18.1 > >
Technical Details
Message-ID:
<20261116090653.GD11319@unreal>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364125-linux-kernel-netdev=dewy.ruReferences:
<20261110134320.34408-1-yishaih@nvidia.com> <20261110134320.34408-23-yishaih@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364125-linux-kernel-netdev=dewy.ru From: leon@kernel.org (Leon Romanovsky) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH V1 rdma-next 22/24] RDMA/mlx5: Clamp log_max_* shifts in query_device and ucontext paths Date: Mon, 16 Nov 2026 11:06:53 +0200 Organization: Usenet Network Message-ID: <20261116090653.GD11319@unreal> References: <20261110134320.34408-1-yishaih@nvidia.com> <20261110134320.34408-23-yishaih@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="2017239"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:3RjniiwKmI6h8iWzzsn10GL8CYY= sha256:q6x7CZpE53wz3B+qkUcIm5tVqDtdvG6+2l0PutnvS04= sha1:qzRfz061KPSGvPfJSD9Vbh2MQhI= sha256:niJ9/BsSU2AG1DrE6D0FYLyEdPPJNqyvA4wZMsHrURc= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id BB3F3114B6D; Mon, 16 Nov 2026 12:07:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qDXK8XmufGaM; Mon, 16 Nov 2026 12:07:29 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364125-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id F268C114B19; Mon, 16 Nov 2026 12:07:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id F304438FE8; Mon, 16 Nov 2026 09:07:08 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794820024; b=Pa94NG78FS0IaelG2/HMfWTpcYaUfiDzcp2Fpv5pT8nvhQXQQoj3NJm8KaE4iiKRF9u7 MI0KEAEw2wpYOEYImOmx+gilMqXisgdv5Jkc68fn4LGPmhVbAUgatIe+va/pgidCJ/mBV CWMW9N+GJ29HHwZxWNXDmghzMFFpdOh6YtI6Y0PBnY+urbU2rxle7SUsSVMI1Kubl+UWi hqbJ2D6eV0PP8BQvx9vNFIEvZkc1/t5eUd4bpbxaaiqIvWMOy45M234jHUpBJg8rm1zS0 R25oMmPfj1986DoYa9uE3dsUZ7NukQAD5CO+Wd14ADke+hptG8XxOVhoA9luiEncuVg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794820024; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=HzdFWao8nHMu2yPSIorlZRQ2GzCXWpvPZ8IlfEMR3o8=; b=yy23GJVIRtTtZd8+QdlPP57gwBnhZHNJ2asyOEY+TwhJCjvQIIO6PNFRtMNixffViZRr +wU+XjN6GJiogzrNVKFA1hneh1p3UHXXP+/VWFFhNttdMsxCUrGVflA4ByRazLcOe6iUs BCpvx7yTfkwZHjbEUP6A7QbKwqHb6DVa7a34ZURPd4NYo1xVoJwxhrSfLgP056PaQuOZQ 8veXjL8H5FACb54iMtC3MxGAqvaVMfcYRPI7c4BLlSI/uFLH7xdi93U26Dya56ZjkwWYW JqD/DA4M4jdEL2LyOZaJcCreWSvxWke0b+2uBRU4EEkLLXMbsu3/DXjvXYxb/v/msOA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZYH9Cbpk; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03600606A331; Mon, 16 Nov 2026 09:07:04 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZYH9Cbpk X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794820017; b=5cVqpnsjNiTXCY3B0oKIqANSN63T65gqBmqFHco421iDQLehr6sYqkCXynmh5NXfjjdk Bj8od6SewJ8j30GZzJad2BjK7uV1hNl55kyHQSYdtdW7YEngRF7wDnza/0ffnpDG6B7E9 288/Wfzm2cZaCydeBW5Wf62i8qiiLUuhOLO43OCyMpB7ra9pnI4VzDR+NwIasBLU83ZGR J+6jHwX/yCfAeFjwT8ji/SH4xqUx21tjGoW5tK92z3Ck4pB6HYFhEAXzAi11B81Ke4AUb 6sd0zoxrAHYjLbTrvaICZLqCk5vt/osGCZ9rVfr2ELDSB5gp6G42WOrWdxKQdTdvHYg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794820017; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=HzdFWao8nHMu2yPSIorlZRQ2GzCXWpvPZ8IlfEMR3o8=; b=EOQneq9gnliQyCebVUu6Bv4CDcpAAlYn0Ac3jK/LceOk5DWeQ5W4bBYKnd6fx6wZqhWY BqLG7r6sMJ1FruJ9Vb9hk9CUWY3BG1XG2+dikWy6mCSAbP+h3vuEhm+Nyr547MlgmVpzG +liYCq+q1L4ZW1IVK3ytvUxPP5DIy9oU6XY9b5Qr/Sa5iC4cvj2Ce0ixqa/YFR2ByS7+1 p5vVnN4EiTIfA4OxJg+QE+bVxk2pf9nSPYrq7vICJtepZKuIM4vAr3iW1ZAkrmqpCGyCA /6q5100c5ZF71CSzurPkd4aMqjBp5VvgnWBpW1WIY7lmEF2Nj80wCA5jmcbzeWt5OOA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZYH9Cbpk; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1456C606A31C; Mon, 16 Nov 2026 09:06:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01C3A1F000C7; Mon, 16 Nov 2026 09:06:55 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794820016; bh=HzdFWao8nHMu2yPSIorlZRQ2GzCXWpvPZ8IlfEMR3o8=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ZYH9CbpkF8jZNGpDn/tzJlFp7sjGDNM9JrH0ksokOFYsYIMI3JdzuxgiggfSnk2Zf xgH1p3c3i2eusMJCdKDHwUhS3KE3G6CgLUJYsm8x4PNGKP05z8c9wElhhFj9sgMovM rgwy/IKg+pHtu6dic4LILzUoC3FAPmOoPF64vKslCjEC4uBGFWwN3gjCoKc1ooi5ey +MAeOuL4+KXNDdEPn19Wc4btraNZr6T+bCdwWndq4fRBd+f9NWkHH8Oq2JZDR/9oVI F0EKXE9ml2kJ9GHgRSEvGgDJlkEJ/HhONeskhWnqeqP/Re807Ki18gzXxGRfP5Kv7Z XtyGQTMX3X5+Q== X-Cc: jgg@ziepe.ca, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org, davem@davemloft.net, andrew+netdev@lunn.ch, dtatulea@nvidia.com, moshe@nvidia.com, maorg@nvidia.com X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261110134320.34408-23-yishaih@nvidia.com>