Skip to content

Strip sa_handler if ptrauth_calls is present#7

Open
jchlanda wants to merge 1 commit intoaccess-softek:v1.2.5-pauth-rev2025-11-21from
jchlanda:jakub/strip_handler
Open

Strip sa_handler if ptrauth_calls is present#7
jchlanda wants to merge 1 commit intoaccess-softek:v1.2.5-pauth-rev2025-11-21from
jchlanda:jakub/strip_handler

Conversation

@jchlanda
Copy link

Strip sa_handler if ptrauth_calls is present

This follows the same logic as for the restorer. Without stripping
kernel would receive a signed address and use it, as is, to call the
signal handler, which would result in an invalid memory access.

For the record, this was spotted when running Rust signal handler as
registered here (fn init()):
https://github.com/rust-lang/rust/blob/main/library/std/src/sys/pal/unix/stack_overflow.rs#L184

Sample strace output showing invalid (signed) pointer:

    rt_sigaction(SIGSEGV, {sa_handler=0x13f96bba92acf8, sa_mask=[],
      sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0xf96bbaad0430},
      NULL, 8) = 0

This follows the same logic as for the restorer. Without stripping
kernel would receive a signed address and use it, as is, to call the
signal handler, which would result in an invalid memory access.

For the record, this was spotted when running Rust signal handler as
registered here (`fn init()`):
https://github.com/rust-lang/rust/blob/main/library/std/src/sys/pal/unix/stack_overflow.rs#L184

Sample strace output showing invalid (signed) pointer:

```
rt_sigaction(SIGSEGV, {sa_handler=0x13f96bba92acf8, sa_mask=[],
  sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0xf96bbaad0430},
  NULL, 8) = 0
```
@kovdan01
Copy link

Thanks! Let me ensure that llvm-test-suite and pauth-testsuite continue passing with this patch applied before giving the final approval

}
ksa.handler = sa->sa_handler;
#if __has_feature(ptrauth_calls)
ksa.handler = __builtin_ptrauth_strip(ksa.handler, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to authenticate the pointer value instead of merely striping here and in similar places? @kovdan01

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.

3 participants