Skip to content

[BUG REPORT] Integer overflow in page_align_up #1077

@Marsman1996

Description

@Marsman1996

描述错误/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.

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

  1. Compile a program which calls system call munmap with large len
#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;
}
  1. 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

Labels

A-mmArea: 内存管理子系统bug-report这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label)needs-triage这个问题可能需要分类处理。如果已经完成分类,请移除它。

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions