sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Don't symbolicate stacktrace during crash

Open brustolin opened this issue 1 year ago • 6 comments

Description

At the moment, we're attempting to symbolicate the stacktrace during crashes using a custom function instead of dladdr, in order to ensure async safety. However, this custom function is slower and doesn't work with Swift async stitching, as noted in this comment.

One alternative solution is to serialize the addresses and symbolicate them in the next session, since we only capture the crash data during the next session anyway

Solving this issue might also fix:

  • https://github.com/getsentry/sentry-cocoa/issues/3687

brustolin avatar May 04 '23 06:05 brustolin

One alternative solution is to serialize the addresses and symbolicate them in the next session, since we only capture the crash data during the next session anyway

The problem is that the addresses can change on the next run, if I'm not mistaken. Maybe we can try a similar approach as we do for MetricKit: https://github.com/getsentry/sentry-cocoa/blob/fd6a31ce3940224432d2ece19de8c052bec3c3d2/Sources/Sentry/SentryMetricKitIntegration.m#L401-L447

philipphofmann avatar May 04 '23 11:05 philipphofmann

The problem is that the addresses can change on the next run, if I'm not mistaken. Maybe we can try a similar approach as we do for MetricKit:

AFAYK the symbols included in a binary are linked to specific memory locations in the binary. Only if the app install a new version we would have a problem, which is a reasonable tradeoff.

brustolin avatar May 04 '23 12:05 brustolin

We should consider completely removing sentrycrashdl_dladdr / local symbolication because isn't async safe and causes problems such as deadlocks https://github.com/getsentry/sentry-cocoa/issues/4056 and the watchdog killing apps using the Cocoa SDK https://github.com/getsentry/sentry-cocoa/issues/3687.

https://github.com/getsentry/sentry-cocoa/blob/d9280eec4f311096709ba84fc6a5d04423503c6c/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.h#L116

philipphofmann avatar Jun 13 '24 08:06 philipphofmann

We should consider completely removing sentrycrashdl_dladdr

We have decided to follow this approach.

brustolin avatar Jun 19 '24 12:06 brustolin

The problem is that the addresses can change on the next run, if I'm not mistaken. Maybe we can try a similar approach as we do for MetricKit:

AFAYK the symbols included in a binary are linked to specific memory locations in the binary. Only if the app install a new version we would have a problem, which is a reasonable tradeoff.

While it is true that the symbols are linked to specific memory locations in the binary, the memory addresses will change due to Address Space Layout Randomization. The binary will be loaded to a different address each time.

From https://support.apple.com/fr-fr/guide/security/sec15bfe098e/web

Address Space Layout Randomization

Address Space Layout Randomization (ASLR) helps protect against the exploitation of memory corruption bugs. Built-in apps use ASLR to help randomize all memory regions upon launch. In addition to work upon launch, ASLR randomly arranges the memory addresses of executable code, system libraries, and related programming constructs, further reducing the likelihood of many exploits. For example, a return-to-libc attack attempts to trick a device into executing malicious code by manipulating memory addresses of the stack and system libraries. Randomizing the placement of these makes the attack more difficult to execute, especially across multiple devices. Xcode, and the iOS or iPadOS development environments, automatically compile third-party programs with ASLR support turned on.

espenrl avatar Jun 19 '24 17:06 espenrl

While it is true that the symbols are linked to specific memory locations in the binary, the memory addresses will change due to Address Space Layout Randomization. The binary will be loaded to a different address each time.

I believe this obscured from the app itself, otherwise no symbolication would ever work. But this does not matter any more, we would symbolicate the crash locally anymore.

brustolin avatar Jun 20 '24 07:06 brustolin