Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for stabilisation of -Z branch-protection #113369

Open
1 of 3 tasks
jacobbramley opened this issue Jul 5, 2023 · 3 comments
Open
1 of 3 tasks

Tracking Issue for stabilisation of -Z branch-protection #113369

jacobbramley opened this issue Jul 5, 2023 · 3 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC

Comments

@jacobbramley
Copy link
Contributor

jacobbramley commented Jul 5, 2023

This is a tracking issue for standardising the -Z branch-protection=... codegen option, which enables control-flow integrity measures using Armv8.3 pointer authentication and/or Armv8.5 branch target identification on AArch64.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

  • Implement the unstable option (-Z branch-protection).
  • Stabilization PR for the stable option (-C branch-protection).

Unresolved Questions

Future Work

Stabilisation of branch-protection is a necessary step for making these technologies straightforward to use, but there are other obstacles beyond the codegen option itself:

std

Deploying these CFI technologies typically requires all code in a process to be compiled with similar mitigations. For example, today you probably also need to use the unstable build-std to rebuild the standard library accordingly, otherwise ROP-style gadgets may still be present in std. One way to improve this for users would be to offer a pre-built standard library with (for example) branch-protection=pac-ret,bti, in addition to the baseline. However, such a mechanism requires further work, and is out of scope of this tracking issue.

LTO and module flag combination

Module flags in LLVM 14 and 15 behave quite differently (e.g. during LTO). LLVM 14 uses Error, so all modules must match. LLVM 15 uses Min, so module flags are downgraded to the lowest value, without notification. As a result, it's quite easy to accidentally disable these flags process-wide with LTO builds, for example by linking a single module that lacks an sign-return-address-* flag that otherwise expect. ::Min also interacts awkwardly with the bkey configuration, which isn't inherently ordered.

We should address this, but it's really an LLVM concern rather than a Rust one. Rust could provide an additional option to use the Warning module flag instead of Min, since LLVM always allows the two to combine, but this is also out of scope of this tracking issue.

Implementation history

@xuyoujun
Copy link

pac and bti are very important feature on AArch64. Android using a mount of rust code, but Android recommend enable pac and bti

@SparrowLii
Copy link
Member

SparrowLii commented Dec 18, 2024

This feature is very important for products which run on aarch64.

When will this feature be stabilized? Are there any other issues that need to be addressed?

@jacobbramley
Copy link
Contributor Author

jacobbramley commented Dec 18, 2024

This feature is very important for products which run on aarch64.

When will this feature be stabilized? Are there any other issues that need to be addressed?

I proposed a unified CLI (merging with cf-protection) shortly after opening this tracking issue. A unified approach was requested on Zulip, if I remember correctly.

  • The question of ABI compatibility, and what that really means for these CFI options, probably affects how we present these flags. The broader issue has been under investigation by @RalfJung and others. We need to re-evaluate this proposal taking those outcomes into account, but it's likely to amount to renaming and filtering of proposed options. They won't be called abi-variant!
  • The proposal includes a mechanism for future expansion without instant stabilisation, but (assuming that I understood correctly) @davidtwco recently told me that there's an existing mechanism for that.
  • @mrkajetanp submitted a PR that makes cc-rs forward these flags. (That's important for std.)

A few people raised concerns about having a stable flag that doesn't actually work out of the box, since effective use also requires the build-std Cargo flag. @adamgemmell is focussing on that, but it's by far the largest piece of work blocking this stabilisation.

There's potentially a justification for stabilising branch-protection for environments that are supplying their own std anyway (or aren't using Cargo). We didn't explore that at the time, but if there's a way to stabilise it but have it fail in a useful way if the available std doesn't match, we could pursue that.

It's likely that @davidtwco will oversee this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC
Projects
None yet
Development

No branches or pull requests

3 participants