FAILED: patch "[PATCH] xfs: save ailp before dropping the AIL lock in push callbacks" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 394d70b86fae9fe865e7e6d9540b7696f73aa9b6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026033014-speak-undiluted-7499@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 394d70b86fae9fe865e7e6d9540b7696f73aa9b6 Mon Sep 17 00:00:00 2001
From: Yuto Ohnuki <[email protected]>
Date: Tue, 10 Mar 2026 18:38:39 +0000
Subject: [PATCH] xfs: save ailp before dropping the AIL lock in push callbacks
In xfs_inode_item_push() and xfs_qm_dquot_logitem_push(), the AIL lock is dropped to perform buffer IO. Once the cluster buffer no longer protects the log item from reclaim, the log item may be freed by background reclaim or the dquot shrinker. The subsequent spin_lock() call dereferences lip->li_ailp, which is a use-after-free.
Fix this by saving the ailp pointer in a local variable while the AIL lock is held and the log item is guaranteed to be valid.
fs/xfs/xfs_dquot_item.c +7 -2
@@ -125,6 +125,7 @@ xfs_qm_dquot_logitem_push(struct xfs_dq_logitem *qlip =DQUOT_ITEM (lip);struct xfs_dquot *dqp = qlip->qli_dquot;struct xfs_buf *bp; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -153,7 +154,7 @@ xfs_qm_dquot_logitem_push( goto out_unlock; } -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock); error =xfs_dquot_use_attached_buf (dqp, &bp);if (error == -EAGAIN ) {
@@ -172,9 +173,13 @@ xfs_qm_dquot_logitem_push( rval =XFS_ITEM_FLUSHING ; }xfs_buf_relse (bp); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ out_relock_ail: -spin_lock (&lip->li_ailp->ail_lock); +spin_lock (&ailp->ail_lock); out_unlock:mutex_unlock (&dqp->q_qlock);return rval;
fs/xfs/xfs_inode_item.c +7 -2
@@ -746,6 +746,7 @@ xfs_inode_item_push(struct xfs_inode_log_item *iip =INODE_ITEM (lip);struct xfs_inode *ip = iip->ili_inode;struct xfs_buf *bp = lip->li_buf; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -771,7 +772,7 @@ xfs_inode_item_push(if (!xfs_buf_trylock (bp))return XFS_ITEM_LOCKED ; -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock);/* * We need to hold a reference for flushing the cluster buffer as it may
@@ -795,7 +796,11 @@ xfs_inode_item_push( rval =XFS_ITEM_LOCKED ; } -spin_lock (&lip->li_ailp->ail_lock); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ +spin_lock (&ailp->ail_lock);return rval; }
Sasha Levin
maintainerPATCH 1/1 xfs: save ailp before dropping the AIL lock in push callbacks
From: Yuto Ohnuki <[email protected]>
[ Upstream commit 394d70b86fae9fe865e7e6d9540b7696f73aa9b6 ]
In xfs_inode_item_push() and xfs_qm_dquot_logitem_push(), the AIL lock is dropped to perform buffer IO. Once the cluster buffer no longer protects the log item from reclaim, the log item may be freed by background reclaim or the dquot shrinker. The subsequent spin_lock() call dereferences lip->li_ailp, which is a use-after-free.
Fix this by saving the ailp pointer in a local variable while the AIL lock is held and the log item is guaranteed to be valid.
--- fs/xfs/xfs_dquot_item.c | 9 +++++++-- fs/xfs/xfs_inode_item.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
fs/xfs/xfs_dquot_item.c +7 -2
@@ -124,6 +124,7 @@ xfs_qm_dquot_logitem_push( {struct xfs_dquot *dqp =DQUOT_ITEM (lip)->qli_dquot;struct xfs_buf *bp = lip->li_buf; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -152,7 +153,7 @@ xfs_qm_dquot_logitem_push( goto out_unlock; } -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock); error =xfs_qm_dqflush (dqp, &bp);if (!error) {
@@ -162,7 +163,11 @@ xfs_qm_dquot_logitem_push( }else if (error == -EAGAIN ) rval =XFS_ITEM_LOCKED ; -spin_lock (&lip->li_ailp->ail_lock); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ +spin_lock (&ailp->ail_lock); out_unlock:xfs_dqunlock (dqp);return rval;
fs/xfs/xfs_inode_item.c +7 -2
@@ -514,6 +514,7 @@ xfs_inode_item_push(struct xfs_inode_log_item *iip =INODE_ITEM (lip);struct xfs_inode *ip = iip->ili_inode;struct xfs_buf *bp = lip->li_buf; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -529,7 +530,7 @@ xfs_inode_item_push(if (!xfs_buf_trylock (bp))return XFS_ITEM_LOCKED ; -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock);/* * We need to hold a reference for flushing the cluster buffer as it may
@@ -553,7 +554,11 @@ xfs_inode_item_push( rval =XFS_ITEM_LOCKED ; } -spin_lock (&lip->li_ailp->ail_lock); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ +spin_lock (&ailp->ail_lock);return rval; }
Signature · 1 line
2.53.0