FAILED: patch "[PATCH] f2fs: validate orphan inode entry count" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 846c499a65816d13f1186e3090e825e8bb8bcb8b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026070202-reptile-shriek-5d21@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 846c499a65816d13f1186e3090e825e8bb8bcb8b Mon Sep 17 00:00:00 2001
From: Wenjie Qi <[email protected]>
Date: Tue, 26 May 2026 13:35:57 +0800
Subject: [PATCH] f2fs: validate orphan inode entry count
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.
fs/f2fs/checkpoint.c +13 -1
@@ -943,6 +943,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)for (i =0 ; i < orphan_blocks; i++) {struct folio *folio;struct f2fs_orphan_block *orphan_blk; +unsigned int entry_count; folio =f2fs_get_meta_folio (sbi, start_blk + i);if (IS_ERR (folio)) {
@@ -951,7 +952,18 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi) } orphan_blk =folio_address (folio); -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 ); +f2fs_handle_error (sbi,ERROR_INCONSISTENT_ORPHAN ); + err = -EFSCORRUPTED ; +f2fs_folio_put (folio, true); + 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);
include/linux/f2fs_fs.h +1 -0
@@ -107,6 +107,7 @@ enum f2fs_error {ERROR_CORRUPTED_XATTR ,ERROR_INVALID_NODE_REFERENCE ,ERROR_INCONSISTENT_NAT , +ERROR_INCONSISTENT_ORPHAN , ERROR_MAX, };
Sasha Levin
maintainerPATCH 1/1 f2fs: validate orphan inode entry count
From: Wenjie Qi <[email protected]>
[ 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.
--- fs/f2fs/checkpoint.c | 14 +++++++++++++- include/linux/f2fs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +13 -1
@@ -743,6 +743,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)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)) {
@@ -751,7 +752,18 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi) } 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 ); +f2fs_handle_error (sbi,ERROR_INCONSISTENT_ORPHAN ); + 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);
include/linux/f2fs_fs.h +3 -0
@@ -104,6 +104,9 @@ enum f2fs_error {ERROR_INCONSISTENT_SIT ,ERROR_CORRUPTED_VERITY_XATTR ,ERROR_CORRUPTED_XATTR , +ERROR_INVALID_NODE_REFERENCE , +ERROR_INCONSISTENT_NAT , +ERROR_INCONSISTENT_ORPHAN , ERROR_MAX, };
Signature · 1 line
2.53.0