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_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. Signed-off-by: Yishai Hadas --- drivers/infiniband/core/device.c | 8 ++++++++ include/rdma/ib_verbs.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 29af9fe860e2..eb6aa567d365 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -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; } /* diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index d6eaa3fee66e..6209a5166f0d 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -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; -- 2.18.1