In adversarial mode the NIC is not trusted. The kernel protects itself, but user space has to protect its own memory as well, since rdma-core parses HW-written data, such as CQEs, directly. Hardened user space might use a different data path with extra checks, so it has to know when a device is in adversarial mode. rdma-core would like to move away from sysfs files, so the mode is reported on the ucontext rather than through the trust-level sysfs file, which has no generic path from an IB device, is unreliable in RDMA containers and races with device renaming. An rdma-core without this support uses that data without validating it, so on a device in adversarial mode the process runs without protection from the NIC, a silent mismatch. Such versions are already released and can't detect this, so fail GET_CONTEXT in the kernel to turn the mismatch into a visible error. The kernel reports adversarial mode in the GET_CONTEXT core_support, and user space declares its support with a new optional GET_CONTEXT flag. In adversarial mode, a GET_CONTEXT without that flag fails. In generic mode, nothing changes for older user space. Signed-off-by: Yishai Hadas --- 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(+) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index cb8532225322..3e65dafbc89f 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -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, diff --git a/drivers/infiniband/core/uverbs_std_types_device.c b/drivers/infiniband/core/uverbs_std_types_device.c index db65032e80b4..72c67f09533e 100644 --- a/drivers/infiniband/core/uverbs_std_types_device.c +++ b/drivers/infiniband/core/uverbs_std_types_device.c @@ -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( diff --git a/include/uapi/rdma/ib_user_ioctl_cmds.h b/include/uapi/rdma/ib_user_ioctl_cmds.h index 816b3107464f..3e482a4338f9 100644 --- a/include/uapi/rdma/ib_user_ioctl_cmds.h +++ b/include/uapi/rdma/ib_user_ioctl_cmds.h @@ -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 { diff --git a/include/uapi/rdma/ib_user_ioctl_verbs.h b/include/uapi/rdma/ib_user_ioctl_verbs.h index ca8b8b8d28f2..0abcbf1c3973 100644 --- a/include/uapi/rdma/ib_user_ioctl_verbs.h +++ b/include/uapi/rdma/ib_user_ioctl_verbs.h @@ -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 { -- 2.18.1