Skip to content

fix(ext4): only validate inode checksums when metadata_csum is enabled - #464

Merged
deitch merged 2 commits into
diskfs:masterfrom
coalaura:fix/ext4-inode-checksum-feature
Nov 22, 2026
Merged

deitch merged 2 commits into
diskfs:masterfrom
coalaura:fix/ext4-inode-checksum-feature

Conversation

@coalaura

Copy link
Copy Markdown
Contributor

Problem

The ext4 reader validates inode checksums even when metadata_csum is disabled. Linux does not maintain these checksums in that case, so valid filesystems can fail to read with a checksum mismatch after Linux modifies an inode.

Change

Only read and validate inode checksums when the filesystem enables metadata_csum.

Tests

Adds regression cases for disabled checksums with zero or stale values, valid enabled checksums, and rejection of invalid enabled checksums. The disabled-checksum cases fail before the fix and pass afterward.

Also verified read-only access to an affected Linux-written Alpine image.

@deitch

deitch commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

No issues with gating it behind an if sb.features.metadataChecksums test; that is correct.

Why did you bother to write the checksum calculation from:

	copy(checksumBytes[0:2], b[0x7c:0x7e])
	copy(checksumBytes[2:4], b[0x82:0x84])
...
	checksum := binary.LittleEndian.Uint32(checksumBytes)

To:

		checksum := uint32(binary.LittleEndian.Uint16(b[0x7c:0x7e])) | uint32(binary.LittleEndian.Uint16(b[0x82:0x84]))<<16

Is that not effectively the same thing?

@coalaura

Copy link
Copy Markdown
Contributor Author

avoids an extra allocation, i can change it to the original version if needed

@coalaura

Copy link
Copy Markdown
Contributor Author

*an extra allocation and 2 copies

@deitch

deitch commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

extra allocation and 2 copies

Kudos for efficiency, although I don't know how much it matters, but I will not complain if something runs slightly faster at no extra cost. Leave it as you put it.

deitch
deitch previously approved these changes Nov 22, 2026
@deitch

deitch commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Linting error.

@coalaura

Copy link
Copy Markdown
Contributor Author

@deitch fixed

@deitch
deitch merged commit f9c652a into diskfs:master Nov 22, 2026
20 checks passed
@coalaura
coalaura deleted the fix/ext4-inode-checksum-feature branch November 22, 2026 18:15
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