]> git.baikalelectronics.ru Git - kernel.git/commit
ext4: fix deadlock due to mbcache entry corruption
authorJan Kara <jack@suse.cz>
Wed, 23 Nov 2022 19:39:50 +0000 (20:39 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:56 +0000 (11:41 +0100)
commitd54c4d3ac62a9e555972f4df45c5bc6c4b3d7c43
tree4961078a0bd0db831107673a3000d1463b45b4a2
parent877a0c5500fa7d6ccf667e279c40e9f64b3eca5e
ext4: fix deadlock due to mbcache entry corruption

[ Upstream commit 246b6193fbe5ccc7680a3405b85510bb3d28ba1f ]

When manipulating xattr blocks, we can deadlock infinitely looping
inside ext4_xattr_block_set() where we constantly keep finding xattr
block for reuse in mbcache but we are unable to reuse it because its
reference count is too big. This happens because cache entry for the
xattr block is marked as reusable (e_reusable set) although its
reference count is too big. When this inconsistency happens, this
inconsistent state is kept indefinitely and so ext4_xattr_block_set()
keeps retrying indefinitely.

The inconsistent state is caused by non-atomic update of e_reusable bit.
e_reusable is part of a bitfield and e_reusable update can race with
update of e_referenced bit in the same bitfield resulting in loss of one
of the updates. Fix the problem by using atomic bitops instead.

This bug has been around for many years, but it became *much* easier
to hit after commit e88aba6caa27 ("ext4: fix race when reusing xattr
blocks").

Cc: stable@vger.kernel.org
Fixes: a1533971a20c ("mbcache: add reusable flag to cache entries")
Fixes: e88aba6caa27 ("ext4: fix race when reusing xattr blocks")
Reported-and-tested-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>
Reported-by: Thilo Fromm <t-lo@linux.microsoft.com>
Link: https://lore.kernel.org/r/c77bf00f-4618-7149-56f1-b8d1664b9d07@linux.microsoft.com/
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/20221123193950.16758-1-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/xattr.c
fs/mbcache.c
include/linux/mbcache.h