diff options
author | Yann Droneaud <ydroneaud@opteya.com> | 2014-05-05 13:33:21 -0400 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2014-05-27 14:53:13 -0400 |
commit | a8237b32a3faab155a5dc8f886452147ce73da3e (patch) | |
tree | d1e5ab19dc27bf0f00fa0e59c61444ff9162000c | |
parent | a74d24168d2df78e7a532567eb0e7538e6b09568 (diff) |
IB/mlx5: add missing padding at end of struct mlx5_ib_create_cq
The i386 ABI disagrees with most other ABIs regarding alignment of
data type larger than 4 bytes: on most ABIs a padding must be added at
end of the structures, while it is not required on i386.
So for most ABI struct mlx5_ib_create_cq get padded to be aligned on a
8 bytes multiple, while for i386, such padding is not added.
The tool pahole can be used to find such implicit padding:
$ pahole --anon_include \
--nested_anon_include \
--recursive \
--class_name mlx5_ib_create_cq \
drivers/infiniband/hw/mlx5/mlx5_ib.o
Then, structure layout can be compared between i386 and x86_64:
+++ obj-i386/drivers/infiniband/hw/mlx5/mlx5_ib.o.pahole.txt 2014-03-28 11:43:07.386413682 +0100
--- obj-x86_64/drivers/infiniband/hw/mlx5/mlx5_ib.o.pahole.txt 2014-03-27 13:06:17.788472721 +0100
@@ -34,9 +34,8 @@ struct mlx5_ib_create_cq {
__u64 db_addr; /* 8 8 */
__u32 cqe_size; /* 16 4 */
- /* size: 20, cachelines: 1, members: 3 */
- /* last cacheline: 20 bytes */
+ /* size: 24, cachelines: 1, members: 3 */
+ /* padding: 4 */
+ /* last cacheline: 24 bytes */
};
This ABI disagreement will make an x86_64 kernel try to read past the
buffer provided by an i386 binary.
When boundary check will be implemented, a x86_64 kernel will refuse
to read past the i386 userspace provided buffer and the uverb will
fail.
Anyway, if the structure lies in memory on a page boundary and next
page is not mapped, ib_copy_from_udata() will fail when trying to read
the 4 bytes of padding and the uverb will fail.
This patch makes create_cq_user() takes care of the input data size to
handle the case where no padding is provided.
This way, x86_64 kernel will be able to handle struct
mlx5_ib_create_cq as sent by unpatched and patched i386 libmlx5.
Link: http://marc.info/?i=cover.1399309513.git.ydroneaud@opteya.com
Cc: <stable@vger.kernel.org>
Fixes: e126ba97dba9e ("mlx5: Add driver for Mellanox Connect-IB adapter")
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
-rw-r--r-- | drivers/infiniband/hw/mlx5/cq.c | 13 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx5/user.h | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c index 62bb6b49dc1d..8ae4f896cb41 100644 --- a/drivers/infiniband/hw/mlx5/cq.c +++ b/drivers/infiniband/hw/mlx5/cq.c | |||
@@ -32,6 +32,7 @@ | |||
32 | 32 | ||
33 | #include <linux/kref.h> | 33 | #include <linux/kref.h> |
34 | #include <rdma/ib_umem.h> | 34 | #include <rdma/ib_umem.h> |
35 | #include <rdma/ib_user_verbs.h> | ||
35 | #include "mlx5_ib.h" | 36 | #include "mlx5_ib.h" |
36 | #include "user.h" | 37 | #include "user.h" |
37 | 38 | ||
@@ -602,14 +603,24 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata, | |||
602 | int *cqe_size, int *index, int *inlen) | 603 | int *cqe_size, int *index, int *inlen) |
603 | { | 604 | { |
604 | struct mlx5_ib_create_cq ucmd; | 605 | struct mlx5_ib_create_cq ucmd; |
606 | size_t ucmdlen; | ||
605 | int page_shift; | 607 | int page_shift; |
606 | int npages; | 608 | int npages; |
607 | int ncont; | 609 | int ncont; |
608 | int err; | 610 | int err; |
609 | 611 | ||
610 | if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) | 612 | ucmdlen = |
613 | (udata->inlen - sizeof(struct ib_uverbs_cmd_hdr) < | ||
614 | sizeof(ucmd)) ? (sizeof(ucmd) - | ||
615 | sizeof(ucmd.reserved)) : sizeof(ucmd); | ||
616 | |||
617 | if (ib_copy_from_udata(&ucmd, udata, ucmdlen)) | ||
611 | return -EFAULT; | 618 | return -EFAULT; |
612 | 619 | ||
620 | if (ucmdlen == sizeof(ucmd) && | ||
621 | ucmd.reserved != 0) | ||
622 | return -EINVAL; | ||
623 | |||
613 | if (ucmd.cqe_size != 64 && ucmd.cqe_size != 128) | 624 | if (ucmd.cqe_size != 64 && ucmd.cqe_size != 128) |
614 | return -EINVAL; | 625 | return -EINVAL; |
615 | 626 | ||
diff --git a/drivers/infiniband/hw/mlx5/user.h b/drivers/infiniband/hw/mlx5/user.h index 0f4f8e42a17f..d44ecd2c2faf 100644 --- a/drivers/infiniband/hw/mlx5/user.h +++ b/drivers/infiniband/hw/mlx5/user.h | |||
@@ -91,6 +91,7 @@ struct mlx5_ib_create_cq { | |||
91 | __u64 buf_addr; | 91 | __u64 buf_addr; |
92 | __u64 db_addr; | 92 | __u64 db_addr; |
93 | __u32 cqe_size; | 93 | __u32 cqe_size; |
94 | __u32 reserved; /* explicit padding (optional on i386) */ | ||
94 | }; | 95 | }; |
95 | 96 | ||
96 | struct mlx5_ib_create_cq_resp { | 97 | struct mlx5_ib_create_cq_resp { |