Add validation on ACPI_S3_CONTEXT.S3DebugBufferAddress, moreover only debug tip could override IDT entry for INT3.

Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13640 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff 2012-08-16 04:36:24 +00:00
parent 54e27ada3e
commit f4a25e813f
3 changed files with 37 additions and 24 deletions

View File

@ -2,7 +2,7 @@
This is an implementation of the ACPI S3 Save protocol. This is defined in This is an implementation of the ACPI S3 Save protocol. This is defined in
S3 boot path specification 0.9. S3 boot path specification 0.9.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions are licensed and made available under the terms and conditions
@ -453,9 +453,10 @@ S3Ready (
ASSERT (AcpiS3Context->BootScriptStackBase != 0); ASSERT (AcpiS3Context->BootScriptStackBase != 0);
// //
// Allocate a code buffer < 4G for S3 debug to load external code // Allocate a code buffer < 4G for S3 debug to load external code, set invalid code instructions in it.
// //
AcpiS3Context->S3DebugBufferAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGE_SIZE); AcpiS3Context->S3DebugBufferAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGE_SIZE);
SetMem ((VOID *)(UINTN)AcpiS3Context->S3DebugBufferAddress, EFI_PAGE_SIZE, 0xff);
DEBUG((EFI_D_INFO, "AcpiS3Context: AcpiFacsTable is 0x%8x\n", AcpiS3Context->AcpiFacsTable)); DEBUG((EFI_D_INFO, "AcpiS3Context: AcpiFacsTable is 0x%8x\n", AcpiS3Context->AcpiFacsTable));
DEBUG((EFI_D_INFO, "AcpiS3Context: IdtrProfile is 0x%8x\n", AcpiS3Context->IdtrProfile)); DEBUG((EFI_D_INFO, "AcpiS3Context: IdtrProfile is 0x%8x\n", AcpiS3Context->IdtrProfile));

View File

@ -50,14 +50,25 @@ SetIdtEntry (
// Restore IDT for debug // Restore IDT for debug
// //
IdtDescriptor = (IA32_DESCRIPTOR *) (UINTN) (AcpiS3Context->IdtrProfile); IdtDescriptor = (IA32_DESCRIPTOR *) (UINTN) (AcpiS3Context->IdtrProfile);
IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);
IdtEntry->OffsetLow = (UINT16)S3DebugBuffer;
IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();
IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE;
IdtEntry->OffsetHigh = (UINT16)(S3DebugBuffer >> 16);
AsmWriteIdtr (IdtDescriptor); AsmWriteIdtr (IdtDescriptor);
//
// Setup the default CPU exception handlers
//
SetupCpuExceptionHandlers ();
DEBUG_CODE (
//
// Update IDT entry INT3 if the instruction is valid in it
//
S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);
if (*(UINTN *)S3DebugBuffer != (UINTN) -1) {
IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
IdtEntry->OffsetLow = (UINT16)S3DebugBuffer;
IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();;
IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE;
IdtEntry->OffsetHigh = (UINT16)(S3DebugBuffer >> 16);
}
);
} }

View File

@ -126,23 +126,24 @@ SetIdtEntry (
// //
SetupCpuExceptionHandlers (); SetupCpuExceptionHandlers ();
// DEBUG_CODE (
// Update IDT entry INT3 //
// // Update IDT entry INT3 if the instruction is valid in it
IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR))); //
S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress); S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);
if (*(UINTN *)S3DebugBuffer != (UINTN) -1) {
IdtEntry->Offset15To0 = (UINT16)S3DebugBuffer; IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
IdtEntry->SegmentSelector = (UINT16)AsmReadCs (); IdtEntry->Offset15To0 = (UINT16)S3DebugBuffer;
IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE; IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();
IdtEntry->Offset31To16 = (UINT16)(S3DebugBuffer >> 16); IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE;
IdtEntry->Offset63To32 = (UINT32)(S3DebugBuffer >> 32); IdtEntry->Offset31To16 = (UINT16)(S3DebugBuffer >> 16);
IdtEntry->Reserved = 0; IdtEntry->Offset63To32 = (UINT32)(S3DebugBuffer >> 32);
IdtEntry->Reserved = 0;
}
);
IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (14 * sizeof (INTERRUPT_GATE_DESCRIPTOR))); IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (14 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
HookPageFaultHandler (IdtEntry); HookPageFaultHandler (IdtEntry);
AsmWriteIdtr (IdtDescriptor);
} }
/** /**