`sigaltstack` returns EPERM after a handler leaves the alternate stack by `siglongjmp`, where Linux returns 0
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c, linux
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Read src/syscall/signal.c, focusing on on_altstack, signal delivery, and sys_sigaltstack; compare how the issue says Linux determines SS_ONSTACK from the guest stack pointer. The issue’s probe provides a reproduction: check the reported flag after siglongjmp, then try installing a new alternate stack. Done means the flag is clear and the install succeeds, matching Linux.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
After a signal handler that runs on the alternate stack leaves through siglongjmp, sigaltstack(NULL, &old) still reports SS_ONSTACK, and every later sigaltstack(&new, NULL) from that thread fails with EPERM. On Linux the thread is no longer on the alternate stack once the jump returns, so SS_ONSTACK is clear and the new stack is installed.
Evidence
On upstream main a20dfab, the probe below compared with elfuse-probe-diff against Linux 6.18.60:
| elfuse | Linux | |
|---|---|---|
SS_ONSTACK after siglongjmp |
1 | 0 |
sigaltstack(&new, NULL) |
-1, EPERM | 0 |
Cause
Checked by reading. src/syscall/signal.c keeps "on the alternate stack" as a stored flag, thread_entry_t.on_altstack. Signal delivery sets it when it builds a frame on the alternate stack, and only rt_sigreturn (from the restored SP) and exec clear it. siglongjmp does not pass through rt_sigreturn, so the flag stays set, and sys_sigaltstack reports SS_ONSTACK and refuses a new stack because of it. Linux keeps no such flag: it derives SS_ONSTACK from the current stack pointer (sas_ss_flags() and on_sig_stack()).
Reproduce
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
static sigjmp_buf env;
static void handler(int sig)
{
(void) sig;
siglongjmp(env, 1); /* leave the alternate stack without rt_sigreturn */
}
int main(void)
{
stack_t ss = {.ss_sp = malloc(SIGSTKSZ), .ss_size = SIGSTKSZ};
if (sigaltstack(&ss, NULL) != 0)
return 1;
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
sa.sa_flags = SA_ONSTACK;
sigaction(SIGUSR1, &sa, NULL);
if (sigsetjmp(env, 1) == 0)
raise(SIGUSR1);
stack_t cur;
sigaltstack(NULL, &cur);
printf("after siglongjmp: SS_ONSTACK=%d\n", !!(cur.ss_flags & SS_ONSTACK));
stack_t ss2 = {.ss_sp = malloc(SIGSTKSZ), .ss_size = SIGSTKSZ};
int rc = sigaltstack(&ss2, NULL);
printf("sigaltstack(new) = %d (%s)\n", rc, rc ? strerror(errno) : "ok");
return 0;
}
Possible fix
Compute "on the alternate stack" from the guest's SP when it is needed (in sys_sigaltstack, and when delivery decides whether to switch stacks), as Linux does, and drop the stored on_altstack flag. Or, smaller: clear the flag whenever a syscall arrives with an SP outside the alternate stack.
Origin
Follow-up from #525.
- Ngôn ngữ chính
- C
- Star
- 287
- Fork
- 33
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sysprog21/elfuse
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của sysprog21/elfuse
Issue tương tự
-
issue: bug report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
BasedHardware/omi#26486 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
The LLVM object can build before collection_config.h is generatedCó thể đã có người làm @Vonng đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
aws/pgcollection#51 ·
-
area/docdb kind/failing-test priority/medium status/awaiting-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
yugabyte/yugabyte-db#39462 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
libreswan/libreswan#3185 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày