diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2018-06-12 09:40:23 -0600 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-06-12 14:39:32 -0600 |
commit | 1eb9364ce81d9445ad6f9d44921a91d2a6597156 (patch) | |
tree | 027b021e6efb08f389e12e1bd7af94bfc7b3f323 /drivers/infiniband | |
parent | 3dc7c7badb7502ec3e3aa817a8bdd9e53aa54c52 (diff) | |
download | linux-1eb9364ce81d9445ad6f9d44921a91d2a6597156.tar.gz linux-1eb9364ce81d9445ad6f9d44921a91d2a6597156.tar.bz2 linux-1eb9364ce81d9445ad6f9d44921a91d2a6597156.zip |
IB/uverbs: Fix ordering of ucontext check in ib_uverbs_write
During disassociation the ucontext will become NULL, however due to how
the SRCU locking works the ucontext must only be examined after looking
at the ib_dev, which governs the RCU control flow.
With the wrong ordering userspace will see EINVAL instead of EIO for a
disassociated uverbs FD, which breaks rdma-core.
Cc: stable@vger.kernel.org
Fixes: 491d5c6a3023 ("RDMA/uverbs: Move uncontext check before SRCU read lock")
Reported-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/uverbs_main.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 3ae2339dd27a..2094d136513d 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -736,10 +736,6 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, if (ret) return ret; - if (!file->ucontext && - (command != IB_USER_VERBS_CMD_GET_CONTEXT || extended)) - return -EINVAL; - if (extended) { if (count < (sizeof(hdr) + sizeof(ex_hdr))) return -EINVAL; @@ -759,6 +755,16 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, goto out; } + /* + * Must be after the ib_dev check, as once the RCU clears ib_dev == + * NULL means ucontext == NULL + */ + if (!file->ucontext && + (command != IB_USER_VERBS_CMD_GET_CONTEXT || extended)) { + ret = -EINVAL; + goto out; + } + if (!verify_command_mask(ib_dev, command, extended)) { ret = -EOPNOTSUPP; goto out; |