Skip to content

Commit 52f31ed

Browse files
Dave ChinnerDarrick J. Wong
authored andcommitted
xfs: dquot shrinker doesn't check for XFS_DQFLAG_FREEING
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: [email protected] Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 1f5619e commit 52f31ed

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

fs/xfs/xfs_qm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ xfs_qm_dquot_isolate(
422422
if (!xfs_dqlock_nowait(dqp))
423423
goto out_miss_busy;
424424

425+
/*
426+
* If something else is freeing this dquot and hasn't yet removed it
427+
* from the LRU, leave it for the freeing task to complete the freeing
428+
* process rather than risk it being free from under us here.
429+
*/
430+
if (dqp->q_flags & XFS_DQFLAG_FREEING)
431+
goto out_miss_unlock;
432+
425433
/*
426434
* This dquot has acquired a reference in the meantime remove it from
427435
* the freelist and try again.
@@ -441,10 +449,8 @@ xfs_qm_dquot_isolate(
441449
* skip it so there is time for the IO to complete before we try to
442450
* reclaim it again on the next LRU pass.
443451
*/
444-
if (!xfs_dqflock_nowait(dqp)) {
445-
xfs_dqunlock(dqp);
446-
goto out_miss_busy;
447-
}
452+
if (!xfs_dqflock_nowait(dqp))
453+
goto out_miss_unlock;
448454

449455
if (XFS_DQ_IS_DIRTY(dqp)) {
450456
struct xfs_buf *bp = NULL;
@@ -478,6 +484,8 @@ xfs_qm_dquot_isolate(
478484
XFS_STATS_INC(dqp->q_mount, xs_qm_dqreclaims);
479485
return LRU_REMOVED;
480486

487+
out_miss_unlock:
488+
xfs_dqunlock(dqp);
481489
out_miss_busy:
482490
trace_xfs_dqreclaim_busy(dqp);
483491
XFS_STATS_INC(dqp->q_mount, xs_qm_dqreclaim_misses);

0 commit comments

Comments
 (0)