Skip to content

[CHERRY-PICK] Stop USB enumeration in case a malformed descriptor is found (#410) - #412

Merged
Oliver Smith-Denny (os-d) merged 1 commit into
microsoft:release/202208from
os-d:osde/cp_usb_enum
May 23, 2023
Merged

Oliver Smith-Denny (os-d) merged 1 commit into
microsoft:release/202208from
os-d:osde/cp_usb_enum

Conversation

@os-d

Copy link
Copy Markdown
Contributor

Description

This is a cherry-pick of commit 714d41b to release/202208.

When parsing interface descriptors for an attached USB device, the USB bus driver correctly handles cases where a device has a malformed interface . UsbParseInterfaceDesc returns NULL in such cases.

UsbParseConfigDesc which parses interface descriptors, stops parsing in case UsbParseInterfaceDesc returns NULL but still returns EFI_SUCCESS along with a partially filled USB_CONFIG_DESC structure.

This causes access exceptions when attempts are made subsequently to communicate with the downstream device (for e.g. during endpoint configuration) as the driver does not have valid interface descriptor structures associated with the device.

To fix this, UsbParseConfigDesc should take the error path in cases where UsbParseInterfaceDesc returns NULL and abandon enumerating the device. This will allow a platform to boot instead of crashing when a buggy USB device is attached to it.

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

How This Was Tested

Tested on a platform with a USB keyboard that returns a malformed USB interface descriptor. The platform fails to boot with an access violation exception without this fix.

Integration Instructions

Updating to the latest MU_BASECORE will automatically include this fix if the UsbBus DXE driver is included in the fdf/dscs.

Preface

Please ensure you have read the contribution docs prior
to submitting the pull request. In particular,
pull request guidelines.

Description

<Please include a description of the change and why this change was made.>

For each item, place an "x" in between [ and ] if true. Example: [x].
(you can also check items in the GitHub UI)

  • Impacts functionality?
    • Functionality - Does the change ultimately impact how firmware functions?
    • Examples: Add a new library, publish a new PPI, update an algorithm, ...
  • Impacts security?
    • Security - Does the change have a direct security impact on an application,
      flow, or firmware?
    • Examples: Crypto algorithm change, buffer overflow fix, parameter
      validation improvement, ...
  • Breaking change?
    • Breaking change - Will anyone consuming this change experience a break
      in build or boot behavior?
    • Examples: Add a new library class, move a module to a different repo, call
      a function in a new library class in a pre-existing module, ...
  • Includes tests?
    • Tests - Does the change include any explicit test code?
    • Examples: Unit tests, integration tests, robot tests, ...
  • Includes documentation?
    • Documentation - Does the change contain explicit documentation additions
      outside direct code modifications (and comments)?
    • Examples: Update readme file, add feature readme file, link to documentation
      on an a separate Web page, ...

How This Was Tested

<Please describe the test(s) that were run to verify the changes.>

Integration Instructions

<Describe how these changes should be integrated. Use N/A if nothing is required.>

…ft#410)

## Description

When parsing interface descriptors for an attached USB device, the USB
bus driver correctly handles cases where a device has a malformed
interface . `UsbParseInterfaceDesc` returns `NULL` in such cases.

`UsbParseConfigDesc` which parses interface descriptors, stops parsing
in case `UsbParseInterfaceDesc` returns NULL but still returns
`EFI_SUCCESS` along with a partially filled `USB_CONFIG_DESC` structure.

This causes access exceptions when attempts are made subsequently to
communicate with the downstream device (for e.g. during endpoint
configuration) as the driver does not have valid interface descriptor
structures associated with the device.

To fix this, `UsbParseConfigDesc` should take the error path in cases
where `UsbParseInterfaceDesc` returns NULL and abandon enumerating the
device. This will allow a platform to boot instead of crashing when a
buggy USB device is attached to it.

- [x] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?


## How This Was Tested

Tested on a platform with a USB keyboard that returns a malformed USB
interface descriptor. The platform fails to boot with an access
violation exception without this fix.

## Integration Instructions

Updating to the latest MU_BASECORE will automatically include this fix
if the UsbBus DXE driver is included in the fdf/dscs.
@github-actions github-actions Bot added the impact:non-functional Does not have a functional impact label May 23, 2023
@os-d
Oliver Smith-Denny (os-d) merged commit 3179184 into microsoft:release/202208 May 23, 2023
@os-d
Oliver Smith-Denny (os-d) deleted the osde/cp_usb_enum branch May 23, 2023 21:26
Project Mu Bot [bot] (ProjectMuBot) referenced this pull request in microsoft/mu_tiano_platforms May 24, 2023
Introduces 10 new commits in [MU_BASECORE](https://github.com/microsoft/mu_basecore.git).

<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/microsoft/mu_basecore/commit/a296f04604fd32db6d862646f3dd25ba2d5514e2">a296f0</a> Introduce Standalone MM Policy Service (<a href="https://github.com/microsoft/mu_basecore/pull/390">#390</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/d4d7856f93bdcfdb785a81aa3830d8e871f6b113">d4d785</a> Add basic wrappers to the Policy Library (<a href="https://github.com/microsoft/mu_basecore/pull/396">#396</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/68f1e801de4c8f1ab970ffb331eb8d4efd69ab9b">68f1e8</a> pip: update edk2-pytool-extensions requirement from ~=0.23.0 to ~=0.23.2 (<a href="https://github.com/microsoft/mu_basecore/pull/397">#397</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/346e17b532854248bf6378b70075142e4751bff8">346e17</a> pip: bump edk2-basetools from 0.1.45 to 0.1.48 (<a href="https://github.com/microsoft/mu_basecore/pull/401">#401</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/19a366b2b3272bc6031fbab65ad1326085f2303c">19a366</a> Create Github Workflow to publish basetools on release (<a href="https://github.com/microsoft/mu_basecore/pull/385">#385</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/656456cd5fcd0f104e9a8813b953b1ab7492cc71">656456</a> Additional CodeQL Fixes (<a href="https://github.com/microsoft/mu_basecore/pull/400">#400</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/01a4ed58fbb9c284fa254ec5b04be4febd8a0c9d">01a4ed</a> pip: update edk2-pytool-library requirement from ~=0.14.1 to ~=0.15.0 (<a href="https://github.com/microsoft/mu_basecore/pull/405">#405</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/f421222215ad57feed9bd29a38ff61e13adcf2df">f42122</a> pip: bump antlr4-python3-runtime from 4.12.0 to 4.13.0 (<a href="https://github.com/microsoft/mu_basecore/pull/408">#408</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/c03dc558c048af7863b7d7e30fbf2e34b5b53c51">c03dc5</a> pip: update edk2-pytool-extensions requirement from ~=0.23.2 to ~=0.23.3 (<a href="https://github.com/microsoft/mu_basecore/pull/406">#406</a>)</li>
<li><a href="https://github.com/microsoft/mu_basecore/commit/3179184b360bb7ad2dc979f45cddb242d6b995c3">317918</a> [CHERRY-PICK] Stop USB enumeration in case a malformed descriptor is found (<a href="https://github.com/microsoft/mu_basecore/pull/410">#410</a>) (<a href="https://github.com/microsoft/mu_basecore/pull/412">#412</a>)</li>
</ul>
</details>

Signed-off-by: Project Mu Bot <mubot@microsoft.com>
Michael Kubacki (makubacki) referenced this pull request in microsoft/mu_tiano_platforms May 24, 2023
Bumps MU_BASECORE from `2022080002.0.1` to `2022080002.0.2`

Introduces 10 new commits in
[MU_BASECORE](https://github.com/microsoft/mu_basecore.git).

<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/a296f04604fd32db6d862646f3dd25ba2d5514e2">a296f0</a>
Introduce Standalone MM Policy Service (<a
href="https://github.com/microsoft/mu_basecore/pull/390">#390</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/d4d7856f93bdcfdb785a81aa3830d8e871f6b113">d4d785</a>
Add basic wrappers to the Policy Library (<a
href="https://github.com/microsoft/mu_basecore/pull/396">#396</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/68f1e801de4c8f1ab970ffb331eb8d4efd69ab9b">68f1e8</a>
pip: update edk2-pytool-extensions requirement from ~=0.23.0 to ~=0.23.2
(<a
href="https://github.com/microsoft/mu_basecore/pull/397">#397</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/346e17b532854248bf6378b70075142e4751bff8">346e17</a>
pip: bump edk2-basetools from 0.1.45 to 0.1.48 (<a
href="https://github.com/microsoft/mu_basecore/pull/401">#401</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/19a366b2b3272bc6031fbab65ad1326085f2303c">19a366</a>
Create Github Workflow to publish basetools on release (<a
href="https://github.com/microsoft/mu_basecore/pull/385">#385</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/656456cd5fcd0f104e9a8813b953b1ab7492cc71">656456</a>
Additional CodeQL Fixes (<a
href="https://github.com/microsoft/mu_basecore/pull/400">#400</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/01a4ed58fbb9c284fa254ec5b04be4febd8a0c9d">01a4ed</a>
pip: update edk2-pytool-library requirement from ~=0.14.1 to ~=0.15.0
(<a
href="https://github.com/microsoft/mu_basecore/pull/405">#405</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/f421222215ad57feed9bd29a38ff61e13adcf2df">f42122</a>
pip: bump antlr4-python3-runtime from 4.12.0 to 4.13.0 (<a
href="https://github.com/microsoft/mu_basecore/pull/408">#408</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/c03dc558c048af7863b7d7e30fbf2e34b5b53c51">c03dc5</a>
pip: update edk2-pytool-extensions requirement from ~=0.23.2 to ~=0.23.3
(<a
href="https://github.com/microsoft/mu_basecore/pull/406">#406</a>)</li>
<li><a
href="https://github.com/microsoft/mu_basecore/commit/3179184b360bb7ad2dc979f45cddb242d6b995c3">317918</a>
[CHERRY-PICK] Stop USB enumeration in case a malformed descriptor is
found (<a
href="https://github.com/microsoft/mu_basecore/pull/410">#410</a>) (<a
href="https://github.com/microsoft/mu_basecore/pull/412">#412</a>)</li>
</ul>
</details>

Signed-off-by: Project Mu Bot <mubot@microsoft.com>
Kat Perez (kat-perez) pushed a commit to kat-perez/mu_basecore that referenced this pull request Nov 9, 2025
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

4 participants