IB/core: Better checking of userspace values for receive flow steering
authorMatan Barak <matanb@mellanox.com>
Sun, 1 Sep 2013 15:39:52 +0000 (18:39 +0300)
committerRoland Dreier <roland@purestorage.com>
Mon, 2 Sep 2013 18:12:48 +0000 (11:12 -0700)
  - Don't allow unsupported comp_mask values, user should check
    ibv_query_device to know which features are supported.
  - Add a check in ib_uverbs_create_flow() to verify the size passed
    from the user space.

Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/core/uverbs_cmd.c
include/rdma/ib_verbs.h

index 6e98df929e29c5b7ea011441d4fe13e4c3b9125e..9112410da11dde6470fd1215c4080c99a548c76f 100644 (file)
@@ -2652,17 +2652,31 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
        if (copy_from_user(&cmd, buf, sizeof(cmd)))
                return -EFAULT;
 
+       if (cmd.comp_mask)
+               return -EINVAL;
+
        if ((cmd.flow_attr.type == IB_FLOW_ATTR_SNIFFER &&
             !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW))
                return -EPERM;
 
+       if (cmd.flow_attr.num_of_specs < 0 ||
+           cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
+               return -EINVAL;
+
+       kern_attr_size = cmd.flow_attr.size - sizeof(cmd) -
+                        sizeof(struct ib_uverbs_cmd_hdr_ex);
+
+       if (cmd.flow_attr.size < 0 || cmd.flow_attr.size > in_len ||
+           kern_attr_size < 0 || kern_attr_size >
+           (cmd.flow_attr.num_of_specs * sizeof(struct ib_kern_spec)))
+               return -EINVAL;
+
        if (cmd.flow_attr.num_of_specs) {
                kern_flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL);
                if (!kern_flow_attr)
                        return -ENOMEM;
 
                memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr));
-               kern_attr_size = cmd.flow_attr.size - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr_ex);
                if (copy_from_user(kern_flow_attr + 1, buf + sizeof(cmd),
                                   kern_attr_size)) {
                        err = -EFAULT;
index 274205d4df974cb8305767a79c24beec9b376261..bd151eac1e61cac316e5f903e578a5524395d782 100644 (file)
@@ -1098,6 +1098,8 @@ enum ib_flow_spec_type {
        IB_FLOW_SPEC_UDP        = 0x41
 };
 
+#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
+
 /* Flow steering rule priority is set according to it's domain.
  * Lower domain value means higher priority.
  */