Skip to content

lib/sb: validate s_log_block_size in nilfs_sb_is_valid()#27

Open
TristanInSec wants to merge 1 commit into
nilfs-dev:masterfrom
TristanInSec:fix/validate-log-block-size
Open

lib/sb: validate s_log_block_size in nilfs_sb_is_valid()#27
TristanInSec wants to merge 1 commit into
nilfs-dev:masterfrom
TristanInSec:fix/validate-log-block-size

Conversation

@TristanInSec

Copy link
Copy Markdown

Reject superblocks with s_log_block_size > 6 (block sizes larger than NILFS_MAX_BLOCK_SIZE). Without this check, a crafted NILFS2 image causes undefined behavior via oversized shifts or OOM conditions in nilfs-tune, dumpseg, and other read-path tools.

The valid range is 0-6 (1024 to 65536 byte blocks), matching the constants in nilfs2_ondisk.h already enforced in mkfs but not in the superblock validator.

One-line fix in nilfs_sb_is_valid().

Fixes: #26

Reject superblocks with s_log_block_size > 6 (corresponding to block
sizes larger than NILFS_MAX_BLOCK_SIZE = 65536). Without this check,
a crafted NILFS2 image can cause undefined behavior via oversized
shifts or OOM conditions via excessive allocations in nilfs-tune,
dumpseg, and other tools that read from devices.

The valid range is 0-6 (1024 to 65536 byte blocks), matching the
NILFS_MIN_BLOCK_SIZE and NILFS_MAX_BLOCK_SIZE constants already
defined in nilfs2_ondisk.h but previously only enforced in mkfs.

Fixes: nilfs-dev#26
@konis

konis commented Jun 11, 2026

Copy link
Copy Markdown
Member

nilfs_sb_is_valid() is not intended to check all parameters in the superblock, but s_log_block_size is a basic parameter and your point is correct. In fact, nilfs_sb_offset_is_too_small(), which can be called immediately after, also depends on it.

Therefore, the patch looks reasonable and I would like to apply it. Could you please add your Signed-off-by line? (We do not accept Git pull requests directly, but I would like to apply it as a patch.)

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.

Security: Missing s_log_block_size validation causes UB shift and OOM DoS

2 participants