From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FDF632D42B; Sat, 30 May 2026 16:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780160268; cv=none; b=BDhEupkia14jpmnhTZVMcpVqNu+UitGCVADrjvaEsy/DFYl2Q32Lw6roCSDNeYsmj1g1Ghmhns+WqbUorvL66V9g9O+MhvJ3kRTavz1IYF3vObk+l+VXCLegXrTDTJIeuZhOOSheB7BtYouWV2DqqWwh3hXtUY6cUmfGdsUP/VE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780160268; c=relaxed/simple; bh=YPfjjEcapclR9D3pczH5ijzQXDoHTowgtdYsLvo4dxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fefXGv4Ok6lVUugs3Ca+OFJJoaOnpdUDLwknf7Zi1Jy3vcW7rcjsoBZeQtpKcu/8vX4uR+IA7fUTc33ho0Psu2Jq7pz6izeJp0fX6Nb52dRXtFQD8TzF98catwhzOoFjjITl9RiNNZaZcLgPE7Q6TWafClM476iUpSTrbKBsu6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=a/6zy6pi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="a/6zy6pi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E7B1F00893; Sat, 30 May 2026 16:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780160267; bh=nmuKJn/EzJXXvHzvVzQXSWaLjAPReb8yFGnZWGa+tek=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a/6zy6pi/Cj0KDhlbJMkl7A6tCh5bSB9bD1yfWIZbSjti187iQ1V4OUFS5uLlD0lG POj50BzMVLSxU8WReSzryigCtH21SgTo55D7e4Chym6gPjjeQzIZUxVhitIgCJ4K7t f3JfS/zM/gZkApEW9+I3NGuDIV/mGcw12Y05Yp5w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+04c4e65cab786a2e5b7e@syzkaller.appspotmail.com, Tejas Bharambe , Theodore Tso , stable@kernel.org, Jianqiang kang , Sasha Levin Subject: [PATCH 6.1 291/969] ext4: validate p_idx bounds in ext4_ext_correct_indexes Date: Sat, 30 May 2026 17:56:55 +0200 Message-ID: <20260530160308.488147866@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tejas Bharambe [ Upstream commit 2acb5c12ebd860f30e4faf67e6cc8c44ddfe5fe8 ] ext4_ext_correct_indexes() walks up the extent tree correcting index entries when the first extent in a leaf is modified. Before accessing path[k].p_idx->ei_block, there is no validation that p_idx falls within the valid range of index entries for that level. If the on-disk extent header contains a corrupted or crafted eh_entries value, p_idx can point past the end of the allocated buffer, causing a slab-out-of-bounds read. Fix this by validating path[k].p_idx against EXT_LAST_INDEX() at both access sites: before the while loop and inside it. Return -EFSCORRUPTED if the index pointer is out of range, consistent with how other bounds violations are handled in the ext4 extent tree code. Reported-by: syzbot+04c4e65cab786a2e5b7e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=04c4e65cab786a2e5b7e Signed-off-by: Tejas Bharambe Link: https://patch.msgid.link/JH0PR06MB66326016F9B6AD24097D232B897CA@JH0PR06MB6632.apcprd06.prod.outlook.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org [ Minor conflict resolved. ] Signed-off-by: Jianqiang kang Signed-off-by: Sasha Levin --- fs/ext4/extents.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 1df7174774694..6d95dab538475 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1740,6 +1740,13 @@ static int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode, err = ext4_ext_get_access(handle, inode, path + k); if (err) return err; + if (unlikely(path[k].p_idx > EXT_LAST_INDEX(path[k].p_hdr))) { + EXT4_ERROR_INODE(inode, + "path[%d].p_idx %p > EXT_LAST_INDEX %p", + k, path[k].p_idx, + EXT_LAST_INDEX(path[k].p_hdr)); + return -EFSCORRUPTED; + } path[k].p_idx->ei_block = border; err = ext4_ext_dirty(handle, inode, path + k); if (err) @@ -1752,6 +1759,14 @@ static int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode, err = ext4_ext_get_access(handle, inode, path + k); if (err) break; + if (unlikely(path[k].p_idx > EXT_LAST_INDEX(path[k].p_hdr))) { + EXT4_ERROR_INODE(inode, + "path[%d].p_idx %p > EXT_LAST_INDEX %p", + k, path[k].p_idx, + EXT_LAST_INDEX(path[k].p_hdr)); + err = -EFSCORRUPTED; + break; + } path[k].p_idx->ei_block = border; err = ext4_ext_dirty(handle, inode, path + k); if (err) -- 2.53.0