`sigaltstack` returns EPERM after a handler leaves the alternate stack by `siglongjmp`, where Linux returns 0
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c, linux
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C
- 星标
- 287
- 派生
- 33
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sysprog21/elfuse 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 80/100
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
相似的 Issue
-
issue: bug report
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 2 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
BasedHardware/omi#26486 ·
维护者通常 1 天内回复
-
The LLVM object can build before collection_config.h is generated可能已有人在做 @Vonng 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
aws/pgcollection#51 ·
-
area/docdb kind/failing-test priority/medium status/awaiting-triage
难度 2/5 1-3 小时 新手友好度 82/100
yugabyte/yugabyte-db#39462 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
libreswan/libreswan#3185 · 1 条评论 ·
维护者通常 1 天内回复