Skip to contentSkip to conversation

x86, amd-ucode: Check UCODE_MAGIC before loading the container file

PATCH In review Andreas Herrmann 4 participants 9 messages Oct 29, 2009 – Nov 10, 2009 x86

lore
Share & tools
lore
#1 lore raw

PATCH 2/2 x86, amd-ucode: Remove needless log messages

In reply to Andreas Herrmann
---
 arch/x86/kernel/microcode_amd.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
arch/x86/kernel/microcode_amd.c +1 -8
index f4c538b..c043534 100644
@@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
 		return 0;
 	}
 
-	if (mc_header->processor_rev_id != equiv_cpu_id) {
-		printk(KERN_ERR	"microcode: CPU%d: patch mismatch "
-		       "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
-		       cpu, mc_header->processor_rev_id, equiv_cpu_id);
+	if (mc_header->processor_rev_id != equiv_cpu_id)
 		return 0;
-	}
 
 	/* ucode might be chipset specific -- currently we don't support this */
 	if (mc_header->nb_dev_id || mc_header->sb_dev_id) {
@@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
 
 	total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));
 
-	printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
-	       size, total_size);
-
 	if (total_size > size || total_size > UCODE_MAX_SIZE) {
 		printk(KERN_ERR "microcode: error: size mismatch\n");
 		return NULL;
Signature · 1 line
1.6.5.1
#0 lore raw

PATCH 1/2 x86, amd-ucode: Check UCODE_MAGIC before loading the container file

Quoted 1 line

From 5183dd763c6dc9f760e29f3313e0ae3dda5228a2 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

---
 arch/x86/kernel/microcode_amd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/microcode_amd.c +6 -0
index 366baa1..f4c538b 100644
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
 		return UCODE_NFOUND;
 	}
 
+	if (*(u32 *)firmware->data != UCODE_MAGIC) {
+		printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+		       *(u32 *)firmware->data);
+		return UCODE_ERROR;
+	}
+
 	ret = generic_load_microcode(cpu, firmware->data, firmware->size);
 
 	release_firmware(firmware);
Signature · 1 line
1.6.5.1
#5 lore raw
Quoted 18 lines · Andreas Herrmann
Quoted 1 line

From 5183dd763c6dc9f760e29f3313e0ae3dda5228a2 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

---
 arch/x86/kernel/microcode_amd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/microcode_amd.c +0 -0
index 366baa1..f4c538b 100644
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
 		return UCODE_NFOUND;
 	}

arch/x86/kernel/microcode_amd.c static enum ucode_state request_microcode_fw(int cpu, struct device *device) · line 328

Quoted 10 lines
arch/x86/kernel/microcode_amd.c +6 -0
 
+	if (*(u32 *)firmware->data != UCODE_MAGIC) {
+		printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+		       *(u32 *)firmware->data);
+		return UCODE_ERROR;
+	}
+
 	ret = generic_load_microcode(cpu, firmware->data, firmware->size);
 
 	release_firmware(firmware);

hm, there's no changelog. How was it found, what's the significance, do we want it for .32 - i suspect we want - but we need a better changelog for that.

Thanks,

Ingo

#6 lore raw

Hi Ingo,

Quoted 1 line · Ingo Molnar

hm, there's no changelog. How was it found,

code staring :)

Quoted 1 line

what's the significance,

required by design.

Quoted 2 lines

do we want it for .32 - i suspect we want - but we need a better changelog for that.

Yes. How's that?

--

Quoted 1 line

From f41bced57e05c8adc0d2c13864b6323c191d45d2 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

When loading a microcode binary, we should check the microcode magic value embedded in the image before continuing loading. The original check got lost somehow so re-add it to the firmware requesting path.

---
 arch/x86/kernel/microcode_amd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/microcode_amd.c +6 -0
index 366baa1..f4c538b 100644
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
 		return UCODE_NFOUND;
 	}
 
+	if (*(u32 *)firmware->data != UCODE_MAGIC) {
+		printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+		       *(u32 *)firmware->data);
+		return UCODE_ERROR;
+	}
+
 	ret = generic_load_microcode(cpu, firmware->data, firmware->size);
 
 	release_firmware(firmware);
Signature · 6 lines
1.6.5


-- 
Regards/Gruss,
    Boris.
#7 lore raw
Quoted 26 lines · Borislav Petkov

Hi Ingo,

Quoted 1 line · Ingo Molnar

hm, there's no changelog. How was it found,

code staring :)

Quoted 1 line

what's the significance,

required by design.

Quoted 2 lines

do we want it for .32 - i suspect we want - but we need a better changelog for that.

Yes. How's that?

--

Quoted 1 line

From f41bced57e05c8adc0d2c13864b6323c191d45d2 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

When loading a microcode binary, we should check the microcode magic value embedded in the image before continuing loading. The original check got lost somehow so re-add it to the firmware requesting path.

Quoted 5 lines
---
 arch/x86/kernel/microcode_amd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Looks good - thanks!

Ingo

#2 lore raw

Re: [PATCH 2/2] x86, amd-ucode: Remove needless log messages

In reply to Andreas Herrmann
Quoted 11 lines · Andreas Herrmann
---
 arch/x86/kernel/microcode_amd.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
arch/x86/kernel/microcode_amd.c +0 -0
index f4c538b..c043534 100644

arch/x86/kernel/microcode_amd.c get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size) · line 190

Quoted 6 lines
arch/x86/kernel/microcode_amd.c +0 -3
@@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
 
 	total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));
 
-	printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
-	       size, total_size);
-

we should remove this one indeed.

Quoted 4 lines
arch/x86/kernel/microcode_amd.c +0 -0
@@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
 		return 0;
 	}
 

arch/x86/kernel/microcode_amd.c static int get_matching_microcode(int cpu, void *mc, int rev) · line 116

Quoted 10 lines
arch/x86/kernel/microcode_amd.c +1 -5
-	if (mc_header->processor_rev_id != equiv_cpu_id) {
-		printk(KERN_ERR	"microcode: CPU%d: patch mismatch "
-		       "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
-		       cpu, mc_header->processor_rev_id, equiv_cpu_id);
+	if (mc_header->processor_rev_id != equiv_cpu_id)
 		return 0;
-	}
 
 	/* ucode might be chipset specific -- currently we don't support this */
 	if (mc_header->nb_dev_id || mc_header->sb_dev_id) {

but why remove this one? Someone tries to load a mismatching microcode file, isnt that some sort of bug in user-space? (Which ought to find out whether it has anything for the CPU at hand, and only attempt it if it's matching - or so.)

maybe it's not a KERN_ERR but KERN_INFO, but still.

Ingo

#3 lore raw

Re: [PATCH 2/2] x86, amd-ucode: Remove needless log messages

Quoted 2 lines · Ingo Molnar

* Andreas Herrmann <[email protected]> wrote:

[...]

Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/microcode_amd.c +1 -5
-	if (mc_header->processor_rev_id != equiv_cpu_id) {
-		printk(KERN_ERR	"microcode: CPU%d: patch mismatch "
-		       "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
-		       cpu, mc_header->processor_rev_id, equiv_cpu_id);
+	if (mc_header->processor_rev_id != equiv_cpu_id)
 		return 0;
-	}
Quoted 7 lines

arch/x86/kernel/microcode_amd.c static int get_matching_microcode(int cpu, void *mc, int rev) · line 116

Quoted 2 lines
arch/x86/kernel/microcode_amd.c +0 -0
 	/* ucode might be chipset specific -- currently we don't support this */
 	if (mc_header->nb_dev_id || mc_header->sb_dev_id) {

but why remove this one? Someone tries to load a mismatching microcode file, isnt that some sort of bug in user-space? (Which ought to find out whether it has anything for the CPU at hand, and only attempt it if it's matching - or so.)

The ucode file that we provide contains many ucode patches -- its a "container" file providing patches for several CPUs. Of course this means that there are patches in the file which are not meant for that CPU -- that is no error case but rather normal.

Quoted 1 line

maybe it's not a KERN_ERR but KERN_INFO, but still.

KERN_DEBUG at the most. It's simple as that: if the CPU has same PATCH_LEVEL before and after microcode.ko tried to update the ucode, there either was no ucode-file available or it just didn't contain a newer ucode version for this CPU.

Andreas

#8 lore raw
In reply to Andreas Herrmann
Commit-ID:  506f90eeae682dc96c11c7aefac0262b3a560b49
Gitweb:     http://git.kernel.org/tip/506f90eeae682dc96c11c7aefac0262b3a560b49
Author:     Borislav Petkov <[email protected]>
AuthorDate: Thu, 29 Oct 2009 14:45:52 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 05:46:09 +0100

x86, amd-ucode: Check UCODE_MAGIC before loading the container file

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/microcode_amd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/microcode_amd.c +6 -0
index 366baa1..f4c538b 100644
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
 		return UCODE_NFOUND;
 	}
 
+	if (*(u32 *)firmware->data != UCODE_MAGIC) {
+		printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+		       *(u32 *)firmware->data);
+		return UCODE_ERROR;
+	}
+
 	ret = generic_load_microcode(cpu, firmware->data, firmware->size);
 
 	release_firmware(firmware);
#4 lore raw

[tip:x86/microcode] x86, amd-ucode: Remove needless log messages

In reply to Andreas Herrmann
Commit-ID:  6e18da75c28b592594fd632cf3e6eb09d3d078de
Gitweb:     http://git.kernel.org/tip/6e18da75c28b592594fd632cf3e6eb09d3d078de
Author:     Andreas Herrmann <[email protected]>
AuthorDate: Thu, 29 Oct 2009 14:47:42 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 05:49:28 +0100

x86, amd-ucode: Remove needless log messages

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/microcode_amd.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
arch/x86/kernel/microcode_amd.c +1 -8
index f4c538b..c043534 100644
@@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
 		return 0;
 	}
 
-	if (mc_header->processor_rev_id != equiv_cpu_id) {
-		printk(KERN_ERR	"microcode: CPU%d: patch mismatch "
-		       "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
-		       cpu, mc_header->processor_rev_id, equiv_cpu_id);
+	if (mc_header->processor_rev_id != equiv_cpu_id)
 		return 0;
-	}
 
 	/* ucode might be chipset specific -- currently we don't support this */
 	if (mc_header->nb_dev_id || mc_header->sb_dev_id) {
@@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
 
 	total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));
 
-	printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
-	       size, total_size);
-
 	if (total_size > size || total_size > UCODE_MAX_SIZE) {
 		printk(KERN_ERR "microcode: error: size mismatch\n");
 		return NULL;