Skip to content

fix(ext4): Prevent group descriptor checksum mismatch for large filesystems - #463

Merged
deitch merged 1 commit into
diskfs:masterfrom
Hrubon:ext4-fix-large-block-group-numbers
Nov 23, 2026
Merged

deitch merged 1 commit into
diskfs:masterfrom
Hrubon:ext4-fix-large-block-group-numbers

Conversation

@Hrubon

@Hrubon Hrubon commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue Description

According to ext4 format description, there is a hard limit for the number of ext4 block groups, which is 2^32. Also in the Linux kernel source, the data-type for ext4 meta block group numbers is unsigned int and in the group descriptor checksum computation, the __le32 data-type is used.

However, in go-diskfs, group descriptor number is defined as uint16 in the groupDescriptor struct. In the checksum computation, uint16 is used as well.

This limits the go-diskfs implementation to 2^16 = 65,536 block groups. Assuming 32,768 blocks per group and block size of 4,096 B, this effectively means that go-diskfs is unable to read ext4 file-systems exceeding 8 TiB in size.

This issue results in the group descriptor checksum mismatch error, when trying to read ext4 file-system larger than 8 TiB using the ext4.Read function:

could not interpret Group Descriptor Table data: error creating group descriptor from bytes: checksum mismatch, passed 53ce, actual 8310

as when the checksum computation reaches block group number 65,536, it overflows to 0.

How to reproduce

First, gather a beefy server with a storage exceeding 8 TiB in total:

fdisk -l /dev/md127
Disk /dev/md127: 20.96 TiB, 23044096524288 bytes, 45008001024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1572864 bytes

And make sure the block device is initialized with ext4:

lsblk -o NAME,SIZE,FSTYPE /dev/md127
NAME  SIZE FSTYPE
md127  21T ext4

Compile and run this code:

package main

import (
	"fmt"

	"github.com/diskfs/go-diskfs/backend/file"
	"github.com/diskfs/go-diskfs/filesystem/ext4"
)

func main() {
	backend, err := file.OpenFromPath("/dev/md127", true)
	if err != nil {
		panic(fmt.Errorf("cannot open block device: %w", err))
	}
	defer backend.Close()

	if _, err := ext4.Read(backend, 23044096524288, 0, 512); err != nil {
		panic(err)
	}
}

You'll get the error described above:

could not interpret Group Descriptor Table data: error creating group descriptor from bytes: checksum mismatch, passed 53ce, actual 8310

Fix

This PR suggests:

  • Extending the block group descriptor number data-type from uint16 to uint32.
  • Add regression tests covering group descriptor checksums across the uint16 overflow boundary and up to the maximum uint32 value.

deitch
deitch previously approved these changes Nov 22, 2026

@deitch deitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid catch, thank you for fixing. I dug in to see if I can figure out how that ended up as a uint16 (there must have been some reason), but I could not find it.

@deitch

deitch commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

linting error.

Fix group descriptor checksum verification for EXT4 filesystems with
more than 65536 block groups.

Previously, group numbers were truncated to uint16, causing checksum
mismatches starting at group 65536.

Use uint32 consistently and add regression tests covering the uint16
overflow boundary and the full uint32 range.
@Hrubon
Hrubon force-pushed the ext4-fix-large-block-group-numbers branch from 57a5094 to b702027 Compare November 23, 2026 10:50
@Hrubon

Hrubon commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Solid catch, thank you for fixing.

Thanks, happy to help!

I dug in to see if I can figure out how that ended up as a uint16 (there must have been some reason), but I could not find it.

Yeah, I know this feeling... 🙂

linting error.

Sorry for inconvenience, should be fixed now. I also updated the groupDescriptorChecksum function comment.

BTW, the linter install-script URL in the Makefile points to an obsoleted golangci-lint master branch, which has a checksum verification mismatch issue in the install script. main branch should be the up-to-date one. Seems that checksum computation bug is the spirit of this MR. 😄

@deitch

deitch commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

BTW, the linter install-script URL in the Makefile points to an obsoleted golangci-lint master branch, which has a checksum verification mismatch issue in the install script. main branch should be the up-to-date one. Seems that checksum computation bug is the spirit of this MR

Ah oops. That should be updated.

@deitch
deitch merged commit 4b085c0 into diskfs:master Nov 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants