Virtual Allocator: vtop masking causes bit virtual bit overflows into physical mappings #32

Closed
opened 2026-03-03 17:50:14 +00:00 by admin · 0 comments
Owner

In the following code snippet an extra 2 bits (22–23) leak through due to $FFFFFF vs the correct $3FFFFF contribute (idx mod 4) * 4MB of error to the result.

function vtop(address : uint32) : uint32;
var
    idx : uint32;
    paddress : uint32;
    loadd    : uint32;

begin
    push_trace('vmemorymanager.vtop');
    idx:= address SHR 22;
    paddress:= uint32(KERNEL_PAGE_DIRECTORY^[idx].address) SHL 12;
    loadd:= address AND $FFFFFF;
    vtop:= paddress + loadd;
    pop_trace;
end;

Kernel pages are mapped starting at KERNEL_PAGE_NUMBER = $C0000000 SHR 22 = 768. And 768 mod 4 = 0. So for any address in that first kernel page, bits 22–23 are both zero, and as such, the wrong mask produces the identical result to the correct one. Which is why this has gone unnoticed for so long.

Proposed fix is a simple modification, where the $FFFFFF bitmask becomes $3FFFFF.

function vtop(address : uint32) : uint32;
var
    idx : uint32;
    paddress : uint32;
    loadd    : uint32;

begin
    push_trace('vmemorymanager.vtop');
    idx:= address SHR 22;
    paddress:= uint32(KERNEL_PAGE_DIRECTORY^[idx].address) SHL 12;
    loadd:= address AND $3FFFFF;
    vtop:= paddress + loadd;
    pop_trace;
end;
In the following code snippet an extra 2 bits (22–23) leak through due to $FFFFFF vs the correct $3FFFFF contribute (idx mod 4) * 4MB of error to the result. ``` function vtop(address : uint32) : uint32; var idx : uint32; paddress : uint32; loadd : uint32; begin push_trace('vmemorymanager.vtop'); idx:= address SHR 22; paddress:= uint32(KERNEL_PAGE_DIRECTORY^[idx].address) SHL 12; loadd:= address AND $FFFFFF; vtop:= paddress + loadd; pop_trace; end; ``` Kernel pages are mapped starting at KERNEL_PAGE_NUMBER = $C0000000 SHR 22 = 768. And 768 mod 4 = 0. So for any address in that first kernel page, bits 22–23 are both zero, and as such, the wrong mask produces the identical result to the correct one. Which is why this has gone unnoticed for so long. Proposed fix is a simple modification, where the $FFFFFF bitmask becomes $3FFFFF. ``` function vtop(address : uint32) : uint32; var idx : uint32; paddress : uint32; loadd : uint32; begin push_trace('vmemorymanager.vtop'); idx:= address SHR 22; paddress:= uint32(KERNEL_PAGE_DIRECTORY^[idx].address) SHL 12; loadd:= address AND $3FFFFF; vtop:= paddress + loadd; pop_trace; end; ```
admin added this to the 2.0.0 milestone 2026-03-03 17:50:14 +00:00
admin added the Bug
Component/Allocator
Virtual
labels 2026-03-03 17:50:14 +00:00
t3hn3rd was assigned by admin 2026-03-03 17:50:14 +00:00
admin added this to the Asuro Release Planning project 2026-03-03 17:50:14 +00:00
admin moved this to Planned in Asuro Release Planning on 2026-03-03 17:50:18 +00:00
t3hn3rd referenced this issue from a commit 2026-03-03 19:10:30 +00:00
admin added reference feature/vtop-fix 2026-03-03 19:15:22 +00:00
admin moved this to In Progress in Asuro Release Planning on 2026-03-03 19:15:34 +00:00
t3hn3rd moved this to Done in Asuro Release Planning on 2026-03-03 20:04:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Spexeah/Asuro#32