Skip to content

Conversation

@Raymond-MS
Copy link
Contributor

@Raymond-MS Raymond-MS commented Jan 9, 2026

Description

Added missing Safety comments to the following files in patina_dxe_core:

allocator.rs
config_tables.rs
cpu.rs
debugger_reload.rs
driver_services.rs

Relates to: #583

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Built SBSA successfully in patina-dxe-core-qemu.

Integration Instructions

N/A

@Raymond-MS Raymond-MS requested a review from makubacki January 9, 2026 01:47
@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Jan 9, 2026
@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_dxe_core/src/driver_services.rs 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Raymond-MS Raymond-MS force-pushed the personal/rdiaz/SafetyComments2 branch from 9fc749a to d6b3944 Compare January 9, 2026 01:52
.or(Err(EfiError::InvalidParameter))?;
let driver_binding_interface = driver_binding_interface as *mut efi::protocols::driver_binding::Protocol;
// Safety: driver_binding_interface is validated above, would have been caught with the .or and ? above with
// the loop being terminated.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is again relying on get_interface_for_handle to give us a valid pointer back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry, I am a little confused, is that not what is mentioned? driver_binding_interface is set twice. Once with the .get_interface_for_handle and then again right after as a mutable pointer. We validate the pointer with the .or, right? Is there a different way you wanted me to word this?

for handle in driver_binding_handles {
match PROTOCOL_DB.get_interface_for_handle(handle, efi::protocols::driver_family_override::PROTOCOL_GUID) {
Ok(protocol) => {
// Safety: Pointer is validated using .expect(), will panic if .as_mut() returns a NULL pointer
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we've been relatively loose with this overall, but there is more than just the pointer being null that needs to be considered. Such as:

  • Aligned for the type
  • Points to a properly initialized type that is not dangling
  • Aliasing - Since this is mutable no other references may violate aliasing expectations to the address
  • Lifetime - This reference won't outlive the region

Most of these are usually handled and accounted for. I just want to make sure they're actually being considered equally to whether the pointer is null and getting called out in comments as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry Michael, was this a general comment when investigating unsafe blocks or does this relate to this line specifically? In this situation, we don't need to validate all of those things, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a general comment to make sure that's being taken into account for each case since a lot end up only describing the null pointer aspect.

@Raymond-MS Raymond-MS force-pushed the personal/rdiaz/SafetyComments2 branch from d6b3944 to 8b7fd50 Compare January 10, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants