From mboxrd@z Thu Jan 1 00:00:00 1970 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=1794046994; b=WcxL8fnulXhjnMQXQgLs6BnYhSlcio1u3k1B1ifTMzYucyYxTm0yjSRDhQKOuuk2FFE6 OkDg02svbLjlfaqYDCZfW+TfZrcXu3hFEQ48RSX8OKBzkQQGyyZS/F07vhAN014wFgsGe dqNo4IUjO6IDTknp2jHwFvC7yqcBWNF4d1mE8ahqaty5oWkiIeDcQ8k4JdJtRbUmsfApP EpRPVzXdpLsmI9VHllyfDp8IsL8v2ocJUD7POcP03l2uJkTSNtimFYNMz4w8B9JWxDVsB vQwZmcK2vZCSVvQ/A98UZmRKdo8JTWzrN5MXKF+/+VJZETtrBPtBy+mkqe7A3AM7IEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794046994; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=y+iwhAafxw72sH33STGQzLbT22dEq5hfDwzJpOWV2Ww=; b=Y+kbygsEH9HmLj6tOvCJHY83W8kQ2kPNNjkX6l1XQTGqaOO395wZKKYvBEYKd2Sh7QW6 onAx1peitR3hot4lzHnh63sYlInL0N9CyfIIWFv9geux1ISBh40V7elmD7kIQGbv9DHIF F9P9t8vbeJwFTqLVUPL2YPytbMgehAR6pshDknrGjtks/QkM3XNwjLqqhV1zQjOT8SE8u elwK1jyhPlGo/SlW9tn9RxAudEMKVDztAd02CPu6lfxEZ2PtH3ihDfTw2nZ2lgUsI4bDL 2mOOw0XY8ogdQcscoLpZIr/ymbNe9cgnBmdkttH9tDVBxd2u4oPTugBWt1okXpZ/mkw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LeYEWDQF; 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 B849E606A8F8 for ; Sat, 7 Nov 2026 10:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LeYEWDQF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A20B1F0089F; Sat, 7 Nov 2026 10:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794046993; bh=y+iwhAafxw72sH33STGQzLbT22dEq5hfDwzJpOWV2Ww=; h=From:To:Cc:Subject:Date; b=LeYEWDQFtxjIcBAR8i1lEdqA4T9XPMqHkPeUNkMyMILP0nYw6uN61tU0yR1pk7vqw 0LT4X1fQJr8k/3Vmps40soTiu8Rged/z4OxC4CTfK4QGN8PUDkbzFJPNSHbNccke81 duT3+tdsN3MpeXCptYg3BtiZYjTOKfr8nG2/UhI8fYT6HEPuU0yS4rtIoAVB79IzP7 q/Sorqbpeko9I3lehnOefkB8xt7JEnIY76qiFHBBO0pt3slIwmVQw/RwGqe4C0FxZ1 OR6r6j3P+nUiUOCxbBleB1EJuHU4sRbevkQyRIZa7SKMRmn7eQ333WyGd3lq1aFO8L Kans09iOJYv4A== From: Sasha Levin To: kaixuanli0131@gmail.com, chao@kernel.org, jaegeuk@kernel.org Cc: stable@vger.kernel.org Subject: FAILED: patch "[PATCH] f2fs: bound the SIT/NAT bitmaps by the checkpoint pack" failed to apply to 6.12-stable tree Date: Sat, 7 Nov 2026 05:23:12 -0500 Message-ID: <20261107052312-failed-6.12-080833a32fd5@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-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 . 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.12.y git checkout FETCH_HEAD git cherry-pick -x 080833a32fd5dc10b3acf2fa9af9b3213e6cb617 # git commit -s git send-email --to '' --in-reply-to '20261107052312-failed-6.12-080833a32fd5@kernel.org' --subject-prefix 'PATCH 6.12.y' 'HEAD^..' Thanks, Sasha ------------------ original commit in Linus's tree ------------------ >From 080833a32fd5dc10b3acf2fa9af9b3213e6cb617 Mon Sep 17 00:00:00 2001 From: Kaixuan Li Date: Sat, 19 Sep 2026 21:09:24 +0800 Subject: [PATCH] f2fs: bound the SIT/NAT bitmaps by the checkpoint pack sit_ver_bitmap_bytesize and nat_ver_bitmap_bytesize are used as memcpy lengths into and out of sbi->ckpt, which is sized from cp_payload alone, and nothing compares either length against that allocation. sanity_check_ckpt() has checked these two fields since c77ec61ca0a4, which added them after a crafted image overran build_sit_info(). That check ties each length to a segment count; it never compares either against the allocation, which is the half this adds. Mounting over-reads in build_sit_info() and build_node_manager(), and the first checkpoint writes the same lengths back through the same pointers, so the over-read's contents reach the on-disk checkpoint. An unmount is enough; the filesystem does not have to be used. Bound both ends the way __bitmap_ptr() lays them out. The three branches differ, so a single sum of the two lengths would still admit a small overflow when cp_payload is non-zero. Fixes: 39a53e0ce0df ("f2fs: add superblock and major in-memory structure") Cc: stable@kernel.org Signed-off-by: Kaixuan Li Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 54431da34edf9..3a191fda7030f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4278,6 +4278,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) block_t avail_node_count, valid_node_count; unsigned int nat_blocks, nat_bits_bytes, nat_bits_blocks; unsigned int sit_blk_cnt; + unsigned long long ckpt_size, sit_end, nat_end; int i, j; total = le32_to_cpu(raw_super->segment_count); @@ -4409,6 +4410,29 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) return 1; } + /* + * Nothing above ties the bitmap lengths to sbi->ckpt, which is + * (1 + cp_payload) blocks. Bound both ends the way __bitmap_ptr() + * lays them out. + */ + ckpt_size = (unsigned long long)(cp_payload + 1) * F2FS_BLKSIZE(sbi); + if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG)) { + nat_end = CP_MIN_CHKSUM_OFFSET + sizeof(__le32) + nat_bitmap_size; + sit_end = nat_end + sit_bitmap_size; + } else if (cp_payload > 0) { + nat_end = CP_MIN_CHKSUM_OFFSET + nat_bitmap_size; + sit_end = F2FS_BLKSIZE(sbi) + sit_bitmap_size; + } else { + sit_end = CP_MIN_CHKSUM_OFFSET + sit_bitmap_size; + nat_end = sit_end + nat_bitmap_size; + } + + if (sit_end > ckpt_size || nat_end > ckpt_size) { + f2fs_err(sbi, "Bitmaps do not fit the checkpoint pack: sit ends at %llu, nat at %llu, pack is %llu bytes", + sit_end, nat_end, ckpt_size); + return 1; + } + if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) && le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) { f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " -- 2.53.0