Skip to content

Patina: Fix RAW FFS file handling and harden section parsing#1369

Merged
vineelko merged 4 commits intoOpenDevicePartnership:mainfrom
vineelko:users/vineelko/fv_section_parsing_fix_0304
Mar 11, 2026
Merged

Patina: Fix RAW FFS file handling and harden section parsing#1369
vineelko merged 4 commits intoOpenDevicePartnership:mainfrom
vineelko:users/vineelko/fv_section_parsing_fix_0304

Conversation

@vineelko
Copy link
Copy Markdown
Contributor

@vineelko vineelko commented Mar 4, 2026

Description

  1. Handle RAW File types:

    • The current implementation tries to produce sections irrespective of the file
      type. This do not hold true for RAW file types. As per PI spec below,

      The file type EFI_FV_FILETYPE_RAW denotes a file that does not contain
      sections and is treated as a raw data file. The consumer of this type of
      file must have a priori knowledge of its format and content. Because there
      are no sections, there are no construction rules.

    • Trying to decode the body of these files as Section header can result in
      incorrect parsing.

    Fixes the following bug:

    [ INFO]: \patina\sdk\patina\src\pi\serializable\serializable_fv.rs@078: Parsing FV: d2c29ba7-3809-480f-9c3d-de389c61425a
    [ INFO]: \patina\sdk\patina\src\pi\serializable\serializable_fv.rs@089:     Parsing file: 197db236-f856-4924-90f8-cdf12fb875f3
    [ INFO]: \patina\sdk\patina\src\pi\fw_fs.rs@801: Section type 0x0 unrecognized 4 1, treating as opaque with no metadata
    [ERROR]: dxe_readiness_capture\src\lib.rs@031: panicked at \patina\sdk\patina\src\pi\fw_fs.rs:805:56:
    [ERROR]: dxe_readiness_capture\src\lib.rs@031: slice index starts at 4 but ends at 1
    
  2. Improve safety in FFS section parsing by replacing direct slice indexing with
    bounds checked get() calls and proper error propagation when buffers are
    malformed. General code cleanup.


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

How This Was Tested

Booted to UEFI Shell on Q35

Integration Instructions

NA

@patina-automation
Copy link
Copy Markdown
Contributor

patina-automation Bot commented Mar 4, 2026

ℹ️ QEMU Validation Skipped - PR Merged

The Patina QEMU PR validation workflow did not run because the PR was merged before validation started.

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/22963784661

Note: Previous results are available in this comment's edit history.

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@github-actions github-actions Bot added impact:non-functional Does not have a functional impact impact:testing Affects testing labels Mar 4, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 96.87500% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdk/patina/src/pi/fw_fs.rs 96.77% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
@vineelko vineelko force-pushed the users/vineelko/fv_section_parsing_fix_0304 branch from 2d91fd6 to 8d5ac18 Compare March 5, 2026 16:54
@vineelko
Copy link
Copy Markdown
Contributor Author

vineelko commented Mar 5, 2026

Please hold on this PR, Got the fv from IDC folks, It looks like there is more to the actual bug. I will notify once I finished root causing the issue.

@vineelko vineelko force-pushed the users/vineelko/fv_section_parsing_fix_0304 branch 2 times, most recently from 67de51a to 6441216 Compare March 6, 2026 00:57
@vineelko
Copy link
Copy Markdown
Contributor Author

vineelko commented Mar 6, 2026

As mentioned before, the section parsing failed with below error(Section Type 0x0).

[ INFO]: E:\repos\patina\sdk\patina\src\pi\serializable\serializable_fv.rs@078: Parsing FV: d2c29ba7-3809-480f-9c3d-de389c61425a
[ INFO]: E:\repos\patina\sdk\patina\src\pi\serializable\serializable_fv.rs@089:     Parsing file: 197db236-f856-4924-90f8-cdf12fb875f3
[ INFO]: E:\repos\patina\sdk\patina\src\pi\fw_fs.rs@801: Section type 0x0 unrecognized 4 1, treating as opaque with no metadata
[ERROR]: dxe_readiness_capture\src\lib.rs@031: panicked at E:\repos\patina\sdk\patina\src\pi\fw_fs.rs:805:56:
[ERROR]: dxe_readiness_capture\src\lib.rs@031: slice index starts at 4 but ends at 1

The parsing of sections in the section iterator required few fixes, especially around handling SectionType::ALL to ensure parity with the C UEFI implementation, where the entire body is returned.

However, after looking at the FV, The current implementation attempts to produce sections regardless of the file type. This assumption does not hold true for RAW file types. According to the PI specification below,

image image image

Trying to decode the body of these files as Section header can result in incorrect parsing. This is addressed in the latest iteration.

PR is up for review.

@vineelko vineelko force-pushed the users/vineelko/fv_section_parsing_fix_0304 branch from 6441216 to 46743be Compare March 6, 2026 16:39
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
Comment thread sdk/patina/src/pi/fw_fs.rs Outdated
@vineelko vineelko force-pushed the users/vineelko/fv_section_parsing_fix_0304 branch from 46743be to 9e9e9ee Compare March 10, 2026 19:15
@makubacki
Copy link
Copy Markdown
Collaborator

@vineelko, the PR title gives the impression this is a broad FFS section parsing issue and I think it really comes down to RAW files and some other cleanup. If that's the case, could you consider updating the title?

@vineelko vineelko changed the title Patina: Fix FFS section parsing Patina: Fix RAW FFS file handling and harden section parsing Mar 11, 2026
@vineelko
Copy link
Copy Markdown
Contributor Author

Fixed the title Michael.

Improve safety in FFS section parsing by replacing direct slice indexing with
bounds checked `get()` calls and proper error propagation when buffers are
malformed.

Add handling for SectionType::ALL to treat the entire section buffer as raw data
per UEFI C implementation.

Update DXEFV.fv test files.

Fixes the following bug:
```
[ INFO]: \patina\sdk\patina\src\pi\serializable\serializable_fv.rs@078: Parsing FV: d2c29ba7-3809-480f-9c3d-de389c61425a
[ INFO]: \patina\sdk\patina\src\pi\serializable\serializable_fv.rs@089:     Parsing file: 197db236-f856-4924-90f8-cdf12fb875f3
[ INFO]: \patina\sdk\patina\src\pi\fw_fs.rs@801: Section type 0x0 unrecognized 4 1, treating as opaque with no metadata
[ERROR]: dxe_readiness_capture\src\lib.rs@031: panicked at \patina\sdk\patina\src\pi\fw_fs.rs:805:56:
[ERROR]: dxe_readiness_capture\src\lib.rs@031: slice index starts at 4 but ends at 1
```

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
- Only a few structs could be marked as ZeroCopy compatible. Structs containing
  r-efi::Guid fields cannot implement ZeroCopy because the r-efi types do not
  implement the required traits.

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
- The current implementation tries to produce sections irrespective of the file
  type. This do not hold true for RAW file types. As per PI spec below,

    The file type EFI_FV_FILETYPE_RAW denotes a file that does not contain
    sections and is treated as a raw data file. The consumer of this type of
    file must have a priori knowledge of its format and content. Because there
    are no sections, there are no construction rules.

- Trying to decode the body of these files as Section header can result in
  incorrect parsing.

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
- Make the Section Type: ALL as filter only, if found in Section type will
  return an error
- Add unaligned reads to prevent undefined behavior

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
@vineelko vineelko force-pushed the users/vineelko/fv_section_parsing_fix_0304 branch from 9e9e9ee to efc7452 Compare March 11, 2026 16:31
@vineelko vineelko enabled auto-merge (squash) March 11, 2026 16:34
@vineelko vineelko merged commit 5d886c6 into OpenDevicePartnership:main Mar 11, 2026
9 checks passed
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 impact:testing Affects testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants