Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cymbal): make apple frame ids stable across aslr slides (#62572)

Catalin Irimiea8527a93f4d3
diff --git a/rust/cymbal-resolution/tests/service_tests.rs b/rust/cymbal-resolution/tests/service_tests.rs
index 66319c75f194..12cfe0dd8efd 100644
--- a/rust/cymbal-resolution/tests/service_tests.rs
+++ b/rust/cymbal-resolution/tests/service_tests.rs
@@ -314,7 +314,7 @@ async fn admitted_items_emit_accepted_before_terminal_outcome() {
async fn raw_frames_are_resolved_into_done_payload() {
let raw_frame = sample_raw_frame();
let mut resolver_frame = sample_resolved_frame(&raw_frame);
- resolver_frame.frame_id = raw_frame.frame_id(123, 99);
+ resolver_frame.frame_id = raw_frame.frame_id(123, 99, &[]);
let service = make_service(FakeResolver {
fail_unhandled: false,
resolved_frames: vec![resolver_frame],
@@ -525,7 +525,7 @@ fn sample_raw_frame() -> RawFrame {
fn sample_resolved_frame(raw_frame: &RawFrame) -> Frame {
Frame {
- frame_id: raw_frame.frame_id(7, 0),
+ frame_id: raw_frame.frame_id(7, 0, &[]),
mangled_name: "f".to_string(),
line: Some(42),
column: Some(7),
diff --git a/rust/cymbal/src/frames/mod.rs b/rust/cymbal/src/frames/mod.rs
index 596562f83fb0..44c0fe55cf16 100644
--- a/rust/cymbal/src/frames/mod.rs
+++ b/rust/cymbal/src/frames/mod.rs
@@ -123,7 +123,7 @@ impl RawFrame {
let res = res.map(|mut fs| {
fs.iter_mut()
.enumerate()
- .for_each(|(index, f)| f.frame_id = self.frame_id(team_id, index));
+ .for_each(|(index, f)| f.frame_id = self.frame_id(team_id, index, debug_images));
fs
});
@@ -170,7 +170,7 @@ impl RawFrame {
}
}
- pub fn raw_id(&self, team_id: i32) -> RawFrameId {
+ pub fn raw_id(&self, team_id: i32, debug_images: &[AppleDebugImage]) -> RawFrameId {
let hash_id = match self {
RawFrame::JavaScriptWeb(raw) | RawFrame::LegacyJS(raw) => raw.frame_id(),
RawFrame::JavaScriptNode(raw) => raw.frame_id(),
@@ -183,14 +183,19 @@ impl RawFrame {
RawFrame::Hermes(raw) => raw.frame_id(),
RawFrame::Java(raw) => raw.frame_id(),
RawFrame::Dart(raw) => raw.frame_id(),
- RawFrame::Apple(raw) => raw.frame_id(),
+ RawFrame::Apple(raw) => raw.frame_id(debug_images),
};
RawFrameId::new(hash_id, team_id)
}
- pub fn frame_id(&self, team_id: i32, index: usize) -> FrameId {
- self.raw_id(team_id).to_full(index as i32)
+ pub fn frame_id(
+ &self,
+ team_id: i32,
+ index: usize,
+ debug_images: &[AppleDebugImage],
+ ) -> FrameId {
+ self.raw_id(team_id, debug_images).to_full(index as i32)
}
pub fn is_suspicious(&self) -> bool {
diff --git a/rust/cymbal/src/langs/apple.rs b/rust/cymbal/src/langs/apple.rs
index 812d3951ae6f..1ea4757bdf07 100644
--- a/rust/cymbal/src/langs/apple.rs
+++ b/rust/cymbal/src/langs/apple.rs
@@ -410,11 +410,23 @@ impl RawAppleFrame {
frame
}
- pub fn frame_id(&self) -> String {
+ pub fn frame_id(&self, debug_images: &[AppleDebugImage]) -> String {
let mut hasher = Sha512::new();
- if let Some(instruction_addr) = &self.instruction_addr {
- hasher.update(instruction_addr.as_bytes());
+ // Absolute instruction addresses are ASLR-slid per process launch, so hashing
+ // them directly gives the same logical frame a different id every launch and
+ // the frame record cache never hits. Hash the launch-invariant
+ // (debug image, relative offset) identity instead whenever we can compute it.
+ match self.launch_invariant_addr(debug_images) {
+ Some((debug_id, relative_addr)) => {
+ hasher.update(debug_id.as_bytes());
+ hasher.update(format!("rel:0x{relative_addr:x}").as_bytes());
+ }
+ None => {
+ if let Some(instruction_addr) = &self.instruction_addr {
+ hasher.update(instruction_addr.as_bytes());
+ }
+ }
}
if let Some(module) = &self.module {
@@ -431,6 +443,15 @@ impl RawAppleFrame {
format!("{:x}", hasher.finalize())
}
+
+ fn launch_invariant_addr(&self, debug_images: &[AppleDebugImage]) -> Option<(String, u64)> {
+ let instruction_addr = parse_hex_address(self.instruction_addr.as_ref()?).ok()?;
+ let debug_image = self.find_debug_image(instruction_addr, debug_images).ok()?;
+ let relative_addr = self
+ .calculate_relative_addr(instruction_addr, debug_image)
+ .ok()?;
+ Some((debug_image.debug_id.clone(), relative_addr))
+ }
}
/// Infer the programming language from a source filename for syntax highlighting.
@@ -983,4 +1004,73 @@ mod test {
"expected 'volatile int x = 99' in inlined_leaf context, got: {all_lines:?}"
);
}
+
+ fn frame_at(instruction_addr: u64, image_addr: u64) -> RawAppleFrame {
+ RawAppleFrame {
+ instruction_addr: Some(format!("0x{instruction_addr:x}")),
+ symbol_addr: None,
+ image_addr: Some(format!("0x{image_addr:x}")),
+ image_uuid: None,
+ module: Some("MyApp".to_string()),
+ function: None,
+ filename: None,
+ lineno: None,
+ colno: None,
+ meta: CommonFrameMetadata::default(),
+ }
+ }
+
+ fn image_at(debug_id: &str, image_addr: u64) -> AppleDebugImage {
+ AppleDebugImage {
+ debug_id: debug_id.to_string(),
+ image_addr: format!("0x{image_addr:x}"),
+ image_vmaddr: None,
+ image_size: Some(0x10000),
+ code_file: None,
+ image_type: None,
+ arch: None,
+ }
+ }
+
+ #[test]
+ fn test_frame_id_stable_across_aslr_slides() {
+ // Same logical frame (same image, same relative offset) from two launches
+ // with different ASLR slides must produce the same frame id.
+ let launch_a = frame_at(0x100004000, 0x100000000);
+ let launch_b = frame_at(0x104f04000, 0x104f00000);
+
+ let id_a = launch_a.frame_id(&[image_at("uuid-build-1", 0x100000000)]);
+ let id_b = launch_b.frame_id(&[image_at("uuid-build-1", 0x104f00000)]);
+
+ assert_eq!(id_a, id_b);
+ }
+
+ #[test]
+ fn test_frame_id_distinguishes_builds() {
+ let launch_a = frame_at(0x100004000, 0x100000000);
+ let launch_b = frame_at(0x100004000, 0x100000000);
+
+ let id_a = launch_a.frame_id(&[image_at("uuid-build-1", 0x100000000)]);
+ let id_b = launch_b.frame_id(&[image_at("uuid-build-2", 0x100000000)]);
+
+ assert_ne!(id_a, id_b);
+ }
+
+ #[test]
+ fn test_frame_id_distinguishes_call_sites_within_image() {
+ let images = [image_at("uuid-build-1", 0x100000000)];
+
+ let id_a = frame_at(0x100004000, 0x100000000).frame_id(&images);
+ let id_b = frame_at(0x100004004, 0x100000000).frame_id(&images);
+
+ assert_ne!(id_a, id_b);
+ }
+
+ #[test]
+ fn test_frame_id_falls_back_to_absolute_addr_without_debug_image() {
+ let launch_a = frame_at(0x100004000, 0x100000000);
+ let launch_b = frame_at(0x104f04000, 0x104f00000);
+
+ assert_ne!(launch_a.frame_id(&[]), launch_b.frame_id(&[]));
+ }
}
diff --git a/rust/cymbal/src/stages/resolution/frame.rs b/rust/cymbal/src/stages/resolution/frame.rs
index c3b186b73b00..7799de5403da 100644
--- a/rust/cymbal/src/stages/resolution/frame.rs
+++ b/rust/cymbal/src/stages/resolution/frame.rs
@@ -89,7 +89,7 @@ impl FrameResolver {
.iter_mut()
.enumerate()
.for_each(|(index, resolved_frame)| {
- resolved_frame.frame_id = frame.frame_id(team_id, index);
+ resolved_frame.frame_id = frame.frame_id(team_id, index, debug_images);
});
Ok(resolved_frames)
diff --git a/rust/cymbal/src/stages/resolution/symbol/local.rs b/rust/cymbal/src/stages/resolution/symbol/local.rs
index 2f0662c2b5bd..125251fed155 100644
--- a/rust/cymbal/src/stages/resolution/symbol/local.rs
+++ b/rust/cymbal/src/stages/resolution/symbol/local.rs
@@ -109,7 +109,7 @@ impl LocalSymbolResolver {
if frame.is_suspicious() {
metrics::counter!(SUSPICIOUS_FRAMES_DETECTED, "frame_type" => "raw").increment(1);
}
- let raw_id = frame.raw_id(team_id);
+ let raw_id = frame.raw_id(team_id, debug_images);
let mut cache_miss = false;
let frames = self
.cache
@@ -445,7 +445,7 @@ mod test {
.unwrap();
// get the frame
- let frame_id = frame.raw_id(0);
+ let frame_id = frame.raw_id(0, &[]);
let frame = ErrorTrackingStackFrame::load_all(&pool, &frame_id, resolver.ttl_policy)
.await
.unwrap()
diff --git a/rust/cymbal/src/types/mod.rs b/rust/cymbal/src/types/mod.rs
index 01bb74a1693b..6056dafac5d2 100644
--- a/rust/cymbal/src/types/mod.rs
+++ b/rust/cymbal/src/types/mod.rs
@@ -498,6 +498,7 @@ impl Stacktrace {
&self,
team_id: i32,
lookup_table: &HashMap<RawFrameId, Vec<Frame>>,
+ debug_images: &[AppleDebugImage],
) -> Option<Self> {
let Stacktrace::Raw { frames: raw_frames } = self else {
return Some(self.clone());
@@ -505,7 +506,7 @@ impl Stacktrace {
let mut resolved_frames = Vec::with_capacity(raw_frames.len() + 10);
for raw_frame in raw_frames {
- match lookup_table.get(&raw_frame.raw_id(team_id)) {
+ match lookup_table.get(&raw_frame.raw_id(team_id, debug_images)) {
Some(resolved) => resolved_frames.extend(resolved.clone()),
None => return None,
}