Skip to contentSkip to conversation

vfs: fix up the assert in i_readcount_dec

PATCH Applied Mateusz Guzik 2 participants 2 messages Aug 11, 2023 – Aug 14, 2023 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: fix up the assert in i_readcount_dec

Drops a race where 2 threads could spot a positive value and both proceed to dec to -1, without reporting anything.

---
 include/linux/fs.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/fs.h +1 -2
index 562f2623c9c9..21c8f8ae014d 100644
@@ -2613,8 +2613,7 @@ static inline bool inode_is_open_for_write(const struct inode *inode)
 #if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING)
 static inline void i_readcount_dec(struct inode *inode)
 {
-	BUG_ON(!atomic_read(&inode->i_readcount));
-	atomic_dec(&inode->i_readcount);
+	BUG_ON(atomic_dec_return(&inode->i_readcount) < 0);
 }
 static inline void i_readcount_inc(struct inode *inode)
 {
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 4 lines · Mateusz Guzik

Drops a race where 2 threads could spot a positive value and both proceed to dec to -1, without reporting anything.

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] vfs: fix up the assert in i_readcount_dec

      https://git.kernel.org/vfs/vfs/c/fbdf4da0ad64