Prevent infinite userspace crash loops.

This commit is contained in:
4lDO2
2024-06-20 22:56:19 +02:00
parent 55fe58adf6
commit 7d5b2e6c21
5 changed files with 18 additions and 6 deletions
+2 -2
View File
@@ -203,8 +203,8 @@ pub struct Context {
pub struct SignalState {
/// Offset to jump to when a signal is received.
pub user_handler: NonZeroUsize,
/// Offset to jump to when a program fault occurs.
pub excp_handler: NonZeroUsize,
/// Offset to jump to when a program fault occurs. If None, the context is sigkilled.
pub excp_handler: Option<NonZeroUsize>,
/// Signal control pages, shared memory
pub thread_control: RaiiFrame,
+13
View File
@@ -48,4 +48,17 @@ pub fn signal_handler() {
.and_then(|_| ptrace::next_breakpoint().map(|f| f.contains(PTRACE_FLAG_IGNORE)));*/
}
pub fn excp_handler(signal: usize) {
let Ok(current) = context::current() else {
panic!("CPU exception but not inside of context! Trying to switch...");
};
let mut context = current.write();
let Some(eh) = context.sig.as_ref().and_then(|s| s.excp_handler) else {
context.being_sigkilled = true;
context::switch();
unreachable!();
};
// TODO
}
-1
View File
@@ -268,7 +268,6 @@ pub fn ksignal(signal: usize) {
if let Some(context_lock) = contexts.current() {
let mut context = context_lock.write();
info!("NAME {}", context.name);
//context.sig.pending |= 1 << (signal - 1);
}
}
crate::context::signal::excp_handler(signal);
+1 -1
View File
@@ -1153,7 +1153,7 @@ impl<const FULL: bool> KernelScheme for ProcScheme<FULL> {
threadctl_off: validate_off(data.thread_control_addr, mem::size_of::<Sigcontrol>())?,
procctl_off: validate_off(data.proc_control_addr, mem::size_of::<SigProcControl>())?,
user_handler: NonZeroUsize::new(data.user_handler).ok_or(Error::new(EINVAL))?,
excp_handler: NonZeroUsize::new(data.excp_handler).ok_or(Error::new(EINVAL))?,
excp_handler: NonZeroUsize::new(data.excp_handler),
thread_control: addrsp
.borrow_frame_enforce_rw_allocated(Page::containing_address(VirtualAddress::new(data.thread_control_addr)))?,
proc_control: addrsp
+2 -2
View File
@@ -176,8 +176,8 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
} else if sig == SIGKILL {
context.being_sigkilled = true;
} else if let Some((ctl, _, st)) = context.sigcontrol() {
let was_new = ctl.word[sig_group].fetch_or(sig_bit(sig), Ordering::Relaxed);
if (ctl.word[sig_group].load(Ordering::Relaxed) >> 32) & sig_bit(sig) != 0 {
let _was_new = ctl.word[sig_group].fetch_or(sig_bit(sig), Ordering::Relaxed);
if (ctl.word[sig_group].load(Ordering::Relaxed) >> 32) & sig_bit(sig) == 0 {
st.is_pending = true;
}
} else {