linux-stable/fs/ext4
Brian Foster e3b83d87c9 ext4: fix racy may inline data check in dio write
commit ce56d21355 upstream.

syzbot reports that the following warning from ext4_iomap_begin()
triggers as of the commit referenced below:

        if (WARN_ON_ONCE(ext4_has_inline_data(inode)))
                return -ERANGE;

This occurs during a dio write, which is never expected to encounter
an inode with inline data. To enforce this behavior,
ext4_dio_write_iter() checks the current inline state of the inode
and clears the MAY_INLINE_DATA state flag to either fall back to
buffered writes, or enforce that any other writers in progress on
the inode are not allowed to create inline data.

The problem is that the check for existing inline data and the state
flag can span a lock cycle. For example, if the ilock is originally
locked shared and subsequently upgraded to exclusive, another writer
may have reacquired the lock and created inline data before the dio
write task acquires the lock and proceeds.

The commit referenced below loosens the lock requirements to allow
some forms of unaligned dio writes to occur under shared lock, but
AFAICT the inline data check was technically already racy for any
dio write that would have involved a lock cycle. Regardless, lift
clearing of the state bit to the same lock critical section that
checks for preexisting inline data on the inode to close the race.

Cc: stable@kernel.org
Reported-by: syzbot+307da6ca5cb0d01d581a@syzkaller.appspotmail.com
Fixes: 310ee0902b ("ext4: allow concurrent unaligned dio overwrites")
Signed-off-by: Brian Foster <bfoster@redhat.com>
Link: https://lore.kernel.org/r/20231002185020.531537-1-bfoster@redhat.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-11-28 17:15:17 +00:00
..
.kunitconfig
acl.c fs: port acl to mnt_idmap 2023-01-19 09:24:28 +01:00
acl.h ext4: apply umask if ACL support is disabled 2023-11-28 17:15:16 +00:00
balloc.c ext4: add correct group descriptors and reserved GDT blocks to system zone 2023-09-19 12:30:22 +02:00
bitmap.c ext4: remove useless conditional branch code 2023-04-19 23:39:08 -04:00
block_validity.c ext4: add correct group descriptors and reserved GDT blocks to system zone 2023-09-19 12:30:22 +02:00
crypto.c ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} 2023-09-19 12:30:22 +02:00
dir.c ext4: fix spelling errors in comments 2022-05-11 15:19:06 -04:00
ext4.h ext4: fix race between writepages and remount 2023-11-28 17:15:16 +00:00
ext4_extents.h
ext4_jbd2.c ext4: split ext4_journal_start trace for debug 2022-12-01 10:46:54 -05:00
ext4_jbd2.h ext4: split ext4_journal_start trace for debug 2022-12-01 10:46:54 -05:00
extents.c ext4: move 'ix' sanity check to corrent position 2023-11-20 11:57:08 +01:00
extents_status.c ext4: correct the start block of counting reserved clusters 2023-11-28 17:15:17 +00:00
extents_status.h ext4: make ext4_es_insert_extent() return void 2023-06-26 19:35:12 -04:00
fast_commit.c ext4: use ext4_fc_tl_mem in fast-commit replay path 2023-02-09 10:43:23 -05:00
fast_commit.h ext4: add missing validation of fast-commit record lengths 2022-12-08 21:49:24 -05:00
file.c ext4: fix racy may inline data check in dio write 2023-11-28 17:15:17 +00:00
fsmap.c ext4: fix another off-by-one fsmap error on 1k block filesystems 2023-03-07 20:20:48 -05:00
fsmap.h
fsync.c \n 2023-06-29 13:39:51 -07:00
hash.c ext4: improve error handling from ext4_dirhash() 2023-05-13 18:05:05 -04:00
ialloc.c ext4: allow ext4_get_group_info() to fail 2023-05-13 18:02:46 -04:00
indirect.c ext4: only update i_reserved_data_blocks on successful block allocation 2023-06-26 19:34:56 -04:00
inline.c ext4: make ext4_es_remove_extent() return void 2023-06-26 19:35:12 -04:00
inode-test.c fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature 2020-12-02 16:07:25 -07:00
inode.c ext4: mark buffer new if it is unwritten to avoid stale data exposure 2023-11-28 17:15:16 +00:00
ioctl.c Various cleanups and bug fixes in ext4's extent status tree, 2023-06-29 13:18:36 -07:00
Kconfig ext: EXT4_KUNIT_TESTS should depend on EXT4_FS instead of selecting it 2021-02-11 23:12:59 -05:00
Makefile ext4: move ext4 crypto code to its own file crypto.c 2022-05-21 22:24:24 -04:00
mballoc.c ext4: do not let fstrim block system suspend 2023-10-06 13:15:46 +02:00
mballoc.h ext4: add two helper functions extent_logical_end() and pa_logical_end() 2023-09-23 11:14:26 +02:00
migrate.c ext4: avoid deadlock in fs reclaim with page writeback 2023-05-13 18:05:04 -04:00
mmp.c ext4: fix lockdep warning when enabling MMP 2023-05-07 21:11:18 -04:00
move_extent.c - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07:00
namei.c ext4: fix rec_len verify error 2023-09-23 11:14:37 +02:00
orphan.c ext4: remove trailing newline from ext4_msg() message 2022-12-08 21:49:23 -05:00
page-io.c ext4: remove unneeded check of nr_to_submit 2023-04-19 23:38:33 -04:00
readpage.c ext4: Call fsverity_verify_folio() 2023-06-15 00:02:10 -04:00
resize.c ext4: add missed brelse in update_backups 2023-11-28 17:15:17 +00:00
super.c ext4: fix race between writepages and remount 2023-11-28 17:15:16 +00:00
symlink.c fs: port ->getattr() to pass mnt_idmap 2023-01-19 09:24:25 +01:00
sysfs.c ext4: Give symbolic names to mballoc criterias 2023-06-26 19:34:56 -04:00
truncate.h ext4: Convert to use mapping->invalidate_lock 2021-07-13 14:29:00 +02:00
verity.c - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07:00
xattr.c ext4: correct inline offset when handling xattrs in inode body 2023-07-23 08:21:05 -04:00
xattr.h ext4: remove EA inode entry from mbcache on inode eviction 2022-08-02 23:56:25 -04:00
xattr_hurd.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_security.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_trusted.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_user.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00