diff mbox series

[1/1] secvar/backend/edk2.h: mark structs as __packed explicitly

Message ID 20210322215821.1193951-1-dja@axtens.net
State Accepted
Headers show
Series [1/1] secvar/backend/edk2.h: mark structs as __packed explicitly | expand

Commit Message

Daniel Axtens March 22, 2021, 9:58 p.m. UTC
The structes we import from EDK2 are expected to be packed.
The code we imported does this a #pragma pack, but it doesn't
restore the original non-packed state at the end of the header.

Rather than changing that, just explictly pack every structure.

The resulting skiboot.elf has the same disassembly (objdump -dr)
and readelf -a output, but I haven't been able to test this on
a real machine.

Signed-off-by: Daniel Axtens <dja@axtens.net>
---
 libstb/secvar/backend/edk2.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Vasant Hegde March 31, 2021, 3:19 p.m. UTC | #1
On 3/23/21 3:28 AM, Daniel Axtens wrote:
> The structes we import from EDK2 are expected to be packed.
> The code we imported does this a #pragma pack, but it doesn't
> restore the original non-packed state at the end of the header.
> 
> Rather than changing that, just explictly pack every structure.
> 
> The resulting skiboot.elf has the same disassembly (objdump -dr)
> and readelf -a output, but I haven't been able to test this on
> a real machine.

Thanks! Merged to master as bc54b94fe.

-Vasant
diff mbox series

Patch

diff --git a/libstb/secvar/backend/edk2.h b/libstb/secvar/backend/edk2.h
index 1ed9a1191ba7..c7b1999ac556 100644
--- a/libstb/secvar/backend/edk2.h
+++ b/libstb/secvar/backend/edk2.h
@@ -42,6 +42,8 @@ 
 #ifndef __EDK2_H__
 #define __EDK2_H__
 
+#include <compiler.h>
+
 #define UUID_SIZE 16
 
 typedef struct {
@@ -138,9 +140,8 @@  struct efi_time {
 ///
 /// The format of a signature database.
 ///
-#pragma pack(1)
 
-typedef struct {
+typedef struct __packed {
   ///
   /// An identifier which identifies the agent which added the signature to the list.
   ///
@@ -151,7 +152,7 @@  typedef struct {
   unsigned char SignatureData[0];
 } EFI_SIGNATURE_DATA;
 
-typedef struct {
+typedef struct __packed {
   ///
   /// Type of the signature. GUID signature types are defined in below.
   ///
@@ -204,7 +205,7 @@  struct win_certificate {
 	 * the certificate depends on wCertificateType.
 	 */
 	/// UINT8 bCertificate[ANYSIZE_ARRAY];
-};
+} __packed;
 
 /*
  * Certificate which encapsulates a GUID-specific digital signature
@@ -226,7 +227,8 @@  struct win_certificate_uefi_guid {
 	 * EFI_CERT_BLOCK_RSA_2048_SHA256 structure.
 	 */
 	u8 cert_data[];
-};
+} __packed;
+
 /*
  * When the attribute EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS is set,
  * then the Data buffer shall begin with an instance of a complete (and
@@ -246,6 +248,6 @@  struct efi_variable_authentication_2 {
 	 * Only a CertType of  EFI_CERT_TYPE_PKCS7_GUID is accepted.
 	 */
 	struct win_certificate_uefi_guid auth_info;
-};
+} __packed;
 
 #endif