Skip to contentSkip to conversation

x86/microcode/intel: Ensure new microcode processor flags match with cpu's pf

PATCH In review Zhenzhong Duan 2 participants 6 messages Jun 4, 2018 – Jun 19, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/microcode/intel: Ensure new microcode processor flags match with cpu's pf

Intel spec says: 'The processor flags in the 48-byte header and the processor flags field associated with the extended processor signature structures may have multiple bits set.'

Make sure processor flags of the new microcode intersect with current cpu's. Comparing with old microcode's pf can't guarantee this.

---
 arch/x86/kernel/cpu/microcode/intel.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +3 -5
index 461e315..54f4014 100644
@@ -371,12 +371,10 @@ static int microcode_sanity_check(void *mc, int print_err)
 				goto next;
 
 		} else {
-			struct microcode_header_intel *phdr = &patch->hdr;
-
 			if (!has_newer_microcode(data,
-						 phdr->sig,
-						 phdr->pf,
-						 phdr->rev))
+						 uci->cpu_sig.sig,
+						 uci->cpu_sig.pf,
+						 patch->hdr.rev))
 				goto next;
 		}
 
Signature · 1 line
1.7.3
maintainer
#1 lore raw
Quoted 23 lines · Zhenzhong Duan

Intel spec says: 'The processor flags in the 48-byte header and the processor flags field associated with the extended processor signature structures may have multiple bits set.'

Make sure processor flags of the new microcode intersect with current cpu's. Comparing with old microcode's pf can't guarantee this.

---
 arch/x86/kernel/cpu/microcode/intel.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +0 -2
index 461e315..54f4014 100644
@@ -371,12 +371,10 @@ static int microcode_sanity_check(void *mc, int print_err)
 				goto next;
 
 		} else {
-			struct microcode_header_intel *phdr = &patch->hdr;
-

arch/x86/kernel/cpu/microcode/intel.c static int microcode_sanity_check(void *mc, int print_err) · line 380

Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +3 -3
 			if (!has_newer_microcode(data,
-						 phdr->sig,
-						 phdr->pf,
-						 phdr->rev))
+						 uci->cpu_sig.sig,
+						 uci->cpu_sig.pf,
+						 patch->hdr.rev))
 				goto next;
 		}
 

So I'm scratching my head over this and have no clue what you're trying to achieve. Is this a fix for a bug you're seeing or what? You'd need to be a lot more verbose when explaining what this patch is trying to do...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#2 lore raw
Quoted 33 lines · Borislav Petkov
Quoted 32 lines · Zhenzhong Duan

Intel spec says: 'The processor flags in the 48-byte header and the processor flags field associated with the extended processor signature structures may have multiple bits set.'

Make sure processor flags of the new microcode intersect with current cpu's. Comparing with old microcode's pf can't guarantee this.

---
  arch/x86/kernel/cpu/microcode/intel.c |    8 +++-----
  1 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +3 -5
index 461e315..54f4014 100644
@@ -371,12 +371,10 @@ static int microcode_sanity_check(void *mc, int print_err)
  				goto next;
 
  		} else {
-			struct microcode_header_intel *phdr = &patch->hdr;
-
  			if (!has_newer_microcode(data,
-						 phdr->sig,
-						 phdr->pf,
-						 phdr->rev))
+						 uci->cpu_sig.sig,
+						 uci->cpu_sig.pf,
+						 patch->hdr.rev))
  				goto next;
  		}
 
Quoted 5 lines
Quoted 1 line

So I'm scratching my head over this and have no clue what you're trying to achieve. Is this a fix for a bug you're seeing or what? You'd need to be a lot more verbose when explaining what this patch is trying to do...

Imagine kernel already found a microcode blob A with extended sig/pf matching current cpu, then another microcode B is checked which doesn't match current cpu but matches the sig/pf of microcode A, then microcode B will replaced A, but it's not suitable for current cpu.

I didn't see same issue in our system. When fixing another bug and reading upstream microcode code, I found this potential issue, feel free to correct me if it's never possible in reality.

Thanks
Zhenzhong

maintainer
#3 lore raw
Quoted 3 lines · Zhenzhong Duan

Imagine kernel already found a microcode blob A with extended sig/pf matching current cpu, then another microcode B is checked which doesn't match current cpu...

Do you see the

	if (!microcode_matches(mc_header, uci->cpu_sig.sig)) {

call a couple of lines earlier?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#4 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 3 lines · Zhenzhong Duan

Imagine kernel already found a microcode blob A with extended sig/pf matching current cpu, then another microcode B is checked which doesn't match current cpu...

Do you see the

	if (!microcode_matches(mc_header, uci->cpu_sig.sig)) {

call a couple of lines earlier?

Sure, but it didn't ensure a match in stepping and pf, is that expected?

Thanks
Zhenzhong

maintainer
#5 lore raw
Quoted 11 lines · Zhenzhong Duan
Quoted 9 lines · Borislav Petkov
Quoted 3 lines · Zhenzhong Duan

Imagine kernel already found a microcode blob A with extended sig/pf matching current cpu, then another microcode B is checked which doesn't match current cpu...

Do you see the

	if (!microcode_matches(mc_header, uci->cpu_sig.sig)) {

call a couple of lines earlier?

Sure, but it didn't ensure a match in stepping and pf, is that expected?

Do you see the

	if (!has_newer_microcode(data,
				 uci->cpu_sig.sig,
                                 uci->cpu_sig.pf,
                                 uci->cpu_sig.rev))

a couple lines later?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.