Skip to content

Commit 51776fb

Browse files
committed
x86/microcode/AMD: Move patch family check to verify_patch()
... where all the microcode patch verification is being concentrated. Signed-off-by: Borislav Petkov <bp@suse.de> Cc: x86@kernel.org Link: https://lkml.kernel.org/r/20181107170218.7596-9-bp@alien8.de
1 parent 6cdce95 commit 51776fb

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

  • arch/x86/kernel/cpu/microcode

‎arch/x86/kernel/cpu/microcode/amd.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ __verify_patch_size(u8 family, u32 sh_psize, unsigned int buf_size)
221221
static unsigned int
222222
verify_patch(u8 family, const u8 *buf, unsigned int buf_size, bool early)
223223
{
224+
struct microcode_header_amd *mc_hdr;
224225
u32 sh_psize;
226+
u16 proc_id;
227+
u8 patch_fam;
225228

226229
if (!__verify_patch_section(buf, buf_size, &sh_psize, early))
227230
return 0;
@@ -243,6 +246,13 @@ verify_patch(u8 family, const u8 *buf, unsigned int buf_size, bool early)
243246
return 0;
244247
}
245248

249+
mc_hdr = (struct microcode_header_amd *)(buf + SECTION_HDR_SIZE);
250+
proc_id = mc_hdr->processor_rev_id;
251+
252+
patch_fam = 0xf + (proc_id >> 12);
253+
if (patch_fam != family)
254+
return 0;
255+
246256
return __verify_patch_size(family, sh_psize, buf_size);
247257
}
248258

@@ -718,7 +728,6 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
718728
struct microcode_header_amd *mc_hdr;
719729
unsigned int patch_size, crnt_size;
720730
struct ucode_patch *patch;
721-
u8 patch_fam;
722731
u16 proc_id;
723732

724733
patch_size = verify_patch(family, fw, leftover, false);
@@ -732,10 +741,6 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
732741
mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE);
733742
proc_id = mc_hdr->processor_rev_id;
734743

735-
patch_fam = 0xf + (proc_id >> 12);
736-
if (patch_fam != family)
737-
return crnt_size;
738-
739744
if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) {
740745
pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n",
741746
mc_hdr->patch_id);

0 commit comments

Comments
 (0)