-
-
Notifications
You must be signed in to change notification settings - Fork 161
Open
Labels
A-mmArea: 内存管理子系统Area: 内存管理子系统bug-report这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label)这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label)needs-triage这个问题可能需要分类处理。如果已经完成分类,请移除它。这个问题可能需要分类处理。如果已经完成分类,请移除它。
Description
描述错误/Describe the bug
There is an integer overflow in page_align_up()
at kernel/src/libs/align.rs:135 when program calls memory related syscall (i.e., mmap
, munmap
, and mprotect
) with large len
.
DragonOS/kernel/src/libs/align.rs
Lines 133 to 136 in 72423f9
pub const fn page_align_up(addr: usize) -> usize { | |
let page_size = MMArch::PAGE_SIZE; | |
return (addr + page_size - 1) & (!(page_size - 1)); | |
} |
请填写您的电脑的信息/Environment
- OS Version:Debian GNU/Linux 11
- DragonOS Version:72423f9
- DADK Version:dadk 0.2.0
- Rust Version:rustc 1.84.0-nightly (fbab78289 2024-11-04)
重现步骤/To Reproduce
- Compile a program which calls system call
munmap
with largelen
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
int main() {
void *addr = mmap(NULL, 0x1000, 0x3, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
munmap(addr, 0xffffffffffffffff);
perror("mmap error");
return EXIT_SUCCESS;
}
- Run the compiled program
期望行为/Expected behavior
DragonOS should check the add behavior first and not overflow here.
屏幕截图/Log
I add log before and after the alignment:
root@DragonOS:/$ /bin/overflow
[ WARN ] (src/syscall/mod.rs:626) len before align: 0xffffffffffffffff
[ WARN ] (src/syscall/mod.rs:628) len after align: 0x0
mmap error: Invalid argument
Metadata
Metadata
Assignees
Labels
A-mmArea: 内存管理子系统Area: 内存管理子系统bug-report这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label)这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label)needs-triage这个问题可能需要分类处理。如果已经完成分类,请移除它。这个问题可能需要分类处理。如果已经完成分类,请移除它。