loader: skip zeroing when we hit a page boundary

Previously, we would unconditionally zero out the remainder of a page
when finished copying. We wrapped to PAGE_SIZE in order to avoid
corrupting another process' memory.

However, an issue was discovered under the following circumstances:

    1. There are fewer than 4096 bytes of `.bss`
    2. The `.bss` ends on a page boundary

Under these conditions, the loader would load the section before the
`.bss` into the page, then clear out the `.bss`, and finally clear the
entire page, overwriting the previous section.

Skip the remainder-of-page clearout when the `.bss` ends on a page
boundary, rather than clearing the entire page.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-10-20 11:24:22 +08:00
parent af501c4303
commit b35d65c3e1

View file

@ -786,14 +786,19 @@ fn copy_processes(cfg: &mut BootConfig) {
if VDBG {println!("Looping to the next section");}
}
println!("Done with sections, zeroing out remaining data");
// Zero-out the trailing bytes
unsafe {
bzero(
top.add(previous_addr as usize & (PAGE_SIZE - 1)),
top.add(PAGE_SIZE as usize),
)
};
println!("Done with sections");
if previous_addr as usize & (PAGE_SIZE - 1) != 0 {
println!("Zeroing out remaining data");
// Zero-out the trailing bytes
unsafe {
bzero(
top.add(previous_addr as usize & (PAGE_SIZE - 1)),
top.add(PAGE_SIZE as usize),
)
};
} else {
println!("Skipping zero step -- we ended on a page boundary");
}
} else if tag.name == u32::from_le_bytes(*b"XKrn") {
let prog = unsafe { &*(tag.data.as_ptr() as *const ProgramDescription) };