xfs: fix AIL push use-after-free during shutdown
Status from this message: Applied to for-next, thanks!
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest4 patches 4 repliesApplied
- v34 patches 13 repliesSuperseded
Changes in v4 from the cover letter
- Fixed unmount ordering: xfs_inodegc_stop before cancel_delayed_work_sync to prevent inodegc from re-queuing m_reclaim_work as suggested by Darrick J. Wong
- Updated xfs_unmount_flush_inodes function comment to reflect new ordering
- Reworked patch ordering so bugfix patches (1-3) do not depend on the refactoring patch, reducing stable backport burden
- Added comment at xfsaild_push_item call site documenting that the log item must not be dereferenced after the call
- Moved refactoring to patch 4 without Cc: stable
- Link to v3: https://lore.kernel.org/all/[email protected]/
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | xfs: stop reclaim before pushing AIL during unmountfs/ | +4 | 1 reply | |
| 2/4 | xfs: avoid dereferencing log items after push callbacksfs/ fs/ | +51 | 1 reply | |
| 3/4 | xfs: save ailp before dropping the AIL lock in push callbacksfs/ fs/ | +14 | 0 replies | |
| 4/4 | xfs: refactor xfsaild_push loop into helperfs/ | +69 | 1 reply |
Reviews trailers per patch
All 4 patches have a Reviewed-by or Acked-by.
| Patch | Darrick J. Wong | Dave Chinner |
|---|---|---|
| 1/4 | R-b | |
| 2/4 | R-b | |
| 3/4 | R-b | R-b |
| 4/4 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v4 0/4] xfs: fix AIL push use-after-free during shutdown
When a filesystem is shut down, background inode reclaim and the xfsaild can race to abort and free dirty inodes. Since commit 90c60e164012 ("xfs: xfs_iflush() is no longer necessary"), xfs_inode_item_push() no longer holds ILOCK_SHARED while flushing, removing the protection that prevented the inode from being reclaimed during the flush.
This results in use-after-free when dereferencing log items after iop_push() returns, or when reacquiring the AIL lock via lip->li_ailp.
This series fixes the issue by:
1. Reordering unmount to stop reclaim and inodegc before pushing the AIL
2. Capturing log item fields before push callbacks for tracepoints
3. Saving the ailp pointer before dropping the AIL lock
4. Factoring the push loop into a helper for readability (non-bugfix)
Changes in v4:
- Fixed unmount ordering: xfs_inodegc_stop before cancel_delayed_work_sync to prevent inodegc from re-queuing m_reclaim_work as suggested by Darrick J. Wong
- Updated xfs_unmount_flush_inodes function comment to reflect new ordering
- Reworked patch ordering so bugfix patches (1-3) do not depend on the refactoring patch, reducing stable backport burden
- Added comment at xfsaild_push_item call site documenting that the log item must not be dereferenced after the call
- Moved refactoring to patch 4 without Cc: stable
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Split into 4 patches as suggested by Dave Chinner
- Moved UAF-unsafe point comments to after xfs_buf_relse()
- Passed ailp instead of dev to tracepoints
- Moved xfs_ail_push_class definition after xfs_log_item_class events
- Factored xfsaild_push() loop body into xfsaild_process_logitem()
- Added xfsaild_push_item() header comment describing post-return lifetime
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Reordered xfs_unmount_flush_inodes() to stop reclaim before pushing AIL suggested by Dave Chinner
- Introduced xfs_ail_push_class trace event to avoid dereferencing freed log items in tracepoints
- Added comments documenting that log items must not be referenced after iop_push() returns
- Saved ailp pointer in local variables in push functions
- Link to v1: https://lore.kernel.org/all/[email protected]/
Yuto Ohnuki (4):
xfs: stop reclaim before pushing AIL during unmount
xfs: avoid dereferencing log items after push callbacks
xfs: save ailp before dropping the AIL lock in push callbacks
xfs: refactor xfsaild_push loop into helper
fs/xfs/xfs_dquot_item.c | 9 ++- fs/xfs/xfs_inode_item.c | 9 ++- fs/xfs/xfs_mount.c | 7 ++- fs/xfs/xfs_trace.h | 36 ++++++++++-- fs/xfs/xfs_trans_ail.c | 127 ++++++++++++++++++++++++---------------- 5 files changed, 125 insertions(+), 63 deletions(-)
Signature · 8 lines
2.50.1 Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284 Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705