From nobody Sat May 30 12:37:34 2026 Received: from mail115-171.sinamail.sina.com.cn (mail115-171.sinamail.sina.com.cn [218.30.115.171]) (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 AFA2B31E107 for ; Fri, 8 May 2026 07:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778223665; cv=none; b=nplqa/fRLUawb0r/a5e2kMvXYN9Bu2A7hkCB7MhXLwChL5w3AHO5vAd8JRmNwq4QJw7sgLFVLdxRuzIMXcjawbqmi15yOtX4vZfbvspd7yrNG002nrBZ65RMPS2h1CGfpfMpv6m7ItP3HPw0Wgyd8JIYpi4PYN3uksc5SDqEfqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778223665; c=relaxed/simple; bh=Ny5lasZHyO87EegPFrBjX2eufmvrdYmaIvUhQ44Lp5M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=im0gBDQ3ygltHF3I0O7HyPzht7IN9vwRWsSqSDxHJQVxNh05TzVVA89RIuv+uuxs4bcJk5pZ7A/5CBQV3MKh+/5c0H2idcXEuYHUyq4IYEy13zObjOBy8qLbKRUTPECuB4tcfEUcf+TOLm7XOX1F9ZfddreyfT7B9oxtyrg6oPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.cn; spf=pass smtp.mailfrom=sina.cn; dkim=pass (1024-bit key) header.d=sina.cn header.i=@sina.cn header.b=hY8TXr72; arc=none smtp.client-ip=218.30.115.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=sina.cn header.i=@sina.cn header.b="hY8TXr72" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sina.cn; s=201208; t=1778223660; bh=mknp58zzNXrMHnzixaFoNMYGsNeXzm8WGz4EEnUO4qM=; h=From:Subject:Date:Message-Id; b=hY8TXr72HA31ByaaTUDoEOjiLNUAqFlHZHj57/CpG7Lg23fIisp62UnWQYY+o8zud XRdGS7CZmOGPxXCRlnwTSP7TDj11CGq2GFtfWRYzAMiW0FMzx6SyH4uUm4oYX3wI3S asFlPB//YBSC+1larvDwBOtMezjPCDCWUeKzzbXk= X-SMAIL-HELO: NTT-kernel-dev Received: from unknown (HELO NTT-kernel-dev)([60.247.85.88]) by sina.cn (10.185.250.24) with ESMTP id 69FD899500007A39; Fri, 8 May 2026 14:58:31 +0800 (CST) X-Sender: jianqkang@sina.cn X-Auth-ID: jianqkang@sina.cn Authentication-Results: sina.cn; spf=none smtp.mailfrom=jianqkang@sina.cn; dkim=none header.i=none; dmarc=none action=none header.from=jianqkang@sina.cn X-SMAIL-MID: 48299210747922 X-SMAIL-UIID: 8D42F8EFFC414A5DA0CB3185ACE2023C-20260508-145831-1 From: Jianqiang kang To: gregkh@linuxfoundation.org, stable@vger.kernel.org, tejas.bharambe@outlook.com Cc: patches@lists.linux.dev, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Subject: [PATCH 6.1.y] ext4: validate p_idx bounds in ext4_ext_correct_indexes Date: Fri, 8 May 2026 14:58:29 +0800 Message-Id: <20260508065829.3030954-1-jianqkang@sina.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D04c4e65cab786a2e5b7e Signed-off-by: Tejas Bharambe Link: https://patch.msgid.link/JH0PR06MB66326016F9B6AD24097D232B897CA@JH0PR= 06MB6632.apcprd06.prod.outlook.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org [ Minor conflict resolved. ] Signed-off-by: Jianqiang kang --- fs/ext4/extents.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 1df717477469..6d95dab53847 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 =3D 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 =3D border; err =3D 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 =3D 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 =3D -EFSCORRUPTED; + break; + } path[k].p_idx->ei_block =3D border; err =3D ext4_ext_dirty(handle, inode, path + k); if (err) --=20 2.34.1