fs: do not update freeing inode i_io_list
PATCH v3 1/1 fs: do not update freeing inode i_io_list
After commit cbfecb927f42 ("fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE") writeback_single_inode can push inode with I_DIRTY_TIME set to b_dirty_time list. In case of freeing inode with I_DIRTY_TIME set this can happen after deletion of inode from i_io_list at evict. Stack trace is following.
evictfat_evict_inodefat_truncate_blocksfat_flush_inodeswriteback_inodesync_inode_metadata(inode, sync=0) writeback_single_inode(inode, wbc) <- wbc->sync_mode == WB_SYNC_NONE
This will lead to use after free in flusher thread.
Similar issue can be triggered if writeback_single_inode in the stack trace update inode->i_io_list. Add explicit check to avoid it.
---
V2 -> V3:
- fix grammar in commit message and comments
V1 -> V2:
- address review comments
- skip inode_cgwb_move_to_attached for freeing inode
fs/fs-writeback.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
fs/fs-writeback.c +19 -11
@@ -1712,18 +1712,26 @@ static int writeback_single_inode(struct inode *inode, wb =inode_to_wb_and_lock_list (inode);spin_lock (&inode->i_lock);/* -* If the inode is now fully clean, then it can be safely removed from -* its writeback list (if any). Otherwise the flusher threads are -* responsible for the writeback lists. +* If the inode is freeing, its i_io_list shoudn't be updated +* as it can be finally deleted at this moment. */ -if (!(inode->i_state &I_DIRTY_ALL )) -inode_cgwb_move_to_attached (inode, wb); -else if (!(inode->i_state &I_SYNC_QUEUED )) { -if ((inode->i_state &I_DIRTY )) -redirty_tail_locked (inode, wb); -else if (inode->i_state &I_DIRTY_TIME ) { - inode->dirtied_when = jiffies; -inode_io_list_move_locked (inode, wb, &wb->b_dirty_time); +if (!(inode->i_state &I_FREEING )) { +/* +* If the inode is now fully clean, then it can be safely +* removed from its writeback list (if any). Otherwise the +* flusher threads are responsible for the writeback lists. +*/ +if (!(inode->i_state &I_DIRTY_ALL )) +inode_cgwb_move_to_attached (inode, wb); +else if (!(inode->i_state &I_SYNC_QUEUED )) { +if ((inode->i_state &I_DIRTY )) +redirty_tail_locked (inode, wb); +else if (inode->i_state &I_DIRTY_TIME ) { + inode->dirtied_when = jiffies; +inode_io_list_move_locked (inode, + wb, + &wb->b_dirty_time); + } } }
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Jan Kara
reviewerQuoted 16 lines · Svyatoslav Feldsherov
After commit
cbfecb927f42("fs: recordI_DIRTY_TIMEeven if inode already hasI_DIRTY_INODE")writeback_single_inodecan push inode withI_DIRTY_TIMEset tob_dirty_timelist. In case of freeing inode withI_DIRTY_TIMEset this can happen after deletion of inode fromi_io_listat evict. Stack trace is following.evict
fat_evict_inodefat_truncate_blocksfat_flush_inodeswriteback_inodesync_inode_metadata(inode, sync=0)writeback_single_inode(inode, wbc)<-wbc->sync_mode==WB_SYNC_NONEThis will lead to use after free in flusher thread.
Quoted 7 lines
Similar issue can be triggered if
writeback_single_inodein the stack trace updateinode->i_io_list. Add explicit check to avoid it.Fixes cbfecb927f42 ("fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE")Reported-by [email protected]Reviewed-by Jan Kara <[email protected]>Signed-off-by Svyatoslav Feldsherov <[email protected]>
Ted, I guess you will merge this patch since you've merged the one from Lukas this patch is fixing?
Honza
Quoted 56 lines
---
V2 -> V3:
- fix grammar in commit message and commentsV1 -> V2:
- address review comments
- skipinode_cgwb_move_to_attachedfor freeing inodefs/fs-writeback.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)fs/fs-writeback.c +19
-11@@ -1712,18 +1712,26 @@ static int writeback_single_inode(struct inode *inode, wb =inode_to_wb_and_lock_list (inode);spin_lock (&inode->i_lock);/* -* If the inode is now fully clean, then it can be safely removed from -* its writeback list (if any). Otherwise the flusher threads are -* responsible for the writeback lists. +* If the inode is freeing, its i_io_list shoudn't be updated +* as it can be finally deleted at this moment. */ -if (!(inode->i_state &I_DIRTY_ALL )) -inode_cgwb_move_to_attached (inode, wb); -else if (!(inode->i_state &I_SYNC_QUEUED )) { -if ((inode->i_state &I_DIRTY )) -redirty_tail_locked (inode, wb); -else if (inode->i_state &I_DIRTY_TIME ) { - inode->dirtied_when = jiffies; -inode_io_list_move_locked (inode, wb, &wb->b_dirty_time); +if (!(inode->i_state &I_FREEING )) { +/* +* If the inode is now fully clean, then it can be safely +* removed from its writeback list (if any). Otherwise the +* flusher threads are responsible for the writeback lists. +*/ +if (!(inode->i_state &I_DIRTY_ALL )) +inode_cgwb_move_to_attached (inode, wb); +else if (!(inode->i_state &I_SYNC_QUEUED )) { +if ((inode->i_state &I_DIRTY )) +redirty_tail_locked (inode, wb); +else if (inode->i_state &I_DIRTY_TIME ) { + inode->dirtied_when = jiffies; +inode_io_list_move_locked (inode, + wb, + &wb->b_dirty_time); + } } }Signature · 1 line
2.38.1.431.g37b22c650d-goog
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 20 lines · Jan Kara
Quoted 19 lines · Svyatoslav Feldsherov
After commit
cbfecb927f42("fs: recordI_DIRTY_TIMEeven if inode already hasI_DIRTY_INODE")writeback_single_inodecan push inode withI_DIRTY_TIMEset tob_dirty_timelist. In case of freeing inode withI_DIRTY_TIMEset this can happen after deletion of inode fromi_io_listat evict. Stack trace is following.evict
fat_evict_inodefat_truncate_blocksfat_flush_inodeswriteback_inodesync_inode_metadata(inode, sync=0)writeback_single_inode(inode, wbc)<-wbc->sync_mode==WB_SYNC_NONEThis will lead to use after free in flusher thread.
Similar issue can be triggered if
writeback_single_inodein the stack trace updateinode->i_io_list. Add explicit check to avoid it.
Quoted 7 lines
Quoted 4 lines
Fixes cbfecb927f42 ("fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE")Reported-by [email protected]Reviewed-by Jan Kara <[email protected]>Signed-off-by Svyatoslav Feldsherov <[email protected]>Ted, I guess you will merge this patch since you've merged the one from Lukas this patch is fixing?
Sorry, I forgot to ack this earlier, but this was pushed to Linus and it's in 6.1-rc7.
- Ted