]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA: Add ib_copy_validate_udata_in_cm()
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 3 Mar 2026 19:50:01 +0000 (15:50 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Sun, 8 Mar 2026 10:20:25 +0000 (06:20 -0400)
For structures with comp_mask also absorb the check of comp_mask valid
bits into the helper. This is slightly tricky because ~ might not fully
extend to 64 bits, the helper inserts an explicit type to ensure that ~
covers all bits.

Link: https://patch.msgid.link/r/4-v3-bd56dd443069+49-bnxt_re_uapi_jgg@nvidia.com
Tested-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Acked-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/uverbs_ioctl.c
include/rdma/uverbs_ioctl.h

index 81798c0875ed3a49e30681c939f565669b10352c..5e5b00c6236fa8e09e2ecf17011f517d509d53b2 100644 (file)
@@ -898,3 +898,15 @@ int _ib_copy_validate_udata_in(struct ib_udata *udata, void *req,
        return 0;
 }
 EXPORT_SYMBOL(_ib_copy_validate_udata_in);
+
+int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata, u64 req_cm,
+                                   u64 valid_cm)
+{
+       ibdev_dbg(
+               rdma_udata_to_dev(udata),
+               "System call driver input udata has unsupported comp_mask %llx & ~%llx = %llx for ioctl %ps called by %pSR\n",
+               req_cm, valid_cm, req_cm & ~valid_cm,
+               uverbs_get_handler_fn(udata), __builtin_return_address(0));
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(_ib_copy_validate_udata_cm_fail);
index 505492443c36b5ff49f00e09578598508b2856af..a73016a977a12d7ac99d0765593e3184fe6c3c91 100644 (file)
@@ -1044,4 +1044,29 @@ uverbs_get_raw_fd(int *to, const struct uverbs_attr_bundle *attrs_bundle,
        _ib_copy_validate_udata_in(_udata, &(_req), sizeof(_req), \
                                   offsetofend(typeof(_req), _end_member))
 
+int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata, u64 req_cm,
+                                   u64 valid_cm);
+
+/**
+ * ib_copy_validate_udata_in_cm - Copy the req structure and check the comp_mask
+ * @_udata: The system calls ib_udata struct
+ * @_req: The name of an on-stack structure that holds the driver data
+ * @_end_member: The member in the struct that is the original end of struct
+ *               from the first kernel to introduce it.
+ * @_valid_cm: A bitmask of bits permitted in the comp_mask_field.
+ *
+ * Check that the udata input request struct is properly formed for this kernel.
+ * Then copy it into req
+ */
+#define ib_copy_validate_udata_in_cm(_udata, _req, _end_member, _valid_cm)    \
+       ({                                                                    \
+               typeof((_req).comp_mask) __valid_cm = _valid_cm;              \
+               int ret =                                                     \
+                       ib_copy_validate_udata_in(_udata, _req, _end_member); \
+               if (!ret && ((_req).comp_mask & ~__valid_cm))                 \
+                       ret = _ib_copy_validate_udata_cm_fail(                \
+                               _udata, (_req).comp_mask, __valid_cm);        \
+               ret;                                                          \
+       })
+
 #endif