xfs: don't allow UAF in xlog_recover_iget
PATCH 1/2 xfs: don't allow UAF in xlog_recover_iget
From: Darrick J. Wong <[email protected]>
Fix this function to avoid touching the passed in ipp argument until we're 100% certain that we're returning zero. This avoids creating a dangling pointer in the caller. The xfs_irele call in xfs_attri_recover_work was never correct and should go away.
--- fs/xfs/xfs_log_recover.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/xfs/xfs_log_recover.c +7 -5
@@ -1745,21 +1745,23 @@ xlog_recover_iget(xfs_ino_t ino, struct xfs_inode **ipp) { + struct xfs_inode *ip;int error; - error =xfs_iget (mp,NULL , ino,0 ,0 , ipp); + error =xfs_iget (mp,NULL , ino,0 ,0 , &ip);if (error)return error; - error =xfs_qm_dqattach (*ipp); + error =xfs_qm_dqattach (ip);if (error) { -xfs_irele (*ipp); +xfs_irele (ip);return error; } -if (VFS_I (*ipp)->i_nlink ==0 ) -xfs_iflags_set (*ipp,XFS_IRECOVERY ); +if (VFS_I (ip)->i_nlink ==0 ) +xfs_iflags_set (ip,XFS_IRECOVERY ); + *ipp = ip;return 0 ; }
PATCH 2/2 xfs: don't irele after failing to iget in xfs_attri_recover_work
From: Darrick J. Wong <[email protected]>
xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.
--- fs/xfs/xfs_attr_item.c | 1 - 1 file changed, 1 deletion(-)
fs/xfs/xfs_attr_item.c +0 -1
@@ -653,7 +653,6 @@ xfs_attri_recover_work(break ; }if (error) { -xfs_irele (ip);XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, attrp,sizeof (*attrp));return ERR_PTR (-EFSCORRUPTED );
Re: [PATCH 2/2] xfs: don't irele after failing to iget in xfs_attri_recover_work
Quoted 18 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.
Cc <[email protected]> # v6.10Fixes ae673f534a3097 ("xfs: record inode generation in xattr update log intent items")Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_attr_item.c | 1 - 1 file changed, 1 deletion(-)fs/xfs/xfs_attr_item.c +0
-0
fs/xfs/xfs_attr_item.c xfs_attri_recover_work( · line 658
Quoted 7 lines
fs/xfs/xfs_attr_item.c +0
-1@@ -653,7 +653,6 @@ xfs_attri_recover_work(break ; }if (error) { -xfs_irele (ip);XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, attrp,sizeof (*attrp));return ERR_PTR (-EFSCORRUPTED );
Looks good
Re: [PATCH 2/2] xfs: don't irele after failing to iget in xfs_attri_recover_work
In reply to Darrick J. WongQuoted 4 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.
Looks good:
Quoted 38 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Fix this function to avoid touching the passed in ipp argument until we're 100% certain that we're returning zero. This avoids creating a dangling pointer in the caller. The
xfs_irelecall inxfs_attri_recover_workwas never correct and should go away.Cc <[email protected]> # v5.15Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_log_recover.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)fs/xfs/xfs_log_recover.c +4
-3@@ -1745,21 +1745,23 @@ xlog_recover_iget(xfs_ino_t ino, struct xfs_inode **ipp) { + struct xfs_inode *ip;int error; - error =xfs_iget (mp,NULL , ino,0 ,0 , ipp); + error =xfs_iget (mp,NULL , ino,0 ,0 , &ip);if (error)return error; - error =xfs_qm_dqattach (*ipp); + error =xfs_qm_dqattach (ip);if (error) { -xfs_irele (*ipp); +xfs_irele (ip);return error; }
fs/xfs/xfs_log_recover.c xlog_recover_iget( · line 1767
Quoted 10 lines
fs/xfs/xfs_log_recover.c +3
-2-if (VFS_I (*ipp)->i_nlink ==0 ) -xfs_iflags_set (*ipp,XFS_IRECOVERY ); +if (VFS_I (ip)->i_nlink ==0 ) +xfs_iflags_set (ip,XFS_IRECOVERY ); + *ipp = ip;return 0 ; }
Looks good
"Don't allow UAF" reads rally giberrish.
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Fix this function to avoid touching the passed in ipp argument until we're 100% certain that we're returning zero. This avoids creating a dangling pointer in the caller.
Why does this matter? The caller need to check the return value.
Quoted 2 lines
The
xfs_irelecall inxfs_attri_recover_workwas never correct and should go away.
No idea what this is supposed to say, seem unrelated to this patch.
Quoted 10 lines · Christoph Hellwig
"Don't allow UAF" reads rally giberrish.
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Fix this function to avoid touching the passed in ipp argument until we're 100% certain that we're returning zero. This avoids creating a dangling pointer in the caller.
Why does this matter? The caller need to check the return value.
I think the fundamental problem here is that Long Li ran a static checker, and the static checker suggested that the callsite in xfs_attri_recover_work should be fixed by guarding the xfs_irele call in the error handler with a null pointer check. That's completely wrong, the xfs_irele should never have been put in the error path at all.
So the proper fix is the one in the next patch that removes the xfs_irele. At the same time, xlog_recover_iget should get fixed so that it never exposes stale pointers in the first place.
"Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails." ?
Quoted 4 lines
Quoted 2 lines
The
xfs_irelecall inxfs_attri_recover_workwas never correct and should go away.No idea what this is supposed to say, seem unrelated to this patch.
Yeah, I'll just drop that.
--D
Quoted 7 lines · Darrick J. Wong
Quoted 1 line
Why does this matter? The caller need to check the return value.
I think the fundamental problem here is that Long Li ran a static checker, and the static checker suggested that the callsite in
xfs_attri_recover_workshould be fixed by guarding thexfs_irelecall in the error handler with a null pointer check. That's completely wrong, thexfs_ireleshould never have been put in the error path at all.
Yes.
Quoted 3 lines
So the proper fix is the one in the next patch that removes the
xfs_irele. At the same time,xlog_recover_igetshould get fixed so that it never exposes stale pointers in the first place.
Agreed.
Quoted 2 lines
"Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails." ?
I'd just drop this patch.