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

Reachable unwrap panic in do_exit() #1194

Closed
Marsman1996 opened this issue Aug 18, 2024 · 0 comments · Fixed by #1433
Closed

Reachable unwrap panic in do_exit() #1194

Marsman1996 opened this issue Aug 18, 2024 · 0 comments · Fixed by #1433
Labels
C-bug Report bugs or unusual behavior in the project

Comments

@Marsman1996
Copy link
Contributor

Describe the bug

There is a reachable unwrap panic in do_exit() at kernel/aster-nix/src/process/posix_thread/exit.rs:32 when make a munmap syscall.

if *clear_ctid != 0 {
futex_wake(*clear_ctid, 1)?;
// FIXME: the correct write length?
CurrentUserSpace::get()
.write_val(*clear_ctid, &0u32)
.unwrap();
*clear_ctid = 0;
}

To Reproduce

  1. Compile a program which calls munmap:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>

int main() {
  void *addr = mmap(NULL, 4096, 0x3, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  munmap(addr, 0xfffff000);

  return EXIT_SUCCESS;
}
  1. Run the compiled program in Asterinas.

Expected behavior

Asterinas reports panic and is terminated.

Environment

  • Official docker asterinas/asterinas:0.6.2
  • 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  • Asterinas version: main ce2af1e

Logs

~ # /root/munmap.c
[    10.404] ERROR: page fault handler failed: addr: 0x447e1b, err: Error { errno: EACCES, msg: Some("page fault addr is not in current vmar") }
[    10.405] ERROR: page fault handler failed: addr: 0x10001690, err: Error { errno: EACCES, msg: Some("page fault addr is not in current vmar") }
panicked at /root/asterinas/kernel/aster-nix/src/process/posix_thread/exit.rs:32:14:
called `Result::unwrap()` on an `Err` value: Error { errno: EFAULT, msg: None }
Printing stack trace:
   1: fn 0xffffffff8876b810 - pc 0xffffffff8876b828 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf160;

   2: fn 0xffffffff8876b5f0 - pc 0xffffffff8876b768 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf170;

   3: fn 0xffffffff88049000 - pc 0xffffffff8804900a / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf2f0;

   4: fn 0xffffffff8897edf0 - pc 0xffffffff8897ee72 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf300;

   5: fn 0xffffffff8895c0d0 - pc 0xffffffff8895c1fb / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf390;

   6: fn 0xffffffff88117a90 - pc 0xffffffff88117ec6 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf490;

   7: fn 0xffffffff882af3a0 - pc 0xffffffff882af840 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bf6e0;

   8: fn 0xffffffff883196c0 - pc 0xffffffff8831a266 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010bfcf0;

   9: fn 0xffffffff88297270 - pc 0xffffffff88297e87 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010c0570;

  10: fn 0xffffffff885a9820 - pc 0xffffffff885a982e / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010c0f90;

  11: fn 0xffffffff88781b60 - pc 0xffffffff88781b76 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010c0fb0;

  12: fn 0xffffffff887b9710 - pc 0xffffffff887b9779 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010c0fd0;

  13: fn                0x0 - pc                0x0 / registers:

     rax               0x12; rdx 0xffffffff889fd928; rcx                0x1; rbx                0x0;
     rsi                0x0; rdi                0x0; rbp                0x0; rsp 0xffff8000010c1000;

[OSDK] The kernel seems panicked. Parsing stack trace for source lines:
(  1) /root/asterinas/ostd/src/panicking.rs:107
(  2) /root/asterinas/ostd/src/panicking.rs:59
(  3) 2aghao2n2kcoquuybdyjuveav:?
(  4) ??:?
(  5) ??:?
(  6) /root/.rustup/toolchains/nightly-2024-06-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1102
(  7) /root/asterinas/kernel/aster-nix/src/process/exit.rs:23
(  8) /root/asterinas/kernel/aster-nix/src/process/signal/mod.rs:108
(  9) /root/asterinas/kernel/aster-nix/src/thread/task.rs:76
( 10) /root/.rustup/toolchains/nightly-2024-06-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:79
( 11) /root/.rustup/toolchains/nightly-2024-06-20-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:2077
( 12) /root/asterinas/ostd/src/task/task/mod.rs:310
make: *** [Makefile:153: run] Error 1
@Marsman1996 Marsman1996 added the C-bug Report bugs or unusual behavior in the project label Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Report bugs or unusual behavior in the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant