1 | /** @file
|
---|
2 | This file includes the function prototypes for the sanitization functions.
|
---|
3 |
|
---|
4 | These are those functions:
|
---|
5 |
|
---|
6 | DxeTpmMeasureBootLibImageRead() function will make sure the PE/COFF image content
|
---|
7 | read is within the image buffer.
|
---|
8 |
|
---|
9 | TcgMeasurePeImage() function will accept untrusted PE/COFF image and validate its
|
---|
10 | data structure within this image buffer before use.
|
---|
11 |
|
---|
12 | TcgMeasureGptTable() function will receive untrusted GPT partition table, and parse
|
---|
13 | partition data carefully.
|
---|
14 |
|
---|
15 | Copyright (c) Microsoft Corporation.<BR>
|
---|
16 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
17 |
|
---|
18 | **/
|
---|
19 |
|
---|
20 | #ifndef DXE_TPM_MEASURE_BOOT_LIB_VALIDATION_
|
---|
21 | #define DXE_TPM_MEASURE_BOOT_LIB_VALIDATION_
|
---|
22 |
|
---|
23 | #include <Uefi.h>
|
---|
24 | #include <Uefi/UefiSpec.h>
|
---|
25 | #include <Protocol/BlockIo.h>
|
---|
26 | #include <IndustryStandard/UefiTcgPlatform.h>
|
---|
27 |
|
---|
28 | /**
|
---|
29 | This function will validate the EFI_PARTITION_TABLE_HEADER structure is safe to parse
|
---|
30 | However this function will not attempt to verify the validity of the GPT partition
|
---|
31 | It will check the following:
|
---|
32 | - Signature
|
---|
33 | - Revision
|
---|
34 | - AlternateLBA
|
---|
35 | - FirstUsableLBA
|
---|
36 | - LastUsableLBA
|
---|
37 | - PartitionEntryLBA
|
---|
38 | - NumberOfPartitionEntries
|
---|
39 | - SizeOfPartitionEntry
|
---|
40 | - BlockIo
|
---|
41 |
|
---|
42 | @param[in] PrimaryHeader
|
---|
43 | Pointer to the EFI_PARTITION_TABLE_HEADER structure.
|
---|
44 |
|
---|
45 | @param[in] BlockIo
|
---|
46 | Pointer to the EFI_BLOCK_IO_PROTOCOL structure.
|
---|
47 |
|
---|
48 | @retval EFI_SUCCESS
|
---|
49 | The EFI_PARTITION_TABLE_HEADER structure is valid.
|
---|
50 |
|
---|
51 | @retval EFI_INVALID_PARAMETER
|
---|
52 | The EFI_PARTITION_TABLE_HEADER structure is invalid.
|
---|
53 | **/
|
---|
54 | EFI_STATUS
|
---|
55 | EFIAPI
|
---|
56 | TpmSanitizeEfiPartitionTableHeader (
|
---|
57 | IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
---|
58 | IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo
|
---|
59 | );
|
---|
60 |
|
---|
61 | /**
|
---|
62 | This function will validate that the allocation size from the primary header is sane
|
---|
63 | It will check the following:
|
---|
64 | - AllocationSize does not overflow
|
---|
65 |
|
---|
66 | @param[in] PrimaryHeader
|
---|
67 | Pointer to the EFI_PARTITION_TABLE_HEADER structure.
|
---|
68 |
|
---|
69 | @param[out] AllocationSize
|
---|
70 | Pointer to the allocation size.
|
---|
71 |
|
---|
72 | @retval EFI_SUCCESS
|
---|
73 | The allocation size is valid.
|
---|
74 |
|
---|
75 | @retval EFI_OUT_OF_RESOURCES
|
---|
76 | The allocation size is invalid.
|
---|
77 | **/
|
---|
78 | EFI_STATUS
|
---|
79 | EFIAPI
|
---|
80 | TpmSanitizePrimaryHeaderAllocationSize (
|
---|
81 | IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
---|
82 | OUT UINT32 *AllocationSize
|
---|
83 | );
|
---|
84 |
|
---|
85 | /**
|
---|
86 | This function will validate that the Gpt Event Size calculated from the primary header is sane
|
---|
87 | It will check the following:
|
---|
88 | - EventSize does not overflow
|
---|
89 |
|
---|
90 | Important: This function includes the entire length of the allocated space, including the
|
---|
91 | TCG_PCR_EVENT_HDR. When hashing the buffer allocated with this size, the caller must subtract
|
---|
92 | the size of the TCG_PCR_EVENT_HDR from the size of the buffer before hashing.
|
---|
93 |
|
---|
94 | @param[in] PrimaryHeader - Pointer to the EFI_PARTITION_TABLE_HEADER structure.
|
---|
95 | @param[in] NumberOfPartition - Number of partitions.
|
---|
96 | @param[out] EventSize - Pointer to the event size.
|
---|
97 |
|
---|
98 | @retval EFI_SUCCESS
|
---|
99 | The event size is valid.
|
---|
100 |
|
---|
101 | @retval EFI_OUT_OF_RESOURCES
|
---|
102 | Overflow would have occurred.
|
---|
103 |
|
---|
104 | @retval EFI_INVALID_PARAMETER
|
---|
105 | One of the passed parameters was invalid.
|
---|
106 | **/
|
---|
107 | EFI_STATUS
|
---|
108 | TpmSanitizePrimaryHeaderGptEventSize (
|
---|
109 | IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
---|
110 | IN UINTN NumberOfPartition,
|
---|
111 | OUT UINT32 *EventSize
|
---|
112 | );
|
---|
113 |
|
---|
114 | /**
|
---|
115 | This function will validate that the PeImage Event Size from the loaded image is sane
|
---|
116 | It will check the following:
|
---|
117 | - EventSize does not overflow
|
---|
118 |
|
---|
119 | @param[in] FilePathSize - Size of the file path.
|
---|
120 | @param[out] EventSize - Pointer to the event size.
|
---|
121 |
|
---|
122 | @retval EFI_SUCCESS
|
---|
123 | The event size is valid.
|
---|
124 |
|
---|
125 | @retval EFI_OUT_OF_RESOURCES
|
---|
126 | Overflow would have occurred.
|
---|
127 |
|
---|
128 | @retval EFI_INVALID_PARAMETER
|
---|
129 | One of the passed parameters was invalid.
|
---|
130 | **/
|
---|
131 | EFI_STATUS
|
---|
132 | TpmSanitizePeImageEventSize (
|
---|
133 | IN UINT32 FilePathSize,
|
---|
134 | OUT UINT32 *EventSize
|
---|
135 | );
|
---|
136 |
|
---|
137 | #endif // DXE_TPM_MEASURE_BOOT_LIB_VALIDATION_
|
---|