fs/ext: support flex-bg writing and update new blocks allocation selection #584
Dismiss Review
Are you sure you want to dismiss this review?
Labels
Clear labels
Influence/Text/TYPO
AI
Eolite
FS
GSoC
Good First PR
HLL
HardwareTested
IRCC
Influence/Settings
Lang/C
Lang/FASM
Pay for the code
Subsystem/API
Subsystem/Audio
Subsystem/Graphics
Subsystem/IPC and events
Subsystem/Memory
Subsystem/Network
Subsystem/Services(daemon)
Subsystem/Taskmanager
Subsystem/VFS
Subsystem/Window
This issue or PR in the Google Source of Code program
The issue is suitable to beginners
Paid task
infinity service, audio drivers, midi, speacker, audio programs
vesa, vga, framebuffer, cursors, blitter, and video drivers
pipes, signals, events, shared memory
virt and phys memory allocators, malloc and other
userspace and kernel(for example: serial) services
process, threads, run apps, scheduler
drivers from filesystem, fs api, blkdev, programs that work with the file system
windows, skins, buttons, mouse and keyboard code for windows (not the base code)
Category
Applications
Category
Drivers
Category
General
Category
Kernel
Category
Libraries
Kind
Breaking
Breaking change that won't be backward compatible
Kind
Bug
Something is not working
Kind
Build
Kind
Documentation
Documentation changes
Kind
Enhancement
Improve existing functionality
Kind
Feature
New functionality
Kind
Security
This is security issue
Kind
Testing
Issue or pull request related to testing
PR
Ready to merge
Pull request is ready for merge
PR
Conflicts
PR conflicts with main
PR
Dependent
This PR is dependent on another PR
PR
Request changes
Changes requested in pull request
PR
Review required
Priority
Critical
1
The priority is critical
Priority
High
2
The priority is high
Priority
Medium
3
The priority is medium
Priority
Low
4
The priority is low
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: KolibriOS/kolibrios#584
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Update
extfsExtentAllocto take edi as a goal block to start allocation at the previous block's group, falling back to the file's inode block group if edi is zero.🔴 OOB block-group descriptor access from an unvalidated goal block
The struct offset (logGroupsPerFlex at 0x174, checksumSeed preserved at 0x270), the symbolic
INCOMPATIBLE_SUPPORT(= old 22C2h), and the flex_bg inode-alloc change all look correct. But the new goal path inextfsExtentAllocis exploitable.edi = goalderives a group index with no upper bound:.next(1008-1019) bounds the group against[descriptorTable, descriptorTableEnd), but the first iteration bypasses it and dereferences the descriptor directly at 883. If that OOB read is nonzero, the completion path then does an OOB write:Source of the bad goal:
extfsExtendFile(1538) takes the goal fromextfsGetExtent, i.e. a physical block number straight out of the file's extent tree, with no check against the filesystem size. A crafted extent (block number e.g. 0xFFFFFFF0) yields a group index far pastdescriptorTableEnd.Trigger: mount a crafted ext image, extend a file whose extent points outside the volume => OOB descriptor read, then a possible arbitrary block read (via the OOB
blockBitmap_lo) and an OOB descriptor write. Same class as #570 - a new unvalidated input indexing an array.Fix: after the
div [blocksPerGroup], validate the group against the group count (or the goal against total blocks) and fall back to the inode-based group, or error, when out of range.512eaa4798to4e928da42c4e928da42ctof9a353349eHi @Burer.
Thanks, please check the latest commit.
🔴 Cross-PR hazard with #570 (the hunks don't overlap, so git will merge both silently). This PR makes
edian input ofextfsExtentAllocand stops preserving it;ext_CreateSymlink.slow_symlinkin #570 calls it withedi= filename pointer and relies on it surviving. If the pointer divides into a group index past the descriptor table, the new OOB check fails long-symlink creation withERROR_FS_FAIL; but user space starts at 0, so the pointer is usually small, the derived group index is often plausible, the OOB check passes - the extent lands in an arbitrary group and the clobberededithen reacheslinkInodeas the name pointer, producing a garbage directory entry. Whichever PR merges second needs, in #570:push edi/xor edi, edi/call extfsExtentAlloc/pop edi. Both halves matter: zero goal (the inode's group is right for a symlink) and explicit preservation -xoralone doesn't survive the call.🟡 The goal lookup in
extfsExtendFilepasses the wrong register.extfsGetExtenttakes the starting file block inecx(per its header), but the new code loadsecxfrom[esp+8]- which at that point is the inode number (ExtendFile's inputecx) - and puts the last-block index intoeax, which GetExtent ignores. The lookup fails past-EOF almost every time, silently falling back toedi = 0, so the goal-directed allocation this PR introduces mostly never engages; when the inode number happens to be smaller than the file's block count, it returns an unrelated block as the goal. Fix:lea ecx, [edx-1]and drop theeaxload -edxsurvives GetExtent (both exit paths restore it).🔵 Contract notes in
extfsExtentAlloc's header: add thatediis clobbered on return (callers previously relied on it being preserved), and that on CF=1ecxis no longer guaranteed 0 (the old.failzeroed it; the new path returns the caller's blocks-max - none of the three current call sites reads it, but the guarantee is gone).🔵
logGroupsPerFlexis read from disk unvalidated;shlmasks the count to 5 bits, so a corrupted value > 31 yields a garbageflexGroupSize. Impact is limited to the inode-allocation heuristic - still would be nice to add a two-line cap hardens against broken images.f9a353349eto1329a809ef