mlx5: Adversarial mode for confidential computing guests
Subsystems (5)
v2 cover mlx5: Adversarial mode for confidential computing guests
In a confidential computing (CC) guest, the hypervisor and any device assigned to the guest are outside its trust boundary. The mlx5 drivers, like most drivers, trust the NIC: they use the capabilities, events and completions it reports to size buffers, index arrays and pick the memory they work on. A malicious or compromised NIC can turn that trust into memory corruption or information leaks inside the guest.
This series adds an adversarial mode, in which the mlx5 drivers treat the NIC as untrusted. It is enabled automatically in CC guests, based on cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT), with no administrator configuration. Outside a CC guest the behaviour is unchanged.
The approach is to keep the attack surface small rather than harden every path. In adversarial mode only the uverbs path is exposed: kernel ULPs don't bind to the device and unneeded features are not offered. The data path is owned by rdma-core, which must be aware of the mode. When it opens a context, rdma-core declares that it supports adversarial mode, and the kernel reports back that the device is in it, so rdma-core validates what the NIC writes to the user queues. An rdma-core that doesn't declare support is refused a context, so it can't use the device while trusting the NIC. What remains in the kernel validates what it gets from the NIC. A NIC can always stop working, so denial of service is out of scope.
We believe that this series provides comprehensive security against an adversarial device within rdma. Many teams at NVIDIA have been involved in evaluating the various attack vectors and developing a comprehensive mitigation, including AI analysis of the driver, fuzzing, and first principles architecture review. It chooses to block and disable functions that may open risk, and results in a reduction in driver functionality rather than leave open potential security holes.
The series is organized as follows:
mlx5_core (patches 1-5)
- Derive adversarial mode from CC guest memory encryption, and keep it per device.
- Filter the FW capabilities: start from none, pass through an allow list, and validate or clamp the numeric ones, failing the load on unexpected values.
- Fail the load when the FW reports fewer EQs than the async EQs need.
- Add helpers to read log-encoded capabilities without an undefined shift.
- Add a forced health recovery, for faults the health sensors can't see, such as a NIC that keeps answering while forging completions.
Attack surface reduction (patches 6-9)
- Check the FW capability for every QP transport type, and accept the DC vendor flags only on IB_QPT_DRIVER.
- Add ib_device::adversarial_mode, set by mlx5_ib from mlx5_core, and keep kernel ULPs off such a device by clearing kverbs_provider, so only uverbs binds.
UMR completion verification (patches 10-13)
- Verify each UMR CQE against a shadow FIFO of the posted requests, instead of trusting its wqe_counter. The UMR CQ is the only CQ the kernel polls, so the generic CQ poll path, which trusts the CQE, is not used in adversarial mode.
- On a forged CQE, keep the UMR path failed and force the health recovery.
Validation of FW reported values (patches 14-20)
- Set the CQ completion handler only once its poll context is set up, and ignore completion events for a kernel CQ that is not ready yet.
- Bound port numbers from EQEs and caps.
- Bound RQ/SQ states from QUERY_RQ and QUERY_SQ.
- Clamp the log_max_* shifts used for the CQ, QP and device limits.
Userspace interface (patch 21)
The GET_CONTEXT handshake: the new UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED input flag and the IB_UVERBS_CORE_SUPPORT_ADVERSARIAL core_support bit, also reported by QUERY_CONTEXT.
The matching rdma-core series [1] declares the support and validates what it reads from the NIC.
[1] https://github.com/linux-rdma/rdma-core/pull/1844
Changes in V2:
V1: https://lore.kernel.org/r/[email protected]
- Patch #2: Keep the mode per device in mlx5_core_dev, set when the PCI function is probed. An SF inherits it from its parent function. mlx5_is_adversarial() takes the device.
- Patch #4: Reject only a negative count, as 0 completion EQs is valid, e.g. for an SF whose max_io_eqs is 0.
- Patch #9: Set ib_device::adversarial_mode from mlx5_core during capability init, instead of a mlx5_ib global, and read it in the mlx5_ib checks. It replaces V1 patches #8 and #24, and comes after the RDMA/core kverbs_provider patch.
- Drop V1 patches #11 and #15. mlx5_ib_poll_cq() checks adversarial mode once per call, and then polls only the UMR CQ, by its verifying poller. The generic poll path is unchanged, with no indirect call. Patch #12 carries the rationale.
- Patch #20: Saturate max_res_rd_atom and max_total_mcast_qp_attach with check_mul_overflow() instead of min_t(), and cap max_cqe with min(). Make srq->msrq.max a u32, so the rounded up SRQ size always fits, and drop the check after rounding.
Changes in V1:
V0: https://lore.kernel.org/r/[email protected]
- Patch #1: Do nothing in the forced work when the command interface is down, as the path that brought it down owns the flush and the recovery. Fall back to force teardown when fast teardown fails, as mlx5_try_fast_unload() does.
- Patch #3: Bound log_min_mkey_entity_size by PAGE_SHIFT, and the max mkey entity size caps by BITS_PER_LONG - 1.
- Patch #4: New patch from Dragos, fail the load when the FW reports too few EQs to leave a completion EQ.
- Patch #7: Add a Fixes tag.
- Patches #8, #12, #15, #21, #24: Commit message improvements.
- Patch #13: Accept a non-flush UMR error CQE only by moving the UMR state from ACTIVE to RECOVER with cmpxchg, and treat it as forged otherwise, so a single recovery runs at a time. Narrow the mlx5_ib_cq_stop_polling() kernel-doc.
- Patch #15: Fix the comment, the uverbs POLL_CQ command doesn't reach this path.
- Patch #17: Cover kernel CQs that are not set up yet. In adversarial mode, kernel CQ events are ignored until the first arm, published with release/acquire, so a weakly ordered CPU can't see the handler without the poll context. Renamed from "Ignore completion events for a CQ without a handler".
- Patch #18: Move the port check into handle_port_change(), before devr.ports[] is indexed, and drop the now dead check in mlx5_ib_handle_event().
- Patch #20: Use check_mul_overflow() for the kernel and user CQ buffer sizes.
- Patch #22: Cap max_cqe to the largest CQ size the create path accepts, and reject SRQ sizes and buffer sizes that don't fit in an int.
Yishai
Dragos Tatulea (3):
net/mlx5: Add capability filtering in adversarial mode net/mlx5: Catch too low max number of EQs net/mlx5: Add macros for reading log-based caps
Yishai Hadas (18):
net/mlx5: Add mlx5_trigger_health_work_force()
net/mlx5: Derive adversarial mode from CC guest memory encryption RDMA/mlx5: Reject QP transport types not enabled by FW capability RDMA/mlx5: Require IB_QPT_DRIVER for the DC vendor QP types RDMA/core: Suppress kverbs_provider for adversarial_mode devices RDMA/mlx5: Set ib_device::adversarial_mode from mlx5_core RDMA/mlx5: Remove duplicate mlx5_ib_umr_context struct RDMA/mlx5: Add shadow FIFO infrastructure for UMR completions RDMA/mlx5: Verify UMR CQ polling against a hostile NIC RDMA/mlx5: Keep the UMR QP failed once a forged CQE is detected RDMA/core: Set the CQ comp_handler after its poll context is set up RDMA/mlx5: Ignore completion events for a kernel CQ that is not ready RDMA/mlx5: Validate EQE port and GSI port before indexing devr.ports[] RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup RDMA/mlx5: Clamp log_max_cq_sz shift in CQ size checks RDMA/mlx5: Clamp log_max_* shifts in QP and WQ limit checks RDMA/mlx5: Clamp log_max_* shifts in query_device and ucontext paths RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
drivers/infiniband/core/cq.c | 19 +- drivers/infiniband/core/device.c | 8 + drivers/infiniband/core/uverbs_cmd.c | 5 + .../infiniband/core/uverbs_std_types_device.c | 16 + drivers/infiniband/hw/mlx5/cq.c | 275 ++++++++++++- drivers/infiniband/hw/mlx5/gsi.c | 4 + drivers/infiniband/hw/mlx5/mad.c | 2 +- drivers/infiniband/hw/mlx5/main.c | 78 ++-- drivers/infiniband/hw/mlx5/mlx5_ib.h | 23 +- drivers/infiniband/hw/mlx5/qp.c | 68 ++-- drivers/infiniband/hw/mlx5/srq.c | 7 +- drivers/infiniband/hw/mlx5/srq.h | 2 +- drivers/infiniband/hw/mlx5/umr.c | 113 +++++- drivers/infiniband/hw/mlx5/umr.h | 6 + .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../ethernet/mellanox/mlx5/core/caps_filter.c | 381 ++++++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/eq.c | 8 +- .../net/ethernet/mellanox/mlx5/core/health.c | 95 ++++- .../net/ethernet/mellanox/mlx5/core/main.c | 17 +- .../ethernet/mellanox/mlx5/core/mlx5_core.h | 2 + .../mellanox/mlx5/core/sf/dev/driver.c | 1 + include/linux/mlx5/device.h | 20 + include/linux/mlx5/driver.h | 4 + include/rdma/ib_verbs.h | 2 + include/uapi/rdma/ib_user_ioctl_cmds.h | 5 + include/uapi/rdma/ib_user_ioctl_verbs.h | 1 + 26 files changed, 1041 insertions(+), 123 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/caps_filter.c
Signature · 1 line
2.18.1
PATCH v2 1/21 net/mlx5: Add mlx5_trigger_health_work_force()
mlx5_trigger_health_work() queues the health recovery, which enters MLX5_DEVICE_STATE_INTERNAL_ERROR only if mlx5_health_check_fatal_sensors() reports a fault.
A consumer can detect a fault the sensors cannot see, such as a device that keeps answering while misbehaving. It then needs the recovery to run with the error state forced, whatever the sensors say.
Add mlx5_trigger_health_work_force(), which queues a dedicated work that runs the recovery with the error state forced. It only queues the work, so it can be called from atomic context.
Before entering the error state the forced work stops the health poller and asks the firmware to stop with mlx5_cmd_fast_teardown_hca(), as the device might still be running. If that fails, it falls back to mlx5_cmd_force_teardown_hca(), as mlx5_try_fast_unload() does. The error state is forced whether or not the teardown succeeds. The teardown runs under intf_state_mutex, so it cannot race an unload.
The forced work does nothing once the interface is down, as the unload has already removed the consumers that need the error flow, or once the command interface is down (fatal error, PCI error or firmware reset), as that path owns the flush and the recovery.
Export it for mlx5_ib, which will use it in a later patch of this series when it detects a NIC forging completion queue entries, a fault the health sensors cannot see.
--- .../net/ethernet/mellanox/mlx5/core/health.c | 95 ++++++++++++++++--- include/linux/mlx5/driver.h | 2 + 2 files changed, 86 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/health.c +84 -11
@@ -627,18 +627,11 @@ mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,return err; } -static void mlx5_fw_fatal_reporter_err_work (struct work_struct *work) +static void mlx5_fw_fatal_reporter_err (struct mlx5_core_dev *dev,bool forced) {struct mlx5_fw_reporter_ctx fw_reporter_ctx; -struct mlx5_core_health *health; -struct mlx5_core_dev *dev; -struct devlink *devlink; -struct mlx5_priv *priv; - - health = container_of(work, struct mlx5_core_health, fatal_report_work); - priv = container_of(health, struct mlx5_priv, health); - dev = container_of(priv, struct mlx5_core_dev, priv); - devlink =priv_to_devlink (dev); +struct mlx5_core_health *health = &dev->priv.health; +struct devlink *devlink =priv_to_devlink (dev);mutex_lock (&dev->intf_state_mutex);if (test_bit (MLX5_DROP_HEALTH_WORK , &health->flags)) {
@@ -646,8 +639,39 @@ static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work)mutex_unlock (&dev->intf_state_mutex);return ; } +if (forced) { +int err; + +/* +* Once the interface is down, the unload already removed the +* consumers that need the error flow. Once the cmd interface +* is down, the path that brought it down owns the flush and +* the recovery. +*/ +if (mlx5_cmd_is_down (dev) || + !test_bit (MLX5_INTERFACE_STATE_UP , &dev->intf_state)) { +mutex_unlock (&dev->intf_state_mutex); +return ; + } +/* +* The firmware might still be running, so stop it first. Do it +* under intf_state_mutex, so the cmd interface is valid. +*/ +mlx5_stop_health_poll (dev, false); + err =mlx5_cmd_fast_teardown_hca (dev); +if (err) + err =mlx5_cmd_force_teardown_hca (dev); +if (err) +mlx5_core_err (dev,"Failed to stop the device before forcing the error state, err %d\n" , + err); + } + +/* +* Enter the error state before unlocking, or an unload could send +* TEARDOWN_HCA to the stopped NIC, fail and skip function disable. +*/ +enter_error_state (dev, forced);mutex_unlock (&dev->intf_state_mutex); -enter_error_state (dev, false);if (IS_ERR_OR_NULL (health->fw_fatal_reporter)) {devl_lock (devlink);if (mlx5_health_try_recover (dev))
@@ -669,6 +693,33 @@ static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work) } } +static void mlx5_fw_fatal_reporter_err_work (struct work_struct *work) +{ +struct mlx5_core_health *health; +struct mlx5_core_dev *dev; +struct mlx5_priv *priv; + + health = container_of(work, struct mlx5_core_health, fatal_report_work); + priv = container_of(health, struct mlx5_priv, health); + dev = container_of(priv, struct mlx5_core_dev, priv); + +mlx5_fw_fatal_reporter_err (dev, false); +} + +static void mlx5_fw_fatal_reporter_force_err_work (struct work_struct *work) +{ +struct mlx5_core_health *health; +struct mlx5_core_dev *dev; +struct mlx5_priv *priv; + + health = container_of(work, struct mlx5_core_health, + force_fatal_report_work); + priv = container_of(health, struct mlx5_priv, health); + dev = container_of(priv, struct mlx5_core_dev, priv); + +mlx5_fw_fatal_reporter_err (dev, true); +} +#define MLX5_FW_REPORTER_ECPF_GRACEFUL_PERIOD 180000#define MLX5_FW_REPORTER_PF_GRACEFUL_PERIOD 60000#define MLX5_FW_REPORTER_VF_GRACEFUL_PERIOD 30000
@@ -759,6 +810,25 @@ void mlx5_trigger_health_work(struct mlx5_core_dev *dev)queue_work (health->wq, &health->fatal_report_work); } +/** +* mlx5_trigger_health_work_force - enter the error state and recover, even +* if the health sensors report the device as healthy +* @dev: mlx5 core device +* +* For faults only a consumer can detect, where the firmware keeps answering +* and mlx5_health_check_fatal_sensors() sees nothing wrong. Without forcing, +* the device would stay in MLX5_DEVICE_STATE_UP and consumers waiting on +* outstanding work would never be released. +*/ +void mlx5_trigger_health_work_force (struct mlx5_core_dev *dev) +{ +struct mlx5_core_health *health = &dev->priv.health; + +if (!mlx5_dev_is_lightweight (dev)) +queue_work (health->wq, &health->force_fatal_report_work); +} +EXPORT_SYMBOL_GPL (mlx5_trigger_health_work_force); +#define MLX5_MSEC_PER_HOUR (MSEC_PER_SEC * 60 * 60)static void mlx5_health_log_ts_update (struct work_struct *work) {
@@ -874,6 +944,7 @@ void mlx5_drain_health_wq(struct mlx5_core_dev *dev)cancel_delayed_work_sync (&health->update_fw_log_ts_work);cancel_work_sync (&health->report_work);cancel_work_sync (&health->fatal_report_work); +cancel_work_sync (&health->force_fatal_report_work); }void mlx5_health_cleanup (struct mlx5_core_dev *dev)
@@ -911,6 +982,8 @@ int mlx5_health_init(struct mlx5_core_dev *dev)if (!health->wq) goto out_err;INIT_WORK (&health->fatal_report_work, mlx5_fw_fatal_reporter_err_work); +INIT_WORK (&health->force_fatal_report_work, + mlx5_fw_fatal_reporter_force_err_work);INIT_WORK (&health->report_work, mlx5_fw_reporter_err_work);INIT_DELAYED_WORK (&health->update_fw_log_ts_work, mlx5_health_log_ts_update);
include/linux/mlx5/driver.h +2 -0
@@ -450,6 +450,7 @@ struct mlx5_core_health {struct workqueue_struct *wq;unsigned long flags;struct work_struct fatal_report_work; +struct work_struct force_fatal_report_work;struct work_struct report_work;struct devlink_health_reporter *fw_reporter;struct devlink_health_reporter *fw_fatal_reporter;
@@ -1034,6 +1035,7 @@ void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);void mlx5_start_health_fw_log_up (struct mlx5_core_dev *dev);void mlx5_drain_health_wq (struct mlx5_core_dev *dev);void mlx5_trigger_health_work (struct mlx5_core_dev *dev); +void mlx5_trigger_health_work_force (struct mlx5_core_dev *dev);int mlx5_frag_buf_alloc_node (struct mlx5_core_dev *dev,int size,struct mlx5_frag_buf *buf,int node);void mlx5_frag_buf_free (struct mlx5_core_dev *dev,struct mlx5_frag_buf *buf);
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 01/21] net/mlx5: Add mlx5_trigger_health_work_force()
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net/mlx5: uncanceled force_fatal_report_work tears down recovered device --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net/mlx5: uncanceled force_fatal_report_work tears down recovered device
--
commit 8880445e0e3559ece304416ceb136dde00d937a0
Author: Yishai Hadas <[email protected]>
net/mlx5: Add mlx5_trigger_health_work_force()
This commit adds mlx5_trigger_health_work_force() to queue a dedicated health work item that stops the firmware and forces the device into the internal error state even when the health sensors report no fault.
Quoted 46 lines
drivers/net/ethernet/mellanox/mlx5/core/health.c +19
-10@@ -627,18 +627,11 @@ mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,return err; } -static void mlx5_fw_fatal_reporter_err_work (struct work_struct *work) +static void mlx5_fw_fatal_reporter_err (struct mlx5_core_dev *dev,bool forced) {struct mlx5_fw_reporter_ctx fw_reporter_ctx; -struct mlx5_core_health *health; -struct mlx5_core_dev *dev; -struct devlink *devlink; -struct mlx5_priv *priv; - - health = container_of(work, struct mlx5_core_health, fatal_report_work); - priv = container_of(health, struct mlx5_priv, health); - dev = container_of(priv, struct mlx5_core_dev, priv); - devlink =priv_to_devlink (dev); +struct mlx5_core_health *health = &dev->priv.health; +struct devlink *devlink =priv_to_devlink (dev);mutex_lock (&dev->intf_state_mutex);if (test_bit (MLX5_DROP_HEALTH_WORK , &health->flags)) {@@ -646,8 +639,39 @@ static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work)mutex_unlock (&dev->intf_state_mutex);return ; } +if (forced) { +int err; + +/* +* Once the interface is down, the unload already removed the +* consumers that need the error flow. Once the cmd interface +* is down, the path that brought it down owns the flush and +* the recovery. +*/ +if (mlx5_cmd_is_down (dev) || + !test_bit (MLX5_INTERFACE_STATE_UP , &dev->intf_state)) { +mutex_unlock (&dev->intf_state_mutex); +return ; + } +/* +* The firmware might still be running, so stop it first. Do it
drivers/net/ethernet/mellanox/mlx5/core/health.c static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work) · line 667
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/health.c +10
-0+* under intf_state_mutex, so the cmd interface is valid. +*/ +mlx5_stop_health_poll (dev, false); + err =mlx5_cmd_fast_teardown_hca (dev); +if (err) + err =mlx5_cmd_force_teardown_hca (dev); +if (err) +mlx5_core_err (dev,"Failed to stop the device before forcing the error state, err %d\n" , + err); + }
[Severity: Medium]
Can a queued force_fatal_report_work run right after an in-progress recovery completes on health->wq and tear down the newly recovered device?
Because force_fatal_report_work is a separate work_struct on the single-threaded health->wq and neither mlx5_unload_one_devl_locked() nor mlx5_function_teardown() cancels it, a forced trigger that races with a fatal sensor error queues force_fatal_report_work behind fatal_report_work:
CPU0 (health->wq) CPU1poll_health()
queue_work(fatal_report_work)
mlx5_trigger_health_work_force()
queue_work(force_fatal_report_work)mlx5_fw_fatal_reporter_err_work()
devlink_health_report()
...
mlx5_health_try_recover()
mlx5_unload_one_devl_locked()
mlx5_recover_device()
mlx5_load_one_devl_locked()
/* restores CMDIF_STATE_UP and INTERFACE_STATE_UP */mlx5_fw_fatal_reporter_force_err_work()
/* mlx5_cmd_is_down() is false, INTERFACE_STATE_UP is set */
mlx5_cmd_fast_teardown_hca() <-- tears down recovered HCA
enter_error_state(dev, true)
devlink_health_report() <-- returns -ECANCELED (grace period)
mlx5_unload_one(dev, false)
When fatal_report_work finishes, the device is back up, so the mlx5_cmd_is_down() and MLX5_INTERFACE_STATE_UP checks pass. force_fatal_report_work then stops the healthy HCA, forces MLX5_DEVICE_STATE_INTERNAL_ERROR, hits -ECANCELED in devlink_health_report() because the reporter is still within the post-recovery graceful period, and unloads the driver. The same thing happens if mlx5_trigger_health_work_force() is called during devlink reload while mlx5_unload_one_devl_locked() is detaching consumers before mlx5_load_one_devl_locked() brings the interface back up.
Cancelling force_fatal_report_work during teardown (or draining it before bringing the interface back up) would prevent stale forced work from acting on the new device instance.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH V2 rdma-next 01/21] net/mlx5: Add mlx5_trigger_health_work_force()
Quoted 67 lines · On 18/11/2026 19:13, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net/mlx5: uncanceledforce_fatal_report_worktears down recovered device
--commit
8880445e0e3559ece304416ceb136dde00d937a0
Author: Yishai Hadas <[email protected]>net/mlx5: Add
mlx5_trigger_health_work_force()This commit adds
mlx5_trigger_health_work_force()to queue a dedicated health work item that stops the firmware and forces the device into the internal error state even when the health sensors report no fault.Quoted 52 lines
drivers/net/ethernet/mellanox/mlx5/core/health.c +25
-10@@ -627,18 +627,11 @@ mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,return err; } -static void mlx5_fw_fatal_reporter_err_work (struct work_struct *work) +static void mlx5_fw_fatal_reporter_err (struct mlx5_core_dev *dev,bool forced) {struct mlx5_fw_reporter_ctx fw_reporter_ctx; -struct mlx5_core_health *health; -struct mlx5_core_dev *dev; -struct devlink *devlink; -struct mlx5_priv *priv; - - health = container_of(work, struct mlx5_core_health, fatal_report_work); - priv = container_of(health, struct mlx5_priv, health); - dev = container_of(priv, struct mlx5_core_dev, priv); - devlink =priv_to_devlink (dev); +struct mlx5_core_health *health = &dev->priv.health; +struct devlink *devlink =priv_to_devlink (dev);mutex_lock (&dev->intf_state_mutex);if (test_bit (MLX5_DROP_HEALTH_WORK , &health->flags)) {@@ -646,8 +639,39 @@ static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work)mutex_unlock (&dev->intf_state_mutex);return ; } +if (forced) { +int err; + +/* +* Once the interface is down, the unload already removed the +* consumers that need the error flow. Once the cmd interface +* is down, the path that brought it down owns the flush and +* the recovery. +*/ +if (mlx5_cmd_is_down (dev) || + !test_bit (MLX5_INTERFACE_STATE_UP , &dev->intf_state)) { +mutex_unlock (&dev->intf_state_mutex); +return ; + } +/* +* The firmware might still be running, so stop it first. Do it +* under intf_state_mutex, so the cmd interface is valid. +*/ +mlx5_stop_health_poll (dev, false); + err =mlx5_cmd_fast_teardown_hca (dev); +if (err) + err =mlx5_cmd_force_teardown_hca (dev);
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/health.c static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work) · line 667
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/health.c +4
-0+if (err) +mlx5_core_err (dev,"Failed to stop the device before forcing the error state, err %d\n" , + err); + }[Severity: Medium]
Can a queuedforce_fatal_report_workrun right after an in-progress recovery completes onhealth->wqand tear down the newly recovered device?
The existing fatal_report_work behaves the same way. If queued before a devlink reload, it runs on the reloaded device and triggers a needless recovery, or an unload within the grace period.
In any case, a device that forges a CQE can cause a DoS anyway, which is out of scope for this series.
Yishai
PATCH v2 2/21 net/mlx5: Derive adversarial mode from CC guest memory encryption
In reply to Yishai HadasAdd mlx5_is_adversarial() to report whether the driver treats the NIC as untrusted. In a confidential computing guest, the hypervisor and any passthrough device are outside the guest's trust boundary, so the mode is derived from cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) when the PCI function is probed. An SF inherits the mode of its parent function.
This turns adversarial mode on automatically in such guests, without any administrator configuration.
--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 9 +++++++++ drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c | 1 + include/linux/mlx5/driver.h | 2 ++ 3 files changed, 12 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/main.c +9 -0
@@ -31,6 +31,7 @@*/ #include <linux/highmem.h> +#include <linux/cc_platform.h> #include <linux/module.h> #include <linux/init.h> #include <linux/errno.h>
@@ -484,6 +485,12 @@ bool mlx5_is_roce_on(struct mlx5_core_dev *dev) }EXPORT_SYMBOL (mlx5_is_roce_on); +bool mlx5_is_adversarial (struct mlx5_core_dev *dev) +{ +return dev->adv_mode; +} +EXPORT_SYMBOL_GPL (mlx5_is_adversarial); +static int handle_hca_cap_2 (struct mlx5_core_dev *dev,void *set_ctx) {bool do_set = false;
@@ -1961,6 +1968,8 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id) goto adev_init_err; } + dev->adv_mode =cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT ); + err =mlx5_mdev_init (dev, prof_sel);if (err) goto mdev_init_err;
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c +1 -0
@@ -40,6 +40,7 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia mdev->coredev_type =MLX5_COREDEV_SF ; mdev->priv.parent_mdev = sf_dev->parent_mdev; mdev->priv.adev_idx = adev->id; + mdev->adv_mode = sf_dev->parent_mdev->adv_mode; sf_dev->mdev = mdev;/* Only local SFs do light probe */
include/linux/mlx5/driver.h +2 -0
@@ -804,6 +804,7 @@ struct mlx5_core_dev {struct mutex wc_state_lock;struct devlink *shd;struct mlx5_data_direct *data_direct; +bool adv_mode; };struct mlx5_db {
@@ -1328,6 +1329,7 @@ enum { };bool mlx5_is_roce_on (struct mlx5_core_dev *dev); +bool mlx5_is_adversarial (struct mlx5_core_dev *dev);static inline bool mlx5_get_roce_state (struct mlx5_core_dev *dev) {
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 02/21] net/mlx5: Derive adversarial mode from CC guest memory encryption
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Add
mlx5_is_adversarial()to report whether the driver treats the NIC as untrusted. In a confidential computing guest, the hypervisor and any passthrough device are outside the guest's trust boundary, so the mode is derived fromcc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)when the PCI function is probed. An SF inherits the mode of its parent function.
Quoted 6 lines
This turns adversarial mode on automatically in such guests, without any administrator configuration.
Reviewed-by Tariq Toukan <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v2 3/21 net/mlx5: Add capability filtering in adversarial mode
In reply to Yishai HadasFrom: Dragos Tatulea <[email protected]>
When in adversarial mode, trust only a subset of capabilities and do some additional validations.
Start off by clearing all firmware capabilities and enabling them one by one. Some numeric capabilities are validated. Unexpected values will trigger a driver load failure flow.
Where it applies, the filtering is done on both current and max caps. Allowed capabilities are simply passed through. Clamped and checked capabilities also apply to max values.
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../ethernet/mellanox/mlx5/core/caps_filter.c | 381 ++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/main.c | 8 +- .../ethernet/mellanox/mlx5/core/mlx5_core.h | 2 + 4 files changed, 388 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/caps_filter.c
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_MLX5_CORE) += mlx5_core.o # # mlx5 core basic # -mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \ +mlx5_core-y := main.o caps_filter.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \ health.o mcg.o cq.o alloc.o port.o mr.o pd.o \ transobj.o vport.o sriov.o fs_cmd.o fs_core.o pci_irq.o \ fs_counters.o fs_ft_pool.o rl.o lag/debugfs.o lag/lag.o dev.o events.o wq.o lib/gid.o \
drivers/net/ethernet/mellanox/mlx5/core/caps_filter.c new file +381 -0
381 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/main.c +4 -4
@@ -325,12 +325,12 @@ int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_tyswitch (cap_mode) {case HCA_CAP_OPMOD_GET_MAX : -memcpy (dev->caps.hca[cap_type]->max, hca_caps, -MLX5_UN_SZ_BYTES (hca_cap_union)); + err =mlx5_store_caps (dev, cap_type, + dev->caps.hca[cap_type]->max, hca_caps);break ;case HCA_CAP_OPMOD_GET_CUR : -memcpy (dev->caps.hca[cap_type]->cur, hca_caps, -MLX5_UN_SZ_BYTES (hca_cap_union)); + err =mlx5_store_caps (dev, cap_type, + dev->caps.hca[cap_type]->cur, hca_caps);break ;default : mlx5_core_warn(dev,
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +2 -0
@@ -215,6 +215,8 @@ static inline int mlx5_flexible_inlen(struct mlx5_core_dev *dev, size_t fixed, mlx5_flexible_inlen(dev, fixed, item_size, num_items, __func__, __LINE__)int mlx5_core_get_caps (struct mlx5_core_dev *dev,enum mlx5_cap_type cap_type); +int mlx5_store_caps (struct mlx5_core_dev *dev,enum mlx5_cap_type cap_type, +void *dst,void *src);int mlx5_core_get_caps_mode (struct mlx5_core_dev *dev,enum mlx5_cap_type cap_type,enum mlx5_cap_mode cap_mode);int mlx5_query_hca_caps (struct mlx5_core_dev *dev);
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 03/21] net/mlx5: Add capability filtering in adversarial mode
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
From: Dragos Tatulea <[email protected]>
When in adversarial mode, trust only a subset of capabilities and do some additional validations.
Start off by clearing all firmware capabilities and enabling them one by one. Some numeric capabilities are validated. Unexpected values will trigger a driver load failure flow.
Quoted 7 lines
Where it applies, the filtering is done on both current and max caps. Allowed capabilities are simply passed through. Clamped and checked capabilities also apply to max values.
Reviewed-by Tariq Toukan <[email protected]>Reviewed-by Yishai Hadas <[email protected]>Signed-off-by Dragos Tatulea <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v2 4/21 net/mlx5: Catch too low max number of EQs
In reply to Yishai HadasFrom: Dragos Tatulea <[email protected]>
get_num_eqs() can return a negative value when an adversarial FW reports fewer EQs than MLX5_MAX_ASYNC_EQS. Return an error in this case.
0 completion EQs is a valid count, e.g. for an SF whose max_io_eqs is set to 0.
--- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eq.c +6 -2
@@ -1195,9 +1195,13 @@ static int get_num_eqs(struct mlx5_core_dev *dev)int mlx5_eq_table_create (struct mlx5_core_dev *dev) {struct mlx5_eq_table *eq_table = dev->priv.eq_table; -int err; +int err, num_eqs; + + num_eqs =get_num_eqs (dev); +if (num_eqs <0 ) +return -EINVAL ; - eq_table->max_comp_eqs =get_num_eqs (dev); + eq_table->max_comp_eqs = num_eqs; err =create_async_eqs (dev);if (err) {mlx5_core_err (dev,"Failed to create async EQs\n" );
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 04/21] net/mlx5: Catch too low max number of EQs
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] net/mlx5: divide-by-zero in alloc_rmap() when get_num_eqs() returns 0 --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] net/mlx5: divide-by-zero in alloc_rmap() when get_num_eqs() returns 0
--
commit 3ffd9856318c7a723d1d765cb083af29c7442990
Author: Dragos Tatulea <[email protected]>
net/mlx5: Catch too low max number of EQs
This commit checks for a negative return value from get_num_eqs() in mlx5_eq_table_create() and returns -EINVAL when firmware reports fewer EQs than MLX5_MAX_ASYNC_EQS.
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/eq.c +0
-0@@ -1195,9 +1195,13 @@ static int get_num_eqs(struct mlx5_core_dev *dev)int mlx5_eq_table_create (struct mlx5_core_dev *dev) {
drivers/net/ethernet/mellanox/mlx5/core/eq.c static int get_num_eqs(struct mlx5_core_dev *dev) · line 1204
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eq.c +6
-2struct mlx5_eq_table *eq_table = dev->priv.eq_table; -int err; +int err, num_eqs; + + num_eqs =get_num_eqs (dev); +if (num_eqs <0 ) +return -EINVAL ; - eq_table->max_comp_eqs =get_num_eqs (dev); + eq_table->max_comp_eqs = num_eqs;
[Severity: High]
Can allowing num_eqs == 0 cause a divide-by-zero in alloc_rmap() on non-SF devices?
When firmware on a PF or VF reports max_dev_eqs == MLX5_MAX_ASYNC_EQS, get_num_eqs() returns 0. mlx5_eq_table_create() stores 0 in eq_table->max_comp_eqs and then calls alloc_rmap():
drivers/net/ethernet/mellanox/mlx5/core/eq.c:alloc_rmap() {
if (mlx5_core_is_sf(mdev))
return 0;
eq_table->rmap = alloc_irq_cpu_rmap(eq_table->max_comp_eqs);
...
}alloc_irq_cpu_rmap(0) passes size == 0 to alloc_cpu_rmap(), which executes cpu % size and crashes the kernel with a divide error.
Even on SFs where alloc_rmap() returns early, eq_table->max_comp_eqs == 0 causes mlx5_comp_vectors_max() to return 0, which triggers divide-by-zero faults in mlx5_ib (via ib_cq_pool_get() dividing by num_comp_vectors) and in mlx5vf_create_tracker().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH V2 rdma-next 04/21] net/mlx5: Catch too low max number of EQs
Quoted 30 lines · On 18/11/2026 19:13, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] net/mlx5: divide-by-zero inalloc_rmap()whenget_num_eqs()returns 0
--commit
3ffd9856318c7a723d1d765cb083af29c7442990
Author: Dragos Tatulea <[email protected]>net/mlx5: Catch too low max number of EQs
This commit checks for a negative return value from
get_num_eqs()inmlx5_eq_table_create()and returns-EINVALwhen firmware reports fewer EQs thanMLX5_MAX_ASYNC_EQS.Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/eq.c +5
-1@@ -1195,9 +1195,13 @@ static int get_num_eqs(struct mlx5_core_dev *dev)int mlx5_eq_table_create (struct mlx5_core_dev *dev) {struct mlx5_eq_table *eq_table = dev->priv.eq_table; -int err; +int err, num_eqs; + + num_eqs =get_num_eqs (dev); +if (num_eqs <0 ) +return -EINVAL ;
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/eq.c static int get_num_eqs(struct mlx5_core_dev *dev) · line 1204
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/eq.c +1
-1- eq_table->max_comp_eqs =get_num_eqs (dev); + eq_table->max_comp_eqs = num_eqs;[Severity: High]
Can allowingnum_eqs== 0 cause a divide-by-zero inalloc_rmap()on non-SF devices?
The num_eqs == 0 case is not specific to adversarial mode. A trusted device can hit it as well, so it's a bug fix for net with a Fixes tag, not part of this hardening series.
We may send it separately, failing alloc_rmap() with -EINVAL when a non-SF function has no completion EQs.
Yishai
PATCH v2 5/21 net/mlx5: Add macros for reading log-based caps
In reply to Yishai HadasFrom: Dragos Tatulea <[email protected]>
Add macros that can be used to exponentiate log based capabilities.
When a capability can represent more than the used version (u32 , u64), value will be clamped to the largest representable power of two.
--- include/linux/mlx5/device.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/linux/mlx5/device.h +20 -0
@@ -38,6 +38,7 @@#include <linux/mlx5/mlx5_ifc.h> #include <linux/mlx5/mlx5_ifc_macros.h> #include <linux/bitfield.h> +#include <linux/minmax.h> #if defined(__LITTLE_ENDIAN)#define MLX5_SET_HOST_ENDIANNESS 0
@@ -47,6 +48,16 @@#error Host endianness not defined#endif +/* Largest shift count that is defined behaviour for a value of type @T. */ +#define __mlx5_max_shift (T ) (BITS_PER_TYPE(T) - 1 - is_signed_type(T)) + +/* Calculate 2^@fld from a log2 cap field. Exponents that don't fit in @T +* saturate to the largest representable power of two (not to the type +* maximum), avoiding undefined shifts. +*/ +#define MLX5_GET_LOGSZ_CLAMP (typ, p, fld,T ) \ + ((T)((T)1 << min_t(u32, MLX5_GET(typ, p, fld), __mlx5_max_shift(T)))) +enum mlx5_inline_modes {MLX5_INLINE_MODE_NONE ,MLX5_INLINE_MODE_L2 ,
@@ -1096,6 +1107,15 @@ enum mlx5_qcam_feature_groups {#define MLX5_CAP_GEN_MAX (mdev, cap) \ MLX5_GET(cmd_hca_cap, mdev->caps.hca[MLX5_CAP_GENERAL]->max, cap) +/* 2^cap for log2-encoded general caps */ +#define MLX5_CAP_GEN_LOGSZ_U32 (mdev, cap) \ + MLX5_GET_LOGSZ_CLAMP(cmd_hca_cap, \ + mdev->caps.hca[MLX5_CAP_GENERAL]->cur, cap, u32) + +#define MLX5_CAP_GEN_LOGSZ_U64 (mdev, cap) \ + MLX5_GET_LOGSZ_CLAMP(cmd_hca_cap, \ + mdev->caps.hca[MLX5_CAP_GENERAL]->cur, cap, u64) +#define MLX5_CAP_GEN_2 (mdev, cap) \ MLX5_GET(cmd_hca_cap_2, mdev->caps.hca[MLX5_CAP_GENERAL_2]->cur, cap)
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 05/21] net/mlx5: Add macros for reading log-based caps
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
From: Dragos Tatulea <[email protected]>
Add macros that can be used to exponentiate log based capabilities.
When a capability can represent more than the used version (u32 , u64), value will be clamped to the largest representable power of two.
Reviewed-by Tariq Toukan <[email protected]>Reviewed-by Yishai Hadas <[email protected]>Signed-off-by Dragos Tatulea <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v2 6/21 RDMA/mlx5: Reject QP transport types not enabled by FW capability
In reply to Yishai Hadascheck_qp_type() checks the FW capability only for XRC and DC. RC, UC and UD QPs are created even if the FW does not report the matching capability bit.
Check the rc, uc and ud capabilities as well, so that QP creation is refused for a transport the FW does not support.
--- drivers/infiniband/hw/mlx5/qp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +11 -2
@@ -2824,15 +2824,24 @@ static int check_qp_type(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr,case IB_QPT_XRC_INI :if (!MLX5_CAP_GEN (dev->mdev, xrc)) goto out; - fallthrough; +break ;case IB_QPT_RC : +if (!MLX5_CAP_GEN (dev->mdev, rc)) + goto out; +break ;case IB_QPT_UC : +if (!MLX5_CAP_GEN (dev->mdev, uc)) + goto out; +break ; +case IB_QPT_UD : +if (!MLX5_CAP_GEN (dev->mdev, ud)) + goto out; +break ;case IB_QPT_SMI :case MLX5_IB_QPT_HW_GSI :case IB_QPT_DRIVER :case IB_QPT_GSI :case IB_QPT_RAW_PACKET : -case IB_QPT_UD :case MLX5_IB_QPT_REG_UMR :break ;default :
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 06/21] RDMA/mlx5: Reject QP transport types not enabled by FW capability
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
check_qp_type()checks the FW capability only for XRC and DC. RC, UC and UD QPs are created even if the FW does not report the matching capability bit.Check the rc, uc and ud capabilities as well, so that QP creation is refused for a transport the FW does not support.
Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v2 7/21 RDMA/mlx5: Require IB_QPT_DRIVER for the DC vendor QP types
In reply to Yishai Hadascheck_qp_type() checks the dct capability only for IB_QPT_DRIVER, but process_vendor_flags() turns any QP that carries a DC type flag into a DCI or DCT QP. A QP created as, for example, IB_QPT_RC with a DC flag thus becomes a DC QP without the capability check.
Accept the DC type flags only on IB_QPT_DRIVER, the type userspace uses to create DC QPs.
--- drivers/infiniband/hw/mlx5/qp.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +10 -6
@@ -2965,18 +2965,22 @@ static int process_vendor_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,switch (flags & (MLX5_QP_FLAG_TYPE_DCT |MLX5_QP_FLAG_TYPE_DCI )) {case MLX5_QP_FLAG_TYPE_DCI : +if (qp->type !=IB_QPT_DRIVER ) +return -EINVAL ; qp->type =MLX5_IB_QPT_DCI ;break ;case MLX5_QP_FLAG_TYPE_DCT : +if (qp->type !=IB_QPT_DRIVER ) +return -EINVAL ; qp->type =MLX5_IB_QPT_DCT ;break ; +case 0 : +/* IB_QPT_DRIVER needs a subtype */ +if (qp->type ==IB_QPT_DRIVER ) +return -EINVAL ; +break ;default : -if (qp->type !=IB_QPT_DRIVER ) -break ; -/* -* It is IB_QPT_DRIVER and or no subtype or -* wrong subtype were provided. -*/ +/* Both subtypes */ return -EINVAL ; }
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 07/21] RDMA/mlx5: Require IB_QPT_DRIVER for the DC vendor QP types
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
check_qp_type()checks the dct capability only forIB_QPT_DRIVER, butprocess_vendor_flags()turns any QP that carries a DC type flag into a DCI or DCT QP. A QP created as, for example,IB_QPT_RCwith a DC flag thus becomes a DC QP without the capability check.Accept the DC type flags only on
IB_QPT_DRIVER, the type userspace uses to create DC QPs.Fixes 37518fa49f76 ("RDMA/mlx5: Process all vendor flags in one place")Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v2 8/21 RDMA/core: Suppress kverbs_provider for adversarial_mode devices
In reply to Yishai HadasIn adversarial mode the NIC is not trusted. Kernel ULPs such as MAD, IB CM, rdma_cm, IPoIB, SRP, iSER and NVMe-oF trust what the device reports, its completions and the data it writes, so they must not use such a device.
Add an adversarial_mode field to struct ib_device and clear kverbs_provider when it is set. add_client_context() then skips every client but uverbs, the only one that sets no_kverbs_req, so the kernel ULPs never bind to the device.
The driver still implements the kverbs ops, as the uverbs path shares them, so kverbs_provider can't be cleared by the existing check of the mandatory ops.
--- drivers/infiniband/core/device.c | 8 ++++++++ include/rdma/ib_verbs.h | 2 ++ 2 files changed, 10 insertions(+)
drivers/infiniband/core/device.c +8 -0
@@ -312,6 +312,14 @@ static void ib_device_check_mandatory(struct ib_device *device)break ; } } + +/* +* Kernel ULPs must not bind to an adversarial_mode device. Its kverbs +* ops are still present, as uverbs uses them, so clear kverbs_provider +* explicitly. uverbs sets no_kverbs_req, so it still binds. +*/ +if (device->adversarial_mode) + device->kverbs_provider = false; }/*
include/rdma/ib_verbs.h +2 -0
@@ -3008,6 +3008,8 @@ struct ib_device { u16 use_cq_dim:1;/* CoCo guest with DMA bounce buffering required */ u16 cc_dma_bounce:1; +/* Untrusted-NIC, adversarial mode is required */ +u8 adversarial_mode;u8 node_type;u32 phys_port_cnt;struct ib_device_attr attrs;
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 08/21] RDMA/core: Suppress kverbs_provider for adversarial_mode devices
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
In adversarial mode the NIC is not trusted. Kernel ULPs such as MAD, IB CM,
rdma_cm, IPoIB, SRP, iSER and NVMe-oF trust what the device reports, its completions and the data it writes, so they must not use such a device.Add an
adversarial_modefield to structib_deviceand clearkverbs_providerwhen it is set.add_client_context()then skips every client but uverbs, the only one that setsno_kverbs_req, so the kernel ULPs never bind to the device.
Quoted 5 lines
The driver still implements the kverbs ops, as the uverbs path shares them, so
kverbs_providercan't be cleared by the existing check of the mandatory ops.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v2 9/21 RDMA/mlx5: Set ib_device::adversarial_mode from mlx5_core
In reply to Yishai HadasSet ib_device::adversarial_mode during capability init from mlx5_is_adversarial(), so that every mlx5 device in a CC guest runs in adversarial mode. The core then keeps the kernel ULPs off the device.
The mlx5_ib checks for adversarial mode, added by the next patches, read this per-device field.
--- drivers/infiniband/hw/mlx5/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/infiniband/hw/mlx5/main.c +1 -0
@@ -4770,6 +4770,7 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) } dev->ib_dev.use_cq_dim = true; + dev->ib_dev.adversarial_mode =mlx5_is_adversarial (dev->mdev);return 0 ;
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 09/21] RDMA/mlx5: Set ib_device::adversarial_mode from mlx5_core
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Set
ib_device::adversarial_modeduring capability init frommlx5_is_adversarial(), so that every mlx5 device in a CC guest runs in adversarial mode. The core then keeps the kernel ULPs off the device.The
mlx5_ibchecks for adversarial mode, added by the next patches, read this per-device field.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v2 10/21 RDMA/mlx5: Remove duplicate mlx5_ib_umr_context struct
In reply to Yishai Hadasmlx5_ib_umr_context in mlx5_ib.h and mlx5r_umr_context in umr.h have identical layouts: an ib_cqe, a status, and a completion. The done callback used mlx5_ib_umr_context via container_of, while every other site in umr.c used mlx5r_umr_context.
Remove the duplicate and use mlx5r_umr_context consistently throughout. No behaviour change.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 6 ------ drivers/infiniband/hw/mlx5/umr.c | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +0 -6
@@ -749,12 +749,6 @@ struct mlx5_ib_mw {struct mlx5_ib_mkey mmkey; }; -struct mlx5_ib_umr_context { -struct ib_cqe cqe; -enum ib_wc_status status; -struct completion done; -}; -enum {MLX5_UMR_STATE_UNINIT ,MLX5_UMR_STATE_ACTIVE ,
drivers/infiniband/hw/mlx5/umr.c +2 -2
@@ -339,8 +339,8 @@ static int mlx5r_umr_recover(struct mlx5_ib_dev *dev, u32 mkey,static void mlx5r_umr_done (struct ib_cq *cq,struct ib_wc *wc) { -struct mlx5_ib_umr_context *context = - container_of(wc->wr_cqe, struct mlx5_ib_umr_context, cqe); +struct mlx5r_umr_context *context = + container_of(wc->wr_cqe, struct mlx5r_umr_context, cqe); context->status = wc->status;complete (&context->done);
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 10/21] RDMA/mlx5: Remove duplicate mlx5_ib_umr_context struct
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
mlx5_ib_umr_contextinmlx5_ib.handmlx5r_umr_contextinumr.hhave identical layouts: anib_cqe, a status, and a completion. The done callback usedmlx5_ib_umr_contextviacontainer_of, while every other site inumr.cusedmlx5r_umr_context.Remove the duplicate and use
mlx5r_umr_contextconsistently throughout. No behaviour change.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v2 11/21 RDMA/mlx5: Add shadow FIFO infrastructure for UMR completions
In reply to Yishai HadasThe UMR CQ is polled by the generic path, which finds the completed request by indexing qp->sq.wrid[] with the CQE wqe_counter. A hostile NIC can forge it to complete a request other than the one that really completed, or one that is not pending at all.
The UMR QP signals every WR, and its send queue completes in posting order. In adversarial mode, keep a FIFO of the posted UMR contexts, so a follow-up patch can check each CQE against the oldest pending request instead of trusting it. Each context also records the SQ producer counter it was posted at, as its address alone doesn't identify the post: it is usually on the stack and reused across posts.
Nothing consumes the FIFO yet.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 10 +++++++ drivers/infiniband/hw/mlx5/umr.c | 42 +++++++++++++++++++++++----- drivers/infiniband/hw/mlx5/umr.h | 6 ++++ 3 files changed, 51 insertions(+), 7 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +10 -0
@@ -756,6 +756,12 @@ enum { MLX5_UMR_STATE_ERR, }; +#define MLX5_UMR_MAX_WR 128 +static_assert ((MLX5_UMR_MAX_WR & (MLX5_UMR_MAX_WR -1 )) ==0 , +"MLX5_UMR_MAX_WR must be a power of two for FIFO index masking" ); + +struct mlx5r_umr_context ; +struct umr_common {struct ib_pd *pd;struct ib_cq *cq;
@@ -769,6 +775,10 @@ struct umr_common {unsigned int state;/* Protects from repeat UMR QP creation */ struct mutex init_lock; +/* Posted UMR contexts in posting order, adversarial_mode only */ +struct mlx5r_umr_context **pending; +u32 pending_head; +u32 pending_tail; };struct mlx5_ib_port_resources {
drivers/infiniband/hw/mlx5/umr.c +35 -7
96 lines not on this page · raw message
drivers/infiniband/hw/mlx5/umr.h +6 -0
@@ -84,6 +84,12 @@ struct mlx5r_umr_context {struct ib_cqe cqe;enum ib_wc_status status;struct completion done; +/* +* SQ producer counter the WQE was posted at, matched against the CQE +* wqe_counter in adversarial_mode. Unlike the context address, which +* is reused across posts, or the ring slot, it identifies the WQE. +*/ +u16 wqe_ctr; };struct mlx5r_umr_wqe {
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 11/21] RDMA/mlx5: Add shadow FIFO infrastructure for UMR completions
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
The UMR CQ is polled by the generic path, which finds the completed request by indexing qp->sq.wrid[] with the CQE
wqe_counter. A hostile NIC can forge it to complete a request other than the one that really completed, or one that is not pending at all.The UMR QP signals every WR, and its send queue completes in posting order. In adversarial mode, keep a FIFO of the posted UMR contexts, so a follow-up patch can check each CQE against the oldest pending request instead of trusting it. Each context also records the SQ producer counter it was posted at, as its address alone doesn't identify the post: it is usually on the stack and reused across posts.
Quoted 3 lines
Nothing consumes the FIFO yet.
Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH v2 12/21 RDMA/mlx5: Verify UMR CQ polling against a hostile NIC
In reply to Yishai HadasThe generic poll path trusts the CQE content: its opcode, QPN and wqe_counter decide which request is completed and which waiter is woken. A forged CQE can therefore complete a request the driver never posted, or one that already completed. The driver then writes through a context it no longer owns, which corrupts memory, as the context is usually on the waiter's stack.
In adversarial mode, poll the UMR CQ with a dedicated poller that does not take the CQE's word for it. The driver keeps a shadow FIFO of its posted requests, and a CQE is accepted only if its opcode and QPN match the UMR QP and its full wqe_counter matches the oldest pending request, one already passed to the doorbell. The context is then taken from the FIFO, never from the CQE. This cannot prove that the NIC really executed the request, as it can always report the oldest one as completed; it ensures that the driver completes only a context it owns, once and in order.
The generic poll path must not run at all in adversarial mode. Kernel ULPs are kept off the device and user CQs are polled by userspace, so the UMR CQ is the only CQ the kernel polls. mlx5_ib_poll_cq() checks the mode once per call, and polls only a CQ marked for UMR verification, which is set under cq->lock before the UMR QP is published. Any other CQ, and the UMR CQ once polling stopped, returns no CQE and nothing is consumed. Outside adversarial mode the poll path is unchanged.
A CQE that fails validation proves the NIC is forging completions, so nothing it reports on this QP can be trusted any more. Mark the UMR path permanently failed, so neither a new post nor a QP recovery can reopen it, stop interpreting this CQ and force the mlx5_core health recovery. The forced variant is needed because such a NIC still looks healthy to the fatal sensors. Recovery moves the device to the internal error state, and the existing flush then completes the pending requests in software and wakes their waiters, so this path does not complete them itself.
A non-flush error CQE is valid only while the UMR path is active: a real failure moves the QP to error, after which the NIC returns only flush errors until the recovery resets it. Accept one only by moving the state from active to recover atomically, and treat it as forged otherwise, so a single recovery runs at a time.
On teardown, stop polling the CQ before destroying the UMR QP, so a CQE for the destroyed QP, or for a reused QPN, is never completed to a waiter.
--- drivers/infiniband/hw/mlx5/cq.c | 192 +++++++++++++++++++++++++++ drivers/infiniband/hw/mlx5/mlx5_ib.h | 5 + drivers/infiniband/hw/mlx5/umr.c | 38 ++++++ 3 files changed, 235 insertions(+)
drivers/infiniband/hw/mlx5/cq.c +192 -0
@@ -37,6 +37,7 @@#include "mlx5_ib.h" #include "srq.h" #include "qp.h" +#include "umr.h" #define UVERBS_MODULE_NAME mlx5_ib#include <rdma/uverbs_named_ioctl.h>
@@ -608,6 +609,190 @@ static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries,return npolled; } +/** +* mlx5_ib_cq_stop_polling - stop interpreting CQEs on a CQ +* @ibcq: the CQ +* +* For adversarial_mode only, where mlx5_ib_poll_cq() polls a CQ only while +* umr_verify is set. Takes cq->lock, which mlx5_ib_poll_cq() holds while +* polling, so no poll is in flight on return and later polls return no CQE +* from the NIC. +*/ +void mlx5_ib_cq_stop_polling (struct ib_cq *ibcq) +{ +struct mlx5_ib_cq *cq =to_mcq (ibcq); +unsigned long flags; + +spin_lock_irqsave (&cq->lock, flags); + cq->umr_verify = false; +spin_unlock_irqrestore (&cq->lock, flags); +} + +/* +* Poll one CQE of the UMR CQ in adversarial_mode. A CQE is accepted only if +* it matches the oldest request in the shadow FIFO, otherwise the device is +* treated as compromised. +*/ +static int mlx5_ib_poll_one_umr (struct mlx5_ib_cq *cq,struct ib_wc *wc) +{ +struct mlx5_ib_dev *dev =to_mdev (cq->ibcq.device); +struct mlx5r_umr_context *expected; +struct umr_common *umrc = &dev->umrc; +struct mlx5_err_cqe err_cqe; +struct mlx5_cqe64 *cqe64; +struct mlx5_ib_wq *wq; +struct mlx5_ib_qp *qp; +struct ib_qp *ibqp; +u16 wqe_ctr; +u8 opcode; +u32 head; +u32 sop_qpn; +u32 qpn; +u8 sop; +int idx; +void *cqe; + + cqe =next_cqe_sw (cq); +if (!cqe) +return -EAGAIN ; + + cqe64 = (cq->mcq.cqe_sz ==64 ) ? cqe : cqe +64 ; + ++cq->mcq.cons_index; +/* +* Read each field once, so a NIC rewriting the CQE cannot change it +* between validation and use. +*/ +rmb (); + opcode =READ_ONCE (cqe64->op_own) >>4 ; + sop_qpn =ntohl (READ_ONCE (cqe64->sop_drop_qpn)); + qpn = sop_qpn &0xffffff ; + sop = sop_qpn >>24 ; + wqe_ctr =be16_to_cpu (READ_ONCE (cqe64->wqe_counter)); + +/* +* umr_verify is set before the UMR QP is published, so a CQE +* seen while the QP is NULL is forged. Teardown stops polling before +* the QP is destroyed. +*/ + ibqp =smp_load_acquire (&dev->umrc.qp); +if (unlikely (!ibqp)) { +mlx5_ib_err (dev,"CQE on the UMR CQ before its QP is published\n" ); + goto forged_cqe; + } + qp =to_mqp (ibqp); + wq = &qp->sq; + idx = wqe_ctr & (wq->wqe_cnt -1 ); + +if (unlikely ((opcode !=MLX5_CQE_REQ && opcode !=MLX5_CQE_REQ_ERR ) || + qpn != umrc->qpn || sop !=MLX5_OPCODE_UMR )) { +mlx5_ib_err (dev, +"Unexpected CQE on UMR CQ: opcode 0x%x sop 0x%x qpn 0x%x\n" , + opcode, sop, qpn); + goto forged_cqe; + } + +/* Pairs with smp_store_release() in mlx5r_umr_post_send() */ + head = umrc->pending_head; + expected =smp_load_acquire (&umrc->pending[head & (MLX5_UMR_MAX_WR -1 )]); + +if (unlikely (!expected)) { +mlx5_ib_err (dev, +"UMR CQE wqe_ctr 0x%x with an empty shadow FIFO, possible NIC forgery\n" , + wqe_ctr); + goto forged_cqe; + } + +if (unlikely (wqe_ctr != expected->wqe_ctr)) { +mlx5_ib_err (dev, +"UMR wqe_ctr 0x%x mismatch with expected context, possible NIC forgery\n" , + wqe_ctr); + goto forged_cqe; + } + +/* +* A WQE records wq->head when posted, and mlx5r_ring_db() then advances +* wq->head. If they are still equal, mlx5r_ring_db() was not reached +* yet, so the WQE was never handed to the NIC. +*/ +if (unlikely (wq->wqe_head[idx] ==READ_ONCE (wq->head))) { +mlx5_ib_err (dev, +"UMR CQE wqe_ctr 0x%x for an uncommitted WQE, possible NIC forgery\n" , + wqe_ctr); + goto forged_cqe; + } + +if (opcode ==MLX5_CQE_REQ ) { + wc->status =IB_WC_SUCCESS ; + }else { +/* Copy the CQE, so its syndrome is read once */ + err_cqe = *(struct mlx5_err_cqe *)cqe64; +mlx5_handle_error_cqe (dev, &err_cqe, wc); +/* +* A real failure during a recovery is forged, the QP +* only flushes. +*/ +if (wc->status !=IB_WC_WR_FLUSH_ERR && +cmpxchg (&umrc->state,MLX5_UMR_STATE_ACTIVE , +MLX5_UMR_STATE_RECOVER ) !=MLX5_UMR_STATE_ACTIVE ) { +mlx5_ib_err (dev, +"UMR error CQE status %d in state %d, possible NIC forgery\n" , + wc->status,READ_ONCE (umrc->state)); + goto forged_cqe; + } + } + +/* Pop the shadow FIFO head: validated, dispatch to its waiter */ +WRITE_ONCE (umrc->pending[head & (MLX5_UMR_MAX_WR -1 )],NULL ); + umrc->pending_head = head +1 ; + wc->wr_cqe = &expected->cqe; + + wc->qp = &qp->ibqp; + wq->tail = wq->wqe_head[idx] +1 ; +/* Advance wq->last_poll, the internal error flush starts from it */ +handle_atomics (qp, cqe64, wq->last_poll, idx); + +return 0 ; + +forged_cqe: +/* mlx5_ib_poll_cq() updates the CI only for a returned completion */ +mlx5_cq_set_ci (&cq->mcq); +/* +* The NIC forged a CQE. Fail the UMR path for good, ignore any later +* CQE and force the health recovery, as the fatal sensors still read +* clean. The internal error flush then completes the waiters. Return +* an error, not -EAGAIN, as a CQE was consumed. +*/ + umrc->state =MLX5_UMR_STATE_ERR ; + cq->umr_verify = false; +mlx5_trigger_health_work_force (dev->mdev); +return -EIO ; +} + +/* +* mlx5_poll_one() trusts the CQE, so it must not run in adversarial_mode. +* Kernel ULPs are kept off the device and user CQs are polled by +* userspace, so only the UMR CQ is polled here, by its verifying poller. +* Any other CQ, and the UMR CQ before its poller is set up or once polling +* stopped, returns no CQE and nothing is consumed. +* +* Called with cq->lock held, which serializes umr_verify changes. +*/ +static int mlx5_ib_poll_cq_adversarial (struct mlx5_ib_cq *cq,int num_entries, +struct ib_wc *wc) +{ +int npolled; + +if (!cq->umr_verify) +return 0 ; + +for (npolled =0 ; npolled < num_entries; npolled++) { +if (mlx5_ib_poll_one_umr (cq, wc + npolled)) +break ; + } + +return npolled; +} +int mlx5_ib_poll_cq (struct ib_cq *ibcq,int num_entries,struct ib_wc *wc) {struct mlx5_ib_cq *cq =to_mcq (ibcq);
@@ -632,11 +817,18 @@ int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)if (unlikely (!list_empty (&cq->wc_list))) soft_polled =poll_soft_wc (cq, num_entries, wc, false); +if (unlikely (dev->ib_dev.adversarial_mode)) { + npolled =mlx5_ib_poll_cq_adversarial (cq, num_entries - soft_polled, + wc + soft_polled); + goto set_ci; + } +for (npolled =0 ; npolled < num_entries - soft_polled; npolled++) {if (mlx5_poll_one (cq, &cur_qp, wc + soft_polled + npolled))break ; } +set_ci:if (npolled)mlx5_cq_set_ci (&cq->mcq); out:
drivers/infiniband/hw/mlx5/mlx5_ib.h +5 -0
@@ -592,6 +592,8 @@ struct mlx5_ib_cq {enum ib_cq_notify_flags notify_flags;struct work_struct notify_work;u16 private_flags;/* Use mlx5_ib_cq_pr_flags */ +/* adversarial_mode: polled by the verifying UMR poller */ +bool umr_verify; };struct mlx5_ib_wc {
@@ -766,6 +768,8 @@ struct umr_common {struct ib_pd *pd;struct ib_cq *cq;struct ib_qp *qp; +/* Checked against each CQE in adversarial_mode */ +u32 qpn;/* Protects from UMR QP overflow */ struct semaphore sem;
@@ -1309,6 +1313,7 @@ int mlx5_ib_create_user_cq(struct ib_cq *ibcq, struct uverbs_attr_bundle *attrs);int mlx5_ib_destroy_cq (struct ib_cq *cq,struct ib_udata *udata);int mlx5_ib_poll_cq (struct ib_cq *ibcq,int num_entries,struct ib_wc *wc); +void mlx5_ib_cq_stop_polling (struct ib_cq *ibcq);int mlx5_ib_pre_destroy_cq (struct ib_cq *cq);void mlx5_ib_post_destroy_cq (struct ib_cq *cq);int mlx5_ib_arm_cq (struct ib_cq *ibcq,enum ib_cq_notify_flags flags);
drivers/infiniband/hw/mlx5/umr.c +38 -0
@@ -194,6 +194,23 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev)sema_init (&dev->umrc.sem,MAX_UMR_WR );mutex_init (&dev->umrc.lock); dev->umrc.state =MLX5_UMR_STATE_ACTIVE ; + +if (dev->ib_dev.adversarial_mode) { +struct mlx5_ib_cq *mcq =to_mcq (cq); +unsigned long flags; + + dev->umrc.qpn = qp->qp_num; +/* +* UMRs can be posted as soon as the QP is published below, by +* this caller or by a concurrent MR registration, so enable +* the verifying UMR poller first. The CQ is already armed, so +* set it under cq->lock, which mlx5_ib_poll_cq() holds. +*/ +spin_lock_irqsave (&mcq->lock, flags); + mcq->umr_verify = true; +spin_unlock_irqrestore (&mcq->lock, flags); + } +smp_store_release (&dev->umrc.qp, qp);mutex_unlock (&dev->umrc.init_lock);
@@ -212,6 +229,14 @@ void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev) {if (dev->umrc.state ==MLX5_UMR_STATE_UNINIT )return ; + +/* +* Stop polling before the QP is destroyed, as its QPN may then be +* reused and a forged CQE carrying it must not be interpreted. +*/ +if (dev->ib_dev.adversarial_mode) +mlx5_ib_cq_stop_polling (dev->umrc.cq); +mutex_destroy (&dev->umrc.lock);/* After device init, UMR cp/qp are not unset during the lifetime. */ ib_destroy_qp (dev->umrc.qp);
@@ -319,6 +344,11 @@ static int mlx5r_umr_recover(struct mlx5_ib_dev *dev, u32 mkey,int err;mutex_lock (&umrc->lock); +if (dev->ib_dev.adversarial_mode && umrc->state ==MLX5_UMR_STATE_ERR ) { +/* The NIC forged a CQE, don't revive the QP */ +mutex_unlock (&umrc->lock); +return -EFAULT ; + }/* Preventing any further WRs to be sent now */ if (umrc->state !=MLX5_UMR_STATE_RECOVER ) { mlx5_ib_warn(dev, "UMR recovery encountered an unexpected state=%d\n",
@@ -425,6 +455,14 @@ static int mlx5r_umr_post_send_wait(struct mlx5_ib_dev *dev, u32 mkey,if (umr_context.status ==IB_WC_WR_FLUSH_ERR )continue ; +if (dev->ib_dev.adversarial_mode) { +/* A forged CQE was detected, don't recover the QP */ +if (umrc->state ==MLX5_UMR_STATE_ERR ) { + err = -EFAULT ; +break ; + } + } +WARN_ON_ONCE (1 ); mlx5_ib_warn(dev, "reg umr failed (%u). Trying to recover and resubmit the flushed WQEs, mkey = %u\n",
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 12/21] RDMA/mlx5: Verify UMR CQ polling against a hostile NIC
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] RDMA/mlx5: incomplete umrc->state checks in mlx5_ib_poll_one_umr() - [High] RDMA/mlx5: deadlock and…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] RDMA/mlx5: incomplete umrc->state checks in mlx5_ib_poll_one_umr()
- [High] RDMA/mlx5: deadlock and lost flush on forged CQE in mlx5_ib_poll_one_umr()
- [Medium] RDMA/mlx5: CQ re-arm loop in mlx5_ib_arm_cq() when umr_verify is false
--
commit d8d114091f7d4e4fa6dc6263146eaffadede67be
Author: Yishai Hadas <[email protected]>
RDMA/mlx5: Verify UMR CQ polling against a hostile NIC
This commit adds a dedicated UMR CQ poller for adversarial mode that validates CQEs against a shadow FIFO of posted UMR requests and triggers forced health recovery if a forged CQE is detected.
Quoted 4 lines
drivers/infiniband/hw/mlx5/cq.c +0
-0
[ ... ]
Quoted 3 lines
drivers/infiniband/hw/mlx5/cq.c +2
-0@@ -608,6 +609,190 @@ static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, +static int mlx5_ib_poll_one_umr (struct mlx5_ib_cq *cq,struct ib_wc *wc) +{
[ ... ]
Quoted 9 lines
drivers/infiniband/hw/mlx5/cq.c +9
-0+if (opcode ==MLX5_CQE_REQ ) { + wc->status =IB_WC_SUCCESS ; + }else { +/* Copy the CQE, so its syndrome is read once */ + err_cqe = *(struct mlx5_err_cqe *)cqe64; +mlx5_handle_error_cqe (dev, &err_cqe, wc); +/* +* A real failure during a recovery is forged, the QP +* only flushes.
drivers/infiniband/hw/mlx5/cq.c static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, · line 742
Quoted 10 lines
drivers/infiniband/hw/mlx5/cq.c +10
-0+*/ +if (wc->status !=IB_WC_WR_FLUSH_ERR && +cmpxchg (&umrc->state,MLX5_UMR_STATE_ACTIVE , +MLX5_UMR_STATE_RECOVER ) !=MLX5_UMR_STATE_ACTIVE ) { +mlx5_ib_err (dev, +"UMR error CQE status %d in state %d, possible NIC forgery\n" , + wc->status,READ_ONCE (umrc->state)); + goto forged_cqe; + } + }
[Severity: High]
Should mlx5_ib_poll_one_umr() also verify umrc->state for IB_WC_WR_FLUSH_ERR and MLX5_CQE_REQ completions?
When wc->status is IB_WC_WR_FLUSH_ERR, umrc->state is not checked. If a hostile NIC reports MLX5_CQE_SYNDROME_WR_FLUSH_ERR while umrc->state is MLX5_UMR_STATE_ACTIVE, mlx5_ib_poll_one_umr() accepts the CQE without changing umrc->state. The waiter in mlx5r_umr_post_send_wait() then sees IB_WC_WR_FLUSH_ERR, loops around while umrc->state is still MLX5_UMR_STATE_ACTIVE, and immediately reposts the WQE without sleeping or running recovery, allowing repeated flush CQEs to trap the thread in an unkillable infinite loop.
Conversely, once a non-flush error has moved the QP to error and umrc->state to MLX5_UMR_STATE_RECOVER, subsequent in-flight WQEs can only flush until mlx5r_umr_recover() resets the QP, but the MLX5_CQE_REQ branch accepts completions as IB_WC_SUCCESS without checking that umrc->state is MLX5_UMR_STATE_ACTIVE.
Quoted 17 lines
drivers/infiniband/hw/mlx5/cq.c +17
-0+ +/* Pop the shadow FIFO head: validated, dispatch to its waiter */ +WRITE_ONCE (umrc->pending[head & (MLX5_UMR_MAX_WR -1 )],NULL ); + umrc->pending_head = head +1 ; + wc->wr_cqe = &expected->cqe; + + wc->qp = &qp->ibqp; + wq->tail = wq->wqe_head[idx] +1 ; +/* Advance wq->last_poll, the internal error flush starts from it */ +handle_atomics (qp, cqe64, wq->last_poll, idx); + +return 0 ; + +forged_cqe: +/* mlx5_ib_poll_cq() updates the CI only for a returned completion */ +mlx5_cq_set_ci (&cq->mcq); +/*
drivers/infiniband/hw/mlx5/cq.c static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, · line 769
Quoted 10 lines
drivers/infiniband/hw/mlx5/cq.c +10
-0+* The NIC forged a CQE. Fail the UMR path for good, ignore any later +* CQE and force the health recovery, as the fatal sensors still read +* clean. The internal error flush then completes the waiters. Return +* an error, not -EAGAIN, as a CQE was consumed. +*/ + umrc->state =MLX5_UMR_STATE_ERR ; + cq->umr_verify = false; +mlx5_trigger_health_work_force (dev->mdev); +return -EIO ; +}
[Severity: High]
Can deferring waiter completion to mlx5_trigger_health_work_force() deadlock on dev->intf_state_mutex or lose the software flush completion?
During driver teardown, mlx5_uninit_one() and mlx5_unload_one_devl_locked() hold dev->intf_state_mutex while unregistering mlx5_ib, which deregisters remaining user MRs via mlx5_ib_dereg_mr() -> mlx5r_umr_revoke_mr() -> mlx5r_umr_post_send_wait(). If the NIC returns a forged CQE at that point, stopping CQ polling without completing umrc->pending deadlocks against force_fatal_report_work:
CPU0 CPU1 (health->wq)
---- -----------------mlx5_unload_one_devl_locked()
mutex_lock(&dev->intf_state_mutex)
...
mlx5r_umr_post_send_wait()
wait_for_completion(&umr_context.done)
<softirq>
mlx5_ib_poll_one_umr()
mlx5_trigger_health_work_force()
mlx5_fw_fatal_reporter_err()
mutex_lock(&dev->intf_state_mutex)*** DEADLOCK ***
In mlx5_uninit_one(), mlx5_unregister_device() has also already set MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV, so mlx5_dev_is_lightweight() is true and mlx5_trigger_health_work_force() drops the work item outright.
Even during normal operation, the UMR CQ uses IB_POLL_SOFTIRQ, where IRQ_POLL_F_SCHED stays set on cq->iop until ib_poll_handler() calls irq_poll_complete() after __ib_process_cq() returns. If mlx5_ib_handle_internal_error() runs on another CPU after mlx5_ib_poll_cq() checks mdev->state and before ib_poll_handler() calls irq_poll_complete(), its irq_poll_sched(&cq->iop) call is a no-op, and mlx5_ib_arm_cq() then returns 0 without rescheduling cq->iop, leaving waiters hung in wait_for_completion().
Quoted 5 lines
drivers/infiniband/hw/mlx5/cq.c +5
-0+static int mlx5_ib_poll_cq_adversarial (struct mlx5_ib_cq *cq,int num_entries, +struct ib_wc *wc) +{ +int npolled; +
drivers/infiniband/hw/mlx5/cq.c static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, · line 794
Quoted 10 lines
drivers/infiniband/hw/mlx5/cq.c +10
-0+if (!cq->umr_verify) +return 0 ; + +for (npolled =0 ; npolled < num_entries; npolled++) { +if (mlx5_ib_poll_one_umr (cq, wc + npolled)) +break ; + } + +return npolled; +}
[Severity: Medium]
Can returning 0 when cq->umr_verify is false cause an interrupt and softirq re-arm storm via mlx5_ib_arm_cq()?
When forged_cqe sets cq->umr_verify = false, it consumes only that single CQE. If the NIC placed another CQE behind it in the UMR CQ (or if a CQE arrives before umr_verify is enabled or after mlx5_ib_cq_stop_polling() clears it), mlx5_ib_poll_cq_adversarial() returns 0 without advancing cq->mcq.cons_index. Because completed < budget, ib_poll_handler() then calls ib_req_notify_cq() -> mlx5_ib_arm_cq(), which rings the CQ arm doorbell at the unadvanced cons_index and causes the NIC to fire another completion EQE immediately in a tight loop.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Re: [PATCH V2 rdma-next 12/21] RDMA/mlx5: Verify UMR CQ polling against a hostile NIC
Quoted 56 lines · On 18/11/2026 19:13, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] RDMA/mlx5: incompleteumrc->statechecks inmlx5_ib_poll_one_umr()
- [High] RDMA/mlx5: deadlock and lost flush on forged CQE inmlx5_ib_poll_one_umr()
- [Medium] RDMA/mlx5: CQ re-arm loop inmlx5_ib_arm_cq()whenumr_verifyis false
--commit
d8d114091f7d4e4fa6dc6263146eaffadede67be
Author: Yishai Hadas <[email protected]>RDMA/mlx5: Verify UMR CQ polling against a hostile NIC
This commit adds a dedicated UMR CQ poller for adversarial mode that validates CQEs against a shadow FIFO of posted UMR requests and triggers forced health recovery if a forged CQE is detected.
Quoted 4 lines
drivers/infiniband/hw/mlx5/cq.c +0
-0[ ... ]
Quoted 3 lines
drivers/infiniband/hw/mlx5/cq.c +2
-0@@ -608,6 +609,190 @@ static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, +static int mlx5_ib_poll_one_umr (struct mlx5_ib_cq *cq,struct ib_wc *wc) +{[ ... ]
Quoted 9 lines
drivers/infiniband/hw/mlx5/cq.c +9
-0+if (opcode ==MLX5_CQE_REQ ) { + wc->status =IB_WC_SUCCESS ; + }else { +/* Copy the CQE, so its syndrome is read once */ + err_cqe = *(struct mlx5_err_cqe *)cqe64; +mlx5_handle_error_cqe (dev, &err_cqe, wc); +/* +* A real failure during a recovery is forged, the QP +* only flushes. drivers/infiniband/hw/mlx5/cq.c static int poll_soft_wc(struct mlx5_ib_cq *cq, int num_entries, · line 742
Quoted 10 lines
drivers/infiniband/hw/mlx5/cq.c +10
-0+*/ +if (wc->status !=IB_WC_WR_FLUSH_ERR && +cmpxchg (&umrc->state,MLX5_UMR_STATE_ACTIVE , +MLX5_UMR_STATE_RECOVER ) !=MLX5_UMR_STATE_ACTIVE ) { +mlx5_ib_err (dev, +"UMR error CQE status %d in state %d, possible NIC forgery\n" , + wc->status,READ_ONCE (umrc->state)); + goto forged_cqe; + } + }[Severity: High]
Shouldmlx5_ib_poll_one_umr()also verifyumrc->stateforIB_WC_WR_FLUSH_ERRandMLX5_CQE_REQcompletions?
Quoted 8 lines
When
wc->statusisIB_WC_WR_FLUSH_ERR,umrc->stateis not checked. If a hostile NIC reportsMLX5_CQE_SYNDROME_WR_FLUSH_ERRwhileumrc->stateisMLX5_UMR_STATE_ACTIVE,mlx5_ib_poll_one_umr()accepts the CQE without changingumrc->state. The waiter inmlx5r_umr_post_send_wait()then seesIB_WC_WR_FLUSH_ERR, loops around whileumrc->stateis stillMLX5_UMR_STATE_ACTIVE, and immediately reposts the WQE without sleeping or running recovery, allowing repeated flush CQEs to trap the thread in an unkillable infinite loop.
Each repost waits in wait_for_completion() for its CQE, so the loop runs only as fast as the NIC returns flush CQEs. A hostile NIC can cause the same load by flooding any EQ with events, so this is a DoS, not a CPU spin. It can also hang the waiter by not returning a CQE at all. This
is out of scope for this series.
Quoted 6 lines
Conversely, once a non-flush error has moved the QP to error and
umrc->statetoMLX5_UMR_STATE_RECOVER, subsequent in-flight WQEs can only flush untilmlx5r_umr_recover()resets the QP, but theMLX5_CQE_REQbranch accepts completions asIB_WC_SUCCESSwithout checking thatumrc->stateisMLX5_UMR_STATE_ACTIVE.
A NIC can report a false success in any state, so checking the state doesn't add protection.
Quoted 3 lines
[Severity: High]
Can deferring waiter completion tomlx5_trigger_health_work_force()deadlock ondev->intf_state_mutexor lose the software flush completion?
The deadlock needs a forged CQE while a UMR is pending during unload, a rare timing that the NIC doesn't fully control. The same deadlock can happen today, when the firmware hits a fatal error while a UMR is
pending during unload, as the fatal report work also takes intf_state_mutex.
The software flush, which completes the pending UMR WRs once the device is in error, can also be lost in rare cases, e.g. during remove, where the health work is no longer queued. This can happen today as well, when the firmware hits a fatal error during remove.
In all these cases the outcome is a hung UMR waiter, which a hostile NIC can cause anyway by not returning a CQE at all. This is out of scope for this series.
Quoted 4 lines
[Severity: Medium]
Can returning 0 whencq->umr_verifyis false cause an interrupt and softirq re-arm storm viamlx5_ib_arm_cq()?
Only a hostile NIC can leave a CQE there, and it's short lived:
- After a forged CQE, the forced health recovery tears down the device.
- A CQE written during UMR init stays in the CQ only until umr_verify is set, once the UMR QP is ready. The next poll then checks it against
the posted UMR WRs, as for any CQE.
- After polling stops, the CQ is destroyed right after.
Again, this is a DoS, which is out of scope for this series.
Yishai
PATCH v2 13/21 RDMA/mlx5: Keep the UMR QP failed once a forged CQE is detected
In reply to Yishai HadasIn adversarial mode MLX5_UMR_STATE_ERR is a final state: the poller sets it when it rejects a forged CQE, after which hardware polling is stopped, and it stops mlx5r_umr_post_send_wait() from posting again.
mlx5r_umr_recover() runs concurrently with that and moves the state with plain stores: it enters RECOVER from whatever state the path is in and ends with an unconditional ACTIVE. An ERR set while a recovery is in flight is therefore overwritten, which opens the UMR path again for a NIC that was just caught lying, with its poller already stopped.
In adversarial mode move the state with cmpxchg() in recovery, ACTIVE to RECOVER on entry and RECOVER to ACTIVE at the end. If ERR was set in the meantime the transition leaves it in place and recovery returns -EFAULT. Outside adversarial mode the transitions are unchanged.
This keeps new UMRs away from the NIC until the forced health recovery moves the device to MLX5_DEVICE_STATE_INTERNAL_ERROR, after which posts fail with -EIO anyway.
--- drivers/infiniband/hw/mlx5/umr.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/umr.c +27 -2
@@ -335,6 +335,25 @@ static int mlx5r_umr_post_send(struct ib_qp *ibqp, u32 mkey,return err; } +/* +* Move the UMR state from @from to @to. In adversarial_mode ERR is a final +* state: it can be set concurrently by the CQ poller, so the move is atomic +* and does not replace it. Returns false if ERR was found, and true +* otherwise. Outside adversarial_mode this is the plain store it always was. +*/ +static bool mlx5r_umr_move_state (struct umr_common *umrc,unsigned int from, +unsigned int to) +{ + struct mlx5_ib_dev *dev = container_of(umrc, struct mlx5_ib_dev, umrc); + +if (!dev->ib_dev.adversarial_mode) { + umrc->state = to; +return true; + } + +return cmpxchg (&umrc->state, from, to) !=MLX5_UMR_STATE_ERR ; +} +static int mlx5r_umr_recover (struct mlx5_ib_dev *dev,u32 mkey,struct mlx5r_umr_context *umr_context,struct mlx5r_umr_wqe *wqe,bool with_data)
@@ -353,7 +372,11 @@ static int mlx5r_umr_recover(struct mlx5_ib_dev *dev, u32 mkey,if (umrc->state !=MLX5_UMR_STATE_RECOVER ) {mlx5_ib_warn (dev,"UMR recovery encountered an unexpected state=%d\n" , umrc->state); - umrc->state =MLX5_UMR_STATE_RECOVER ; +if (!mlx5r_umr_move_state (umrc,MLX5_UMR_STATE_ACTIVE , +MLX5_UMR_STATE_RECOVER )) { +mutex_unlock (&umrc->lock); +return -EFAULT ; + } }mutex_unlock (&umrc->lock);
@@ -387,7 +410,9 @@ static int mlx5r_umr_recover(struct mlx5_ib_dev *dev, u32 mkey, goto err; } - umrc->state =MLX5_UMR_STATE_ACTIVE ; +if (!mlx5r_umr_move_state (umrc,MLX5_UMR_STATE_RECOVER , +MLX5_UMR_STATE_ACTIVE )) +return -EFAULT ;return 0 ; err:
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 13/21] RDMA/mlx5: Keep the UMR QP failed once a forged CQE is detected
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
In adversarial mode
MLX5_UMR_STATE_ERRis a final state: the poller sets it when it rejects a forged CQE, after which hardware polling is stopped, and it stopsmlx5r_umr_post_send_wait()from posting again.
mlx5r_umr_recover()runs concurrently with that and moves the state with plain stores: it enters RECOVER from whatever state the path is in and ends with an unconditional ACTIVE. An ERR set while a recovery is in flight is therefore overwritten, which opens the UMR path again for a NIC that was just caught lying, with its poller already stopped.In adversarial mode move the state with
cmpxchg()in recovery, ACTIVE to RECOVER on entry and RECOVER to ACTIVE at the end. If ERR was set in the meantime the transition leaves it in place and recovery returns-EFAULT. Outside adversarial mode the transitions are unchanged.
Quoted 5 lines
This keeps new UMRs away from the NIC until the forced health recovery moves the device to
MLX5_DEVICE_STATE_INTERNAL_ERROR, after which posts fail with-EIOanyway.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH v2 14/21 RDMA/core: Set the CQ comp_handler after its poll context is set up
In reply to Yishai Hadas__ib_alloc_cq() sets comp_handler before it initializes the poll context the handler schedules, and for the workqueue contexts it arms the CQ before setting comp_wq. The CQ is reachable from the completion interrupt once ops.create_cq() returns, so a completion event raised in that window would schedule an uninitialized irq_poll or work, or queue work on a NULL workqueue. A conforming device raises no event for a new, empty CQ, but nothing in the core relies on that.
Initialize the poll context first, then set comp_handler, and arm the CQ only after that.
--- drivers/infiniband/core/cq.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/infiniband/core/cq.c +13 -6
@@ -217,6 +217,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe, .cqe = nr_cqe, .comp_vector = comp_vector, }; +ib_comp_handler comp_handler;struct ib_cq *cq;int ret = -ENOMEM ;
@@ -248,19 +249,16 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,switch (cq->poll_ctx) {case IB_POLL_DIRECT : - cq->comp_handler = ib_cq_completion_direct; + comp_handler = ib_cq_completion_direct;break ;case IB_POLL_SOFTIRQ : - cq->comp_handler = ib_cq_completion_softirq; - + comp_handler = ib_cq_completion_softirq;irq_poll_init (&cq->iop,IB_POLL_BUDGET_IRQ , ib_poll_handler); -ib_req_notify_cq (cq,IB_CQ_NEXT_COMP );break ;case IB_POLL_WORKQUEUE :case IB_POLL_UNBOUND_WORKQUEUE : - cq->comp_handler = ib_cq_completion_workqueue; + comp_handler = ib_cq_completion_workqueue;INIT_WORK (&cq->work, ib_cq_poll_work); -ib_req_notify_cq (cq,IB_CQ_NEXT_COMP ); cq->comp_wq = (cq->poll_ctx ==IB_POLL_WORKQUEUE ) ? ib_comp_wq : ib_comp_unbound_wq;break ;
@@ -269,6 +267,15 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe, goto out_destroy_cq; } +/* +* The CQ is reachable from the completion interrupt once created. Set +* the handler only after the poll context it schedules is set up, and +* arm the CQ only after that. +*/ + cq->comp_handler = comp_handler; +if (cq->poll_ctx !=IB_POLL_DIRECT ) +ib_req_notify_cq (cq,IB_CQ_NEXT_COMP ); +rdma_restrack_add (&cq->res);trace_cq_alloc (cq, nr_cqe, comp_vector, poll_ctx);return cq;
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 14/21] RDMA/core: Set the CQ comp_handler after its poll context is set up
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
__ib_alloc_cq()setscomp_handlerbefore it initializes the poll context the handler schedules, and for the workqueue contexts it arms the CQ before settingcomp_wq. The CQ is reachable from the completion interrupt onceops.create_cq()returns, so a completion event raised in that window would schedule an uninitializedirq_pollor work, or queue work on a NULL workqueue. A conforming device raises no event for a new, empty CQ, but nothing in the core relies on that.
Quoted 5 lines
Initialize the poll context first, then set
comp_handler, and arm the CQ only after that.Fixes 14d3a3b2498e ("IB: add a proper completion queue abstraction")Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
PATCH v2 15/21 RDMA/mlx5: Ignore completion events for a kernel CQ that is not ready
In reply to Yishai HadasA kernel CQ can be reached from the completion interrupt before it is set up: __ib_alloc_cq() sets its poll context and handler only after ops.create_cq(), and devr->c0 has no handler, as it is never armed.
A trusted NIC raises no event for a CQ that is not armed, but a hostile NIC in adversarial mode can. For devr->c0 that ends in a NULL call. For a CQ from __ib_alloc_cq(), on a weakly ordered CPU, the interrupt can see the handler but not the poll context, and crash in irq_poll.
In adversarial mode, give kernel CQs their own event callback, which ignores events until the first arm, the point where the core has finished setting up the CQ. mlx5_ib_arm_cq() marks the CQ ready with a release before the doorbell, and the callback checks it with an acquire.
--- drivers/infiniband/hw/mlx5/cq.c | 31 +++++++++++++++++++++++++++- drivers/infiniband/hw/mlx5/mlx5_ib.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/cq.c +30 -1
@@ -49,6 +49,24 @@ static void mlx5_ib_cq_comp(struct mlx5_core_cq *cq, struct mlx5_eqe *eqe) ibcq->comp_handler (ibcq, ibcq->cq_context); } +/* +* A hostile NIC can raise an event for a kernel CQ before the core arms it, +* when its poll context and handler may not be visible yet. Ignore events +* until the core finished setting up the CQ. +*/ +static void mlx5_ib_kernel_cq_comp (struct mlx5_core_cq *cq, +struct mlx5_eqe *eqe) +{ +/* +* Only the first events can find it unset. Pairs with the release in +* mlx5_ib_arm_cq(). +*/ +if (!smp_load_acquire (&to_mibcq (cq)->ready)) +return ; + +mlx5_ib_cq_comp (cq, eqe); +} +static void mlx5_ib_cq_event (struct mlx5_core_cq *mcq,enum mlx5_event type) { struct mlx5_ib_cq *cq = container_of(mcq, struct mlx5_ib_cq, mcq);
@@ -853,6 +871,16 @@ int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) ret =1 ;spin_unlock_irqrestore (&cq->lock, irq_flags); +/* +* The core arms a kernel CQ only after its poll context and handler +* are set. Mark it ready before the doorbell, so an event raised +* right after it is not dropped. +*/ +if (ibcq->device->adversarial_mode && !cq->ready) { +/* Pairs with the acquire in mlx5_ib_kernel_cq_comp() */ +smp_store_release (&cq->ready, true); + } + mlx5_cq_arm(&cq->mcq, (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED ? MLX5_CQ_DB_REQ_NOT_SOL : MLX5_CQ_DB_REQ_NOT,
@@ -1284,7 +1312,8 @@ int mlx5_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,MLX5_SET (cqc, cqc, c_eqn_or_apu_element, eqn);MLX5_SET64 (cqc, cqc, dbr_addr, cq->db.dma); - cq->mcq.comp = mlx5_ib_cq_comp; + cq->mcq.comp = dev->ib_dev.adversarial_mode ? mlx5_ib_kernel_cq_comp : + mlx5_ib_cq_comp; err =mlx5_core_create_cq (dev->mdev, &cq->mcq, cqb, inlen, out,sizeof (out));
drivers/infiniband/hw/mlx5/mlx5_ib.h +2 -0
@@ -592,6 +592,8 @@ struct mlx5_ib_cq {enum ib_cq_notify_flags notify_flags;struct work_struct notify_work;u16 private_flags;/* Use mlx5_ib_cq_pr_flags */ +/* adversarial_mode: kernel CQ events are handled only once set */ +bool ready;/* adversarial_mode: polled by the verifying UMR poller */ bool umr_verify; };
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 15/21] RDMA/mlx5: Ignore completion events for a kernel CQ that is not ready
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
A kernel CQ can be reached from the completion interrupt before it is set up:
__ib_alloc_cq()sets its poll context and handler only afterops.create_cq(), anddevr->c0has no handler, as it is never armed.A trusted NIC raises no event for a CQ that is not armed, but a hostile NIC in adversarial mode can. For
devr->c0that ends in a NULL call. For a CQ from__ib_alloc_cq(), on a weakly ordered CPU, the interrupt can see the handler but not the poll context, and crash inirq_poll.
Quoted 7 lines
In adversarial mode, give kernel CQs their own event callback, which ignores events until the first arm, the point where the core has finished setting up the CQ.
mlx5_ib_arm_cq()marks the CQ ready with a release before the doorbell, and the callback checks it with an acquire.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
PATCH v2 16/21 RDMA/mlx5: Validate EQE port and GSI port before indexing devr.ports[]
In reply to Yishai Hadasdevr.ports[] has 2 entries, but it is indexed by port numbers taken from the NIC, which adversarial mode does not trust.
handle_port_change() uses the EQE port before any validation, so port 0 wraps the index to UINT_MAX and a port above 2 overflows the array. mlx5_ib_create_gsi() gets a port already checked against phys_port_cnt, but that comes from the num_ports and num_vhca_ports FW caps, which may report more than 2 ports.
Validate the port and bound it by ARRAY_SIZE() in both paths.
--- drivers/infiniband/hw/mlx5/gsi.c | 4 ++++ drivers/infiniband/hw/mlx5/main.c | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/infiniband/hw/mlx5/gsi.c +4 -0
@@ -95,6 +95,10 @@ int mlx5_ib_create_gsi(struct ib_pd *pd, struct mlx5_ib_qp *mqp,int num_qps =0 ;int ret; +if (!rdma_is_port_valid (&dev->ib_dev, port_num) || + port_num >ARRAY_SIZE (dev->devr.ports)) +return -EINVAL ; +if (mlx5_ib_deth_sqpn_cap (dev)) {if (MLX5_CAP_GEN (dev->mdev, port_type) ==MLX5_CAP_PORT_TYPE_IB )
drivers/infiniband/hw/mlx5/main.c +6 -5
@@ -3062,6 +3062,12 @@ static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe, {u32 port = (eqe->data.port.port >>4 ) &0xf ; +if (!rdma_is_port_valid (&ibdev->ib_dev, port) || + port >ARRAY_SIZE (ibdev->devr.ports)) { +mlx5_ib_warn (ibdev,"warning: event on port %d\n" , port); +return -EINVAL ; + } + ibev->element.port_num = port;switch (eqe->sub_type) {
@@ -3139,11 +3145,6 @@ static void mlx5_ib_handle_event(struct work_struct *_work) ibev.device = &ibdev->ib_dev; -if (!rdma_is_port_valid (&ibdev->ib_dev, ibev.element.port_num)) { -mlx5_ib_warn (ibdev,"warning: event on port %d\n" , ibev.element.port_num); - goto out; - } -if (ibdev->ib_active)ib_dispatch_event (&ibev);
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 16/21] RDMA/mlx5: Validate EQE port and GSI port before indexing devr.ports[]
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
devr.ports[] has 2 entries, but it is indexed by port numbers taken from the NIC, which adversarial mode does not trust.
handle_port_change()uses the EQE port before any validation, so port 0 wraps the index toUINT_MAXand a port above 2 overflows the array.mlx5_ib_create_gsi()gets a port already checked againstphys_port_cnt, but that comes from thenum_portsandnum_vhca_portsFW caps, which may report more than 2 ports.
Quoted 3 lines
Validate the port and bound it by
ARRAY_SIZE()in both paths.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
PATCH v2 17/21 RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup
In reply to Yishai Hadassqrq_state_to_qp_state() indexes the 5x5 sqrq_trans[] table with the RQ and SQ states returned by QUERY_RQ and QUERY_SQ. The state fields are 4 bits wide, so an untrusted NIC can return a state above 4 and the lookup reads past the table.
Reject out of range states with -EIO before the lookup.
--- drivers/infiniband/hw/mlx5/qp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/hw/mlx5/qp.c +3 -0
@@ -5081,6 +5081,9 @@ static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, }, }; +if (sq_state >=MLX5_SQ_NUM_STATE || rq_state >=MLX5_RQ_NUM_STATE ) +return -EIO ; + *qp_state = sqrq_trans[rq_state][sq_state];if (*qp_state ==MLX5_QP_STATE_BAD ) {
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 17/21] RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] RDMA/mlx5: sqrq_state_to_qp_state() accepts invalid FW states 2 and 4 --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] RDMA/mlx5: sqrq_state_to_qp_state() accepts invalid FW states 2 and 4
--
commit 3eeb50e819c6aa09e6f32a3af53732e8d4d484f9
Author: Yishai Hadas <[email protected]>
RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup
This commit bounds-checks the RQ and SQ states returned by firmware against MLX5_RQ_NUM_STATE and MLX5_SQ_NUM_STATE before indexing sqrq_trans[] in sqrq_state_to_qp_state().
Quoted 5 lines
drivers/infiniband/hw/mlx5/qp.c +0
-0
drivers/infiniband/hw/mlx5/qp.c static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, · line 5089
Quoted 9 lines
drivers/infiniband/hw/mlx5/qp.c +3
-0@@ -5081,6 +5081,9 @@ static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, }, }; +if (sq_state >=MLX5_SQ_NUM_STATE || rq_state >=MLX5_RQ_NUM_STATE ) +return -EIO ; + *qp_state = sqrq_trans[rq_state][sq_state];if (*qp_state ==MLX5_QP_STATE_BAD ) {
[Severity: Medium]
Can an untrusted NIC still return invalid hardware states 2 or 4 from QUERY_SQ and QUERY_RQ and bypass this check?
In mlx5_ifc.h, the defined hardware states are RST (0x0), RDY (0x1), and ERR (0x3). State 2 is undefined in the hardware interface and indexes an uninitialized row or column in sqrq_trans[][], which evaluates to 0 (IB_QPS_RESET) and overwrites qp->state with IB_QPS_RESET. State 4 is the driver-internal sentinel MLX5_SQ_STATE_NA / MLX5_RQ_STATE_NA (used when wqe_cnt is 0), which either misreports the QP state or maps to MLX5_QP_STATE_BAD and triggers the WARN(1) below.
In addition, query_raw_packet_qp_sq_state() and query_raw_packet_qp_rq_state() assign sq->state and rq->state before sqrq_state_to_qp_state() validates the state, so an invalid firmware value still corrupts the cached queue state even when the query fails:
drivers/infiniband/hw/mlx5/qp.c:query_raw_packet_qp_sq_state() {
err = mlx5_core_query_sq_state(dev->mdev, sq->base.mqp.qpn, sq_state);
if (err)
goto out;
sq->state = *sq_state;
...
}Validating that the firmware state is RST, RDY, or ERR inside query_raw_packet_qp_sq_state() and query_raw_packet_qp_rq_state() before assigning sq->state and rq->state would avoid both issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Re: [PATCH V2 rdma-next 17/21] RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup
Quoted 28 lines · On 18/11/2026 19:13, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] RDMA/mlx5:sqrq_state_to_qp_state()accepts invalid FW states 2 and 4
--commit
3eeb50e819c6aa09e6f32a3af53732e8d4d484f9
Author: Yishai Hadas <[email protected]>RDMA/mlx5: Validate firmware RQ/SQ state before sqrq_trans[] lookup
This commit bounds-checks the RQ and SQ states returned by firmware against
MLX5_RQ_NUM_STATEandMLX5_SQ_NUM_STATEbefore indexing sqrq_trans[] insqrq_state_to_qp_state().Quoted 13 lines
drivers/infiniband/hw/mlx5/qp.c +3
-0@@ -5081,6 +5081,9 @@ static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, }, }; +if (sq_state >=MLX5_SQ_NUM_STATE || rq_state >=MLX5_RQ_NUM_STATE ) +return -EIO ; + *qp_state = sqrq_trans[rq_state][sq_state];
Quoted 6 lines
drivers/infiniband/hw/mlx5/qp.c static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, · line 5089
Quoted 1 line
drivers/infiniband/hw/mlx5/qp.c +0
-0if (*qp_state ==MLX5_QP_STATE_BAD ) {[Severity: Medium]
Can an untrusted NIC still return invalid hardware states 2 or 4 fromQUERY_SQandQUERY_RQand bypass this check?
This patch prevents an out of bounds sqrq_trans[] access, as the series
targets memory safety. A wrong QP state isn't a memory safety issue, and the firmware can return a valid but wrong state anyway.
Yishai
PATCH v2 18/21 RDMA/mlx5: Clamp log_max_cq_sz shift in CQ size checks
In reply to Yishai HadasThe 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.
--- drivers/infiniband/hw/mlx5/cq.c | 52 ++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-)
drivers/infiniband/hw/mlx5/cq.c +39 -13
@@ -897,10 +897,14 @@ static int alloc_cq_frag_buf(struct mlx5_ib_dev *dev,struct mlx5_frag_buf *frag_buf = &buf->frag_buf;u8 log_wq_stride =6 + (cqe_size ==128 ?1 :0 );u8 log_wq_sz =ilog2 (cqe_size); +int size;int err; +if (check_mul_overflow (nent, cqe_size, &size)) +return -EINVAL ; + err =mlx5_frag_buf_alloc_node (dev->mdev, - nent * cqe_size, + size, frag_buf, dev->mdev->priv.numa_node);if (err)
@@ -943,6 +947,7 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata, {struct mlx5_ib_create_cq ucmd;unsigned long page_size; +size_t buf_size;unsigned int page_offset_quantized;__be64 *pas;int ncont;
@@ -966,9 +971,13 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata, *cqe_size = ucmd.cqe_size; +if (check_mul_overflow ((size_t )entries, (size_t )ucmd.cqe_size, + &buf_size)) +return -EINVAL ; + cq->buf.umem =ib_umem_get_cq_buf_or_va (&dev->ib_dev, attrs, ucmd.buf_addr, - entries * ucmd.cqe_size, + buf_size,IB_ACCESS_LOCAL_WRITE );if (IS_ERR (cq->buf.umem))return PTR_ERR (cq->buf.umem);
@@ -1167,6 +1176,15 @@ static void notify_soft_wc_handler(struct work_struct *work) cq->ibcq.comp_handler (&cq->ibcq, cq->ibcq.cq_context); } +/* +* 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. +*/ +static u64 cq_roundup_entries (u64 entries) +{ +return 1ULL <<fls64 (entries); +} +int mlx5_ib_create_user_cq (struct ib_cq *ibcq,const struct ib_cq_init_attr *attr,struct uverbs_attr_bundle *attrs)
@@ -1174,7 +1192,7 @@ int mlx5_ib_create_user_cq(struct ib_cq *ibcq,struct ib_udata *udata = &attrs->driver_udata;struct ib_device *ibdev = ibcq->device;struct mlx5_ib_create_cq_resp uresp = {}; -int entries = attr->cqe; +u64 entries = attr->cqe;int vector = attr->comp_vector;struct mlx5_ib_dev *dev =to_mdev (ibdev);struct mlx5_ib_cq *cq =to_mcq (ibcq);
@@ -1186,15 +1204,17 @@ int mlx5_ib_create_user_cq(struct ib_cq *ibcq,int cqe_size;int eqn;int err; +u64 max_cq_entries =MLX5_CAP_GEN_LOGSZ_U64 (dev->mdev, log_max_cq_sz); -if (attr->cqe > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz))) +if (attr->cqe > max_cq_entries)return -EINVAL ;if (check_cq_create_flags (attr->flags))return -EOPNOTSUPP ; - entries =roundup_pow_of_two (entries +1 ); -if (entries > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz))) + entries =cq_roundup_entries (entries); +/* cq->ibcq.cqe and create_cq_user() take an int */ +if (entries > max_cq_entries || entries >INT_MAX )return -EINVAL ; cq->ibcq.cqe = entries -1 ;
@@ -1262,7 +1282,7 @@ int mlx5_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, struct uverbs_attr_bundle *attrs) {struct ib_device *ibdev = ibcq->device; -int entries = attr->cqe; +u64 entries = attr->cqe;int vector = attr->comp_vector;struct mlx5_ib_dev *dev =to_mdev (ibdev);struct mlx5_ib_cq *cq =to_mcq (ibcq);
@@ -1274,12 +1294,14 @@ int mlx5_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,int cqe_size;int eqn;int err; +u64 max_cq_entries =MLX5_CAP_GEN_LOGSZ_U64 (dev->mdev, log_max_cq_sz); -if (attr->cqe > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz))) +if (attr->cqe > max_cq_entries)return -EINVAL ; - entries =roundup_pow_of_two (entries +1 ); -if (entries > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz))) + entries =cq_roundup_entries (entries); +/* cq->ibcq.cqe and create_cq_kernel() take an int */ +if (entries > max_cq_entries || entries >INT_MAX )return -EINVAL ; cq->ibcq.cqe = entries -1 ;
@@ -1577,18 +1599,22 @@ int mlx5_ib_resize_cq(struct ib_cq *ibcq, unsigned int entries,int inlen;int cqe_size;unsigned long flags; +u64 entries64 = entries; +u64 max_cq_entries =MLX5_CAP_GEN_LOGSZ_U64 (dev->mdev, log_max_cq_sz);if (!MLX5_CAP_GEN (dev->mdev, cq_resize)) {pr_info ("Firmware does not support resize CQ\n" );return -ENOSYS ; } -if (entries > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz))) +if (entries64 > max_cq_entries)return -EINVAL ; - entries =roundup_pow_of_two (entries +1 ); -if (entries > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_cq_sz)) +1 ) + entries64 =cq_roundup_entries (entries64); +/* resize_user() and resize_kernel() take an int */ +if (entries64 > max_cq_entries +1 || entries64 >INT_MAX )return -EINVAL ; + entries = entries64;if (entries == ibcq->cqe +1 )return 0 ;
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 18/21] RDMA/mlx5: Clamp log_max_cq_sz shift in CQ size checks
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
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 exceedINT_MAX, and it is then truncated when passed on as an int.Such a size also overflows the CQ buffer size, entries *
cqe_size, whichcreate_cq_user()andalloc_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 thatinit_cq_frag_buf()writes to.
Quoted 5 lines
Take the limit from
MLX5_CAP_GEN_LOGSZ_U64(), round up in 64 bits, and reject sizes aboveINT_MAX. Compute the buffer size withcheck_mul_overflow(), asresize_user()already does.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
PATCH v2 19/21 RDMA/mlx5: Clamp log_max_* shifts in QP and WQ limit checks
In reply to Yishai HadasSeveral QP and WQ size checks in qp.c compute their limit as 1 << cap, where cap is a log_max_* FW capability. An untrusted NIC can report 31 or more, which makes the shift undefined.
Use MLX5_CAP_GEN_LOGSZ_U32() for these limits, as done for log_max_cq_sz.
--- drivers/infiniband/hw/mlx5/qp.c | 36 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 20 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +16 -20
@@ -447,7 +447,7 @@ static int set_rq_size(struct mlx5_ib_dev *dev, struct ib_qp_cap *cap,int wq_size;/* Sanity check RQ size before proceeding */ -if (cap->max_recv_wr > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_qp_sz))) +if (cap->max_recv_wr >MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_qp_sz))return -EINVAL ;if (!has_rq) {
@@ -621,11 +621,11 @@ static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, wq_size =roundup_pow_of_two (attr->cap.max_send_wr * wqe_size); qp->sq.wqe_cnt = wq_size /MLX5_SEND_WQE_BB ; -if (qp->sq.wqe_cnt > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_qp_sz))) { -mlx5_ib_dbg (dev,"send queue size (%d * %d / %d -> %d) exceeds limits(%d)\n" , +if (qp->sq.wqe_cnt >MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_qp_sz)) { +mlx5_ib_dbg (dev,"send queue size (%d * %d / %d -> %d) exceeds limits(%u)\n" , attr->cap.max_send_wr, wqe_size,MLX5_SEND_WQE_BB , qp->sq.wqe_cnt, -1 <<MLX5_CAP_GEN (dev->mdev, log_max_qp_sz)); +MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_qp_sz));return -ENOMEM ; } qp->sq.wqe_shift =ilog2 (MLX5_SEND_WQE_BB );
@@ -663,10 +663,10 @@ static int set_user_buf_size(struct mlx5_ib_dev *dev, qp->sq.wqe_cnt = ucmd->sq_wqe_count; -if (qp->sq.wqe_cnt > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_qp_sz))) { -mlx5_ib_warn (dev,"wqe_cnt %d, max_wqes %d\n" , +if (qp->sq.wqe_cnt >MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_qp_sz)) { +mlx5_ib_warn (dev,"wqe_cnt %d, max_wqes %u\n" , qp->sq.wqe_cnt, -1 <<MLX5_CAP_GEN (dev->mdev, log_max_qp_sz)); +MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_qp_sz));return -EINVAL ; }
@@ -2155,7 +2155,7 @@ static int create_dci(struct mlx5_ib_dev *dev, struct ib_pd *pd, ucmd->rq_wqe_count != qp->rq.wqe_cnt)return -EINVAL ; -if (ucmd->sq_wqe_count > (1 <<MLX5_CAP_GEN (mdev, log_max_qp_sz))) +if (ucmd->sq_wqe_count >MLX5_CAP_GEN_LOGSZ_U32 (mdev, log_max_qp_sz))return -EINVAL ; ts_format = get_qp_ts_format(dev, to_mcq(init_attr->send_cq),
@@ -2322,7 +2322,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, ucmd->rq_wqe_count != qp->rq.wqe_cnt)return -EINVAL ; -if (ucmd->sq_wqe_count > (1 <<MLX5_CAP_GEN (mdev, log_max_qp_sz))) +if (ucmd->sq_wqe_count >MLX5_CAP_GEN_LOGSZ_U32 (mdev, log_max_qp_sz))return -EINVAL ;if (init_attr->qp_type !=IB_QPT_RAW_PACKET ) {
@@ -4809,19 +4809,15 @@ static bool mlx5_ib_modify_qp_allowed(struct mlx5_ib_dev *dev,static int validate_rd_atomic (struct mlx5_ib_dev *dev,struct ib_qp_attr *attr,int attr_mask,enum ib_qp_type qp_type) { -int log_max_ra_res; -int log_max_ra_req; +u32 log_max_ra_res; +u32 log_max_ra_req;if (qp_type ==MLX5_IB_QPT_DCI ) { - log_max_ra_res =1 <<MLX5_CAP_GEN (dev->mdev, - log_max_ra_res_dc); - log_max_ra_req =1 <<MLX5_CAP_GEN (dev->mdev, - log_max_ra_req_dc); + log_max_ra_res =MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_ra_res_dc); + log_max_ra_req =MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_ra_req_dc); }else { - log_max_ra_res =1 <<MLX5_CAP_GEN (dev->mdev, - log_max_ra_res_qp); - log_max_ra_req =1 <<MLX5_CAP_GEN (dev->mdev, - log_max_ra_req_qp); + log_max_ra_res =MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_ra_res_qp); + log_max_ra_req =MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_ra_req_qp); } if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
@@ -5511,7 +5507,7 @@ static int set_user_rq_size(struct mlx5_ib_dev *dev, struct mlx5_ib_rwq *rwq) {/* Sanity check RQ size before proceeding */ -if (wq_init_attr->max_wr > (1 <<MLX5_CAP_GEN (dev->mdev, log_max_wq_sz))) +if (wq_init_attr->max_wr >MLX5_CAP_GEN_LOGSZ_U32 (dev->mdev, log_max_wq_sz))return -EINVAL ;if (!ucmd->rq_wqe_count)
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 19/21] RDMA/mlx5: Clamp log_max_* shifts in QP and WQ limit checks
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Several QP and WQ size checks in
qp.ccompute their limit as 1 << cap, where cap is a log_max_* FW capability. An untrusted NIC can report 31 or more, which makes the shift undefined.Use
MLX5_CAP_GEN_LOGSZ_U32()for these limits, as done forlog_max_cq_sz.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
PATCH v2 20/21 RDMA/mlx5: Clamp log_max_* shifts in query_device and ucontext paths
In reply to Yishai HadasThe 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 reach 2^31, which doesn't fit the int srq->msrq.max, so make it a u32. The SRQ buffer size can also exceed the int passed to create_srq_user() and create_srq_kernel(). Reject it above INT_MAX, computing it with check_mul_overflow().
--- drivers/infiniband/hw/mlx5/mad.c | 2 +- drivers/infiniband/hw/mlx5/main.c | 66 +++++++++++++++++-------------- drivers/infiniband/hw/mlx5/srq.c | 7 ++-- drivers/infiniband/hw/mlx5/srq.h | 2 +- 4 files changed, 42 insertions(+), 35 deletions(-)
drivers/infiniband/hw/mlx5/mad.c +1 -1
@@ -629,7 +629,7 @@ int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u32 port, props->phys_state = out_mad->data[33 ] >>4 ; props->port_cap_flags =be32_to_cpup ((__be32 *)(out_mad->data +20 )); props->gid_tbl_len = out_mad->data[50 ]; - props->max_msg_sz =1 <<MLX5_CAP_GEN (mdev, log_max_msg); + props->max_msg_sz =MLX5_CAP_GEN_LOGSZ_U32 (mdev, log_max_msg); props->pkey_tbl_len = dev->pkey_table_len; props->bad_pkey_cntr =be16_to_cpup ((__be16 *)(out_mad->data +46 )); props->qkey_viol_cntr =be16_to_cpup ((__be16 *)(out_mad->data +48 ));
drivers/infiniband/hw/mlx5/main.c +36 -30
156 lines not on this page · raw message
drivers/infiniband/hw/mlx5/srq.c +4 -3
@@ -198,7 +198,7 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq,size_t buf_size;int err;struct mlx5_srq_attr in = {}; -__u32 max_srq_wqes =1 <<MLX5_CAP_GEN (dev->mdev, log_max_srq_sz); +__u32 max_srq_wqes =MLX5_CAP_GEN_LOGSZ_U32 (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 );
@@ -238,8 +238,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 (srq->msrq.max, desc_size, &buf_size) || + buf_size >INT_MAX )return -EINVAL ; in.type = init_attr->srq_type;
drivers/infiniband/hw/mlx5/srq.h +1 -1
@@ -41,7 +41,7 @@ struct mlx5_ib_dev;struct mlx5_core_srq {struct mlx5_core_rsc_common common;/* must be first */ u32 srqn; -int max; +u32 max;size_t max_gs;size_t max_avail_gather;int wqe_shift;
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 20/21] RDMA/mlx5: Clamp log_max_* shifts in query_device and ucontext paths
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
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_szwith a value of 64 or more, and to themax_tsocomputed as 1 <<max_lso_cap, which can be 31.Use
MLX5_CAP_GEN_LOGSZ_U32()andMLX5_CAP_GEN_LOGSZ_U64()for these values, andBIT()formax_tso. As the limits can now reach 2^31, computemax_qp_wrin 64 bits and saturate themax_res_rd_atomandmax_total_mcast_qp_attachproducts atU32_MAX. Capmax_cqeat 2^30 - 1, the largest CQ size the create path accepts.
Quoted 7 lines
The SRQ size limit then lets the rounded up SRQ size reach 2^31, which doesn't fit the int
srq->msrq.max, so make it a u32. The SRQ buffer size can also exceed the int passed tocreate_srq_user()andcreate_srq_kernel(). Reject it aboveINT_MAX, computing it withcheck_mul_overflow().Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
PATCH v2 21/21 RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
In reply to Yishai HadasUserspace must know when a device is in adversarial mode, and an unaware rdma-core must not get a context on such a device, as it doesn't harden itself against the NIC.
Report the mode with IB_UVERBS_CORE_SUPPORT_ADVERSARIAL in the core_support of GET_CONTEXT and QUERY_CONTEXT. Add an optional UVERBS_ATTR_GET_CONTEXT_FLAGS input, where userspace declares UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED. In adversarial mode, GET_CONTEXT without that flag fails with -EPERM, and so does the legacy write() GET_CONTEXT, which has no way to pass it.
--- drivers/infiniband/core/uverbs_cmd.c | 5 +++++ .../infiniband/core/uverbs_std_types_device.c | 16 ++++++++++++++++ include/uapi/rdma/ib_user_ioctl_cmds.h | 5 +++++ include/uapi/rdma/ib_user_ioctl_verbs.h | 1 + 4 files changed, 27 insertions(+)
drivers/infiniband/core/uverbs_cmd.c +5 -0
@@ -292,6 +292,11 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) goto err_ucontext; } +if (ib_dev->adversarial_mode) { + ret = -EPERM ; + goto err_uobj; + } + resp = (struct ib_uverbs_get_context_resp ){ .num_comp_vectors = attrs->ufile->device->num_comp_vectors, .async_fd = uobj->id,
drivers/infiniband/core/uverbs_std_types_device.c +16 -0
@@ -248,6 +248,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(u32 num_comp = attrs->ufile->device->num_comp_vectors;u64 core_support =IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS ;struct ib_device *ib_dev; +u32 ctx_flags;int ret; ib_dev = srcu_dereference(attrs->ufile->device->ib_dev,
@@ -255,6 +256,15 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (!ib_dev)return -EIO ; + ret =uverbs_get_flags32 (&ctx_flags, attrs,UVERBS_ATTR_GET_CONTEXT_FLAGS , +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED ); +if (ret) +return ret; + +if (ib_dev->adversarial_mode && + !(ctx_flags &UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED )) +return -EPERM ; + ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS , &num_comp,sizeof (num_comp));if (IS_UVERBS_COPY_ERR (ret))
@@ -262,6 +272,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (ib_dev->ops.uverbs_robust_udata) core_support |=IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA ; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))
@@ -303,6 +315,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_CONTEXT)(if (IS_UVERBS_COPY_ERR (ret))return ret; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_QUERY_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))
@@ -519,6 +533,8 @@ DECLARE_UVERBS_NAMED_METHOD( UVERBS_ATTR_MIN_SIZE(sizeof(int)),UA_OPTIONAL , UA_ALLOC_AND_COPY), +UVERBS_ATTR_FLAGS_IN (UVERBS_ATTR_GET_CONTEXT_FLAGS ,u32 , +UA_OPTIONAL ), UVERBS_ATTR_UHW()); DECLARE_UVERBS_NAMED_METHOD(
include/uapi/rdma/ib_user_ioctl_cmds.h +5 -0
@@ -101,10 +101,15 @@ enum uverbs_attrs_query_comp_cntr_caps_attr_ids { UVERBS_ATTR_QUERY_COMP_CNTR_CAPS_SUPPORTED_QP_ATTACH_OPS, }; +enum uverbs_attrs_get_context_flags { +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED =1 <<0 , +}; +enum uverbs_attrs_get_context_attr_ids {UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS ,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT ,UVERBS_ATTR_GET_CONTEXT_FD_ARR , +UVERBS_ATTR_GET_CONTEXT_FLAGS , };enum uverbs_attrs_query_context_attr_ids {
include/uapi/rdma/ib_user_ioctl_verbs.h +1 -0
@@ -47,6 +47,7 @@enum ib_uverbs_core_support {IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS =1 <<0 ,IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA =1 <<1 , +IB_UVERBS_CORE_SUPPORT_ADVERSARIAL =1 <<2 , };enum ib_uverbs_access_flags {
Signature · 1 line
2.18.1
[email protected]
AI reviewRe: [PATCH V2 rdma-next 21/21] RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Userspace must know when a device is in adversarial mode, and an unaware rdma-core must not get a context on such a device, as it doesn't harden itself against the NIC.
Quoted 8 lines
Report the mode with
IB_UVERBS_CORE_SUPPORT_ADVERSARIALin thecore_supportofGET_CONTEXTandQUERY_CONTEXT. Add an optionalUVERBS_ATTR_GET_CONTEXT_FLAGSinput, where userspace declaresUVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED. In adversarial mode,GET_CONTEXTwithout that flag fails with-EPERM, and so does the legacywrite()GET_CONTEXT, which has no way to pass it.Signed-off-by Yishai Hadas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Re: [PATCH V2 rdma-next 21/21] RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
In reply to Yishai HadasQuoted 3 lines · Yishai Hadas
Userspace must know when a device is in adversarial mode, and an unaware rdma-core must not get a context on such a device, as it doesn't harden itself against the NIC.
Why is this a “must”? If it is required, please describe in the commit message the scenario that cannot be supported without this new UAPI flag.
Quoted 7 lines
Report the mode with
IB_UVERBS_CORE_SUPPORT_ADVERSARIALin thecore_supportofGET_CONTEXTandQUERY_CONTEXT. Add an optionalUVERBS_ATTR_GET_CONTEXT_FLAGSinput, where userspace declaresUVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED. In adversarial mode,GET_CONTEXTwithout that flag fails with-EPERM, and so does the legacywrite()GET_CONTEXT, which has no way to pass it.
The above is AI generated useless information, completely useless.
Thanks
Quoted 115 lines
Signed-off-by Yishai Hadas <[email protected]>--- drivers/infiniband/core/uverbs_cmd.c | 5 +++++ .../infiniband/core/uverbs_std_types_device.c | 16 ++++++++++++++++ include/uapi/rdma/ib_user_ioctl_cmds.h | 5 +++++ include/uapi/rdma/ib_user_ioctl_verbs.h | 1 + 4 files changed, 27 insertions(+)drivers/infiniband/core/uverbs_cmd.c +5
-0@@ -292,6 +292,11 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) goto err_ucontext; } +if (ib_dev->adversarial_mode) { + ret = -EPERM ; + goto err_uobj; + } + resp = (struct ib_uverbs_get_context_resp ){ .num_comp_vectors = attrs->ufile->device->num_comp_vectors, .async_fd = uobj->id,drivers/infiniband/core/uverbs_std_types_device.c +16
-0@@ -248,6 +248,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(u32 num_comp = attrs->ufile->device->num_comp_vectors;u64 core_support =IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS ;struct ib_device *ib_dev; +u32 ctx_flags;int ret; ib_dev = srcu_dereference(attrs->ufile->device->ib_dev,@@ -255,6 +256,15 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (!ib_dev)return -EIO ; + ret =uverbs_get_flags32 (&ctx_flags, attrs,UVERBS_ATTR_GET_CONTEXT_FLAGS , +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED ); +if (ret) +return ret; + +if (ib_dev->adversarial_mode && + !(ctx_flags &UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED )) +return -EPERM ; + ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS , &num_comp,sizeof (num_comp));if (IS_UVERBS_COPY_ERR (ret))@@ -262,6 +272,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (ib_dev->ops.uverbs_robust_udata) core_support |=IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA ; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))@@ -303,6 +315,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_CONTEXT)(if (IS_UVERBS_COPY_ERR (ret))return ret; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_QUERY_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))@@ -519,6 +533,8 @@ DECLARE_UVERBS_NAMED_METHOD( UVERBS_ATTR_MIN_SIZE(sizeof(int)),UA_OPTIONAL , UA_ALLOC_AND_COPY), +UVERBS_ATTR_FLAGS_IN (UVERBS_ATTR_GET_CONTEXT_FLAGS ,u32 , +UA_OPTIONAL ), UVERBS_ATTR_UHW()); DECLARE_UVERBS_NAMED_METHOD(include/uapi/rdma/ib_user_ioctl_cmds.h +5
-0@@ -101,10 +101,15 @@ enum uverbs_attrs_query_comp_cntr_caps_attr_ids { UVERBS_ATTR_QUERY_COMP_CNTR_CAPS_SUPPORTED_QP_ATTACH_OPS, }; +enum uverbs_attrs_get_context_flags { +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED =1 <<0 , +}; +enum uverbs_attrs_get_context_attr_ids {UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS ,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT ,UVERBS_ATTR_GET_CONTEXT_FD_ARR , +UVERBS_ATTR_GET_CONTEXT_FLAGS , };enum uverbs_attrs_query_context_attr_ids {include/uapi/rdma/ib_user_ioctl_verbs.h +1
-0@@ -47,6 +47,7 @@enum ib_uverbs_core_support {IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS =1 <<0 ,IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA =1 <<1 , +IB_UVERBS_CORE_SUPPORT_ADVERSARIAL =1 <<2 , };enum ib_uverbs_access_flags {Signature · 1 line
2.18.1
Re: [PATCH V2 rdma-next 21/21] RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
Quoted 8 lines · Leon Romanovsky
Quoted 3 lines · Yishai Hadas
Userspace must know when a device is in adversarial mode, and an unaware rdma-core must not get a context on such a device, as it doesn't harden itself against the NIC.
Why is this a “must”? If it is required, please describe in the commit message the scenario that cannot be supported without this new UAPI flag.
User space must protect itself from an untrusted NIC, as the kernel does. Hardening has a cost, so user space must know when to apply it, and unhardened user space must not run on such a device.
More details are in the suggested commit message below.
Quoted 10 lines
Quoted 7 lines
Report the mode with
IB_UVERBS_CORE_SUPPORT_ADVERSARIALin thecore_supportofGET_CONTEXTandQUERY_CONTEXT. Add an optionalUVERBS_ATTR_GET_CONTEXT_FLAGSinput, where userspace declaresUVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED. In adversarial mode,GET_CONTEXTwithout that flag fails with-EPERM, and so does the legacywrite()GET_CONTEXT, which has no way to pass it.The above is AI generated useless information, completely useless.
Sure, it's dropped in the suggested commit message below.
If no V3 is needed, could you please replace the commit message with this one when applying?
RDMA/core: Report and enforce adversarial mode via GET_CONTEXT
In adversarial mode the NIC is not trusted. As the kernel protects its own code from it, user space has to protect its own area, e.g. the data path that polls CQEs directly from the HW.
Hardened user space might use a different data path, with extra checks,
and support a smaller surface. This isn't needed for a trusted NIC, so user space must know when a device is in adversarial mode.
Add a GET_CONTEXT handshake. User space that supports adversarial mode
declares it, and the kernel reports the mode back, so user space moves
to the hardened mode. If user space doesn't declare it, GET_CONTEXT
fails with -EPERM on a device in adversarial mode. This prevents unhardened user space from running on such a device.
Yishai
Quoted 116 lines
Quoted 116 lines
Signed-off-by Yishai Hadas <[email protected]>--- drivers/infiniband/core/uverbs_cmd.c | 5 +++++ .../infiniband/core/uverbs_std_types_device.c | 16 ++++++++++++++++ include/uapi/rdma/ib_user_ioctl_cmds.h | 5 +++++ include/uapi/rdma/ib_user_ioctl_verbs.h | 1 + 4 files changed, 27 insertions(+)drivers/infiniband/core/uverbs_cmd.c +5
-0@@ -292,6 +292,11 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) goto err_ucontext; } +if (ib_dev->adversarial_mode) { + ret = -EPERM ; + goto err_uobj; + } + resp = (struct ib_uverbs_get_context_resp ){ .num_comp_vectors = attrs->ufile->device->num_comp_vectors, .async_fd = uobj->id,drivers/infiniband/core/uverbs_std_types_device.c +16
-0@@ -248,6 +248,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(u32 num_comp = attrs->ufile->device->num_comp_vectors;u64 core_support =IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS ;struct ib_device *ib_dev; +u32 ctx_flags;int ret; ib_dev = srcu_dereference(attrs->ufile->device->ib_dev,@@ -255,6 +256,15 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (!ib_dev)return -EIO ; + ret =uverbs_get_flags32 (&ctx_flags, attrs,UVERBS_ATTR_GET_CONTEXT_FLAGS , +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED ); +if (ret) +return ret; + +if (ib_dev->adversarial_mode && + !(ctx_flags &UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED )) +return -EPERM ; + ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS , &num_comp,sizeof (num_comp));if (IS_UVERBS_COPY_ERR (ret))@@ -262,6 +272,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(if (ib_dev->ops.uverbs_robust_udata) core_support |=IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA ; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))@@ -303,6 +315,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_CONTEXT)(if (IS_UVERBS_COPY_ERR (ret))return ret; +if (ib_dev->adversarial_mode) + core_support |=IB_UVERBS_CORE_SUPPORT_ADVERSARIAL ; ret =uverbs_copy_to (attrs,UVERBS_ATTR_QUERY_CONTEXT_CORE_SUPPORT , &core_support,sizeof (core_support));if (IS_UVERBS_COPY_ERR (ret))@@ -519,6 +533,8 @@ DECLARE_UVERBS_NAMED_METHOD( UVERBS_ATTR_MIN_SIZE(sizeof(int)),UA_OPTIONAL , UA_ALLOC_AND_COPY), +UVERBS_ATTR_FLAGS_IN (UVERBS_ATTR_GET_CONTEXT_FLAGS ,u32 , +UA_OPTIONAL ), UVERBS_ATTR_UHW()); DECLARE_UVERBS_NAMED_METHOD(include/uapi/rdma/ib_user_ioctl_cmds.h +5
-0@@ -101,10 +101,15 @@ enum uverbs_attrs_query_comp_cntr_caps_attr_ids { UVERBS_ATTR_QUERY_COMP_CNTR_CAPS_SUPPORTED_QP_ATTACH_OPS, }; +enum uverbs_attrs_get_context_flags { +UVERBS_ATTR_GET_CONTEXT_FLAG_ADVERSARIAL_SUPPORTED =1 <<0 , +}; +enum uverbs_attrs_get_context_attr_ids {UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS ,UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT ,UVERBS_ATTR_GET_CONTEXT_FD_ARR , +UVERBS_ATTR_GET_CONTEXT_FLAGS , };enum uverbs_attrs_query_context_attr_ids {include/uapi/rdma/ib_user_ioctl_verbs.h +1
-0@@ -47,6 +47,7 @@enum ib_uverbs_core_support {IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS =1 <<0 ,IB_UVERBS_CORE_SUPPORT_ROBUST_UDATA =1 <<1 , +IB_UVERBS_CORE_SUPPORT_ADVERSARIAL =1 <<2 , };enum ib_uverbs_access_flags {Signature · 1 line
2.18.1