Messages in this thread Patch in this message | | | From | Jun Nie <> | Subject | [PATCH] ext4: reject 1k block fs on the first block of disk | Date | Thu, 29 Dec 2022 09:45:02 +0800 |
| |
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
| |