Skip to content

Conversation

al45tair
Copy link
Contributor

Add the ability to specify a filename or directory name as the output-to setting in SWIFT_BACKTRACE. If the option is set to a directory name, generate a unique filename in that directory using the process name, process ID and timestamp.

rdar://136977833

Add the ability to specify a filename or directory name as the output-to
setting in `SWIFT_BACKTRACE`.  If the option is set to a directory name,
generate a unique filename in that directory using the process name,
process ID and timestamp.

rdar://136977833
Mike rightly points out that it's possible for `open()` to fail
with `EINTR`, which we should handle here.

rdar://136977833
@al45tair al45tair added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.1 labels Jan 30, 2025
@al45tair al45tair requested a review from a team as a code owner January 30, 2025 16:31
@al45tair
Copy link
Contributor Author

Explanation: Adds support for redirection of crash logs to a named file or to a directory.
Risk: Low. Only affects the backtracer, which will only kick in if the program crashes.
Original PR: #79007
Reviewed by: @mikeash @czechboy0
Resolves: rdar://136977833
Tests: Adds a test of the new functionality.

@al45tair
Copy link
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Contributor Author

(I've got another changeset to add to this — some security hardening that I think is worthwhile. Just testing it now.)

We should harden the output path setting so that it can't be used
as part of an exploit to get a crashing process to overwrite a
file at an attacker-controller path, or to divert the crash report
to `/dev/null` to hide their tracks or other such undesirable
activity.

Take a copy of the setting at start-up and write-protect it to
prevent attackers overwriting it.

Note that we already protect against attempts to trigger the
backtracer from privileged programs (both on Darwin and Linux);
this is really a belt and braces measure to make life harder for
attackers.

rdar://136977833
@al45tair
Copy link
Contributor Author

al45tair commented Feb 3, 2025

@swift-ci Please test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, was looking forward to this for a while! Glad you got to it so quickly :)

airspeedswift
airspeedswift previously approved these changes Mar 20, 2025
@airspeedswift airspeedswift dismissed their stale review March 20, 2025 23:28

Missed there was an unaddressed issue

It looks like we aren't actually using it, so let's just delete it.

rdar://136977833
@al45tair
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Contributor Author

@swift-ci Please test macOS platform

@al45tair al45tair requested a review from airspeedswift March 25, 2025 11:57
@ktoso
Copy link
Contributor

ktoso commented Mar 25, 2025

Yes please, would love to have this for swift-java work when we crash sometimes and the outputs get jumbled together with java's crash :-)

@al45tair al45tair merged commit 0414cb2 into swiftlang:release/6.1 Mar 27, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 6.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants