Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795019577; b=b9y4JwZBKKglH8TLB0LVtDbVBfAUrxKKbWWqrx69T8ZGQEooCyK7fDI3+6ehKYQWY/Q8 tX3aTSTyXSm2ZEQ62mI7pU2RZCFCuI5cuJJKJgRGl8pgR0NMrzOe+ObQdIgIMcMbTMuv7 IBJ7wSG7aFHfCOwRiumhh4RyxmCeQFAPMOtXcMrv07HJatariu8+tkrv9ik3Q+CXgafzt iOHi/vE/nbGZhV/1gzJ9VNrD9Ltkf56tE+mE+6zaD6xxOXYyoofK+0ZbZ91gonYuUqH+4 H2zvBHUTTBN8LUyxIQV7is3gs3BNAkkCjpqYZlbckOCTjfDO5szbmwuTPTkOGdfnytg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795019577; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=W/+rMD2RAohNpWpHWvElqjR457tmnVfDvR5TD8lkJ1g=; b=OVnfUG+j5cxIIVfcEcii3thI88x6mu01grtBkSCLEcXIYTzCtymR0rDhxJktf8RZrCY+ jF93OhyVF+juk2QvPRTBb1jFx8KJT0TlOIXuHKJY8UbAiLiUcjJrPj7xNtfwo9tQMLzhW ImiHG78ErsUfdQlDZhwvPeVhk6y7Wm6lYQBcj3iGrysyyZ1QeD1WzPcte/XVQWiL3EMXT 4Q+k6XCFOfAD7SseWRF/dNw9RB3UMiakqOAhJ7NW7kmMq0vfJQUZJgKniJOd8dH+sN9dJ eNuIrulQihXNUtJzZbBi/bxJfpNXpl15GOy3X54ZOeX/19YTYBxayaqrLdLmSUXxJyQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oj9i+JGD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10428606A325; Wed, 18 Nov 2026 16:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oj9i+JGD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CA5D1F000C6; Wed, 18 Nov 2026 16:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795019576; bh=W/+rMD2RAohNpWpHWvElqjR457tmnVfDvR5TD8lkJ1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oj9i+JGD8PcDhRgtiuPLOZFR2iAqNa0QFxjlbX8twsUn8WNld/bcSdRb0gnDdpMCK 0erZgT9dsqAD6zYcIjQWmrSTGa/xvKMGyF68sCJleTFs6kxscFEf64CI4q3p8tpULs iByCjtUPNChZMvQGj4AM7BhcmCmWCPImW91ghDNo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hannes Reinecke , Christoph Hellwig , Shinichiro Kawasaki , Tal Zussman , Jens Axboe , Sasha Levin Subject: [PATCH 7.3 1644/2651] block: take i_rwsem for the splice read path Date: Wed, 18 Nov 2026 15:48:04 +0100 Message-ID: <20261118150346.993176603@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tal Zussman [ Upstream commit 5574b81c642e83d962732e86399020517f5f15af ] def_blk_fops wires ->splice_read directly to filemap_splice_read(), which allocates folios based on mapping_min_folio_order() without any lock against set_blocksize(). A splice from a block device can race set_blocksize() raising the minimum folio order and insert a folio that is too small for the mapping. blkdev_read_iter() wraps filemap_read() in inode_lock_shared() for this reason, but the splice path was missed. Splicing from a block device while toggling the block size between 512 bytes and 64K with BLKBSZSET hits this within seconds on a CONFIG_DEBUG_VM kernel: page dumped because: VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping)) kernel BUG at mm/filemap.c:858! Oops: invalid opcode: 0000 [#1] SMP NOPTI RIP: 0010:__filemap_add_folio+0x51c/0x570 Call Trace: filemap_add_folio+0x64/0x140 page_cache_ra_order+0x1dd/0x3d0 filemap_get_pages+0x153/0x760 filemap_splice_read+0x13f/0x300 splice_file_to_pipe+0xc0/0xd0 do_splice+0x6a8/0x890 __do_splice+0xb0/0x210 __x64_sys_splice+0x80/0x100 do_syscall_64+0x10e/0x520 entry_SYSCALL_64_after_hwframe+0x77/0x7f Take inode_lock_shared() around filemap_splice_read(), like the read path does. Fixes: 3c20917120ce ("block/bdev: enable large folio support for large logical block sizes") Assisted-by: Claude:claude-fable-5 Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Tested-by: Shin'ichiro Kawasaki Signed-off-by: Tal Zussman Link: https://patch.msgid.link/20261009-blkdev-fixes-v6-3-307939c387df@columbia.edu Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/fops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 6aef34865d1ad..847d22094d326 100644 --- a/block/fops.c +++ b/block/fops.c @@ -888,6 +888,22 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +/* + * Take i_rwsem to avoid racing with set_blocksize changing i_blkbits/folio + * order and punching out the pagecache. + */ +static ssize_t blkdev_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, unsigned int flags) +{ + struct inode *bd_inode = bdev_file_inode(in); + ssize_t ret; + + inode_lock_shared(bd_inode); + ret = filemap_splice_read(in, ppos, pipe, len, flags); + inode_unlock_shared(bd_inode); + return ret; +} + #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ FALLOC_FL_ZERO_RANGE | FALLOC_FL_WRITE_ZEROES) @@ -989,7 +1005,7 @@ const struct file_operations def_blk_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = compat_blkdev_ioctl, #endif - .splice_read = filemap_splice_read, + .splice_read = blkdev_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, .uring_cmd = blkdev_uring_cmd, -- 2.53.0