jfs: fix kernel BUG in jfs_evict_inode
PATCH 1/1 jfs: fix kernel BUG in jfs_evict_inode
syzbot reported a kernel BUG in jfs_evict_inode() triggered by the following check:
BUG_ON(!list_empty(&JFS_IP(inode)->anon_inode_list));
When an inode reaches jfs_evict_inode() with outstanding anonymous transactions, the filesystem state is already inconsistent. However, crashing the whole kernel in this situation is too heavy-handed and can be triggered by a corrupted or fuzzed filesystem image.
The transaction manager uses anon_inode_list to track inodes that have anonymous tlocks attached. Leaving an evicted inode on this list is wrong as it leaves a dangling pointer behind and risks a use-after-free when the list is walked later.
Instead of panicking, log the condition and remove the inode from anon_inode_list under TXN_LOCK using a new helper, jfs_free_anon_inode(). This keeps the internal list consistent while avoiding a user-triggerable kernel BUG.
--- fs/jfs/inode.c | 2 +- fs/jfs/jfs_txnmgr.c | 14 ++++++++++++++ fs/jfs/jfs_txnmgr.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-)
fs/jfs/inode.c +1 -1
@@ -172,7 +172,7 @@ void jfs_evict_inode(struct inode *inode)clear_inode (inode);dquot_drop (inode); -BUG_ON (!list_empty (&ji->anon_inode_list)); +jfs_free_anon_inode (inode);spin_lock_irq (&ji->ag_lock);if (ji->active_ag !=-1 ) {
fs/jfs/jfs_txnmgr.c +14 -0
@@ -3018,3 +3018,17 @@ int jfs_txstats_proc_show(struct seq_file *m, void *v) return 0; }#endif + +void jfs_free_anon_inode (struct inode *inode) +{ +struct jfs_inode_info *ji =JFS_IP (inode); + +TXN_LOCK (); +if (!list_empty (&ji->anon_inode_list)) { +jfs_err ("inode %lu evicted with anonymous tlocks" , + inode->i_ino); +list_del_init (&ji->anon_inode_list); + } +TXN_UNLOCK (); +} +
fs/jfs/jfs_txnmgr.h +1 -0
@@ -295,4 +295,5 @@ extern void txResume(struct super_block *);extern void txLazyUnlock (struct tblock *);extern int jfs_lazycommit (void *);extern int jfs_sync (void *); +extern void jfs_free_anon_inode (struct inode *);#endif /* _H_JFS_TXNMGR */
Signature · 1 line
2.43.0