diff options
author | Matan Barak <matanb@mellanox.com> | 2013-09-01 11:39:52 -0400 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2013-09-02 14:12:48 -0400 |
commit | 22878dbc9173a7f0322dd697b1b5b49a83a1d4d5 (patch) | |
tree | cfb2e55461d5893c65de39e3472e8f78264273c4 | |
parent | f77c0162a339400ad16f657603fdc3bf11654fd3 (diff) |
IB/core: Better checking of userspace values for receive flow steering
- 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>
-rw-r--r-- | drivers/infiniband/core/uverbs_cmd.c | 16 | ||||
-rw-r--r-- | include/rdma/ib_verbs.h | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 6e98df929e29..9112410da11d 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c | |||
@@ -2652,17 +2652,31 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file, | |||
2652 | if (copy_from_user(&cmd, buf, sizeof(cmd))) | 2652 | if (copy_from_user(&cmd, buf, sizeof(cmd))) |
2653 | return -EFAULT; | 2653 | return -EFAULT; |
2654 | 2654 | ||
2655 | if (cmd.comp_mask) | ||
2656 | return -EINVAL; | ||
2657 | |||
2655 | if ((cmd.flow_attr.type == IB_FLOW_ATTR_SNIFFER && | 2658 | if ((cmd.flow_attr.type == IB_FLOW_ATTR_SNIFFER && |
2656 | !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW)) | 2659 | !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW)) |
2657 | return -EPERM; | 2660 | return -EPERM; |
2658 | 2661 | ||
2662 | if (cmd.flow_attr.num_of_specs < 0 || | ||
2663 | cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS) | ||
2664 | return -EINVAL; | ||
2665 | |||
2666 | kern_attr_size = cmd.flow_attr.size - sizeof(cmd) - | ||
2667 | sizeof(struct ib_uverbs_cmd_hdr_ex); | ||
2668 | |||
2669 | if (cmd.flow_attr.size < 0 || cmd.flow_attr.size > in_len || | ||
2670 | kern_attr_size < 0 || kern_attr_size > | ||
2671 | (cmd.flow_attr.num_of_specs * sizeof(struct ib_kern_spec))) | ||
2672 | return -EINVAL; | ||
2673 | |||
2659 | if (cmd.flow_attr.num_of_specs) { | 2674 | if (cmd.flow_attr.num_of_specs) { |
2660 | kern_flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL); | 2675 | kern_flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL); |
2661 | if (!kern_flow_attr) | 2676 | if (!kern_flow_attr) |
2662 | return -ENOMEM; | 2677 | return -ENOMEM; |
2663 | 2678 | ||
2664 | memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr)); | 2679 | memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr)); |
2665 | kern_attr_size = cmd.flow_attr.size - sizeof(cmd) - sizeof(struct ib_uverbs_cmd_hdr_ex); | ||
2666 | if (copy_from_user(kern_flow_attr + 1, buf + sizeof(cmd), | 2680 | if (copy_from_user(kern_flow_attr + 1, buf + sizeof(cmd), |
2667 | kern_attr_size)) { | 2681 | kern_attr_size)) { |
2668 | err = -EFAULT; | 2682 | err = -EFAULT; |
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 274205d4df97..bd151eac1e61 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h | |||
@@ -1098,6 +1098,8 @@ enum ib_flow_spec_type { | |||
1098 | IB_FLOW_SPEC_UDP = 0x41 | 1098 | IB_FLOW_SPEC_UDP = 0x41 |
1099 | }; | 1099 | }; |
1100 | 1100 | ||
1101 | #define IB_FLOW_SPEC_SUPPORT_LAYERS 4 | ||
1102 | |||
1101 | /* Flow steering rule priority is set according to it's domain. | 1103 | /* Flow steering rule priority is set according to it's domain. |
1102 | * Lower domain value means higher priority. | 1104 | * Lower domain value means higher priority. |
1103 | */ | 1105 | */ |