aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@mellanox.com>2018-06-12 11:40:23 -0400
committerJason Gunthorpe <jgg@mellanox.com>2018-06-12 16:39:32 -0400
commit1eb9364ce81d9445ad6f9d44921a91d2a6597156 (patch)
tree027b021e6efb08f389e12e1bd7af94bfc7b3f323
parent3dc7c7badb7502ec3e3aa817a8bdd9e53aa54c52 (diff)
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>
-rw-r--r--drivers/infiniband/core/uverbs_main.c14
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,
736 if (ret) 736 if (ret)
737 return ret; 737 return ret;
738 738
739 if (!file->ucontext &&
740 (command != IB_USER_VERBS_CMD_GET_CONTEXT || extended))
741 return -EINVAL;
742
743 if (extended) { 739 if (extended) {
744 if (count < (sizeof(hdr) + sizeof(ex_hdr))) 740 if (count < (sizeof(hdr) + sizeof(ex_hdr)))
745 return -EINVAL; 741 return -EINVAL;
@@ -759,6 +755,16 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
759 goto out; 755 goto out;
760 } 756 }
761 757
758 /*
759 * Must be after the ib_dev check, as once the RCU clears ib_dev ==
760 * NULL means ucontext == NULL
761 */
762 if (!file->ucontext &&
763 (command != IB_USER_VERBS_CMD_GET_CONTEXT || extended)) {
764 ret = -EINVAL;
765 goto out;
766 }
767
762 if (!verify_command_mask(ib_dev, command, extended)) { 768 if (!verify_command_mask(ib_dev, command, extended)) {
763 ret = -EOPNOTSUPP; 769 ret = -EOPNOTSUPP;
764 goto out; 770 goto out;