Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Leon Romanovsky
Mon, 16 Nov 2026 09:35
Re: [PATCH V1 rdma-next 20/24] RDMA/mlx5: Clamp log_max_cq_sz shift in CQ size checks
Author: Leon Romanovsky
Date: Mon, 16 Nov 2026 09:35
Date: Mon, 16 Nov 2026 09:35
40 lines
9176 bytes
9176 bytes
On Tue, Nov 10, 2026 at 03:43:16PM +0200, Yishai Hadas wrote:
> The CQ create and resize paths check the requested size against
> 1 << log_max_cq_sz. The cap is 8 bits wide, so an untrusted NIC can
> report 31 or more, which makes the shift undefined. A large limit also
> lets the rounded up CQ size exceed INT_MAX, and it is then truncated
> when passed on as an int.
>
> Such a size also overflows the CQ buffer size, entries * cqe_size,
> which create_cq_user() and alloc_cq_frag_buf() compute as an int. A
> user CQ buffer smaller than the CQ the NIC is given then passes the
> umem size check, and a kernel CQ gets a zero-sized buffer that
> init_cq_frag_buf() writes to.
>
> Take the limit from MLX5_CAP_GEN_LOGSZ_U64(), round up in 64 bits, and
> reject sizes above INT_MAX. Compute the buffer size with
> check_mul_overflow(), as resize_user() already does.
>
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> ---
> drivers/infiniband/hw/mlx5/cq.c | 52 ++++++++++++++++++++++++---------
> 1 file changed, 39 insertions(+), 13 deletions(-)
<...>
> +/*
> + * Next power of 2 above entries. It can be 2^32, which doesn't fit the
> + * unsigned long of roundup_pow_of_two() on 32-bit archs.
This is not correct. unsigned long in the kernel continue to be 64bits
even for 32bits archs.
Thanks
> + */
> +static u64 cq_roundup_entries(u64 entries)
> +{
> + return 1ULL << fls64(entries);
> +}
> +
Re: [PATCH V1 rdma-next 20/24] RDMA/mlx5: Clamp log_max_cq_sz shift in CQ size checks
Author: Jason Gunthorpe
Date: Mon, 16 Nov 2026 19:19
Date: Mon, 16 Nov 2026 19:19
38 lines
12656 bytes
12656 bytes
On Mon, Nov 16, 2026 at 11:35:48AM +0200, Leon Romanovsky wrote: > On Tue, Nov 10, 2026 at 03:43:16PM +0200, Yishai Hadas wrote: > > The CQ create and resize paths check the requested size against > > 1 << log_max_cq_sz. The cap is 8 bits wide, so an untrusted NIC can > > report 31 or more, which makes the shift undefined. A large limit also > > lets the rounded up CQ size exceed INT_MAX, and it is then truncated > > when passed on as an int. > > > > Such a size also overflows the CQ buffer size, entries * cqe_size, > > which create_cq_user() and alloc_cq_frag_buf() compute as an int. A > > user CQ buffer smaller than the CQ the NIC is given then passes the > > umem size check, and a kernel CQ gets a zero-sized buffer that > > init_cq_frag_buf() writes to. > > > > Take the limit from MLX5_CAP_GEN_LOGSZ_U64(), round up in 64 bits, and > > reject sizes above INT_MAX. Compute the buffer size with > > check_mul_overflow(), as resize_user() already does. > > > > Signed-off-by: Yishai Hadas <yishaih@nvidia.com> > > --- > > drivers/infiniband/hw/mlx5/cq.c | 52 ++++++++++++++++++++++++--------- > > 1 file changed, 39 insertions(+), 13 deletions(-) > > <...> > > > +/* > > + * Next power of 2 above entries. It can be 2^32, which doesn't fit the > > + * unsigned long of roundup_pow_of_two() on 32-bit archs. > > This is not correct. unsigned long in the kernel continue to be 64bits > even for 32bits archs. We forget so quickly, long is 32 bit on 32 bit arches The kernel quirk is that u64 is uniformly 'unsigned long long' Jason
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads