[Docs] Add documentation for ptrauth ELF module flags #237916
The Keys subsection of this document does not seem to use this process-dependent/independent terms: https://github.com/llvm/llvm-project/blob/main/llvm/docs/PointerAuth.md#keys
Would it be better to avoid such terms here as well (as not defined in the document)? Especially given that e.g. on Linux, to the best of my knowledge, all 4 keys are generated uniquely for each process
Same applies to the ptrauth-elf-got point above
You've likely meant .init_array and .fini_array, not .init/.fini. The point about address discrimination below is also probably worth updating accordingly.
Would it be better to name it somehow like "ELF-Specific IR Module Flags"? My concern is that now "ELF Module" might be misinterpreted as single entity by a non-specialist reader
While the instruction key IA is used for STT_FUNC symbols, the DA data key is used for other symbol types. So "instruction key" sounds not quire precise here, if I'm not missing smth.
Would it be worth also mentioning the ptrauth-sign-personality IR module flag?
That is an interesting question, and as I've used the terms process-independent and process-dependent key in the driver and LLVM patches to match what is written in https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/ptrauth.h#L19
While not mentioned in llvm there is some documentation in the clang equivalent https://clang.llvm.org/docs/PointerAuthentication.html#key-assignments quoted below [1]
Granted that the concept of process-dependent and process-independent is arm64e specific, but the same conventions are followed by Linux (and bare-metal default), I'm thinking what the best way forward is. Some options:
1.) Adopt the "ptrauth.h" arm64e naming conventions, even if the keys may not actually be process-independent. Then all the names in ptrauth.h and the one other reference I could find in https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Attr.td#L5494 would match up. I think that would need some additional documentation in clang to state that on non arm64e the same naming conventions are used, even if the keys are not actually process independent. I would need to add documentation to the key assignment in LLVM too.
2.) For LLVM, which doesn't have any references to the process-independent and process-dependent keys we could use "global (A key)" and "local (B key)" for process-independent and process-dependent respectively. I will alter my LLVM and clang patches to use global-code, global-data, local-code and local-data (with comments stating the mapping to Clang's process-independent and process-dependent.
I don't think I can touch the use of process-independent and process-dependent in ptrauth.h as that might break existing code.
Any preferences? I think global and local are better and shorter, but there's some benefit in being consistent with ptrauth.h.
[1] quote from clang key-assignments:
arm64e then further subdivides the keys as follows:
>The A keys are used for primarily “global” purposes like signing v-tables and function pointers. These keys are sometimes called process-independent or cross-process because on existing OSes they are not changed when changing processes, although this is not a platform guarantee.
> The B keys are used for primarily “local” purposes like signing return addresses. These keys are sometimes called process-specific because they are typically different between processes. However, they are in fact shared across processes in one situation: systems which provide fork cannot change these keys in the child process; they can only be changed during exec.
Thanks, will fix.
OK, will do.
Thanks, I expect you're right there and both instruction and data keys can be used. Will double check and update.
Thanks for the comments. I've updated the patch to not use process-independent and process-dependent, and have applied the corrections.
Definitely interested in opinions on whether I should avoid using process-independent and process-dependent throughout the remainder of the patch set.
I'm inclined to try and use global and local where possible, with mappings to process-independent and process-dependent. Global and local would fit bare-metal much better as there may not even be the concept of a process.
LGTM, thanks! And, as discussed during the call, it would be very nice to adopt global/local terminology throughout the documentation where applicable.
One minor nit-pick remaining in context of this PR though:
Would it be worth also mentioning the ptrauth-sign-personality IR module flag?LGTM, thanks! And, as discussed during the call, it would be very nice to adopt global/local terminology throughout the documentation where applicable.
> One minor nit-pick remaining in context of this PR though:
> > Would it be worth also mentioning the ptrauth-sign-personality IR module flag?
Yes, apologies for missing that one. I've added it to the patch and have updated the description. Let me know if you'd like any changes, or whether I should split into a separate patch?
Nit: I guess that the personality routine is actually __gxx_personality_v0, while the DW.ref.__gxx_personality_v0 is an object containing the pointer to it. Like:
DW.ref.__gxx_personality_v0:
.xword __gxx_personality_v0@AUTH(ia,32429,addr)
Might be worth making it clear here to avoid misunderstanding by someone not too deeply in the context and trying to figure out why this DW.ref.... object is called a personality routine :)
LGTM module one very minor nit-pick, thanks!
Ack. Have changed to __gc_personality_v0.
kovdan01
smithp35
There are four module flags that influence code-generation for PAuthABI on ELF platforms.
ptrauth-elf-got
ptrauth-init-fini
ptrauth-init-fini-address-discrimination
ptrauth-sign-personality
Although largely self-explanatory, add a section in the documentation to collect all the available module flags.
The ptrauth-init-fini module flags will work on the Mach-O equivalents, but they are intended only to be used on ELF platforms.