Repository navigation
Conversation
| // 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_FindEnclosingFunctionotherwise?
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@philipc / @ChrisDenton is there anything else you'd like me to do for this PR?
Thank you.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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") { |
There was a problem hiding this comment.
Should this not check for the respective target feature being enabled? Not every target with pointer authentication enabled will use that target env, right?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
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. |
|
@davidtwco, @folkertdev, @tgross35, @madsmtm FWI this is a follow up to rust-lang/rust#155722 |
|
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! |
|
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! |
|
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. |
|
And my time is uncompensated, as it is for many reviewers. This is a problem that Access Softek can address if it wants. |
|
@bjorn3 the other PAC related rust-lang PRs have now been earmarked for merge, could we please move this one forward? |
cfa50f4 to
c0ae25f
Compare
|
@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
left a comment
There was a problem hiding this comment.
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 For reference, the document introducing I also keep the tracking issue up to date with work related to the target. |
|
Friendly ping @ChrisDenton. Thank you. |
|
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 Full log |
Does the above answer your question @ChrisDenton ? |
| // 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"), |
There was a problem hiding this comment.
| not(target_env = "pauthtest"), | |
| not(target_abi = "pauthtest"), |
| // 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)] |
There was a problem hiding this comment.
| #[cfg_attr(target_env = "pauthtest", ignore)] | |
| #[cfg_attr(target_abi = "pauthtest", ignore)] |
17dc484 to
f465586
Compare
f465586 to
c3b9013
Compare
|
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.
c3b9013 to
b759785
Compare
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