linux-stable/fs/xfs/scrub
Dave Chinner 8bb0402836 xfs: don't use current->journal_info
commit f2e812c152 upstream.

syzbot reported an ext4 panic during a page fault where found a
journal handle when it didn't expect to find one. The structure
it tripped over had a value of 'TRAN' in the first entry in the
structure, and that indicates it tripped over a struct xfs_trans
instead of a jbd2 handle.

The reason for this is that the page fault was taken during a
copy-out to a user buffer from an xfs bulkstat operation. XFS uses
an "empty" transaction context for bulkstat to do automated metadata
buffer cleanup, and so the transaction context is valid across the
copyout of the bulkstat info into the user buffer.

We are using empty transaction contexts like this in XFS to reduce
the risk of failing to release objects we reference during the
operation, especially during error handling. Hence we really need to
ensure that we can take page faults from these contexts without
leaving landmines for the code processing the page fault to trip
over.

However, this same behaviour could happen from any other filesystem
that triggers a page fault or any other exception that is handled
on-stack from within a task context that has current->journal_info
set.  Having a page fault from some other filesystem bounce into XFS
where we have to run a transaction isn't a bug at all, but the usage
of current->journal_info means that this could result corruption of
the outer task's journal_info structure.

The problem is purely that we now have two different contexts that
now think they own current->journal_info. IOWs, no filesystem can
allow page faults or on-stack exceptions while current->journal_info
is set by the filesystem because the exception processing might use
current->journal_info itself.

If we end up with nested XFS transactions whilst holding an empty
transaction, then it isn't an issue as the outer transaction does
not hold a log reservation. If we ignore the current->journal_info
usage, then the only problem that might occur is a deadlock if the
exception tries to take the same locks the upper context holds.
That, however, is not a problem that setting current->journal_info
would solve, so it's largely an irrelevant concern here.

IOWs, we really only use current->journal_info for a warning check
in xfs_vm_writepages() to ensure we aren't doing writeback from a
transaction context. Writeback might need to do allocation, so it
can need to run transactions itself. Hence it's a debug check to
warn us that we've done something silly, and largely it is not all
that useful.

So let's just remove all the use of current->journal_info in XFS and
get rid of all the potential issues from nested contexts where
current->journal_info might get misused by another filesystem
context.

Reported-by: syzbot+cdee56dbcdf0096ef605@syzkaller.appspotmail.com
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Mark Tinguely <mark.tinguely@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-21 14:38:45 +02:00
..
agheader.c xfs: teach scrub to check for sole ownership of metadata objects 2023-04-11 19:00:15 -07:00
agheader_repair.c xfs: fix agf_fllast when repairing an empty AGFL 2023-08-10 07:48:11 -07:00
alloc.c xfs: flag free space btree records that could be merged 2023-04-11 19:00:26 -07:00
attr.c xfs: don't load local xattr values during scrub 2023-04-11 19:00:35 -07:00
attr.h xfs: check used space of shortform xattr structures 2023-04-11 19:00:33 -07:00
bitmap.c xfs: use per-AG bitmaps to reap unused AG metadata blocks during repair 2023-08-10 07:48:04 -07:00
bitmap.h xfs: use per-AG bitmaps to reap unused AG metadata blocks during repair 2023-08-10 07:48:04 -07:00
bmap.c xfs: don't check reflink iflag state when checking cow fork 2023-08-10 07:48:13 -07:00
btree.c xfs: fix imprecise logic in xchk_btree_check_block_owner 2024-06-21 14:38:44 +02:00
btree.h overflow: Add struct_size_t() helper 2023-05-26 13:52:19 -07:00
common.c xfs: don't use current->journal_info 2024-06-21 14:38:45 +02:00
common.h xfs: make xchk_iget safer in the presence of corrupt inode btrees 2024-04-03 15:28:47 +02:00
dabtree.c xfs: scrub should use ECHRNG to signal that the drain is needed 2023-04-11 19:00:00 -07:00
dabtree.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
dir.c xfs: manage inode DONTCACHE status at irele time 2023-04-11 19:00:20 -07:00
fscounters.c xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h 2024-04-03 15:28:46 +02:00
health.c xfs: always rescan allegedly healthy per-ag metadata after repair 2023-08-10 07:48:09 -07:00
health.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
ialloc.c xfs: rewrite xchk_inode_is_allocated to work properly 2023-08-10 07:48:12 -07:00
inode.c xfs: add missing nrext64 inode flag check to scrub 2024-04-03 15:28:48 +02:00
parent.c xfs: wrap ilock/iunlock operations on sc->ip 2023-08-10 07:48:08 -07:00
quota.c xfs: wrap ilock/iunlock operations on sc->ip 2023-08-10 07:48:08 -07:00
readdir.c xfs: streamline the directory iteration code for scrub 2023-04-11 19:00:17 -07:00
readdir.h xfs: streamline the directory iteration code for scrub 2023-04-11 19:00:17 -07:00
reap.c xfs: fix an off-by-one error in xreap_agextent_binval 2024-04-03 15:28:48 +02:00
reap.h xfs: use per-AG bitmaps to reap unused AG metadata blocks during repair 2023-08-10 07:48:04 -07:00
refcount.c xfs: fix duplicate includes 2023-04-20 08:18:34 +10:00
repair.c xfs: track usage statistics of online fsck 2023-08-10 07:48:07 -07:00
repair.h xfs: track usage statistics of online fsck 2023-08-10 07:48:07 -07:00
rmap.c xfs: cross-reference rmap records with refcount btrees 2023-04-11 19:00:39 -07:00
rtbitmap.c xfs: remove conditional building of rt geometry validator functions 2024-04-03 15:28:49 +02:00
rtsummary.c xfs: remove conditional building of rt geometry validator functions 2024-04-03 15:28:49 +02:00
scrub.c xfs: only call xchk_stats_merge after validating scrub inputs 2023-09-12 10:31:08 -07:00
scrub.h New code for 6.6: 2023-08-30 12:34:12 -07:00
stats.c xfs: fix scrub stats file permissions 2024-06-21 14:38:45 +02:00
stats.h xfs: track usage statistics of online fsck 2023-08-10 07:48:07 -07:00
symlink.c xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
trace.c xfs: create a big array data structure 2023-08-10 07:48:04 -07:00
trace.h xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t 2024-04-03 15:28:46 +02:00
xfarray.c xfs: improve xfarray quicksort pivot 2023-08-10 07:48:07 -07:00
xfarray.h xfs: improve xfarray quicksort pivot 2023-08-10 07:48:07 -07:00
xfile.c xfs: Remove duplicate include 2023-10-12 10:14:45 +05:30
xfile.h xfs: cache pages used for xfarray quicksort convergence 2023-08-10 07:48:06 -07:00
xfs_scrub.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00