Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bc4fc81 authored by Jan Kara's avatar Jan Kara Committed by Sasha Levin
Browse files

ext4: fix crashes in dioread_nolock mode



[ Upstream commit 74dae4278546b897eb81784fdfcce872ddd8b2b8 ]

Competing overwrite DIO in dioread_nolock mode will just overwrite
pointer to io_end in the inode. This may result in data corruption or
extent conversion happening from IO completion interrupt because we
don't properly set buffer_defer_completion() when unlocked DIO races
with locked DIO to unwritten extent.

Since unlocked DIO doesn't need io_end for anything, just avoid
allocating it and corrupting pointer from inode for locked DIO.
A cleaner fix would be to avoid these games with io_end pointer from the
inode but that requires more intrusive changes so we leave that for
later.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent bec2f3e6
Loading
Loading
Loading
Loading
+20 −20
Original line number Original line Diff line number Diff line
@@ -3033,6 +3033,9 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
	 * case, we allocate an io_end structure to hook to the iocb.
	 * case, we allocate an io_end structure to hook to the iocb.
	 */
	 */
	iocb->private = NULL;
	iocb->private = NULL;
	if (overwrite) {
		get_block_func = ext4_get_block_write_nolock;
	} else {
		ext4_inode_aio_set(inode, NULL);
		ext4_inode_aio_set(inode, NULL);
		if (!is_sync_kiocb(iocb)) {
		if (!is_sync_kiocb(iocb)) {
			io_end = ext4_init_io_end(inode, GFP_NOFS);
			io_end = ext4_init_io_end(inode, GFP_NOFS);
@@ -3041,7 +3044,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
				goto retake_lock;
				goto retake_lock;
			}
			}
			/*
			/*
		 * Grab reference for DIO. Will be dropped in ext4_end_io_dio()
			 * Grab reference for DIO. Will be dropped in
			 * ext4_end_io_dio()
			 */
			 */
			iocb->private = ext4_get_io_end(io_end);
			iocb->private = ext4_get_io_end(io_end);
			/*
			/*
@@ -3052,10 +3056,6 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
			 */
			 */
			ext4_inode_aio_set(inode, io_end);
			ext4_inode_aio_set(inode, io_end);
		}
		}

	if (overwrite) {
		get_block_func = ext4_get_block_write_nolock;
	} else {
		get_block_func = ext4_get_block_write;
		get_block_func = ext4_get_block_write;
		dio_flags = DIO_LOCKING;
		dio_flags = DIO_LOCKING;
	}
	}