OpenDevicePartnership / OpenDevicePartnership/patina
[Task] Review FV `new_from_address()` safety invariants
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 544
- Forks
- 54
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 30
Description
VolumeRef::new_from_address() and FirmwareVolume::new_from_address() are unsafe fn functions whose safety contracts are difficult for callers to satisfy correctly.
Callers must guarantee the backing memory is valid for fv_length bytes, but fv_length is not known until the function reads it from untrusted memory at base_address. The API only accepts an address and not an independently trusted size so callers have no way to supply a bound even when they have one. As a result, the function passes an untrusted fv_length to slice::from_raw_parts(), and the internal validation in new() is defeated because the buffer was created from the same value being checked.
As unsafe fn functions, they require that the caller must ensure this address is valid for N bytes, but the contract only works if the caller can actually know N. In this instance, the new_from_address function takes base_address then reads fv_length from the memory at that address and uses it immediately. Whether the contract can lead to real Undefined Behavior depends on whether callers can independently bound the memory region. Some callers do this, for example Firmware Volume HOBS have both base_address and length fields.
This issue tracks reviewing the safety conditions and interface/documentation to determine if there is a clearer and safer way to have the size be passed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read sdk/patina_ffs/src/volume.rs at the implementations of VolumeRef::new_from_address() and FirmwareVolume::new_from_address(), then inspect callers such as Firmware Volume HOB handling, which provides both an address and length. Review whether the safety contracts and interface give callers an independently trusted bound; done means the safety conditions and resulting API or documentation are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- embedded-iot
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100