]> git.itanic.dy.fi Git - linux-stable/commit
IB/uverbs: Fix race between ib_uverbs_open and remove_one
authorYishai Hadas <yishaih@mellanox.com>
Thu, 13 Aug 2015 15:32:03 +0000 (18:32 +0300)
committerJiri Slaby <jslaby@suse.cz>
Wed, 30 Sep 2015 09:13:10 +0000 (11:13 +0200)
commitd59a6097eb633280452bb656bd440ec83b42bc58
tree915a5eabe3302c28843486180c21cf9a5232c0cc
parent6c1375b0ef61048fb83ae9dc1cf42254faa3ac38
IB/uverbs: Fix race between ib_uverbs_open and remove_one

commit 35d4a0b63dc0c6d1177d4f532a9deae958f0662c upstream.

Fixes: 2a72f212263701b927559f6850446421d5906c41 ("IB/uverbs: Remove dev_table")
Before this commit there was a device look-up table that was protected
by a spin_lock used by ib_uverbs_open and by ib_uverbs_remove_one. When
it was dropped and container_of was used instead, it enabled the race
with remove_one as dev might be freed just after:
dev = container_of(inode->i_cdev, struct ib_uverbs_device, cdev) but
before the kref_get.

In addition, this buggy patch added some dead code as
container_of(x,y,z) can never be NULL and so dev can never be NULL.
As a result the comment above ib_uverbs_open saying "the open method
will either immediately run -ENXIO" is wrong as it can never happen.

The solution follows Jason Gunthorpe suggestion from below URL:
https://www.mail-archive.com/linux-rdma@vger.kernel.org/msg25692.html

cdev will hold a kref on the parent (the containing structure,
ib_uverbs_device) and only when that kref is released it is
guaranteed that open will never be called again.

In addition, fixes the active count scheme to use an atomic
not a kref to prevent WARN_ON as pointed by above comment
from Jason.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Shachar Raindel <raindel@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/infiniband/core/uverbs.h
drivers/infiniband/core/uverbs_main.c