Repository navigation
Conversation
9052b2a to
5b223de
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5b223de to
45f422b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
45f422b to
8659b72
Compare
This comment has been minimized.
This comment has been minimized.
8392cdf to
5399226
Compare
| /// emitted at that offset. | ||
| /// | ||
| /// Offsets are relative to the beginning of the allocation. | ||
| pub(crate) struct FnPtrDiscriminatorAtOffset { |
There was a problem hiding this comment.
What is the established naming convention in rust for such kind of things? Should this be plural (discriminators)? Especially given the fact that we already have collect_fn_ptr_discriminators
There was a problem hiding this comment.
Sure, FnPtrDiscriminatorsAtOffset it is.
| let variant = def.non_enum_variant(); | ||
|
|
||
| let Some((_, field)) = variant.fields.iter_enumerated().next() else { | ||
| return; |
There was a problem hiding this comment.
Could you please refer me to tests covering these early-return paths (from this case and from the below cases)? The logic by itself looks sound, but it definitely deserves its own test coverage (which I'm not sure I can correctly identify by myself in the new test suite from PR 8)
There was a problem hiding this comment.
Interesting, this is actually redundant. I initially though it would serve for something like:
#[repr(transparent)]
struct Wrapper(extern "C" fn(i32));
impl Sync for Wrapper {}
static T_WRAPPED_FN_PTR: Wrapper = Wrapper(g);in https://github.com/jchlanda/rust/blob/fb279532dbf253c1f78dd02a3268bfdde8d6d7ad/tests/codegen-llvm/pauth/pauth-fn-ptr-type-discrimination-struct-members.rs#L1, but turns out struct arm handles it just fine. Removing.
While at it, I added a test case for Tupel which was missing (T_TUPLE, T_TUPLE_2 and test_8_tuple_members in the same file). Tests added to the 8th PR.
Thanks!
ef6b34d to
e08ffe7
Compare
| .as_ref() | ||
| .and_then(|m| m.map.get(&Size::from_bytes(offset as u64))); | ||
|
|
||
| // Init/fini entries must not participate in function pointer type discrimination. |
There was a problem hiding this comment.
Nit: maybe worth slightly re-phrasing this - now it might be understood as "init/fini pointers are zero-discriminated", while in reality they receive their own special constant discriminator
| // FIXME: should we cache `const_alloc_to_llvm` to avoid repeating this for the | ||
| // same `ConstAllocation`? | ||
| let cv = const_alloc_to_llvm(self, alloc.inner(), IsStatic::No, IsInitOrFini::No); | ||
| let cv = const_alloc_to_llvm(self, alloc.inner(), IsStatic::No, IsInitOrFini::No, None); |
There was a problem hiding this comment.
Could you please explain why fn_ptr_discriminators is guaranteed to be None here? Is ConstAllocation something which is guaranteed not to contain nested function pointers?
There was a problem hiding this comment.
Looked at this code again, and I think this is incorrect. Type discrimination should also be applied when computing addresses for statics; it just didn't come up in the existing tests.
From a quick look, this seems a little more involved because we don't have the necessary type information when calling static_addr_of. We'll likely need to either extend its API or compute the discriminator map at the call sites that still have access to the Rust type.
I've added an in-code FIXME to capture this, and if you're okay with it, I'd like to address it in a follow-up PR.
| alloc: &Allocation, | ||
| is_static: IsStatic, | ||
| is_init_fini: IsInitOrFini, | ||
| fn_ptr_discriminators: Option<&FnPtrDiscriminatorsAtOffset>, |
There was a problem hiding this comment.
Nit: I'm not sure of a particular suggestion, but just as a thought - it might be worth somehow prefixing such things with ptrauth_ in order to (a) indicate that it's ptrauth-specific for readers wondering what's it all about (b) make it easier to grep ptrauth-related stuff.
If just adding prefix right now, the identifier would become too long though. So maybe the rest of the name could be somehow reconsidered.
I would appreciate if you could do a pass over all newly added data structures/variables/argument names which exist in "generic" non-ptrauth-specific context and ensure if in all such places it's clear that the corresponding item is ptrauth-specific
There was a problem hiding this comment.
For new fields that are extending already existing data structures, I'll add the ptrauth_ prefix.
I'll also do a follow-up PR to take another look at session.rs, as it doesn't really belong in this patch series. At that point I'll also review the names of the data structures/functions we're introducing. I agree that public-facing identifiers should be prefixed, but for local, throwaway-style types/funcs I'm less convinced. Since they're context-specific, they should be easier to reason about without additional prefixes.
f77edea to
58601d5
Compare
This comment has been minimized.
This comment has been minimized.
58601d5 to
286014f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
91ffd1d to
3ae948f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3ae948f to
b266f9d
Compare
This comment has been minimized.
This comment has been minimized.
b266f9d to
377e8ee
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
377e8ee to
ea9e93d
Compare
This patch brings: * adds `FnAbi::ptrauth_discriminator` * `is_ptrauth_signed_abi` unified point of control for pauth-supported ABIs * `ptrauth_signing_discriminator_for` - discriminator for given pointer under the schema (None - not supported ABI, constant, or calculated for pointer type)
And a test for it. `compute_fn_ptr_type_discriminator` was split into the encoding and the hash (both public) for the test use.
…rules Under type discrimination a fn pointer is signed with a discriminator of a pointee and authenticated with a discriminator of the function pointer that it is called through. In order to make a call through ABI-compatible function pointers work we must make sure that they produce the same discriminator. ABI-compatible types must generate the same discriminator. In order to do that this patch canonicalizes types by their ABI representation before encoding: * `repr(transparent)` wrappers as their non-1-ZST field; * two-variant niche enums (`Option<&T>`, `Option<NonZero<_>>`, `Option<fn()>`) as the payload; * size-0, alignment-1 types as `()` (C's void); * `Box<T>` as a pointer, and pattern types as their base type; * `!` as `()`. `discriminator-abi-compat.rs` checks three groups of signatures: * ABI-compatible types, must have the same discriminator (a failure is a soundness bug) * types that are not ABI-compatible but share the discriminator because Clang's encoding is coarser (a failure breaks C interoperability) * distinct types - distinct discriminators
Clang's `encodeTypeForFunctionPointerAuth` uses Itanium type codes: * `_Float16` is `DF16_` * `f128` is the C type with its representation: `long double` (`e`) on AArch64 Linux, where `long double` is IEEE quad precision, and `__float128` (`g`) elsewhere.
This comment has been minimized.
This comment has been minimized.
Match `core::num::Complex<T>` (the `complex` lang item) against C `_Complex T` for float and integer `T`.
A function pointers read from a constant (for example a `const` item used by a value, or a field of a constant aggregate), were emitted unsigned: `from_const` and `from_const_alloc` lowered pointers without a schema. This aligns constants lowering to, already implemented, statics.
Enable `-Zpointer-authentication=+function-pointer-type-discrimination`. Function pointers are signed with the discriminators of the functions they point to, calls authenticate with the discriminators of the type they are made through. Pointers are never implicitly resigned, transmutes, `as` casts, union puns etc are plain bit blasts. ABI-compatible calls authenticate fine, because the encoder honours the compatibility rules and encodes ABI-compatible types with the same discriminators. Calls through any other signatures are UB and will fail to authenticate. This patch brings: * Set `FPTR_TYPE_DISCR` (bit 11) in the PAuth ABI version and drop the "not supported" error. * `maybe_sign_fn_ptr` signs with the discriminator of the instance. * The address of an `extern_weak` function is called through the function pointer type of its static. * Init/fini entries keep their own schema, which is not type discriminated.
The `libc` changes for the target are upstream, so `libc` no longer needs patching. `cc-rs` no longer needs a fork either: `cc` 1.4.3 supports the target, but `bootstrap` still pins 1.2.62, so the doc describes the pin bump. With 1.4.3, `bootstrap` finds the sysroot through `PAUTHTEST_SYSROOT` and `PAUTHTEST_RESOURCE_DIR`, so the doc lists those as well.
View all comments
Implements function pointer type discrimination behind
-Zpointer-authentication=+function-pointer-type-discriminationonaarch64-unknown-linux-pauthtest.The model:
extern "C"orextern "system"function pointer is signed with the discriminator of the function it points to.The commits:
extern_weaksymbols signed with theirFnAbidiscriminator, theFPTR_TYPE_DISCRbit (11) in the PAuth ABI version, and removal of the error that rejected the flag.libc._Complex.This is step 4 of a series implementing function pointer type discrimination for
aarch64-unknown-linux-pauthtest, using the pointee-signature model discussed in rust-lang/unsafe-code-guidelines#624.It stays a draft until that discussion concludes.
Each PR contains the commits of the previous ones.
FnAbif16/f128,_Complex#[russtc_ptrauth_c_discriminator(N)]Already merged: #159071 (encoder and hash).
Folded into step 4: #159075, #159084.
Closed: #159082 (resign on transmute, dropped), #159087 (tests moved into each step).
Useful links:
pauthtestintroduction: Introduce aarch64-unknown-linux-pauthtest target #155722