linux-stable/fs
Ojaswin Mujoo eddca44ddf ext4: avoid journaling sb update on error if journal is destroying
commit ce2f26e737 upstream.

Presently we always BUG_ON if trying to start a transaction on a journal marked
with JBD2_UNMOUNT, since this should never happen. However, while ltp running
stress tests, it was observed that in case of some error handling paths, it is
possible for update_super_work to start a transaction after the journal is
destroyed eg:

(umount)
ext4_kill_sb
  kill_block_super
    generic_shutdown_super
      sync_filesystem /* commits all txns */
      evict_inodes
        /* might start a new txn */
      ext4_put_super
	flush_work(&sbi->s_sb_upd_work) /* flush the workqueue */
        jbd2_journal_destroy
          journal_kill_thread
            journal->j_flags |= JBD2_UNMOUNT;
          jbd2_journal_commit_transaction
            jbd2_journal_get_descriptor_buffer
              jbd2_journal_bmap
                ext4_journal_bmap
                  ext4_map_blocks
                    ...
                    ext4_inode_error
                      ext4_handle_error
                        schedule_work(&sbi->s_sb_upd_work)

                                               /* work queue kicks in */
                                               update_super_work
                                                 jbd2_journal_start
                                                   start_this_handle
                                                     BUG_ON(journal->j_flags &
                                                            JBD2_UNMOUNT)

Hence, introduce a new mount flag to indicate journal is destroying and only do
a journaled (and deferred) update of sb if this flag is not set. Otherwise, just
fallback to an un-journaled commit.

Further, in the journal destroy path, we have the following sequence:

  1. Set mount flag indicating journal is destroying
  2. force a commit and wait for it
  3. flush pending sb updates

This sequence is important as it ensures that, after this point, there is no sb
update that might be journaled so it is safe to update the sb outside the
journal. (To avoid race discussed in 2d01ddc866)

Also, we don't need a similar check in ext4_grp_locked_error since it is only
called from mballoc and AFAICT it would be always valid to schedule work here.

Fixes: 2d01ddc866 ("ext4: save error info to sb through journal if available")
Reported-by: Mahesh Kumar <maheshkumar657g@gmail.com>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/9613c465d6ff00cd315602f99283d5f24018c3f7.1742279837.git.ojaswin@linux.ibm.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-09-09 18:58:20 +02:00
..
9p
adfs
affs
afs
autofs
bcachefs
befs
bfs
btrfs btrfs: zoned: skip ZONE FINISH of conventional zones 2025-09-09 18:58:03 +02:00
cachefiles
ceph
coda
configfs
cramfs
crypto
debugfs debugfs: fix mount options not being applied 2025-08-28 16:31:08 +02:00
devpts
dlm
ecryptfs
efivarfs efivarfs: Fix slab-out-of-bounds in efivarfs_d_compare 2025-09-04 15:31:52 +02:00
efs
erofs erofs: fix atomic context detection when !CONFIG_DEBUG_LOCK_ALLOC 2025-09-04 15:31:44 +02:00
exfat exfat: add cluster chain loop check for dir 2025-08-20 18:30:47 +02:00
exportfs
ext2 ext2: Handle fiemap on empty files to prevent EINVAL 2025-08-20 18:30:21 +02:00
ext4 ext4: avoid journaling sb update on error if journal is destroying 2025-09-09 18:58:20 +02:00
f2fs f2fs: fix to avoid out-of-boundary access in dnode page 2025-08-28 16:30:59 +02:00
fat
freevxfs
fuse
gfs2 gfs2: Set .migrate_folio in gfs2_{rgrp,meta}_aops 2025-08-20 18:30:20 +02:00
hfs hfs: fix not erasing deleted b-tree node issue 2025-08-20 18:30:20 +02:00
hfsplus hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file() 2025-08-20 18:30:19 +02:00
hostfs
hpfs
hugetlbfs
iomap
isofs
jbd2 jbd2: prevent softlockup in jbd2_log_do_checkpoint() 2025-08-28 16:30:59 +02:00
jffs2
jfs jfs: upper bound check of tree index in dbAllocAG 2025-08-20 18:30:42 +02:00
kernfs
lockd
minix
netfs netfs: Fix unbuffered write error handling 2025-08-28 16:31:04 +02:00
nfs NFS: Fix a race when updating an existing write 2025-08-28 16:31:05 +02:00
nfs_common
nfsd
nilfs2
nls
notify
ntfs3 fs/ntfs3: correctly create symlink for relative path 2025-08-20 18:30:21 +02:00
ocfs2 ocfs2: prevent release journal inode after journal shutdown 2025-09-09 18:58:16 +02:00
omfs
openpromfs
orangefs fs/orangefs: use snprintf() instead of sprintf() 2025-08-20 18:30:41 +02:00
overlayfs ovl: use I_MUTEX_PARENT when locking parent in ovl_create_temp() 2025-08-28 16:31:10 +02:00
proc proc: fix missing pde_set_flags() for net proc files 2025-09-09 18:58:16 +02:00
pstore
qnx4
qnx6
quota
ramfs
reiserfs
romfs
smb cifs: prevent NULL pointer dereference in UTF16 conversion 2025-09-09 18:58:18 +02:00
squashfs squashfs: fix memory leak in squashfs_fill_super 2025-08-28 16:31:05 +02:00
sysfs
sysv
tests
tracefs tracefs: Add d_delete to remove negative dentries 2025-08-20 18:30:21 +02:00
ubifs
udf udf: Verify partition map count 2025-08-20 18:30:20 +02:00
ufs
unicode
vboxsf
verity
xfs xfs: do not propagate ENODATA disk errors into xattr code 2025-09-04 15:31:54 +02:00
zonefs
aio.c
anon_inodes.c
attr.c
backing-file.c
bad_inode.c
binfmt_elf_fdpic.c
binfmt_elf.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
bpf_fs_kfuncs.c
buffer.c fs/buffer: fix use-after-free when call bh_read() helper 2025-08-28 16:31:08 +02:00
char_dev.c
compat_binfmt_elf.c
coredump.c
d_path.c
dax.c
dcache.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c
fcntl.c
fhandle.c
file_table.c
file.c alloc_fdtable(): change calling conventions. 2025-08-28 16:31:16 +02:00
filesystems.c
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fs-writeback.c fs: writeback: fix use-after-free in __mark_inode_dirty() 2025-09-09 18:58:03 +02:00
fsopen.c
init.c
inode.c
internal.h
ioctl.c
Kconfig
Kconfig.binfmt
kernel_read_file.c
libfs.c better lockdep annotations for simple_recursive_removal() 2025-08-20 18:30:20 +02:00
locks.c
Makefile
mbcache.c
mnt_idmapping.c
mount.h
mpage.c
namei.c
namespace.c fs/fhandle.c: fix a race in call of has_locked_children() 2025-09-09 18:58:19 +02:00
nsfs.c
open.c
pidfs.c pidfs: raise SB_I_NODEV and SB_I_NOEXEC 2025-08-20 18:30:21 +02:00
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
remap_range.c
select.c
seq_file.c
signalfd.c
splice.c netfs: Fix unbuffered write error handling 2025-08-28 16:31:04 +02:00
stack.c
stat.c
statfs.c
super.c
sync.c
sysctls.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c