Skip to content

Commit

Permalink
signals/sigaltstack: Report current flag bits in sigaltstack()
Browse files Browse the repository at this point in the history
sigaltstack()'s reported previous state uses a somewhat odd
convention, but the concept of flag bits is new, and we can do the
flag bits sensibly.  Specifically, let's just report them directly.

This will allow saving and restoring the sigaltstack state using
sigaltstack() to work correctly.

Signed-off-by: Andy Lutomirski <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Amanieu d'Antras <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Peter Zijlstra (Intel) <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Sasha Levin <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Stas Sergeev <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/94b291ec9fd47741a9264851e316e158ded0b00d.1462296606.git.luto@kernel.org
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
amluto authored and Ingo Molnar committed May 4, 2016
1 parent 158b67b commit 0318bc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3099,7 +3099,8 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s

oss.ss_sp = (void __user *) current->sas_ss_sp;
oss.ss_size = current->sas_ss_size;
oss.ss_flags = sas_ss_flags(sp);
oss.ss_flags = sas_ss_flags(sp) |
(current->sas_ss_flags & SS_FLAG_BITS);

if (uss) {
void __user *ss_sp;
Expand Down
19 changes: 16 additions & 3 deletions tools/testing/selftests/sigaltstack/sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ int main(void)
perror("mmap()");
return EXIT_FAILURE;
}

err = sigaltstack(NULL, &stk);
if (err) {
perror("[FAIL]\tsigaltstack()");
exit(EXIT_FAILURE);
}
if (stk.ss_flags == SS_DISABLE) {
printf("[OK]\tInitial sigaltstack state was SS_DISABLE\n");
} else {
printf("[FAIL]\tInitial sigaltstack state was %i; should have been SS_DISABLE\n", stk.ss_flags);
return EXIT_FAILURE;
}

stk.ss_sp = sstack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
Expand Down Expand Up @@ -151,12 +164,12 @@ int main(void)
perror("[FAIL]\tsigaltstack()");
exit(EXIT_FAILURE);
}
if (stk.ss_flags != 0) {
printf("[FAIL]\tss_flags=%i, should be 0\n",
if (stk.ss_flags != SS_AUTODISARM) {
printf("[FAIL]\tss_flags=%i, should be SS_AUTODISARM\n",
stk.ss_flags);
exit(EXIT_FAILURE);
}
printf("[OK]\tsigaltstack is enabled after signal\n");
printf("[OK]\tsigaltstack is still SS_AUTODISARM after signal\n");

printf("[OK]\tTest passed\n");
return 0;
Expand Down

0 comments on commit 0318bc8

Please sign in to comment.