Skip to content

Fix sigaltstack error path leaking sighand lock#2727

Open
SongXiaoXi wants to merge 1 commit intoish-app:masterfrom
SongXiaoXi:master
Open

Fix sigaltstack error path leaking sighand lock#2727
SongXiaoXi wants to merge 1 commit intoish-app:masterfrom
SongXiaoXi:master

Conversation

@SongXiaoXi
Copy link
Copy Markdown

sys_sigaltstack() returns _ENOMEM while still holding sighand->lock when the new alt stack is smaller than MINSIGSTKSZ_, causing a permanent lock leak/deadlock on later signal operations.

A simple reproducer:

#define _GNU_SOURCE
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
int main(void) {
    setvbuf(stdout, NULL, _IONBF, 0);
    stack_t ss = {0};
    ss.ss_sp = malloc(1);
    ss.ss_size = 1; // intentionally smaller than MINSIGSTKSZ
    ss.ss_flags = 0;
    printf("[1] calling sigaltstack(tiny stack)...\n");
    errno = 0;
    long r = syscall(SYS_sigaltstack, &ss, NULL);
    printf("[1] ret=%ld errno=%d (%s)\n", r, errno, strerror(errno));
    return 0;
}

When this reproducer is compiled and run inside the iSH app, the whole app becomes stuck after the first failing sigaltstack() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant