ext4: fix deadlock due to mbcache entry corruption
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 65f8b800 ("ext4: fix race when reusing xattr blocks"). Cc: stable@vger.kernel.org Fixes: 6048c64b ("mbcache: add reusable flag to cache entries") Fixes: 65f8b800 ("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>
-
mentioned in commit 127b80ce
-
mentioned in commit cc1538c6
-
mentioned in commit 5bc0b2fd
-
mentioned in commit a6e4094f
-
mentioned in commit 4c363e29
-
mentioned in commit 0da99012
-
mentioned in commit 1be16a0c
-
mentioned in commit 27c08673
-
mentioned in commit 0e6fbc56
-
mentioned in commit fb59d12a
-
mentioned in commit 4cc218e2
-
mentioned in commit 1a56cd97
-
mentioned in commit a99ff9e9
-
mentioned in commit 61dc6cdf
-
mentioned in commit efaa0ca6
-
mentioned in commit bb337d8d
-
mentioned in commit 8a9ce3a5
-
mentioned in commit 98953044
-
mentioned in commit 2babfff1
-
mentioned in commit 9f0d01ea
-
mentioned in commit c2f1e12b
-
mentioned in commit 81b0bb1e
-
mentioned in commit 711ef736
-
mentioned in commit af530652
-
mentioned in commit 951ea4d3
-
mentioned in commit ea4b9091
-
mentioned in commit a5f9bd4b
-
mentioned in commit af8ecc8d