From: Dave Chinner <dchinner@xxxxxxxxxx> [ Upstream commit 52f31ed228212ba572c44e15e818a3a5c74122c0 ] Resulting in a UAF if the shrinker races with some other dquot freeing mechanism that sets XFS_DQFLAG_FREEING before the dquot is removed from the LRU. This can occur if a dquot purge races with drop_caches. Reported-by: syzbot+912776840162c13db1a3@xxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx> Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Leah Rumancik <leah.rumancik@xxxxxxxxx> Acked-by: Chandan Babu R <chandanbabu@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/xfs/xfs_qm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -423,6 +423,14 @@ xfs_qm_dquot_isolate( goto out_miss_busy; /* + * If something else is freeing this dquot and hasn't yet removed it + * from the LRU, leave it for the freeing task to complete the freeing + * process rather than risk it being free from under us here. + */ + if (dqp->q_flags & XFS_DQFLAG_FREEING) + goto out_miss_unlock; + + /* * This dquot has acquired a reference in the meantime remove it from * the freelist and try again. */ @@ -441,10 +449,8 @@ xfs_qm_dquot_isolate( * skip it so there is time for the IO to complete before we try to * reclaim it again on the next LRU pass. */ - if (!xfs_dqflock_nowait(dqp)) { - xfs_dqunlock(dqp); - goto out_miss_busy; - } + if (!xfs_dqflock_nowait(dqp)) + goto out_miss_unlock; if (XFS_DQ_IS_DIRTY(dqp)) { struct xfs_buf *bp = NULL; @@ -478,6 +484,8 @@ xfs_qm_dquot_isolate( XFS_STATS_INC(dqp->q_mount, xs_qm_dqreclaims); return LRU_REMOVED; +out_miss_unlock: + xfs_dqunlock(dqp); out_miss_busy: trace_xfs_dqreclaim_busy(dqp); XFS_STATS_INC(dqp->q_mount, xs_qm_dqreclaim_misses); Patches currently in stable-queue which might be from leah.rumancik@xxxxxxxxx are queue-6.1/xfs-fix-the-calculation-for-end-and-length.patch queue-6.1/xfs-journal-geometry-is-not-properly-bounds-checked.patch queue-6.1/xfs-use-i_prev_unlinked-to-distinguish-inodes-that-are-not-on-the-unlinked-list.patch queue-6.1/xfs-load-uncached-unlinked-inodes-into-memory-on-demand.patch queue-6.1/xfs-fix-extent-busy-updating.patch queue-6.1/xfs-reload-entire-unlinked-bucket-lists.patch queue-6.1/xfs-block-reservation-too-large-for-minleft-allocation.patch queue-6.1/xfs-don-t-use-bmbt-btree-split-workers-for-io-completion.patch queue-6.1/xfs-prefer-free-inodes-at-enospc-over-chunk-allocation.patch queue-6.1/xfs-quotacheck-failure-can-race-with-background-inode-inactivation.patch queue-6.1/xfs-dquot-shrinker-doesn-t-check-for-xfs_dqflag_freeing.patch queue-6.1/xfs-buffer-pins-need-to-hold-a-buffer-reference.patch queue-6.1/xfs-fix-agf-vs-inode-cluster-buffer-deadlock.patch queue-6.1/xfs-fix-bug_on-in-xfs_getbmap.patch queue-6.1/xfs-remove-warn-when-dquot-cache-insertion-fails.patch queue-6.1/xfs-correct-calculation-for-agend-and-blockcount.patch queue-6.1/xfs-defered-work-could-create-precommits.patch queue-6.1/xfs-fix-low-space-alloc-deadlock.patch queue-6.1/xfs-fix-unlink-vs-cluster-buffer-instantiation-race.patch queue-6.1/xfs-set-bnobt-cntbt-numrecs-correctly-when-formatting-new-ags.patch queue-6.1/xfs-fix-negative-array-access-in-xfs_getbmap.patch queue-6.1/xfs-collect-errors-from-inodegc-for-unlinked-inode-recovery.patch queue-6.1/xfs-fix-deadlock-on-xfs_inodegc_worker.patch queue-6.1/xfs-fix-reloading-entire-unlinked-bucket-lists.patch queue-6.1/xfs-fix-uninitialized-variable-access.patch queue-6.1/xfs-fix-ag-count-overflow-during-growfs.patch queue-6.1/xfs-make-inode-unlinked-bucket-recovery-work-with-quotacheck.patch