Skip to contentSkip to conversation

xen/ucode: Make Intel's microcode_sanity_check() stricter

PATCH In review Andrew Cooper 2 participants 2 messages Sep 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/ucode: Make Intel's microcode_sanity_check() stricter

From: Demi Marie Obenour <[email protected]>

The SDM states that data size must be a multiple of 4, but Xen doesn't check this propery.

This is liable to cause a later failures, but should be checked explicitly.

---
 xen/arch/x86/cpu/microcode/intel.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/cpu/microcode/intel.c +5 -2
index 6f6957058684..bad51f64724a 100644
@@ -155,10 +155,13 @@ static int microcode_sanity_check(const struct microcode_patch *patch)
     uint32_t sum;
 
     /*
-     * Total size must be a multiple of 1024 bytes.  Data size and the header
-     * must fit within it.
+     * The SDM states:
+     * - Data size must be a multiple of 4.
+     * - Total size must be a multiple of 1024 bytes.  Data size and the
+     *   header must fit within it.
      */
     if ( (total_size & 1023) ||
+         (data_size & 3) ||
          data_size > (total_size - MC_HEADER_SIZE) )
     {
         printk(XENLOG_WARNING "microcode: Bad size\n");
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

From: Demi Marie Obenour <[email protected]>

The SDM states that data size must be a multiple of 4, but Xen doesn't check this propery.

This is liable to cause a later failures, but should be checked explicitly.

Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0 -0
@@ -155,10 +155,13 @@ static int microcode_sanity_check(const struct microcode_patch *patch)
     uint32_t sum;
 
     /*

xen/arch/x86/cpu/microcode/intel.c static int microcode_sanity_check(const struct microcode_patch *patch) · line 165

Quoted 10 lines
xen/arch/x86/cpu/microcode/intel.c +5 -2
-     * Total size must be a multiple of 1024 bytes.  Data size and the header
-     * must fit within it.
+     * The SDM states:
+     * - Data size must be a multiple of 4.
+     * - Total size must be a multiple of 1024 bytes.  Data size and the
+     *   header must fit within it.
      */
     if ( (total_size & 1023) ||
+         (data_size & 3) ||
          data_size > (total_size - MC_HEADER_SIZE) )

And luckily get_totalsize() guarantees total_size > 0, for this subtraction not to underflow. Maybe worth also mentioning in the comment as you adjust it anyway.

Jan