Commit Graph

180 Commits

Author SHA1 Message Date
Arthur Paulino 888eecb350 Patch a futex vulnerability
If the futex wait operation was interrupted by a signal or timed out, the
`FutexItem` must be dequeued and dropped. Otherwise, malicious user programs
could repeatedly issue futex wait operations to exhaust kernel memory.

Due to asynchronicity, this removal can't be done by queue position nor by
futex key match up:
* The position might have changed during the pause as some earlier futex might
  have been dequeued
* If two futexes with the same key are enqueued and then one of them times out
  or is interrupted, a removal by key would likely dequeue the wrong futex

Therefore, we need to perform a removal by unique global futex ID.
2025-08-26 18:04:34 +08:00
Ruihan Li a6d37f0e79 Mark all kernel modules as private 2025-08-26 18:02:56 +08:00
Chen Chengjun b1bbd6c3fe Optimize the initialization logic during Asterinas init phase 2025-08-26 14:36:59 +08:00
Zejun Zhao 47b05143cf Correct vDSO data segment's permission 2025-08-23 12:38:22 +08:00
Zejun Zhao e68631d1b6 Implement arch-aware vDSO 2025-08-23 12:38:22 +08:00
Ruihan Li f457acdb8b Rewrite documentations in the vDSO module 2025-08-22 16:20:01 +08:00
Ruihan Li 6b6c64c591 Rename `atomic_update` to `atomic_fetch_update` 2025-08-20 13:17:57 +08:00
Arthur Paulino a73f210c7a Make `wake_robust_futex` atomic
Replace `VmWriter::atomic_update` with `VmWriter::atomic_compare_exchange`,
which takes the old value for comparison and new value instead of a
closure to compute it. This version has one less unsafe call.

Then use `atomic_compare_exchange` to reimplement the looping logic
of `wake_robust_futex` and make it atomic.
2025-08-19 19:22:12 +08:00
Chen Chengjun fc5a12356a Fix LOONGARCH clippy warnings 2025-08-19 19:20:54 +08:00
Chen Chengjun 9507475102 Fix RISCV clippy warnings 2025-08-19 19:20:54 +08:00
Arthur Paulino c31c6110f6 chore: use `jhash` to compute the `FutexKey` hash
This patch pays the price of making the instantiation of `FutexKey`
more expensive to achieve two goals:
* Minor: make `match_up` slightly faster
* Major: make futex bucket allocation balancing more robust
2025-08-16 09:16:50 +08:00
Arthur Paulino 91351e338f fix: avoid distribution skew in `FutexBucketVec::get_bucket`
Doing `addr / self.size()` before masking with `(self.size() - 1)`
removes the low bits entirely, which causes adjacent addresses
(modulo `self.size()`) to map to the same bucket, entailing bad
load balance. This patch solves that.

Further, make `FutexBucketVec::new` and `FutexBucketVec::get_bucket`
private, as they only make sense within the scope of `futex.rs`,
where the invariant of `size` being a power of two is guaranteed to
hold via `get_bucket_count` (which is also private).
2025-08-16 09:16:50 +08:00
Arthur Paulino c345876bc0 chore: avoid several `FutexKey` copies
Use shared references instead of copied objects on some functions
that don't necessarily require ownership of `FutexKey`.

Remove the `Copy` derivation of `FutexKey` to discourage suboptimal
copies.
2025-08-16 09:16:50 +08:00
Ruihan Li 5b91064316 Add a method that disables page fault handlers 2025-08-14 11:59:05 +08:00
Ruihan Li e4fafb13b1 Add atomic operations for VM readers/writers 2025-08-14 11:59:05 +08:00
Ruihan Li 923982c2e5 Remove `user_ctx` from `Task` 2025-08-12 19:19:34 +08:00
jiangjianfeng 9a56028afc Support parsing shebang with multiple arguments in intepreter line 2025-08-12 11:23:30 +08:00
Ruihan Li 2700d88bef Provide efficient `VmIo` with VM readers/writers 2025-08-10 16:40:11 +08:00
jiangjianfeng f6478d62cc Refactor the implementation about sigstack 2025-08-08 12:06:26 +08:00
Ruihan Li c19c7765d8 Fix race conditions in `pause_timeout` 2025-08-06 17:17:34 +08:00
Chen Chengjun c6a6e66aac Rename Dentry to Path in the other modules and rename some local variables 2025-08-06 14:06:39 +08:00
jiangjianfeng de97644b4c Move `ThreadFsInfo` from `PosixThread` to `ThreadLocal` 2025-08-06 13:38:42 +08:00
Zhang Junyang afe63e7123 Fix ELF loading when shebang/loader path is too long/far 2025-08-05 15:42:13 +08:00
Ruihan Li e52634cb78 Add some references for signal-related types 2025-07-28 10:50:38 +08:00
王英泰 345cc9d055 Save FPU context on signal stack for LoongArch 2025-07-25 17:37:24 +08:00
王英泰 5c590f0c6b Add the process support for LoongArch in kernel 2025-07-25 17:37:24 +08:00
jiangjianfeng 9219207b97 Add CLONE_PIDFD & pidfd_open support 2025-07-24 21:11:24 +08:00
jiangjianfeng dbc6e7c71a Add support for `/proc/sys/kernel/pid_max` 2025-07-24 21:11:24 +08:00
Ruihan Li c3572e9548 Support SCM_CREDENTIALS 2025-07-23 20:02:15 +08:00
Qingsong Chen e86f7584a3 Fix atomic mode issue when VMO commit needs IO 2025-07-23 11:23:03 +08:00
Cautreoxit 6ecccad3ee Add sys_ioprio_set and sys_ioprio_get 2025-07-22 17:22:52 +08:00
Chen Chengjun ef0382b164 Enhance waitid syscall support 2025-07-21 21:31:32 +08:00
Chen Chengjun 4d52241c6c Fix some definition errors of siginfo_t 2025-07-21 21:31:32 +08:00
Qingsong Chen f1299d4b8d Save FPU context on signal stack 2025-07-18 11:40:16 +08:00
Qingsong Chen 6cd53fbb8a Refactor FPU context using pre_schedule_handler 2025-07-18 11:40:16 +08:00
jiangjianfeng 010da31b3e Align execve argument limits with Linux 2025-07-14 15:43:34 +08:00
Wang Siyuan 37cc54f2aa Store `offset` in `MappedVmo` instead of `range` 2025-07-03 18:54:53 +08:00
Wang Siyuan a13297ae4c Add fields in `/proc/*/stat` and `/proc/*/status` 2025-07-02 20:13:47 +08:00
jiangjianfeng e4c5c36be9 Support SO_PEERCRED & SO_PEERGROUPS 2025-06-24 17:25:44 +08:00
Zhang Junyang 93015a6090 Make user program relocation code readable 2025-06-24 10:15:09 +08:00
Marsman1996 1c56fbc871 Fix unwrap panic of dropped VMAR in PID status 2025-06-22 17:58:33 +08:00
Wang Siyuan 11f9675f37 Support the system call `mremap` 2025-06-21 16:18:09 +08:00
Marsman1996 bb3f21b41e Fix integer overflow in futex wake 2025-06-20 15:58:19 +08:00
jiangjianfeng 95faea0fb0 Support WSTOPPED and WCONTINUED 2025-06-20 11:51:44 +08:00
Chen Chengjun 627dd0386b Enable FUTEX_WAKE_OP 2025-06-16 11:02:17 +08:00
Chen Chengjun 860bb6c07f Adjust and correct parts of the futex implementation code 2025-06-16 11:02:17 +08:00
Wang Siyuan b605bed576 Fix some typos 2025-06-12 22:35:54 +08:00
Zhang Junyang e78927b449 Manage frame tracking outside the page table 2025-06-12 22:34:46 +08:00
Ruihan Li 0661a0656b Never queue an ignored signal 2025-06-12 16:15:53 +08:00
Cautreoxit 3e32a38316 Add sys_close_range 2025-06-11 19:56:12 +08:00