]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Include Secure Boot Advanced Targeting (SBAT) metadata
authorMichael Brown <mcb30@ipxe.org>
Thu, 13 Jan 2022 14:10:03 +0000 (14:10 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 13 Jan 2022 14:12:44 +0000 (14:12 +0000)
SBAT defines an encoding for security generation numbers stored as a
CSV file within a special ".sbat" section in the signed binary.  If a
Secure Boot exploit is discovered then the generation number will be
incremented alongside the corresponding fix.

Platforms may then record the minimum generation number required for
any given product.  This allows for an efficient revocation mechanism
that consumes minimal flash storage space (in contrast to the DBX
mechanism, which allows for only a single-digit number of revocation
events to ever take place across all possible signed binaries).

Add SBAT metadata to iPXE EFI binaries to support this mechanism.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/scripts/i386-kir.lds
src/arch/i386/scripts/linux.lds
src/arch/x86/scripts/pcbios.lds
src/arch/x86/scripts/prefixonly.lds
src/arch/x86_64/scripts/linux.lds
src/config/branding.h
src/core/version.c
src/include/ipxe/sbat.h [new file with mode: 0644]
src/scripts/efi.lds

index 66bf804e6fb7d95aa41b4f820be65657e9adffb5..13c36f2bfa0b1a8263988d24ce1bc95cd31a9077 100644 (file)
@@ -136,6 +136,8 @@ SECTIONS {
        *(.note.*)
        *(.discard)
        *(.discard.*)
+       *(.sbat)
+       *(.sbat.*)
     }
 
     /*
index 9f2eeaf3c55e26b4145c96afaef748e87ef1892a..8c3a7b0baaefde3d424b58a18aa4e10d12e95bd5 100644 (file)
@@ -100,5 +100,7 @@ SECTIONS {
                *(.rel.*)
                *(.discard)
                *(.discard.*)
+               *(.sbat)
+               *(.sbat.*)
        }
 }
index de59adca9b6deeb90666d46772353b66f7b8b87e..e208b174b4f0cb0ddfcf72d54ab48a838e0fc665 100644 (file)
@@ -229,6 +229,8 @@ SECTIONS {
        *(.einfo.*)
        *(.discard)
        *(.discard.*)
+       *(.sbat)
+       *(.sbat.*)
     }
 
     /*
index dce0930b59d51470838d2d02c17413a43b405d78..2fe5b03be8540cde627548a63c2dc2ab6d74df72 100644 (file)
@@ -24,6 +24,8 @@ SECTIONS {
        *(.einfo.*)
        *(.discard)
        *(.discard.*)
+       *(.sbat)
+       *(.sbat.*)
     }
 
 }
index 47db21745d927db6ac53c3cadeaea2bd2af76ffe..a093787e595d789d7259fb13ff54c896270d0400 100644 (file)
@@ -100,5 +100,7 @@ SECTIONS {
                *(.rel.*)
                *(.discard)
                *(.discard.*)
+               *(.sbat)
+               *(.sbat.*)
        }
 }
index e503dff9a5996e4c993deb584a099e95d4a502ff..454bf0c03aca2bf20a06da2a41efc25cbd1414fe 100644 (file)
@@ -169,6 +169,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  */
 #define PRODUCT_SETTING_URI "https://ipxe.org/cfg/%s"
 
+/*
+ * Product security name suffix
+ *
+ * Vendors creating signed iPXE binaries must set this to a non-empty
+ * value (e.g. "2pint").
+ */
+#define PRODUCT_SBAT_NAME ""
+
+/*
+ * Product security generation
+ *
+ * Vendors creating signed iPXE binaries must set this to a non-zero
+ * value, and must increment the value whenever a Secure Boot exploit
+ * is fixed (unless the upstream IPXE_SBAT_GENERATION has already been
+ * incremented as part of that fix).
+ */
+#define PRODUCT_SBAT_GENERATION 0
+
 #include <config/local/branding.h>
 
 #endif /* CONFIG_BRANDING_H */
index c984335c23bde6b6afa6d7f3ee3dadb0e3b9db9e..22f4440652e5dd153d73e370552611b85c960623 100644 (file)
@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <wchar.h>
 #include <ipxe/features.h>
 #include <ipxe/version.h>
+#include <ipxe/sbat.h>
 #include <config/general.h>
 #include <config/branding.h>
 
@@ -92,3 +93,32 @@ const wchar_t build_wname[] = WSTRING ( BUILD_NAME );
 /** Copy of build name string within ".prefix" */
 const char build_name_prefix[] __attribute__ (( section ( ".prefix.name" ) ))
        = BUILD_NAME;
+
+/** SBAT upstream iPXE line
+ *
+ * This line represents the security generation of the upstream
+ * codebase from which this build is derived.
+ */
+#define SBAT_IPXE                                                      \
+       SBAT_LINE ( "ipxe", IPXE_SBAT_GENERATION,                       \
+                   "iPXE", BUILD_NAME, VERSION, "https://ipxe.org" )
+
+/** SBAT local build line
+ *
+ * This line states the security generation of the local build, which
+ * may include non-default features or non-upstreamed modifications.
+ */
+#if PRODUCT_SBAT_GENERATION
+#define SBAT_PRODUCT                                                   \
+       SBAT_LINE ( "ipxe." PRODUCT_SBAT_NAME, PRODUCT_SBAT_GENERATION, \
+                   PRODUCT_SHORT_NAME, BUILD_NAME, VERSION,            \
+                   PRODUCT_URI )
+#else
+#define SBAT_PRODUCT ""
+#endif
+
+/** SBAT data */
+#define SBAT_DATA SBAT_HEADER "" SBAT_IPXE "" SBAT_PRODUCT
+
+/** SBAT data (without any NUL terminator) */
+const char sbat[ sizeof ( SBAT_DATA ) - 1 ] __sbat = SBAT_DATA;
diff --git a/src/include/ipxe/sbat.h b/src/include/ipxe/sbat.h
new file mode 100644 (file)
index 0000000..4b74670
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef _IPXE_SBAT_H
+#define _IPXE_SBAT_H
+
+/** @file
+ *
+ * Secure Boot Advanced Targeting (SBAT)
+ *
+ * SBAT defines an encoding for security generation numbers stored as
+ * a CSV file within a special ".sbat" section in the signed binary.
+ * If a Secure Boot exploit is discovered then the generation number
+ * will be incremented alongside the corresponding fix.
+ *
+ * Platforms may then record the minimum generation number required
+ * for any given product.  This allows for an efficient revocation
+ * mechanism that consumes minimal flash storage space (in contrast to
+ * the DBX mechanism, which allows for only a single-digit number of
+ * revocation events to ever take place across all possible signed
+ * binaries).
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/**
+ * A single line within an SBAT CSV file
+ *
+ * @v name             Machine-readable component name
+ * @v generation       Security generation number
+ * @v vendor           Human-readable vendor name
+ * @v package          Human-readable package name
+ * @v version          Human-readable package version
+ * @v uri              Contact URI
+ * @ret line           CSV line
+ */
+#define SBAT_LINE( name, generation, vendor, package, version, uri )   \
+       name "," _S2 ( generation ) "," vendor "," package ","          \
+       version "," uri "\n"
+
+/** SBAT format generation */
+#define SBAT_GENERATION 1
+
+/** Upstream security generation
+ *
+ * This represents the security generation of the upstream codebase.
+ * It will be incremented whenever a Secure Boot exploit is fixed in
+ * the upstream codebase.
+ *
+ * If you do not have commit access to the upstream iPXE repository,
+ * then you may not modify this value under any circumstances.
+ */
+#define IPXE_SBAT_GENERATION 1
+
+/* Seriously, do not modify this value */
+#if IPXE_SBAT_GENERATION != 1
+#error "You may not modify IPXE_SBAT_GENERATION"
+#endif
+
+/** SBAT header line */
+#define SBAT_HEADER                                                    \
+       SBAT_LINE ( "sbat", SBAT_GENERATION, "SBAT Version", "sbat",    \
+                   _S2 ( SBAT_GENERATION ),                            \
+                   "https://github.com/rhboot/shim/blob/main/SBAT.md" )
+
+/** Mark variable as being in the ".sbat" section */
+#define __sbat __attribute__ (( section ( ".sbat" ), aligned ( 512 ) ))
+
+extern const char sbat[] __sbat;
+
+#endif /* _IPXE_SBAT_H */
index dd7b3f0195a763846a180ad49017d6af5347626d..218b1df663f224d0394e6fad08834540cde4ed33 100644 (file)
@@ -74,6 +74,19 @@ SECTIONS {
        _ebss = .;
     }
 
+    /*
+     * The SBAT section
+     *
+     */
+
+    . = ALIGN ( _page_align );
+    .sbat : {
+       _sbat = .;
+       KEEP(*(.sbat))
+       KEEP(*(.sbat.*))
+       _esbat = .;
+    }
+
     /*
      * Weak symbols that need zero values if not otherwise defined
      *