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 298E0415F23; Tue, 21 Jul 2026 21:54:23 +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=1784670864; cv=none; b=BsqsOnSl5Dmj7HIYYKYz5p0lmxdlkT4c+NOkOwL7CROjZzk8VRBFiKkfLhRx87doL/u+XssPFjcGgfsRdRvdoPMqtPk47JGsvU20q9g7vXPFAHmywjjvHE+eI0qyS+UaCu+k7frM8iaY8lXtsg4GAZGG6pV88gRkM9Zz0DbQCPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784670864; c=relaxed/simple; bh=x2+os7kvzdxkCFf1UWtP6y2t2ez476R1HijiruFKTmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=doQM4ld5tnXQ2/vsprnuzt0g9xDJk6GC0iwt4YuAHQ9pa/UzXWv/GH+uQWayLBOFcFlTbXtOgY7sslOcZ2EJtzzhV/xNs6PeZjDDVaQnVSmtItsU0i9X2qJ7wgfj6LsOjgE/5WTsQD645KVrLyTHy2iWmhjAuY1fSOYGOprFvYI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ijdwQAq4; 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="ijdwQAq4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89EA41F000E9; Tue, 21 Jul 2026 21:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784670863; bh=nUETHtlQ11RtKZ7aeDDCUUwfdvgktdVl90mAtf+KC+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ijdwQAq4P1GznOXuXwJfc4AXbn0s2O9WdjzzmL3LymXtWcSh6pl2Bckvjq8nDVb56 a6OoW1Sw3bP+DflWemx8/X1KhqeZLoEwkipCLMmN7eqrs+u/UDS7S28v1sY6Wt1WRQ NKW+zqVKSEMv3v2wz4rM1TktjVqp/KXJsaAKAGTA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Wenjie Qi , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.15 029/843] f2fs: validate orphan inode entry count Date: Tue, 21 Jul 2026 17:14:24 +0200 Message-ID: <20260721152406.623910728@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wenjie Qi [ Upstream commit 846c499a65816d13f1186e3090e825e8bb8bcb8b ] f2fs_recover_orphan_inodes() trusts the orphan block entry_count when replaying orphan inodes from the checkpoint pack. A corrupted entry_count larger than F2FS_ORPHANS_PER_BLOCK makes the recovery loop read past the ino[] array and interpret footer or following data as inode numbers. On a crafted image, mounting an unpatched kernel can drive orphan recovery into f2fs_bug_on() and panic the kernel. Validate entry_count before consuming entries so corrupted checkpoint data fails the mount with -EFSCORRUPTED and requests fsck instead. Set ERROR_INCONSISTENT_ORPHAN as well, so the corruption reason can be recorded in the superblock s_errors[] field. This gives fsck a persistent hint even though mount-time orphan recovery failure may leave no chance to persist SBI_NEED_FSCK through a checkpoint. Cc: stable@kernel.org Fixes: 127e670abfa7 ("f2fs: add checkpoint operations") Signed-off-by: Wenjie Qi Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim [ Folio API ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/checkpoint.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -738,6 +738,7 @@ int f2fs_recover_orphan_inodes(struct f2 for (i = 0; i < orphan_blocks; i++) { struct page *page; struct f2fs_orphan_block *orphan_blk; + unsigned int entry_count; page = f2fs_get_meta_page(sbi, start_blk + i); if (IS_ERR(page)) { @@ -746,7 +747,17 @@ int f2fs_recover_orphan_inodes(struct f2 } orphan_blk = (struct f2fs_orphan_block *)page_address(page); - for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) { + entry_count = le32_to_cpu(orphan_blk->entry_count); + if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + f2fs_err(sbi, "invalid orphan inode entry count %u", + entry_count); + set_sbi_flag(sbi, SBI_NEED_FSCK); + err = -EFSCORRUPTED; + f2fs_put_page(page, 1); + goto out; + } + + for (j = 0; j < entry_count; j++) { nid_t ino = le32_to_cpu(orphan_blk->ino[j]); err = recover_orphan_inode(sbi, ino);