Acquire a lock when iterating gHandleList, as in EDK2

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2021-11-27 21:48:24 +03:00
parent fbd1d0fbc9
commit f6334a521c
8 changed files with 121 additions and 47 deletions

View File

@ -74,7 +74,9 @@ CoreConnectController (
//
// Make sure ControllerHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (ControllerHandle);
CoreReleaseProtocolLock ();
if (EFI_ERROR(Status)) {
return Status;
}
@ -159,7 +161,9 @@ CoreConnectController (
//
// Make sure the DriverBindingHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (ControllerHandle);
CoreReleaseProtocolLock ();
if (EFI_ERROR(Status)) {
//
// Release the protocol lock on the handle database
@ -273,7 +277,9 @@ AddSortedDriverBindingProtocol (
//
// Make sure the DriverBindingHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (DriverBindingHandle);
CoreReleaseProtocolLock ();
if (EFI_ERROR(Status)) {
return;
}
@ -782,8 +788,10 @@ CoreDisconnectController (
//
// Make sure ControllerHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
CoreReleaseProtocolLock ();
return Status;
}
@ -793,10 +801,12 @@ CoreDisconnectController (
if (ChildHandle != NULL) {
Status = CoreValidateHandle (ChildHandle);
if (EFI_ERROR(Status)) {
CoreReleaseProtocolLock ();
return Status;
}
}
CoreReleaseProtocolLock ();
Handle = ControllerHandle;
//

View File

@ -727,18 +727,24 @@ CoreUninstallProtocolInterface (
return EFI_INVALID_PARAMETER;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//
// Check that UserHandle is a valid handle
//
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
// CoreAcquireProtocolLock ();
//
// Check that Protocol exists on UserHandle, and Interface matches the interface in the database
@ -1013,12 +1019,18 @@ CoreOpenProtocol (
}
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//
// Check for invalid UserHandle
//
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
//
@ -1028,21 +1040,26 @@ CoreOpenProtocol (
case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
if (UserHandle == ControllerHandle) {
return EFI_INVALID_PARAMETER;
// return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
break;
case EFI_OPEN_PROTOCOL_BY_DRIVER :
case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
@ -1052,7 +1069,8 @@ CoreOpenProtocol (
case EFI_OPEN_PROTOCOL_EXCLUSIVE :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
// return Status;
goto Done;
}
break;
case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :
@ -1060,13 +1078,15 @@ CoreOpenProtocol (
case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :
break;
default:
return EFI_INVALID_PARAMETER;
// return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//CoreAcquireProtocolLock ();
//
// Look at each protocol interface for a match
@ -1224,31 +1244,37 @@ CoreCloseProtocol (
LIST_ENTRY *Link;
OPEN_PROTOCOL_DATA *OpenData;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//
// Check for invalid parameters
//
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
Status = CoreValidateHandle (AgentHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
if (ControllerHandle != NULL) {
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
}
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//CoreAcquireProtocolLock ();
//
// Look at each protocol interface for a match
@ -1442,6 +1468,14 @@ CoreProtocolsPerHandle (
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR (Status)) {
goto Done;
}
Handle = (IHANDLE *)UserHandle;
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
ProtocolCount++;
}

View File

@ -248,6 +248,7 @@ CoreReleaseProtocolLock (
/**
Check whether a handle is a valid EFI_HANDLE
The gProtocolDatabaseLock must be owned
@param UserHandle The handle to check

View File

@ -193,22 +193,28 @@ CoreReinstallProtocolInterface (
PROTOCOL_INTERFACE *Prot;
PROTOCOL_ENTRY *ProtEntry;
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
}
// Status = CoreValidateHandle (UserHandle);
// if (EFI_ERROR(Status)) {
// return Status;
// }
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
}
Handle = (IHANDLE *) UserHandle;
// Handle = (IHANDLE *) UserHandle;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR (Status)) {
goto Done;
}
Handle = (IHANDLE *) UserHandle;
//
// Check that Protocol exists on UserHandle, and Interface matches the interface in the database
//

View File

@ -68,7 +68,9 @@ CoreConnectController (
//
// Make sure ControllerHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (ControllerHandle);
CoreReleaseProtocolLock ();
if (EFI_ERROR(Status)) {
return Status;
}
@ -268,7 +270,9 @@ AddSortedDriverBindingProtocol (
//
// Make sure the DriverBindingHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (DriverBindingHandle);
CoreReleaseProtocolLock ();
if (EFI_ERROR(Status)) {
return;
}
@ -746,8 +750,10 @@ CoreDisconnectController (
//
// Make sure ControllerHandle is valid
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
CoreReleaseProtocolLock ();
return Status;
}
@ -757,10 +763,11 @@ CoreDisconnectController (
if (ChildHandle != NULL) {
Status = CoreValidateHandle (ChildHandle);
if (EFI_ERROR(Status)) {
CoreReleaseProtocolLock ();
return Status;
}
}
CoreReleaseProtocolLock ();
Handle = ControllerHandle;
//

View File

@ -1002,12 +1002,17 @@ CoreOpenProtocol (
return EFI_INVALID_PARAMETER;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//
// Check for invalid UserHandle
//
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
//
@ -1017,31 +1022,32 @@ CoreOpenProtocol (
case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
if (UserHandle == ControllerHandle) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
break;
case EFI_OPEN_PROTOCOL_BY_DRIVER :
case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
break;
case EFI_OPEN_PROTOCOL_EXCLUSIVE :
Status = CoreValidateHandle (ImageHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
break;
case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :
@ -1049,13 +1055,14 @@ CoreOpenProtocol (
case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :
break;
default:
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//CoreAcquireProtocolLock ();
//
// Look at each protocol interface for a match
@ -1238,31 +1245,37 @@ CoreCloseProtocol (
LIST_ENTRY *Link;
OPEN_PROTOCOL_DATA *OpenData;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//
// Check for invalid parameters
//
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
Status = CoreValidateHandle (AgentHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
if (ControllerHandle != NULL) {
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR(Status)) {
return Status;
goto Done;
}
}
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
//CoreAcquireProtocolLock ();
//
// Look at each protocol interface for a match
@ -1435,12 +1448,6 @@ CoreProtocolsPerHandle (
UINTN ProtocolCount;
EFI_GUID **Buffer;
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
}
Handle = (IHANDLE *)UserHandle;
if (ProtocolBuffer == NULL) {
return EFI_INVALID_PARAMETER;
@ -1456,6 +1463,14 @@ CoreProtocolsPerHandle (
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
goto Done;
}
Handle = (IHANDLE *)UserHandle;
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
ProtocolCount++;
}

View File

@ -242,6 +242,7 @@ CoreReleaseProtocolLock (
/**
Check whether a handle is a valid EFI_HANDLE
The gProtocolDatabaseLock must be owned
@param UserHandle The handle to check

View File

@ -188,22 +188,22 @@ CoreReinstallProtocolInterface (
PROTOCOL_INTERFACE *Prot;
PROTOCOL_ENTRY *ProtEntry;
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR(Status)) {
return Status;
}
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
}
Handle = (IHANDLE *) UserHandle;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
Status = CoreValidateHandle (UserHandle);
if (EFI_ERROR (Status)) {
goto Done;
}
Handle = (IHANDLE *) UserHandle;
//
// Check that Protocol exists on UserHandle, and Interface matches the interface in the database
//