Skip to content

fix(vfs): saturate EROFS inode/dir/data offset arithmetic#137

Merged
kernalix7 merged 1 commit into
mainfrom
fix/erofs-offset-overflow
Jun 23, 2026
Merged

fix(vfs): saturate EROFS inode/dir/data offset arithmetic#137
kernalix7 merged 1 commit into
mainfrom
fix/erofs-offset-overflow

Conversation

@kernalix7

Copy link
Copy Markdown
Owner

Sibling sweep to the blkszbits shift fix (#136). EROFS computes image byte offsets from parsed nid / inode.size / raw_blkaddr / caller offset without bounding the arithmetic; crafted values overflow usize/u64 (overflow-checks ON = ring-0 panic) before the following > self.data.len() bounds check can reject them:

  • nid_to_offset: meta_blkaddr*block_size + nid*32 (nid is a parsed u64 → nid*32 overflows).
  • read_inode: off + 2 / off + format.size().
  • readdir: dir_start + dir_size (dir_size = parsed inode.size).
  • read_flat_plain: raw_blkaddr*block_size + offset, + to_copy.
  • read_flat_inline: inode_off + format.size(), raw_blkaddr*block_size + blk*block_size + blk_off, inline_start + tail_off, + to_copy.

Use saturating_mul/saturating_add so out-of-range values saturate to a huge offset the existing bounds checks reject with IoError. Valid images unaffected. (readdir name_start slice + the block-relative subtractions verified already-guarded; not changed.) Found via kimi agentic lane + verified/sibling-swept by hand.

Sibling sweep to the blkszbits shift fix. EROFS computes image byte
offsets from parsed nid / inode.size / raw_blkaddr / caller offset
without bounding the arithmetic; crafted values overflow usize/u64
(overflow-checks ON = ring-0 panic) before the following bounds check
can reject them:
- nid_to_offset: meta_blkaddr*block_size + nid*32 (nid is a parsed u64).
- read_inode: off + 2 / off + format.size() bounds checks.
- readdir: dir_start + dir_size (dir_size = parsed inode.size).
- read_flat_plain: raw_blkaddr*block_size + offset, + to_copy.
- read_flat_inline: inode_off + format.size(), raw_blkaddr*block_size +
  blk*block_size + blk_off, inline_start + tail_off, + to_copy.
Use saturating_mul/saturating_add so an out-of-range value saturates to
a huge offset that the existing '> self.data.len()' checks reject with
IoError instead of panicking. Valid images are unaffected.
@kernalix7 kernalix7 merged commit 97bee0f into main Jun 23, 2026
2 checks passed
@kernalix7 kernalix7 deleted the fix/erofs-offset-overflow branch June 23, 2026 03:30
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.

1 participant