diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2018-07-10 13:43:06 -0600 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-07-25 14:21:46 -0600 |
commit | 22fa27fbc64d01cbbe1e4da751e64cc22d24a6e4 (patch) | |
tree | 98ba4f304011ac9a6e05d9bbdd12045b7a6b4598 /drivers/infiniband/core/uverbs_ioctl.c | |
parent | c36ee46dafaea1bb525c4e34d3e35dd9a6768a47 (diff) | |
download | lwn-22fa27fbc64d01cbbe1e4da751e64cc22d24a6e4.tar.gz lwn-22fa27fbc64d01cbbe1e4da751e64cc22d24a6e4.zip |
IB/uverbs: Fix locking around struct ib_uverbs_file ucontext
We have a parallel unlocked reader and writer with ib_uverbs_get_context()
vs everything else, and nothing guarantees this works properly.
Audit and fix all of the places that access ucontext to use one of the
following locking schemes:
- Call ib_uverbs_get_ucontext() under SRCU and check for failure
- Access the ucontext through an struct ib_uobject context member
while holding a READ or WRITE lock on the uobject.
This value cannot be NULL and has no race.
- Hold the ucontext_lock and check for ufile->ucontext !NULL
This also re-implements ib_uverbs_get_ucontext() in a way that is safe
against concurrent ib_uverbs_get_context() and disassociation.
As a side effect, every access to ucontext in the commands is via
ib_uverbs_get_context() with an error check, or via the uobject, so there
is no longer any need for the core code to check ucontext on every command
call. These checks are also removed.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core/uverbs_ioctl.c')
-rw-r--r-- | drivers/infiniband/core/uverbs_ioctl.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 26ddc5cadcdb..db7a92ea5dbe 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -140,7 +140,7 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile, if (uattr->attr_data.reserved) return -EINVAL; - if (uattr->len != 0 || !ufile->ucontext) + if (uattr->len != 0) return -EINVAL; o_attr = &e->obj_attr; @@ -373,9 +373,6 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, if (!method_spec) return -EPROTONOSUPPORT; - if ((method_spec->flags & UVERBS_ACTION_FLAG_CREATE_ROOT) ^ !file->ucontext) - return -EINVAL; - ctx_size = sizeof(*ctx) + sizeof(struct uverbs_attr_bundle) + sizeof(struct uverbs_attr_bundle_hash) * method_spec->num_buckets + |