Subject: x86/ucode: Digests for TSA microcode
From: Andrew Cooper <[email-masked]>
Date: Fri, 27 Sep 2024 11:28:39 +0100

AMD are releasing microcode for TSA, so extend the known-provenance list with
their hashes.  These were produced before the remediation of the microcode
signature issues (the entrysign vulnerability), so can be OS-loaded on
out-of-date firmware.

Include an off-by-default check for the sorted-ness of patch_digests[].  It's
not worth running generally under SELF_TESTS, but is useful when editing the
digest list.

This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.

Signed-off-by: Andrew Cooper <[email-masked]>
Acked-by: Jan Beulich <[email-masked]>

diff --git a/xen/arch/x86/cpu/microcode/amd-patch-digests.c b/xen/arch/x86/cpu/microcode/amd-patch-digests.c
index d32761226712..d2c4e0178a1e 100644
--- a/xen/arch/x86/cpu/microcode/amd-patch-digests.c
+++ b/xen/arch/x86/cpu/microcode/amd-patch-digests.c
@@ -80,6 +80,15 @@
         0x0d, 0x5b, 0x65, 0x34, 0x69, 0xb2, 0x62, 0x21,
     },
 },
+{
+    .patch_id = 0x0a0011d7,
+    .digest = {
+        0x35, 0x07, 0xcd, 0x40, 0x94, 0xbc, 0x81, 0x6b,
+        0xfc, 0x61, 0x56, 0x1a, 0xe2, 0xdb, 0x96, 0x12,
+        0x1c, 0x1c, 0x31, 0xb1, 0x02, 0x6f, 0xe5, 0xd2,
+        0xfe, 0x1b, 0x04, 0x03, 0x2c, 0x8f, 0x4c, 0x36,
+    },
+},
 {
     .patch_id = 0x0a001238,
     .digest = {
@@ -89,6 +98,15 @@
         0xc0, 0xcd, 0x33, 0xf2, 0x8d, 0xf9, 0xef, 0x59,
     },
 },
+{
+    .patch_id = 0x0a00123b,
+    .digest = {
+        0xef, 0xa1, 0x1e, 0x71, 0xf1, 0xc3, 0x2c, 0xe2,
+        0xc3, 0xef, 0x69, 0x41, 0x7a, 0x54, 0xca, 0xc3,
+        0x8f, 0x62, 0x84, 0xee, 0xc2, 0x39, 0xd9, 0x28,
+        0x95, 0xa7, 0x12, 0x49, 0x1e, 0x30, 0x71, 0x72,
+    },
+},
 {
     .patch_id = 0x0a00820c,
     .digest = {
@@ -98,6 +116,15 @@
         0xe1, 0x3b, 0x8d, 0xb2, 0xf8, 0x22, 0x03, 0xe2,
     },
 },
+{
+    .patch_id = 0x0a00820d,
+    .digest = {
+        0xf9, 0x2a, 0xc0, 0xf4, 0x9e, 0xa4, 0x87, 0xa4,
+        0x7d, 0x87, 0x00, 0xfd, 0xab, 0xda, 0x19, 0xca,
+        0x26, 0x51, 0x32, 0xc1, 0x57, 0x91, 0xdf, 0xc1,
+        0x05, 0xeb, 0x01, 0x7c, 0x5a, 0x95, 0x21, 0xb7,
+    },
+},
 {
     .patch_id = 0x0a101148,
     .digest = {
@@ -107,6 +134,15 @@
         0xf1, 0x5e, 0xb0, 0xde, 0xb4, 0x98, 0xae, 0xc4,
     },
 },
+{
+    .patch_id = 0x0a10114c,
+    .digest = {
+        0x9e, 0xb6, 0xa2, 0xd9, 0x87, 0x38, 0xc5, 0x64,
+        0xd8, 0x88, 0xfa, 0x78, 0x98, 0xf9, 0x6f, 0x74,
+        0x39, 0x90, 0x1b, 0xa5, 0xcf, 0x5e, 0xb4, 0x2a,
+        0x02, 0xff, 0xd4, 0x8c, 0x71, 0x8b, 0xe2, 0xc0,
+    },
+},
 {
     .patch_id = 0x0a101248,
     .digest = {
@@ -116,6 +152,15 @@
         0x1b, 0x7d, 0x64, 0x9d, 0x4b, 0x53, 0x13, 0x75,
     },
 },
+{
+    .patch_id = 0x0a10124c,
+    .digest = {
+        0x29, 0xea, 0xf1, 0x2c, 0xb2, 0xe4, 0xef, 0x90,
+        0xa4, 0xcd, 0x1d, 0x86, 0x97, 0x17, 0x61, 0x46,
+        0xfc, 0x22, 0xcb, 0x57, 0x75, 0x19, 0xc8, 0xcc,
+        0x0c, 0xf5, 0xbc, 0xac, 0x81, 0x9d, 0x9a, 0xd2,
+    },
+},
 {
     .patch_id = 0x0a108108,
     .digest = {
@@ -125,6 +170,15 @@
         0x28, 0x1e, 0x9c, 0x59, 0x69, 0x99, 0x4d, 0x16,
     },
 },
+{
+    .patch_id = 0x0a108109,
+    .digest = {
+        0x85, 0xb4, 0xbd, 0x7c, 0x49, 0xa7, 0xbd, 0xfa,
+        0x49, 0x36, 0x80, 0x81, 0xc5, 0xb7, 0x39, 0x1b,
+        0x9a, 0xaa, 0x50, 0xde, 0x9b, 0xe9, 0x32, 0x35,
+        0x42, 0x7e, 0x51, 0x4f, 0x52, 0x2c, 0x28, 0x59,
+    },
+},
 {
     .patch_id = 0x0a20102d,
     .digest = {
@@ -134,6 +188,15 @@
         0x8c, 0xe9, 0x19, 0x3e, 0xcc, 0x3f, 0x7b, 0xb4,
     },
 },
+{
+    .patch_id = 0x0a20102e,
+    .digest = {
+        0xbe, 0x1f, 0x32, 0x04, 0x0d, 0x3c, 0x9c, 0xdd,
+        0xe1, 0xa4, 0xbf, 0x76, 0x3a, 0xec, 0xc2, 0xf6,
+        0x11, 0x00, 0xa7, 0xaf, 0x0f, 0xe5, 0x02, 0xc5,
+        0x54, 0x3a, 0x1f, 0x8c, 0x16, 0xb5, 0xff, 0xbe,
+    },
+},
 {
     .patch_id = 0x0a201210,
     .digest = {
@@ -143,6 +206,15 @@
         0xf7, 0x55, 0xf0, 0x13, 0xbb, 0x22, 0xf6, 0x41,
     },
 },
+{
+    .patch_id = 0x0a201211,
+    .digest = {
+        0x69, 0xa1, 0x17, 0xec, 0xd0, 0xf6, 0x6c, 0x95,
+        0xe2, 0x1e, 0xc5, 0x59, 0x1a, 0x52, 0x0a, 0x27,
+        0xc4, 0xed, 0xd5, 0x59, 0x1f, 0xbf, 0x00, 0xff,
+        0x08, 0x88, 0xb5, 0xe1, 0x12, 0xb6, 0xcc, 0x27,
+    },
+},
 {
     .patch_id = 0x0a404107,
     .digest = {
@@ -152,6 +224,15 @@
         0x13, 0xbc, 0xc5, 0x25, 0xe4, 0xc5, 0xc3, 0x99,
     },
 },
+{
+    .patch_id = 0x0a404108,
+    .digest = {
+        0x69, 0x67, 0x43, 0x06, 0xf8, 0x0c, 0x62, 0xdc,
+        0xa4, 0x21, 0x30, 0x4f, 0x0f, 0x21, 0x2c, 0xcb,
+        0xcc, 0x37, 0xf1, 0x1c, 0xc3, 0xf8, 0x2f, 0x19,
+        0xdf, 0x53, 0x53, 0x46, 0xb1, 0x15, 0xea, 0x00,
+    },
+},
 {
     .patch_id = 0x0a500011,
     .digest = {
@@ -161,6 +242,15 @@
         0x11, 0x5e, 0x96, 0x7e, 0x71, 0xe9, 0xfc, 0x74,
     },
 },
+{
+    .patch_id = 0x0a500012,
+    .digest = {
+        0xeb, 0x74, 0x0d, 0x47, 0xa1, 0x8e, 0x09, 0xe4,
+        0x93, 0x4c, 0xad, 0x03, 0x32, 0x4c, 0x38, 0x16,
+        0x10, 0x39, 0xdd, 0x06, 0xaa, 0xce, 0xd6, 0x0f,
+        0x62, 0x83, 0x9d, 0x8e, 0x64, 0x55, 0xbe, 0x63,
+    },
+},
 {
     .patch_id = 0x0a601209,
     .digest = {
@@ -170,6 +260,15 @@
         0xe8, 0x73, 0xe2, 0xd6, 0xdb, 0xd2, 0x77, 0x1d,
     },
 },
+{
+    .patch_id = 0x0a60120a,
+    .digest = {
+        0x0c, 0x8b, 0x3d, 0xfd, 0x52, 0x52, 0x85, 0x7d,
+        0x20, 0x3a, 0xe1, 0x7e, 0xa4, 0x21, 0x3b, 0x7b,
+        0x17, 0x86, 0xae, 0xac, 0x13, 0xb8, 0x63, 0x9d,
+        0x06, 0x01, 0xd0, 0xa0, 0x51, 0x9a, 0x91, 0x2c,
+    },
+},
 {
     .patch_id = 0x0a704107,
     .digest = {
@@ -179,6 +278,15 @@
         0x64, 0x39, 0x71, 0x8c, 0xce, 0xe7, 0x41, 0x39,
     },
 },
+{
+    .patch_id = 0x0a704108,
+    .digest = {
+        0xd7, 0x55, 0x15, 0x2b, 0xfe, 0xc4, 0xbc, 0x93,
+        0xec, 0x91, 0xa0, 0xae, 0x45, 0xb7, 0xc3, 0x98,
+        0x4e, 0xff, 0x61, 0x77, 0x88, 0xc2, 0x70, 0x49,
+        0xe0, 0x3a, 0x1d, 0x84, 0x38, 0x52, 0xbf, 0x5a,
+    },
+},
 {
     .patch_id = 0x0a705206,
     .digest = {
@@ -188,6 +296,15 @@
         0x03, 0x35, 0xe9, 0xbe, 0xfb, 0x06, 0xdf, 0xfc,
     },
 },
+{
+    .patch_id = 0x0a705208,
+    .digest = {
+        0x30, 0x1d, 0x55, 0x24, 0xbc, 0x6b, 0x5a, 0x19,
+        0x0c, 0x7d, 0x1d, 0x74, 0xaa, 0xd1, 0xeb, 0xd2,
+        0x16, 0x62, 0xf7, 0x5b, 0xe1, 0x1f, 0x18, 0x11,
+        0x5c, 0xf0, 0x94, 0x90, 0x26, 0xec, 0x69, 0xff,
+    },
+},
 {
     .patch_id = 0x0a708007,
     .digest = {
@@ -197,6 +314,15 @@
         0xdf, 0x92, 0x73, 0x84, 0x87, 0x3c, 0x73, 0x93,
     },
 },
+{
+    .patch_id = 0x0a708008,
+    .digest = {
+        0x08, 0x6e, 0xf0, 0x22, 0x4b, 0x8e, 0xc4, 0x46,
+        0x58, 0x34, 0xe6, 0x47, 0xa2, 0x28, 0xfd, 0xab,
+        0x22, 0x3d, 0xdd, 0xd8, 0x52, 0x9e, 0x1d, 0x16,
+        0xfa, 0x01, 0x68, 0x14, 0x79, 0x3e, 0xe8, 0x6b,
+    },
+},
 {
     .patch_id = 0x0a70c005,
     .digest = {
@@ -206,6 +332,15 @@
         0xee, 0x49, 0xac, 0xe1, 0x8b, 0x13, 0xc5, 0x13,
     },
 },
+{
+    .patch_id = 0x0a70c008,
+    .digest = {
+        0x0f, 0xdb, 0x37, 0xa1, 0x10, 0xaf, 0xd4, 0x21,
+        0x94, 0x0d, 0xa4, 0xa2, 0xe9, 0x86, 0x6c, 0x0e,
+        0x85, 0x7c, 0x36, 0x30, 0xa3, 0x3a, 0x78, 0x66,
+        0x18, 0x10, 0x60, 0x0d, 0x78, 0x3d, 0x44, 0xd0,
+    },
+},
 {
     .patch_id = 0x0aa00116,
     .digest = {
@@ -224,3 +359,12 @@
         0x68, 0x2f, 0x46, 0xee, 0xfe, 0xc6, 0x6d, 0xef,
     },
 },
+{
+    .patch_id = 0x0aa00216,
+    .digest = {
+        0x79, 0xfb, 0x5b, 0x9f, 0xb6, 0xe6, 0xa8, 0xf5,
+        0x4e, 0x7c, 0x4f, 0x8e, 0x1d, 0xad, 0xd0, 0x08,
+        0xc2, 0x43, 0x7c, 0x8b, 0xe6, 0xdb, 0xd0, 0xd2,
+        0xe8, 0x39, 0x26, 0xc1, 0xe5, 0x5a, 0x48, 0xf1,
+    },
+},
diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index ebd9ecbeef0f..8b09231c6c66 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -528,3 +528,18 @@ void __init ucode_probe_amd(struct microcode_ops *ops)
 
     *ops = amd_ucode_ops;
 }
+
+#if 0 /* Manual CONFIG_SELF_TESTS */
+static void __init __constructor test_digests_sorted(void)
+{
+    for ( unsigned int i = 1; i < ARRAY_SIZE(patch_digests); ++i )
+    {
+        if ( patch_digests[i - 1].patch_id < patch_digests[i].patch_id )
+            continue;
+
+        panic("patch_digests[] not sorted: %08x >= %08x\n",
+              patch_digests[i - 1].patch_id,
+              patch_digests[i].patch_id);
+    }
+}
+#endif /* CONFIG_SELF_TESTS */