Skip to content

Add a build flavor to opt-out of BTCFI on OpenBSD. #80389

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

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

3405691582
Copy link
Member

To work-around #80059, we need to stop return address signing and opt-out of BTCFI enforcement via enabling a platform linker option.

We don't want to completely undo the BTCFI work in the rare case that we later figure out how to properly address the above issue, or allow users who might want to benefit from BTCFI enforcement and won't use Concurrency. To do this, condition the existing BTCFI flag enforcement into a configuration option that defaults to off for now.

Because the new swift-driver needs to "know" whether the frontend is configured to opt-out or not, and since the new driver communicates with the frontend via the target info JSON to begin with, we add a field that emits the build flavor to signal the right behavior.

To work-around swiftlang#80059, we need to stop return address signing and
opt-out of BTCFI enforcement via enabling a platform linker option.

We don't want to completely undo the BTCFI work in the rare case that
we later figure out how to properly address the above issue, or allow
users who might want to benefit from BTCFI enforcement and won't use
Concurrency. To do this, condition the existing BTCFI flag enforcement
into a configuration option that defaults to off for now.

Because the new swift-driver needs to "know" whether the frontend is
configured to opt-out or not, and since the new driver communicates with
the frontend via the target info JSON to begin with, we add a field
that emits the build flavor to signal the right behavior.
@3405691582
Copy link
Member Author

@swift-ci please test.

3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Mar 29, 2025
On the swift side, we added a new build flavor in swiftlang/swift#80389
to opt-out of BTCFI as a way of working around swiftlang/swift#80059.
We communicate this to swift-driver via the frontend with
FrontendTargetInfo.
@3405691582
Copy link
Member Author

@swift-ci please test Windows platform.

@3405691582
Copy link
Member Author

@swift-ci please smoke test macOS platform.

@3405691582
Copy link
Member Author

(I don't believe the macOS CI failures are related to this pr.)

@DougGregor
Copy link
Member

@swift-ci please test macOS

@DougGregor
Copy link
Member

I'd love to better understand this comment

The hypothesis is that Concurrency may perform some manipulations for task switching that would otherwise require manual pointer signing, but the intrinsics for manual pointer signing in LLVM are gated on Darwin, so manual signing does not occur.

and whether it's a technical issue (there's nontrivial work to do) or a choice that we could undo. In other words, what kind of path do we have toward not needing this option in the future on OpenBSD?

@3405691582
Copy link
Member Author

3405691582 commented Apr 2, 2025

Right now, my suspicion is solely because of indications like __ptrauth_swift_task_resume_context in Task.h (and seeing that ResumeContext appear in debugging sessions), and that I can reproduce this on Linux if I manually turn on -msign-return-address on aarch64. At some point I would certainly like to dig a little deeper, but I want to ensure that the ability to build a toolchain end-to-end exists first.

@DougGregor
Copy link
Member

Right now, my suspicion is solely because of indications like __ptrauth_swift_task_resume_context in Task.h (and seeing that ResumeContext appear in debugging sessions), and that I can reproduce this on Linux if I manually turn on -msign-return-address on aarch64. At some point I would certainly like to dig a little deeper, but I want to ensure that the ability to build a toolchain end-to-end exists first.

Okay! It makes sense to get a toolchain building end-to-end first, then figure out how to get BTCFI enforcement working.

@DougGregor
Copy link
Member

@swift-ci please test macOS

@3405691582
Copy link
Member Author

Please merge on my behalf when ready, thank you!

@DougGregor DougGregor merged commit e49afc8 into swiftlang:main Apr 3, 2025
5 checks passed
@DougGregor
Copy link
Member

Please merge on my behalf when ready, thank you!

Done!

3405691582 added a commit to 3405691582/swift that referenced this pull request Apr 4, 2025
This was accidentally left off from swiftlang#80389, and will properly ensure
BTCFI enforcement is disabled on the platform when required.
3405691582 added a commit to 3405691582/swift that referenced this pull request Apr 15, 2025
This was accidentally left off from swiftlang#80389, and will properly ensure
BTCFI enforcement is disabled on the platform when required.
3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Apr 19, 2025
On the swift side, we added a new build flavor in swiftlang/swift#80389
to opt-out of BTCFI as a way of working around swiftlang/swift#80059.
We communicate this to swift-driver via the frontend with
FrontendTargetInfo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants