linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: reject 1k block fs on the first block of disk
@ 2022-12-29  1:45 Jun Nie
  2023-01-03 19:17 ` Darrick J. Wong
  0 siblings, 1 reply; 8+ messages in thread
From: Jun Nie @ 2022-12-29  1:45 UTC (permalink / raw)
  To: djwong, tytso, adilger.kernel, linux-ext4, linux-kernel; +Cc: tudor.ambarus

For 1k-block filesystems, the filesystem starts at block 1, not block 0.
If start_fsb is 0, it will be bump up to s_first_data_block. Then
ext4_get_group_no_and_offset don't know what to do and return garbage
results (blockgroup 2^32-1). The underflow make index
exceed es->s_groups_count in ext4_get_group_info() and trigger the BUG_ON.

Fixes: 4a4956249dac0 ("ext4: fix off-by-one fsmap error on 1k block filesystems")
Link: https://syzkaller.appspot.com/bug?id=79d5768e9bfe362911ac1a5057a36fc6b5c30002
Reported-by: syzbot+6be2b977c89f79b6b153@syzkaller.appspotmail.com
Signed-off-by: Jun Nie <jun.nie@linaro.org>
---
 fs/ext4/fsmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c
index 4493ef0c715e..1aef127b0634 100644
--- a/fs/ext4/fsmap.c
+++ b/fs/ext4/fsmap.c
@@ -702,6 +702,12 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head,
 		if (handlers[i].gfd_dev > head->fmh_keys[0].fmr_device)
 			memset(&dkeys[0], 0, sizeof(struct ext4_fsmap));
 
+		/*
+		 * Re-check the range after above limit operation and reject
+		 * 1K fs on block 0 as fs should start block 1. */
+		if (dkeys[0].fmr_physical ==0 && dkeys[1].fmr_physical == 0)
+			continue;
+
 		info.gfi_dev = handlers[i].gfd_dev;
 		info.gfi_last = false;
 		info.gfi_agno = -1;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-22 15:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-29  1:45 [PATCH] ext4: reject 1k block fs on the first block of disk Jun Nie
2023-01-03 19:17 ` Darrick J. Wong
2023-01-04  1:58   ` Jun Nie
2023-02-15  4:32     ` Theodore Ts'o
2023-02-15 11:46       ` Tudor Ambarus
2023-02-15 11:53         ` Tudor Ambarus
2023-02-15 16:26           ` Tudor Ambarus
2023-02-22 15:27       ` Tudor Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).