Skip to content

Commit

Permalink
Fix invalid mapping to zero page caused by off-by-one bug
Browse files Browse the repository at this point in the history
The `zero_end` bound is exclusive, but we treat the `end_page` as inclusive. So when `zero_end` is page-aligned, we allocate one additional bss page. If this page was already mapped to some other segment, we remap it to a page with random content.

This is the same bug as #362.
  • Loading branch information
phil-opp committed Feb 16, 2024
1 parent 3531dfb commit 4b80d28
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn map_segment(
zero_start.as_u64(),
Size4KiB::SIZE,
)));
let end_page = Page::containing_address(zero_end);
let end_page = Page::containing_address(zero_end - 1usize);
for page in Page::range_inclusive(start_page, end_page) {
let frame = frame_allocator
.allocate_frame(MemoryRegionType::Kernel)
Expand Down

0 comments on commit 4b80d28

Please sign in to comment.