Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer overflow caused by multiply in munmap() #41

Open
Marsman1996 opened this issue Oct 17, 2024 · 1 comment
Open

Integer overflow caused by multiply in munmap() #41

Marsman1996 opened this issue Oct 17, 2024 · 1 comment

Comments

@Marsman1996
Copy link

There is a multiply with overflow problem in kernel/src/syscall/munmap.rs, munmap(), Maestro.
The div_ceil() rounds the result towards positive infinity.
As a result, when user calls munmap with large length (i.e., 0xfffffff0), the following multiplication operation will cause an integer overflow problem.

let pages = length.div_ceil(PAGE_SIZE);
let length = pages * PAGE_SIZE;

For example:

use std::usize;

fn main() {
    let length: usize = usize::MAX;
    let page_size = 0x1000;
    let pages = length.div_ceil(page_size);
    let length = pages * page_size;
    println!("length = 0x{length:x}");
}
thread 'main' panicked at src/main.rs:7:18:
attempt to multiply with overflow
@llenotre
Copy link
Member

Thank you for the report! I am putting this on my todolist

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

No branches or pull requests

2 participants