mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-27 23:54:02 +02:00
Ring3: Added sanity checks.
This commit is contained in:
parent
6365e5bc8e
commit
aba3b264df
@ -156,6 +156,7 @@ Ring3Call (
|
||||
Status = Function5 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4]);
|
||||
break;
|
||||
default:
|
||||
Status = EFI_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -238,23 +238,31 @@ CoreFileRead (
|
||||
VOID *Ring3Buffer;
|
||||
|
||||
File = (RING3_EFI_FILE_PROTOCOL *)This;
|
||||
DEBUG ((DEBUG_INFO, "Ring3 Read: check 1\n"));
|
||||
Ring3Buffer = NULL;
|
||||
Ring3BufferSize = NULL;
|
||||
|
||||
DisableSMAP ();
|
||||
if (BufferSize != NULL) {
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, sizeof (UINTN *), (VOID **)&Ring3BufferSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Ring3BufferSize = *BufferSize;
|
||||
}
|
||||
|
||||
if (Buffer != NULL) {
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, *BufferSize, (VOID **)&Ring3Buffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if (Ring3BufferSize != NULL) {
|
||||
FreePool (Ring3BufferSize);
|
||||
}
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
EnableSMAP ();
|
||||
DEBUG ((DEBUG_INFO, "Ring3 Read: check 2\n"));
|
||||
|
||||
Status = GoToRing3 (
|
||||
3,
|
||||
@ -263,20 +271,22 @@ CoreFileRead (
|
||||
Ring3BufferSize,
|
||||
Ring3Buffer
|
||||
);
|
||||
DEBUG ((DEBUG_INFO, "Ring3 Read: check 3\n"));
|
||||
|
||||
DisableSMAP ();
|
||||
if ((!EFI_ERROR (Status)) && (Ring3Buffer != NULL) && (Buffer != NULL)) {
|
||||
if ((Ring3Buffer != NULL) && (Buffer != NULL) && (*BufferSize >= *Ring3BufferSize)) {
|
||||
CopyMem (Buffer, Ring3Buffer, *Ring3BufferSize);
|
||||
}
|
||||
|
||||
if (Ring3Buffer != NULL) {
|
||||
FreePool (Ring3Buffer);
|
||||
}
|
||||
|
||||
if (Ring3BufferSize != NULL) {
|
||||
*BufferSize = *Ring3BufferSize;
|
||||
|
||||
DEBUG ((DEBUG_INFO, "Ring3 Read: check 3.5\n"));
|
||||
FreePool (Ring3BufferSize);
|
||||
}
|
||||
EnableSMAP ();
|
||||
DEBUG ((DEBUG_INFO, "Ring3 Read: check 4\n"));
|
||||
|
||||
return Status;
|
||||
}
|
||||
@ -326,14 +336,20 @@ CoreFileGetPosition (
|
||||
UINT64 *Ring3Position;
|
||||
|
||||
File = (RING3_EFI_FILE_PROTOCOL *)This;
|
||||
Ring3Position = NULL;
|
||||
|
||||
if (Position != NULL) {
|
||||
DisableSMAP ();
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, sizeof (UINT64), (VOID **)&Ring3Position);
|
||||
EnableSMAP ();
|
||||
if (EFI_ERROR (Status)) {
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Ring3Position = *Position;
|
||||
EnableSMAP ();
|
||||
}
|
||||
|
||||
Status = GoToRing3 (
|
||||
2,
|
||||
(VOID *)mRing3FileProtocol.GetPosition,
|
||||
@ -341,11 +357,13 @@ CoreFileGetPosition (
|
||||
Ring3Position
|
||||
);
|
||||
|
||||
if (Ring3Position != NULL) {
|
||||
DisableSMAP ();
|
||||
*Position = *Ring3Position;
|
||||
|
||||
FreePool (Ring3Position);
|
||||
EnableSMAP ();
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
@ -367,30 +385,47 @@ CoreFileGetInfo (
|
||||
VOID *Ring3Buffer;
|
||||
|
||||
File = (RING3_EFI_FILE_PROTOCOL *)This;
|
||||
Ring3Buffer = NULL;
|
||||
Ring3BufferSize = NULL;
|
||||
Ring3InformationType = NULL;
|
||||
|
||||
DisableSMAP ();
|
||||
if (BufferSize != NULL) {
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, sizeof (UINTN *), (VOID **)&Ring3BufferSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Ring3BufferSize = *BufferSize;
|
||||
}
|
||||
|
||||
if (Buffer != NULL) {
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, *BufferSize, (VOID **)&Ring3Buffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if (Ring3BufferSize != NULL) {
|
||||
FreePool (Ring3BufferSize);
|
||||
}
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
if (InformationType != NULL) {
|
||||
Status = CoreAllocatePool (EfiRing3MemoryType, sizeof (EFI_GUID), (VOID **)&Ring3InformationType);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if (Ring3BufferSize != NULL) {
|
||||
FreePool (Ring3BufferSize);
|
||||
}
|
||||
if (Ring3Buffer != NULL) {
|
||||
FreePool (Ring3Buffer);
|
||||
}
|
||||
EnableSMAP ();
|
||||
return Status;
|
||||
}
|
||||
|
||||
CopyGuid (Ring3InformationType, InformationType);
|
||||
}
|
||||
EnableSMAP ();
|
||||
|
||||
Status = GoToRing3 (
|
||||
@ -403,13 +438,23 @@ CoreFileGetInfo (
|
||||
);
|
||||
|
||||
DisableSMAP ();
|
||||
if ((Ring3Buffer != NULL) && (Buffer != NULL) && (*BufferSize >= *Ring3BufferSize)) {
|
||||
CopyMem (Buffer, Ring3Buffer, *Ring3BufferSize);
|
||||
}
|
||||
|
||||
if (Ring3BufferSize != NULL) {
|
||||
*BufferSize = *Ring3BufferSize;
|
||||
|
||||
CopyMem (Buffer, Ring3Buffer, *Ring3BufferSize);
|
||||
|
||||
FreePool (Ring3BufferSize);
|
||||
}
|
||||
|
||||
if (Ring3Buffer != NULL) {
|
||||
FreePool (Ring3Buffer);
|
||||
}
|
||||
|
||||
if (Ring3InformationType != NULL) {
|
||||
FreePool (Ring3InformationType);
|
||||
}
|
||||
EnableSMAP ();
|
||||
|
||||
return Status;
|
||||
|
Loading…
x
Reference in New Issue
Block a user