Skip to content

Add support for aarch64-unknown-linux-pauthtest - #755

Open
jchlanda wants to merge 1 commit into
rust-lang:mainfrom
jchlanda:jakub/pauthtest
Open

jchlanda wants to merge 1 commit into
rust-lang:mainfrom
jchlanda:jakub/pauthtest

Conversation

@jchlanda

@jchlanda jchlanda commented Apr 20, 2026 •

Copy link
Copy Markdown

This PR adds support for aarch64-unknown-linux-pauthtest, a target that enables Pointer Authentication Code (PAC) support in Rust on AArch64 ELF based Linux systems. It uses the aarch64-unknown-linux-pauthtest LLVM target and a pointer-authentication-enabled sysroot with a custom musl as a reference libc implementation. Dynamic linking is required, with a dynamic linker acting as the ELF interpreter that can resolve pauth relocations and enforce pointer authentication constraints.

Please consult a rust-lang PR for the details on the target: rust-lang/rust#155722

// as uw::_Unwind_FindEnclosingFunction creates a new context so
// the SP used for signing here would belong to a different frame
// that the one used for auth-resign. Hence return a raw value.
self.ip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is ip not signed? It is directly the result of _Unwind_GetIP. It should be possible to pass that to _Unwind_FindEnclosingFunction. How else would you even be able to use _Unwind_FindEnclosingFunction otherwise?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Why is ip not signed? It is directly the result of _Unwind_GetIP.

A raw ip is expected. _Unwind_GetIP authenticates the pointer and returns a stripped version (via ptrauth_auth_data here).

It should be possible to pass that to _Unwind_FindEnclosingFunction. How
else would you even be able to use _Unwind_FindEnclosingFunction otherwise?

This is the crux of the issue. _Unwind_FindEnclosingFunction is fundamentally incompatible with the pointer authentication model. The problem is that _Unwind_FindEnclosingFunction does not follow PAC semantics, it blindly creates a fresh unwind cursor and then resets the instruction pointer here: __unw_set_reg(cursor, UNW_REG_IP, pc);. As if to say: "treat this pc as if it belonged to this new cursor's frame".

__unw_set_reg does apply PAC logic internally (authenticates) under the assumption that the ip behaves like a return address for the current frame.

This cannot be fixed on the Rust side. _Unwind_FindEnclosingFunction constructs a new cursor (and therefore a new sp), so there is no way to correctly sign pointer: any signing we would perform would use the wrong context and would still fail authentication inside libunwind.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds like a bug in libunwind to me. What purpose does _Unwind_FindEnclosingFunction have at all if you can't pass the result of _Unwind_GetIP to it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not sure, the documentation seems to be pretty scarce, and one I found is rather quite lax about possible outcomes of the call, explicitly allowing failure.

I personally don't read it as a bug. To me it is more that _Unwind_FindEnclosingFunction was designed before pointer authentication existed, and its API implicitly assumes that instruction pointers are context-free values. But in PAC-aware code PC is only meaningful in the context of the (original) SP.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does _Unwind_FindEnclosingFunction need an authenticated pointer? It doesn't dereference the pointer, only looks it up in a side table with the result not having any security relevance. The only useful thing you can do with it afaik is looking up debuginfo for the function. Due to inlining and outlining you can't guarantee that it points to any particular function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes and comments added in this PR read as though this is just the way it has to be for pauthtest.

However, it seems to me that _Unwind_FindEnclosingFunction is implemented wrong, and if it were fixed then the changes in this PR would not be needed (but I don't know much about libunwind and even less about pointer authentication).

If that's the case, then this PR is adding a workaround that is the same as what we do for Apple, so that seems fine, but maybe it would be better if the comments indicated it is only a workaround. For example, instead of long explanations in the tests, it would be better as short note that it is a workaround for _Unwind_FindEnclosingFunction with a link to an issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've created an upstream libunwind issue here: llvm/llvm-project#223698
I'm not certain that it is genuinely a libunwind bug though. There was somewhat similar discussion on an unrelated PR: https://github.com/llvm/llvm-project/pull/202772/changes#r3633237542

One could argue that the reasoning behind that comment:

If you are fabricating a new sp that means you are taking on responsibility for constructing that new sp value correctly. Removing that requirement means that the stack pointer returned by __unw_get_reg would necessarily have lost its PAC signature.

Should be applied here as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@philipc / @ChrisDenton is there anything else you'd like me to do for this PR?
Thank you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How fixable is that LLVM issue? If that can be resolved first then it makes things here more straightforward.

If we are forced to keep the hacks, it would be good to open a Rust issue that can get closed out once the LLVM fix lands, and mark everything related as FIXME(rust-lang/rust#1234): ... so we eventually clean it up.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The honest answer is that I don't know, fwiw it did not yet attract much attention.

I've created https://github.com/rust-lang/backtrace-rs/issues/790 and added FIXMEs in code.

Comment thread src/backtrace/libunwind.rs Outdated
// clause, and if this is fixed that test in theory can be run on macOS!
if cfg!(target_vendor = "apple") {
self.ip()
} else if cfg!(target_env = "pauthtest") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this not check for the respective target feature being enabled? Not every target with pointer authentication enabled will use that target env, right?

@jchlanda jchlanda Apr 23, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right.
We're in the middle of preparing an upstream patch that introduces a pointer authentication aware target. It just so happens that in there I ended up using (incorrectly) the target environment as the gating mechanism.

We have a follow up task to resolve the target to a set of features, just like it's done in clang where it solves platform/environment specifics on the driver level and later on everything is based on language flags that are there regardless of the platform. And finally are resolved to a concrete signing schema.

This will become a bit more clear once the PR lands and I submit a ticket.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It was decided that using target_env = "musl" and target_abi = "pauthtest"is the way forward, I've updated the check to be target_abi = "pauthtest".

The rust-lang commit introducing the change: rust-lang/rust@229e0f5

@jchlanda
jchlanda marked this pull request as ready for review May 12, 2026 17:19
@jchlanda

Copy link
Copy Markdown
Author

Although the parent change (introduction of aarch64-unknown-linux-pauthtest) has not landed yet, it seems this should not prevent this PR from being marked as ready for review.

@jchlanda

Copy link
Copy Markdown
Author

@davidtwco, @folkertdev, @tgross35, @madsmtm FWI this is a follow up to rust-lang/rust#155722

@workingjubilee

Copy link
Copy Markdown
Member

Hello. That PR needs to land first for this to be accepted, but it can be reviewed now? Noted. Drawing up my queue again.

@jchlanda

jchlanda commented May 27, 2026 •

Copy link
Copy Markdown
Author

Hello. That PR needs to land first for this to be accepted, but it can be reviewed now? Noted. Drawing up my queue again.

Yeap, it's ready for review. If you feel like going on a review spree, there is plenty more pointer auth stuff:

Thank you!

@jchlanda

jchlanda commented Jul 1, 2026

Copy link
Copy Markdown
Author

Hi all (@davidtwco, @folkertdev, @tgross35, @madsmtm, @bjorn3, @workingjubilee),

The PR introducing the pauthtest target has been merged into main. I'd be very grateful if we could move this one forward as well.

Thank you!

@tgross35

tgross35 commented Jul 2, 2026

Copy link
Copy Markdown
Member

No need to ping me on pauthtest events - you already have reviewers on your PRs, I'm not following pauthtest anything special, and I don't really do reviews for backtrace or cc. I believe that applies to most of the people in that list.

@jchlanda

jchlanda commented Jul 2, 2026

Copy link
Copy Markdown
Author

No need to ping me on pauthtest events - you already have reviewers on your PRs, I'm not following pauthtest anything special, and I don't really do reviews for backtrace or cc. I believe that applies to most of the people in that list.

Feel free to ignore it then, apologies for the noise.

@workingjubilee

Copy link
Copy Markdown
Member

And my time is uncompensated, as it is for many reviewers. This is a problem that Access Softek can address if it wants.

@jchlanda

jchlanda commented Jul 7, 2026

Copy link
Copy Markdown
Author

@bjorn3 the other PAC related rust-lang PRs have now been earmarked for merge, could we please move this one forward?

@jchlanda

jchlanda commented Aug 3, 2026

Copy link
Copy Markdown
Author

@ChrisDenton, would you be able to help with a review? We've had a somewhat lengthy discussion about the merits of this change, and I believe the last message in the thread (#755 (comment)) provides a fairly comprehensive justification for the patch.

@ChrisDenton ChrisDenton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would need to read up on all the context first. Which might take me a while atm.

Comment thread tests/smoke.rs Resolved
@jchlanda

jchlanda commented Aug 3, 2026

Copy link
Copy Markdown
Author

I would need to read up on all the context first. Which might take me a while atm.

If you need any help with the pauthtest target or have any questions, I'd be happy to help.

For reference, the document introducing aarch64-unknown-linux-pauthtest can be found here: aarch64-unknown-linux-pauthtest.md

I also keep the tracking issue up to date with work related to the target.

@jchlanda
jchlanda requested a review from ChrisDenton August 17, 2026 12:43
@jchlanda

Copy link
Copy Markdown
Author

Friendly ping @ChrisDenton. Thank you.

@ChrisDenton

Copy link
Copy Markdown
Member

Sorry, just getting back to this. My fear here is that backtrace-rs, as currently designed, isn't going to be a great fit for this. But just to be clear on what we can currently support, with the standard library's usage, we can get accurate backtrace right? And symbolization of that backtrace works?

@jchlanda

jchlanda commented Sep 4, 2026

Copy link
Copy Markdown
Author

Sorry, just getting back to this. My fear here is that backtrace-rs, as currently designed, isn't going to be a great fit for this. But just to be clear on what we can currently support, with the standard library's usage, we can get accurate backtrace right? And symbolization of that backtrace works?

Yes, both work on this target.

For example:

use std::panic;

fn main() {
    let _ = panic::catch_unwind(|| {
        panic!("BOOM");
    });
}

Compiled for aarch64-unknown-linux-pauthtest and run with RUST_BACKTRACE=full, the standard library produces a backtrace with correctly symbolized function names and source locations (shortened):

16: ... - panic[... ]::main::{closure#0}
    at .../local_tests/panic/panic.rs:5:9
17: ... - std[... ]::panicking::catch_unwind::do_call<...>
    at .../library/std/src/panicking.rs:573:43
20: ... - panic[... ]::main
    at .../local_tests/panic/panic.rs:4:13
33: ... - main
Full log
$ RUST_BACKTRACE=full ./panic_O3_g

thread 'main' (1851724) panicked at panic.rs:5:9:
BOOM
stack backtrace:
   0:     0xaeeb874fae0c - trace
                               at /home/Work/pauth/rust/library/std/src/../../backtrace/src/backtrace/libunwind.rs:208:9
   1:     0xaeeb874fae0c - trace_unsynchronized<std::sys::backtrace::_print_fmt::{closure_env#1}>
                               at /home/Work/pauth/rust/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0xaeeb874fae0c - _print_fmt
                               at /home/Work/pauth/rust/library/std/src/sys/backtrace.rs:74:9
   3:     0xaeeb874fae0c - fmt
                               at /home/Work/pauth/rust/library/std/src/sys/backtrace.rs:44:26
   4:     0xaeeb8750f0e0 - fmt
                               at /home/Work/pauth/rust/library/core/src/fmt/rt.rs:152:76
   5:     0xaeeb8750f0e0 - write
   6:     0xaeeb874fea10 - default_write_fmt<std::sys::stdio::unix::Stderr>
                               at /home/Work/pauth/rust/library/core/src/io/write.rs:402:11
   7:     0xaeeb874fea10 - write_fmt<std::sys::stdio::unix::Stderr>
                               at /home/Work/pauth/rust/library/core/src/io/write.rs:335:13
   8:     0xaeeb874e4c3c - print
                               at /home/Work/pauth/rust/library/std/src/sys/backtrace.rs:47:9
   9:     0xaeeb874e4c3c - {closure#0}
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:289:27
  10:     0xaeeb874f6aac - default_hook
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:316:9
  11:     0xaeeb874f6ce0 - panic_with_hook
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:811:13
  12:     0xaeeb874e4d60 - {closure#0}
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:678:13
  13:     0xaeeb874db160 - std[9a20e64c0bb2485b]::sys::backtrace::__rust_end_short_backtrace::<std[9a20e64c0bb2485b]::panicking::panic_handler::{closure#0}, !>
                               at /home/Work/pauth/rust/library/std/src/sys/backtrace.rs:182:18
  14:     0xaeeb874e58b4 - panic_handler
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:676:5
  15:     0xaeeb8750fb14 - panic_fmt
                               at /home/Work/pauth/rust/library/core/src/panicking.rs:80:14
  16:     0xaeeb874cf280 - panic[50ad4060d4f2f1db]::main::{closure#0}
                               at /home/Work/pauth/rust/local_tests/panic/panic.rs:5:9
  17:     0xaeeb874cf1b8 - std[9a20e64c0bb2485b]::panicking::catch_unwind::do_call::<panic[50ad4060d4f2f1db]::main::{closure#0}, !>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:573:43
  18:     0xaeeb874cf1b8 - std[9a20e64c0bb2485b]::panicking::catch_unwind::<!, panic[50ad4060d4f2f1db]::main::{closure#0}>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:541:19
  19:     0xaeeb874cf2b8 - std[9a20e64c0bb2485b]::panic::catch_unwind::<panic[50ad4060d4f2f1db]::main::{closure#0}, !>
                               at /home/Work/pauth/rust/library/std/src/panic.rs:359:14
  20:     0xaeeb874cf2b8 - panic[50ad4060d4f2f1db]::main
                               at /home/Work/pauth/rust/local_tests/panic/panic.rs:4:13
  21:     0xaeeb874cf1e8 - <fn() as core[c3c78aaece9448f7]::ops::function::FnOnce<()>>::call_once
                               at /home/Work/pauth/rust/library/core/src/ops/function.rs:250:5
  22:     0xaeeb874cf1e8 - std[9a20e64c0bb2485b]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/Work/pauth/rust/library/std/src/sys/backtrace.rs:166:18
  23:     0xaeeb874cf250 - std[9a20e64c0bb2485b]::rt::lang_start::<()>::{closure#0}
                               at /home/Work/pauth/rust/library/std/src/rt.rs:206:18
  24:     0xaeeb874f5f38 - call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)>
                               at /home/Work/pauth/rust/library/core/src/ops/function.rs:287:21
  25:     0xaeeb874f5f38 - do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:573:43
  26:     0xaeeb874f5f38 - catch_unwind<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:541:19
  27:     0xaeeb874f5f38 - catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32>
                               at /home/Work/pauth/rust/library/std/src/panic.rs:359:14
  28:     0xaeeb874f5f38 - {closure#0}
                               at /home/Work/pauth/rust/library/std/src/rt.rs:175:24
  29:     0xaeeb874f5f38 - do_call<std::rt::lang_start_internal::{closure_env#0}, isize>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:573:43
  30:     0xaeeb874f5f38 - catch_unwind<isize, std::rt::lang_start_internal::{closure_env#0}>
                               at /home/Work/pauth/rust/library/std/src/panicking.rs:541:19
  31:     0xaeeb874f5f38 - catch_unwind<std::rt::lang_start_internal::{closure_env#0}, isize>
                               at /home/Work/pauth/rust/library/std/src/panic.rs:359:14
  32:     0xaeeb874f5f38 - lang_start_internal
                               at /home/Work/pauth/rust/library/std/src/rt.rs:171:5
  33:     0xaeeb874cf370 - main

@jchlanda

jchlanda commented Sep 15, 2026 •

Copy link
Copy Markdown
Author

Sorry, just getting back to this. My fear here is that backtrace-rs, as currently designed, isn't going to be a great fit for this. But just to be clear on what we can currently support, with the standard library's usage, we can get accurate backtrace right? And symbolization of that backtrace works?

Yes, both work on this target.

For example:

use std::panic;

fn main() {
    let _ = panic::catch_unwind(|| {
        panic!("BOOM");
    });
}

Compiled for aarch64-unknown-linux-pauthtest and run with RUST_BACKTRACE=full, the standard library produces a backtrace with correctly symbolized function names and source locations (shortened):

16: ... - panic[... ]::main::{closure#0}
    at .../local_tests/panic/panic.rs:5:9
17: ... - std[... ]::panicking::catch_unwind::do_call<...>
    at .../library/std/src/panicking.rs:573:43
20: ... - panic[... ]::main
    at .../local_tests/panic/panic.rs:4:13
33: ... - main

Full log

Does the above answer your question @ChrisDenton ?

Comment thread tests/skip_inner_frames.rs Outdated
// suitable for authentication/resigning, so `symbol_address()` returns the
// raw IP instead. In this case the returned address may be inside the
// function body rather than at its entry.
not(target_env = "pauthtest"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
not(target_env = "pauthtest"),
not(target_abi = "pauthtest"),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, thank you.

Comment thread tests/smoke.rs Outdated
// instruction pointers. As a result, symbol resolution cannot reliably
// recover a canonical function entry address, and `sym.addr()` will often be
// `None`. Therefore this test is disabled.
#[cfg_attr(target_env = "pauthtest", ignore)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[cfg_attr(target_env = "pauthtest", ignore)]
#[cfg_attr(target_abi = "pauthtest", ignore)]

@jchlanda
jchlanda force-pushed the jakub/pauthtest branch 2 times, most recently from 17dc484 to f465586 Compare September 15, 2026 07:24
@jchlanda

Copy link
Copy Markdown
Author

Friendly ping @ChrisDenton / @philipc. Thank you.

This PR adds support for `aarch64-unknown-linux-pauthtest`, a target that
enables Pointer Authentication Code (PAC) support in Rust on AArch64 ELF based
Linux systems using a pauthtest ABI (provided by LLVM) and pauthtest-enabled
sysroot with custom musl, serving as a reference libc implementation.

This branch has not been deployed

No deployments
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.

7 participants