|
1 | 1 | # Signal Handling in Hyperlight |
2 | 2 |
|
3 | | -Hyperlight registers custom signal handlers to intercept and manage specific signals, primarily `SIGSYS` and `SIGRTMIN`. Here's an overview of the registration process: |
4 | | -- **Preserving Old Handlers**: When registering a new signal handler, Hyperlight first retrieves and stores the existing handler using `OnceCell`. This allows Hyperlight to delegate signals to the original handler if necessary. |
| 3 | +Hyperlight registers custom signal handlers to intercept and manage specific signals, primarily `SIGRTMIN`. Here's an overview of the registration process: |
5 | 4 | - **Custom Handlers**: |
6 | | - - **`SIGSYS` Handler**: Captures disallowed syscalls enforced by seccomp. If the signal originates from a hyperlight thread, Hyperlight logs the syscall details. Otherwise, it delegates the signal to the previously registered handler. |
7 | | - - **`SIGRTMIN` Handler**: Utilized for inter-thread signaling, such as execution cancellation. Similar to SIGSYS, it distinguishes between application and non-hyperlight threads to determine how to handle the signal. |
8 | | -- **Thread Differentiation**: Hyperlight uses thread-local storage (IS_HYPERLIGHT_THREAD) to identify whether the current thread is a hyperlight thread. This distinction ensures that signals are handled appropriately based on the thread's role. |
9 | | - |
10 | | -## Potential Issues and Considerations |
11 | | - |
12 | | -### Handler Invalidation |
13 | | - |
14 | | -**Issue**: After Hyperlight registers its custom signal handler and preserves the `old_handler`, if the host or another component modifies the signal handler for the same signal, it can lead to: |
15 | | - - **Invalidation of `old_handler`**: The stored old_handler reference may no longer point to a valid handler, causing undefined behavior when Hyperlight attempts to delegate signals. |
16 | | - - **Loss of Custom Handling**: Hyperlight's custom handler might not be invoked as expected, disrupting its ability to enforce syscall restrictions or manage inter-thread signals. |
17 | | - |
| 5 | + - **`SIGRTMIN` Handler**: Utilized for inter-thread signaling, such as execution cancellation. |
| 6 | +- **Killing a sandbox**: |
| 7 | + - To stop a sandboxed process, a `SIGRTMIN` signal must be delivered to the thread running the sandboxed code. |
| 8 | + - The sandbox provides an interface to obtain an interrupt handle, which includes the thread ID and a method to dispatch the signal. |
| 9 | + - Hyperlight uses the `pthread_kill` function to send this signal directly to the targeted thread. |
0 commit comments