Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi: Introduce EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER and corresponding structures

Platform Firmware Runtime Update image starts with UEFI headers, and the
headers are defined in UEFI specification, but some of them have not been
defined in the kernel yet.

For example, the header layout of a capsule file looks like this:

EFI_CAPSULE_HEADER
EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER
EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER
EFI_FIRMWARE_IMAGE_AUTHENTICATION

These structures would be used by the Platform Firmware Runtime Update
driver to parse the format of capsule file to verify if the corresponding
version number is valid. In this way, if the user provides an invalid
capsule image, the kernel could be used as a guard to reject it, without
switching to the Management Mode (which might be costly).

EFI_CAPSULE_HEADER has been defined in the kernel, but the other
structures have not been defined yet, so do that. Besides,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER and
EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER are required to be packed
in the uefi specification. For this reason, use the __packed attribute
to indicate to the compiler that the entire structure can appear
misaligned in memory (as suggested by Ard) in case one of them follows
the other directly in a capsule header.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Chen Yu and committed by
Rafael J. Wysocki
1882de7f fc74e0a4

+46
+46
include/linux/efi.h
··· 148 148 u32 imagesize; 149 149 } efi_capsule_header_t; 150 150 151 + /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER */ 152 + struct efi_manage_capsule_header { 153 + u32 ver; 154 + u16 emb_drv_cnt; 155 + u16 payload_cnt; 156 + /* 157 + * Variable-size array of the size given by the sum of 158 + * emb_drv_cnt and payload_cnt. 159 + */ 160 + u64 offset_list[]; 161 + } __packed; 162 + 163 + /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER */ 164 + struct efi_manage_capsule_image_header { 165 + u32 ver; 166 + efi_guid_t image_type_id; 167 + u8 image_index; 168 + u8 reserved_bytes[3]; 169 + u32 image_size; 170 + u32 vendor_code_size; 171 + /* hw_ins was introduced in version 2 */ 172 + u64 hw_ins; 173 + /* capsule_support was introduced in version 3 */ 174 + u64 capsule_support; 175 + } __packed; 176 + 177 + /* WIN_CERTIFICATE */ 178 + struct win_cert { 179 + u32 len; 180 + u16 rev; 181 + u16 cert_type; 182 + }; 183 + 184 + /* WIN_CERTIFICATE_UEFI_GUID */ 185 + struct win_cert_uefi_guid { 186 + struct win_cert hdr; 187 + efi_guid_t cert_type; 188 + u8 cert_data[]; 189 + }; 190 + 191 + /* EFI_FIRMWARE_IMAGE_AUTHENTICATION */ 192 + struct efi_image_auth { 193 + u64 mon_count; 194 + struct win_cert_uefi_guid auth_info; 195 + }; 196 + 151 197 /* 152 198 * EFI capsule flags 153 199 */