This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][PAC] Declare FPAC subtarget feature
Needs ReviewPublic

Authored by atrosinenko on Aug 1 2023, 3:30 AM.

Details

Summary

In some situations, such as re-signing pointers or performing tail
calls, the code generator has to authenticate a signed pointer that will
not be dereferenced immediately. In such cases it may be necessary to
emit extra code to make sure that the authentication succeeded to prevent
introducing authentication/signing oracles.

If the target CPU is known to support FEAT_FPAC, this extra code can be
skipped as AUT* instructions are known to fault on invalid PAC by
themselves.

Note that unlike many other features, FEAT_FPAC does not add any new
supported instructions, but changes the semantics of several existing
ones. Thus, care should be taken to not enable FPAC when not actually
supported as it does not make code fail explicitly under normal
operation, but makes it less secure on unsupported CPUs.

Diff Detail

Event Timeline

atrosinenko created this revision.Aug 1 2023, 3:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 3:30 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
atrosinenko requested review of this revision.Aug 1 2023, 3:30 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 1 2023, 3:30 AM
atrosinenko planned changes to this revision.Aug 14 2023, 9:50 AM

Looks like adding FeatureFPAC may require changes in more places - need to investigate whether I have to add something like AEK_FPAC constant, etc.

Updated the patch:

  • added FPAC to Extensions array in AArch64TargetParser.h, so it can be used in -march=...+fpac command line option. Adding one more feature seems mostly harmless after PR 65423 was merged
  • dropped changes to clang/lib/Basic/Targets/AArch64.(h|cpp) as I don't actually use them to set any C defines or so (I don't see any mentioning of FPAC in ACLE 2023Q2)
  • not adding FPAC to ExtensionMap in AArch64AsmParser.cpp as it doesn't look relevant for assembler (maybe it would be relevant someday for storing the set of expected features to object files)

As discussed in D156716, it is not clear if I have to add FeatureFPAC to every relevant CPU. Maybe it is worth conservatively assuming that this feature should only be enabled manually by the user as a precaution against "I have CPU core X but it is not listed, so let's use cpu=Y because X supports all the instructions supported by Y (but not FEAT_FPAC)" - that would not cause any obvious run-time crashes under normal operation, but would make the code less secure.

chill added a subscriber: chill.Oct 14 2023, 4:56 AM

As discussed in D156716, it is not clear if I have to add FeatureFPAC to every relevant CPU.

I would say, yes, it has to be added to each CPU that has that feature - that's what a subtarget feature is for. If we need to a way to alter code generation
as a response to a user choice, that ought to be done with a specific command line option and TargetOptions and/or function and module level
attributes.

Maybe it is worth conservatively assuming that this feature should only be enabled manually by the user as a precaution against "I have CPU core X but it is not listed, so let's use cpu=Y because X supports all the instructions supported by Y (but not FEAT_FPAC)" - that would not cause any obvious run-time crashes under normal operation, but would make the code less secure.

As far as I can tell, the existing practice for security-related code generation is to have it disabled by default
and enable it explicitly by clang command line options (c.f -mbranch-protection=..., -mharden-sls=..., -fstack-clash-protection, -fsanitize=memtag, ...).

In that spirit, I would suggest not using target features to alter code generation in a rather obscure way but being quite explicit about it.
For example, have an option -mauth-ret-check=default|force where:

  • the presence of the option enables LR check before tail calls
  • default (or enable) would mean FEAT_FPAC takes precedence
  • force would mean FEAT_FPAC is ignored

Alternatively, maybe even better, these could be options to -mbranch-protection=....