Skip to content

fix(node): enforce RTMR3 validation on event checks#780

Merged
barakeinav1 merged 9 commits intomainfrom
RTMR3-event-check-fix
Aug 10, 2025
Merged

fix(node): enforce RTMR3 validation on event checks#780
barakeinav1 merged 9 commits intomainfrom
RTMR3-event-check-fix

Conversation

@barakeinav1
Copy link
Copy Markdown
Contributor

@barakeinav1 barakeinav1 commented Aug 5, 2025

fixes #735

@barakeinav1 barakeinav1 force-pushed the RTMR3-event-check-fix branch from b6a772e to 9ff5760 Compare August 5, 2025 14:27
@barakeinav1 barakeinav1 requested review from a user and pbeza August 5, 2025 14:27
@barakeinav1 barakeinav1 changed the title Fix(node): enforce RTMR3 validation on event checks and add tests fix(node): enforce RTMR3 validation on event checks and add tests Aug 5, 2025
@barakeinav1 barakeinav1 changed the title fix(node): enforce RTMR3 validation on event checks and add tests fix(node): enforce RTMR3 validation on event checks Aug 5, 2025
Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Thank you.

Comment on lines +196 to +197
e["event"].as_str() == Some("compose-hash")
&& e["imr"].as_u64() == Some(RTMR3_INDEX)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
e["event"].as_str() == Some("compose-hash")
&& e["imr"].as_u64() == Some(RTMR3_INDEX)
let is_compose_hash_event = log_entry["event"].as_str() == Some("compose-hash");
let is_rtmr3_measurement = log_entry["imr"].as_u64() == Some(RTMR3_INDEX);
is_compose_hash_event && is_rtmr3_measurement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I assume you meant

let expected_compose_hash = event_log
.iter()
.find(|e| {
let is_compose_hash_event = e["event"].as_str() == Some("compose-hash");
let is_rtmr3_measurement = e["imr"].as_u64() == Some(RTMR3_INDEX);
is_compose_hash_event && is_rtmr3_measurement
})
.and_then(|e| e["digest"].as_str());

I would think this will have worse performance since both check will be computed each time. but maybe the complier will optimise this.


anyway I don't think it is much clearer.
but if you prefer I can change it.

let me know.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see what you are saying. I'm not worried about the performance, as it's just indexing a map of values (nothing is being computed), and in the happy case is unaffected as valid rtmrs will always require all checks.

I'd like extracting them as variables because it gives the reader a better understanding of what is being checked. As someone without expertise knowledge of TEE it's not obvious what that check is doing.

Comment on lines +278 to +298
.find(|e| {
e["event"].as_str() == Some("local-sgx") && e["imr"].as_u64() == Some(RTMR3_INDEX)
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly to the suggestion above, can you extract each condition into a variable with a descriptive name? It's not obvious what we are checking for if one is not familiar with TEE.

Comment on lines +294 to +317
.find(|e| {
e["event"].as_str() == Some("mpc-image-digest")
&& e["imr"].as_u64() == Some(RTMR3_INDEX)
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ditto

None => return false,
};
let replayed_rtmr3 = replay_rtmr(event_log.to_owned(), 3);
let replayed_rtmr3 = replay_rtmr(event_log.to_owned(), RTMR3_INDEX.try_into().unwrap());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What type are we converting to here in the try_into() call? We should avoid unwraps to not cause panics.

Suggested change
let replayed_rtmr3 = replay_rtmr(event_log.to_owned(), RTMR3_INDEX.try_into().unwrap());
let replayed_rtmr3 = replay_rtmr(event_log.to_owned(), RTMR3_INDEX.try_into().unwrap());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

replay_rtmr is expecting u8.

Why not have the const RTMR3_INDEX be u8 instead of u64 instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

serde_json does not have a as_u8 only as_64.
so I'll need to cast either way. this direction seemed a bit better

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see it will be more casting if you cast up from u8 to u64 but it will always give us a strong guarantee at compile time that the conversion never fails, and code won't panic.

It's also obvious to the reader of the code that RTMR3_INDEX is supposed to be a small value by setting it to a u8.

If you cast up to u64 from u8 it will be quite simple, just add as u64 as a suffix.

 e["imr"].as_u64() == Some(RTMR3_INDEX as u64)

@barakeinav1 barakeinav1 force-pushed the RTMR3-event-check-fix branch from e8f0d00 to b1890a5 Compare August 6, 2025 06:59
@barakeinav1 barakeinav1 requested a review from a user August 6, 2025 07:00
@barakeinav1 barakeinav1 enabled auto-merge August 6, 2025 07:11
@barakeinav1 barakeinav1 disabled auto-merge August 6, 2025 11:26
@barakeinav1 barakeinav1 force-pushed the RTMR3-event-check-fix branch from 8a1b332 to fd1931d Compare August 10, 2025 08:30
@barakeinav1 barakeinav1 force-pushed the RTMR3-event-check-fix branch from 5982cf0 to a41cdb6 Compare August 10, 2025 08:56
@barakeinav1 barakeinav1 enabled auto-merge August 10, 2025 09:26
@barakeinav1 barakeinav1 added this pull request to the merge queue Aug 10, 2025
Merged via the queue into main with commit 07b9590 Aug 10, 2025
14 checks passed
@barakeinav1 barakeinav1 deleted the RTMR3-event-check-fix branch August 10, 2025 10:22
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.

bug: Verification missing RTMR3 type check for event logs

2 participants