xfs: don't ever return a stale pointer from __xfs_dir3_free_read

If we decide that a directory free block is corrupt, we must take care
not to leak a buffer pointer to the caller.  After xfs_trans_brelse
returns, the buffer can be freed or reused, which means that we have to
set *bpp back to NULL.

Callers are supposed to notice the nonzero return value and not use the
buffer pointer, but we should code more defensively, even if all current
callers handle this situation correctly.

Fixes: de14c5f541 ("xfs: verify free block header fields")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
This commit is contained in:
Darrick J. Wong 2020-03-11 10:37:55 -07:00
parent ce99494c96
commit 1cb5deb5bc
1 changed files with 1 additions and 0 deletions

View File

@ -228,6 +228,7 @@ __xfs_dir3_free_read(
if (fa) { if (fa) {
__xfs_buf_mark_corrupt(*bpp, fa); __xfs_buf_mark_corrupt(*bpp, fa);
xfs_trans_brelse(tp, *bpp); xfs_trans_brelse(tp, *bpp);
*bpp = NULL;
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }