* [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
@ 2026-03-12 18:16 Erni Sri Satya Vennela
2026-03-12 18:43 ` Long Li
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Erni Sri Satya Vennela @ 2026-03-12 18:16 UTC (permalink / raw)
To: longli, kotaranov, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
linux-hyperv, linux-kernel
Cc: Erni Sri Satya Vennela
As part of MANA hardening for CVM, clamp hardware-reported adapter
capability values from the MANA_IB_GET_ADAPTER_CAP response before
they are used by the IB subsystem.
The response fields (max_qp_count, max_cq_count, max_mr_count,
max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
assigned to signed int members in struct ib_device_attr. If hardware
returns a value exceeding INT_MAX, the implicit u32-to-int conversion
produces a negative value, which can cause incorrect behavior in the
IB core and userspace applications.
Clamp these fields to INT_MAX in mana_ib_gd_query_adapter_caps() so
all downstream consumers receive safe values.
Additionally, fix an integer overflow in mana_ib_query_device() where
max_res_rd_atom is computed as max_qp_rd_atom * max_qp. Both operands
are int and the multiplication can overflow. Widen to s64 before
multiplying and clamp the result to INT_MAX.
Signed-off-by: Erni Sri Satya Vennela <ernis@linux.microsoft.com>
---
Changes in v2:
* Update patch title.
---
drivers/infiniband/hw/mana/main.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 8d99cd00f002..2869660077ef 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -599,7 +599,8 @@ int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
props->max_mr = dev->adapter_caps.max_mr_count;
props->max_pd = dev->adapter_caps.max_pd_count;
props->max_qp_rd_atom = dev->adapter_caps.max_inbound_read_limit;
- props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
+ props->max_res_rd_atom =
+ min_t(s64, (s64)props->max_qp_rd_atom * props->max_qp, INT_MAX);
props->max_qp_init_rd_atom = dev->adapter_caps.max_outbound_read_limit;
props->atomic_cap = IB_ATOMIC_NONE;
props->masked_atomic_cap = IB_ATOMIC_NONE;
@@ -694,20 +695,22 @@ int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *dev)
caps->max_sq_id = resp.max_sq_id;
caps->max_rq_id = resp.max_rq_id;
caps->max_cq_id = resp.max_cq_id;
- caps->max_qp_count = resp.max_qp_count;
- caps->max_cq_count = resp.max_cq_count;
- caps->max_mr_count = resp.max_mr_count;
- caps->max_pd_count = resp.max_pd_count;
- caps->max_inbound_read_limit = resp.max_inbound_read_limit;
- caps->max_outbound_read_limit = resp.max_outbound_read_limit;
+ caps->max_qp_count = min_t(u32, resp.max_qp_count, INT_MAX);
+ caps->max_cq_count = min_t(u32, resp.max_cq_count, INT_MAX);
+ caps->max_mr_count = min_t(u32, resp.max_mr_count, INT_MAX);
+ caps->max_pd_count = min_t(u32, resp.max_pd_count, INT_MAX);
+ caps->max_inbound_read_limit = min_t(u32, resp.max_inbound_read_limit,
+ INT_MAX);
+ caps->max_outbound_read_limit = min_t(u32, resp.max_outbound_read_limit,
+ INT_MAX);
caps->mw_count = resp.mw_count;
caps->max_srq_count = resp.max_srq_count;
caps->max_qp_wr = min_t(u32,
resp.max_requester_sq_size / GDMA_MAX_SQE_SIZE,
resp.max_requester_rq_size / GDMA_MAX_RQE_SIZE);
caps->max_inline_data_size = resp.max_inline_data_size;
- caps->max_send_sge_count = resp.max_send_sge_count;
- caps->max_recv_sge_count = resp.max_recv_sge_count;
+ caps->max_send_sge_count = min_t(u32, resp.max_send_sge_count, INT_MAX);
+ caps->max_recv_sge_count = min_t(u32, resp.max_recv_sge_count, INT_MAX);
caps->feature_flags = resp.feature_flags;
caps->page_size_cap = PAGE_SZ_BM;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* RE: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-12 18:16 [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP Erni Sri Satya Vennela
@ 2026-03-12 18:43 ` Long Li
2026-03-12 22:48 ` Jason Gunthorpe
2026-03-16 19:49 ` Leon Romanovsky
2 siblings, 0 replies; 8+ messages in thread
From: Long Li @ 2026-03-12 18:43 UTC (permalink / raw)
To: Erni Sri Satya Vennela, Konstantin Taranov, Jason Gunthorpe,
Leon Romanovsky, linux-rdma@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
> Subject: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter
> capability values from MANA_IB_GET_ADAPTER_CAP
>
> As part of MANA hardening for CVM, clamp hardware-reported adapter capability
> values from the MANA_IB_GET_ADAPTER_CAP response before they are used by
> the IB subsystem.
>
> The response fields (max_qp_count, max_cq_count, max_mr_count,
> max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> assigned to signed int members in struct ib_device_attr. If hardware returns a
> value exceeding INT_MAX, the implicit u32-to-int conversion produces a negative
> value, which can cause incorrect behavior in the IB core and userspace
> applications.
>
> Clamp these fields to INT_MAX in mana_ib_gd_query_adapter_caps() so all
> downstream consumers receive safe values.
>
> Additionally, fix an integer overflow in mana_ib_query_device() where
> max_res_rd_atom is computed as max_qp_rd_atom * max_qp. Both operands
> are int and the multiplication can overflow. Widen to s64 before multiplying and
> clamp the result to INT_MAX.
>
> Signed-off-by: Erni Sri Satya Vennela <ernis@linux.microsoft.com>
Reviewed-by: Long Li <longli@microsoft.com>
> ---
> Changes in v2:
> * Update patch title.
> ---
> drivers/infiniband/hw/mana/main.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/infiniband/hw/mana/main.c
> b/drivers/infiniband/hw/mana/main.c
> index 8d99cd00f002..2869660077ef 100644
> --- a/drivers/infiniband/hw/mana/main.c
> +++ b/drivers/infiniband/hw/mana/main.c
> @@ -599,7 +599,8 @@ int mana_ib_query_device(struct ib_device *ibdev, struct
> ib_device_attr *props,
> props->max_mr = dev->adapter_caps.max_mr_count;
> props->max_pd = dev->adapter_caps.max_pd_count;
> props->max_qp_rd_atom = dev->adapter_caps.max_inbound_read_limit;
> - props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
> + props->max_res_rd_atom =
> + min_t(s64, (s64)props->max_qp_rd_atom * props->max_qp,
> INT_MAX);
> props->max_qp_init_rd_atom = dev-
> >adapter_caps.max_outbound_read_limit;
> props->atomic_cap = IB_ATOMIC_NONE;
> props->masked_atomic_cap = IB_ATOMIC_NONE; @@ -694,20 +695,22
> @@ int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *dev)
> caps->max_sq_id = resp.max_sq_id;
> caps->max_rq_id = resp.max_rq_id;
> caps->max_cq_id = resp.max_cq_id;
> - caps->max_qp_count = resp.max_qp_count;
> - caps->max_cq_count = resp.max_cq_count;
> - caps->max_mr_count = resp.max_mr_count;
> - caps->max_pd_count = resp.max_pd_count;
> - caps->max_inbound_read_limit = resp.max_inbound_read_limit;
> - caps->max_outbound_read_limit = resp.max_outbound_read_limit;
> + caps->max_qp_count = min_t(u32, resp.max_qp_count, INT_MAX);
> + caps->max_cq_count = min_t(u32, resp.max_cq_count, INT_MAX);
> + caps->max_mr_count = min_t(u32, resp.max_mr_count, INT_MAX);
> + caps->max_pd_count = min_t(u32, resp.max_pd_count, INT_MAX);
> + caps->max_inbound_read_limit = min_t(u32,
> resp.max_inbound_read_limit,
> + INT_MAX);
> + caps->max_outbound_read_limit = min_t(u32,
> resp.max_outbound_read_limit,
> + INT_MAX);
> caps->mw_count = resp.mw_count;
> caps->max_srq_count = resp.max_srq_count;
> caps->max_qp_wr = min_t(u32,
> resp.max_requester_sq_size /
> GDMA_MAX_SQE_SIZE,
> resp.max_requester_rq_size /
> GDMA_MAX_RQE_SIZE);
> caps->max_inline_data_size = resp.max_inline_data_size;
> - caps->max_send_sge_count = resp.max_send_sge_count;
> - caps->max_recv_sge_count = resp.max_recv_sge_count;
> + caps->max_send_sge_count = min_t(u32, resp.max_send_sge_count,
> INT_MAX);
> + caps->max_recv_sge_count = min_t(u32, resp.max_recv_sge_count,
> +INT_MAX);
> caps->feature_flags = resp.feature_flags;
>
> caps->page_size_cap = PAGE_SZ_BM;
> --
> 2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-12 18:16 [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP Erni Sri Satya Vennela
2026-03-12 18:43 ` Long Li
@ 2026-03-12 22:48 ` Jason Gunthorpe
2026-03-16 19:49 ` Leon Romanovsky
2 siblings, 0 replies; 8+ messages in thread
From: Jason Gunthorpe @ 2026-03-12 22:48 UTC (permalink / raw)
To: Erni Sri Satya Vennela
Cc: longli, kotaranov, Leon Romanovsky, linux-rdma, linux-hyperv,
linux-kernel
On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> The response fields (max_qp_count, max_cq_count, max_mr_count,
> max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> assigned to signed int members in struct ib_device_attr.
There is no reason they should be signed, you should just fix the
type.
I'm also not convinced clamping to such a high value has any value
whatsoever, as it probably still triggers maths overflows elsewhere. I
think you should clamp to reasonable limits for your device if you
want to do this.
Jason
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-12 18:16 [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP Erni Sri Satya Vennela
2026-03-12 18:43 ` Long Li
2026-03-12 22:48 ` Jason Gunthorpe
@ 2026-03-16 19:49 ` Leon Romanovsky
2026-03-16 20:50 ` [EXTERNAL] " Long Li
2 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2026-03-16 19:49 UTC (permalink / raw)
To: Erni Sri Satya Vennela
Cc: longli, kotaranov, Jason Gunthorpe, linux-rdma, linux-hyperv,
linux-kernel
On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> As part of MANA hardening for CVM, clamp hardware-reported adapter
> capability values from the MANA_IB_GET_ADAPTER_CAP response before
> they are used by the IB subsystem.
>
> The response fields (max_qp_count, max_cq_count, max_mr_count,
> max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> assigned to signed int members in struct ib_device_attr. If hardware
> returns a value exceeding INT_MAX, the implicit u32-to-int conversion
> produces a negative value, which can cause incorrect behavior in the
> IB core and userspace applications.
This sentence does not make sense in the context of the Linux kernel.
The fundamental assumption is that the underlying hardware behaves
correctly, and driver code should not attempt to guard against purely
hypothetical failures. The kernel only implements such self‑protection
when there is a documented hardware issue accompanied by official
errata.
Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [EXTERNAL] Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-16 19:49 ` Leon Romanovsky
@ 2026-03-16 20:50 ` Long Li
2026-03-17 9:44 ` Leon Romanovsky
0 siblings, 1 reply; 8+ messages in thread
From: Long Li @ 2026-03-16 20:50 UTC (permalink / raw)
To: Leon Romanovsky, Erni Sri Satya Vennela
Cc: Konstantin Taranov, Jason Gunthorpe, linux-rdma@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
> On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> > As part of MANA hardening for CVM, clamp hardware-reported adapter
> > capability values from the MANA_IB_GET_ADAPTER_CAP response before
> > they are used by the IB subsystem.
> >
> > The response fields (max_qp_count, max_cq_count, max_mr_count,
> > max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> > max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> > assigned to signed int members in struct ib_device_attr. If hardware
> > returns a value exceeding INT_MAX, the implicit u32-to-int conversion
> > produces a negative value, which can cause incorrect behavior in the
> > IB core and userspace applications.
>
> This sentence does not make sense in the context of the Linux kernel.
> The fundamental assumption is that the underlying hardware behaves correctly,
> and driver code should not attempt to guard against purely hypothetical
> failures. The kernel only implements such self‑protection when there is a
> documented hardware issue accompanied by official errata.
>
> Thanks
The idea is that a malicious hardware can't corrupt and steal other data from the kernel.
The assumption is that in a public cloud environment, you can't trust the hardware 100%.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [EXTERNAL] Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-16 20:50 ` [EXTERNAL] " Long Li
@ 2026-03-17 9:44 ` Leon Romanovsky
2026-03-21 0:56 ` Long Li
0 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2026-03-17 9:44 UTC (permalink / raw)
To: Long Li
Cc: Erni Sri Satya Vennela, Konstantin Taranov, Jason Gunthorpe,
linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
On Mon, Mar 16, 2026 at 08:50:39PM +0000, Long Li wrote:
> > On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> > > As part of MANA hardening for CVM, clamp hardware-reported adapter
> > > capability values from the MANA_IB_GET_ADAPTER_CAP response before
> > > they are used by the IB subsystem.
> > >
> > > The response fields (max_qp_count, max_cq_count, max_mr_count,
> > > max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> > > max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> > > assigned to signed int members in struct ib_device_attr. If hardware
> > > returns a value exceeding INT_MAX, the implicit u32-to-int conversion
> > > produces a negative value, which can cause incorrect behavior in the
> > > IB core and userspace applications.
> >
> > This sentence does not make sense in the context of the Linux kernel.
> > The fundamental assumption is that the underlying hardware behaves correctly,
> > and driver code should not attempt to guard against purely hypothetical
> > failures. The kernel only implements such self‑protection when there is a
> > documented hardware issue accompanied by official errata.
> >
> > Thanks
>
> The idea is that a malicious hardware can't corrupt and steal other data from the kernel.
>
> The assumption is that in a public cloud environment, you can't trust the hardware 100%.
You cannot separate functionality and claim that one line of code is trusted
while another is not.
Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [EXTERNAL] Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-17 9:44 ` Leon Romanovsky
@ 2026-03-21 0:56 ` Long Li
2026-03-22 18:50 ` Leon Romanovsky
0 siblings, 1 reply; 8+ messages in thread
From: Long Li @ 2026-03-21 0:56 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Erni Sri Satya Vennela, Konstantin Taranov, Jason Gunthorpe,
linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
-next v2] RDMA/mana_ib: hardening:
> Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
>
> On Mon, Mar 16, 2026 at 08:50:39PM +0000, Long Li wrote:
> > > On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> > > > As part of MANA hardening for CVM, clamp hardware-reported adapter
> > > > capability values from the MANA_IB_GET_ADAPTER_CAP response before
> > > > they are used by the IB subsystem.
> > > >
> > > > The response fields (max_qp_count, max_cq_count, max_mr_count,
> > > > max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> > > > max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> > > > assigned to signed int members in struct ib_device_attr. If
> > > > hardware returns a value exceeding INT_MAX, the implicit
> > > > u32-to-int conversion produces a negative value, which can cause
> > > > incorrect behavior in the IB core and userspace applications.
> > >
> > > This sentence does not make sense in the context of the Linux kernel.
> > > The fundamental assumption is that the underlying hardware behaves
> > > correctly, and driver code should not attempt to guard against
> > > purely hypothetical failures. The kernel only implements such
> > > self‑protection when there is a documented hardware issue accompanied by
> official errata.
> > >
> > > Thanks
> >
> > The idea is that a malicious hardware can't corrupt and steal other data from
> the kernel.
> >
> > The assumption is that in a public cloud environment, you can't trust the
> hardware 100%.
>
> You cannot separate functionality and claim that one line of code is trusted while
> another is not.
>
> Thanks
How we rephrase this in this way: the driver should not corrupt or overflow other parts of the kernel if its device is misbehaving (or has a bug).
Long
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [EXTERNAL] Re: [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
2026-03-21 0:56 ` Long Li
@ 2026-03-22 18:50 ` Leon Romanovsky
0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2026-03-22 18:50 UTC (permalink / raw)
To: Long Li
Cc: Erni Sri Satya Vennela, Konstantin Taranov, Jason Gunthorpe,
linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
On Sat, Mar 21, 2026 at 12:56:39AM +0000, Long Li wrote:
> -next v2] RDMA/mana_ib: hardening:
> > Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP
> >
> > On Mon, Mar 16, 2026 at 08:50:39PM +0000, Long Li wrote:
> > > > On Thu, Mar 12, 2026 at 11:16:41AM -0700, Erni Sri Satya Vennela wrote:
> > > > > As part of MANA hardening for CVM, clamp hardware-reported adapter
> > > > > capability values from the MANA_IB_GET_ADAPTER_CAP response before
> > > > > they are used by the IB subsystem.
> > > > >
> > > > > The response fields (max_qp_count, max_cq_count, max_mr_count,
> > > > > max_pd_count, max_inbound_read_limit, max_outbound_read_limit,
> > > > > max_qp_wr, max_send_sge_count, max_recv_sge_count) are u32 but are
> > > > > assigned to signed int members in struct ib_device_attr. If
> > > > > hardware returns a value exceeding INT_MAX, the implicit
> > > > > u32-to-int conversion produces a negative value, which can cause
> > > > > incorrect behavior in the IB core and userspace applications.
> > > >
> > > > This sentence does not make sense in the context of the Linux kernel.
> > > > The fundamental assumption is that the underlying hardware behaves
> > > > correctly, and driver code should not attempt to guard against
> > > > purely hypothetical failures. The kernel only implements such
> > > > self‑protection when there is a documented hardware issue accompanied by
> > official errata.
> > > >
> > > > Thanks
> > >
> > > The idea is that a malicious hardware can't corrupt and steal other data from
> > the kernel.
> > >
> > > The assumption is that in a public cloud environment, you can't trust the
> > hardware 100%.
> >
> > You cannot separate functionality and claim that one line of code is trusted while
> > another is not.
> >
> > Thanks
>
> How we rephrase this in this way: the driver should not corrupt or overflow other parts of the kernel if its device is misbehaving (or has a bug).
It shouldn't be theoretical claim, do you have errata?
Thanks
>
> Long
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-03-22 18:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 18:16 [PATCH rdma-next v2] RDMA/mana_ib: hardening: Clamp adapter capability values from MANA_IB_GET_ADAPTER_CAP Erni Sri Satya Vennela
2026-03-12 18:43 ` Long Li
2026-03-12 22:48 ` Jason Gunthorpe
2026-03-16 19:49 ` Leon Romanovsky
2026-03-16 20:50 ` [EXTERNAL] " Long Li
2026-03-17 9:44 ` Leon Romanovsky
2026-03-21 0:56 ` Long Li
2026-03-22 18:50 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox