Skip to content

[Bug]: Potential infinite loop and incorrect DeviceList handling in OpalPassword #11336

@HunterChang030

Description

@HunterChang030

Is there an existing issue for this?

  • I have searched existing issues

Bug Type

  • Firmware
  • Tool
  • Unit Test

What packages are impacted?

SecurityPkg

Which targets are impacted by this bug?

DEBUG, RELEASE

Current Behavior

In Line 2331, RemoveDevice (), SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
The logic here is incorrect if there are multiple devices in DeviceList.
This way will clear all devices in DeviceList and then cause issue when removing other devices.

if (mOpalDriver.DeviceList == Dev) {
  mOpalDriver.DeviceList = NULL;
  return;
}

In Line 2336, RemoveDevice (), SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
There is a potential infinite loop if TmpDev->Next not equal to Dev

TmpDev = mOpalDriver.DeviceList;
while (TmpDev->Next != NULL) {
  if (TmpDev->Next == Dev) {
    TmpDev->Next = Dev->Next;
    break;
  }
}

Expected Behavior

In Line 2331, RemoveDevice (), SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
It should point to Dev->Next

if (mOpalDriver.DeviceList == Dev) {
  mOpalDriver.DeviceList = Dev->Next;
  return;
}

In Line 2336, RemoveDevice (), SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
TmpDev should point to next device if TmpDev->Next not equal to Dev

TmpDev = mOpalDriver.DeviceList;
while (TmpDev->Next != NULL) {
  if (TmpDev->Next == Dev) {
    TmpDev->Next = Dev->Next;
    break;
  }
  TmpDev = TmpDev->Next;
}

Steps To Reproduce

  1. Add debug msg in OpalEfiDriverBindingStop().
  2. Connect two nvme Opal devices on systems.
  3. Boot to EFI Shell.
  4. Enter drivers, find OpalPasswordDxe.
  5. Unload OpalPasswordDxe with unload command.
  6. OpalEfiDriverBindingStop() return EFI_NOT_FOUND for the second devices.

Build Environment

- OS(s): Windows 11
- Tool Chain(s): VS2019

Version Information

ALL

Urgency

Medium

Are you going to fix this?

I will fix it

Do you need maintainer feedback?

Maintainer feedback requested

Anything else?

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions