linux/fs/ceph
Jeff Layton e9b2b2b29c ceph: take snap_empty_lock atomically with snaprealm refcount change
commit 8434ffe71c874b9c4e184b88d25de98c2bf5fe3f upstream.

There is a race in ceph_put_snap_realm. The change to the nref and the
spinlock acquisition are not done atomically, so you could decrement
nref, and before you take the spinlock, the nref is incremented again.
At that point, you end up putting it on the empty list when it
shouldn't be there. Eventually __cleanup_empty_realms runs and frees
it when it's still in-use.

Fix this by protecting the 1->0 transition with atomic_dec_and_lock,
and just drop the spinlock if we can get the rwsem.

Because these objects can also undergo a 0->1 refcount transition, we
must protect that change as well with the spinlock. Increment locklessly
unless the value is at 0, in which case we take the spinlock, increment
and then take it off the empty list if it did the 0->1 transition.

With these changes, I'm removing the dout() messages from these
functions, as well as in __put_snap_realm. They've always been racy, and
it's better to not print values that may be misleading.

Cc: stable@vger.kernel.org
URL: https://tracker.ceph.com/issues/46419
Reported-by: Mark Nelson <mnelson@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Luis Henriques <lhenriques@suse.de>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-08-18 08:57:04 +02:00
..
Kconfig
Makefile
acl.c
addr.c ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty 2021-07-20 16:10:48 +02:00
cache.c
cache.h
caps.c ceph: reduce contention in ceph_check_delayed_caps() 2021-08-18 08:56:57 +02:00
ceph_frag.c
debugfs.c
dir.c
export.c ceph: fix inode leak on getattr error in __fh_to_dentry 2021-05-19 10:08:26 +02:00
file.c
inode.c ceph: fix fscache invalidation 2021-05-22 11:38:29 +02:00
io.c ceph: add buffered/direct exclusionary locking for reads and writes 2019-09-16 12:06:25 +02:00
io.h
ioctl.c
ioctl.h
locks.c
mds_client.c ceph: reduce contention in ceph_check_delayed_caps() 2021-08-18 08:56:57 +02:00
mds_client.h
mdsmap.c
quota.c
snap.c ceph: take snap_empty_lock atomically with snaprealm refcount change 2021-08-18 08:57:04 +02:00
strings.c
super.c
super.h ceph: reduce contention in ceph_check_delayed_caps() 2021-08-18 08:56:57 +02:00
xattr.c