Skip to content

Commit 69cb33e

Browse files
author
Ingo Molnar
committed
Merge branch 'x86/microcode' into x86/core, to merge dependent commits
Prepare to resolve conflicts with an upstream series of fixes that conflict with pending x86 changes: 6f5bf94 Merge tag 'its-for-linus-20250509' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Signed-off-by: Ingo Molnar <[email protected]>
2 parents ec8f353 + 4804f5a commit 69cb33e

File tree

11 files changed

+248
-4
lines changed

11 files changed

+248
-4
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ What: /sys/devices/system/cpu/vulnerabilities
516516
/sys/devices/system/cpu/vulnerabilities/mds
517517
/sys/devices/system/cpu/vulnerabilities/meltdown
518518
/sys/devices/system/cpu/vulnerabilities/mmio_stale_data
519+
/sys/devices/system/cpu/vulnerabilities/old_microcode
519520
/sys/devices/system/cpu/vulnerabilities/reg_file_data_sampling
520521
/sys/devices/system/cpu/vulnerabilities/retbleed
521522
/sys/devices/system/cpu/vulnerabilities/spec_store_bypass

Documentation/admin-guide/hw-vuln/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ are configurable at compile, boot or run time.
2323
gather_data_sampling
2424
reg-file-data-sampling
2525
rsb
26+
old_microcode
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=============
4+
Old Microcode
5+
=============
6+
7+
The kernel keeps a table of released microcode. Systems that had
8+
microcode older than this at boot will say "Vulnerable". This means
9+
that the system was vulnerable to some known CPU issue. It could be
10+
security or functional, the kernel does not know or care.
11+
12+
You should update the CPU microcode to mitigate any exposure. This is
13+
usually accomplished by updating the files in
14+
/lib/firmware/intel-ucode/ via normal distribution updates. Intel also
15+
distributes these files in a github repo:
16+
17+
https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files.git
18+
19+
Just like all the other hardware vulnerabilities, exposure is
20+
determined at boot. Runtime microcode updates do not change the status
21+
of this vulnerability.

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,6 @@
534534
#define X86_BUG_BHI X86_BUG( 1*32+ 3) /* "bhi" CPU is affected by Branch History Injection */
535535
#define X86_BUG_IBPB_NO_RET X86_BUG( 1*32+ 4) /* "ibpb_no_ret" IBPB omits return target predictions */
536536
#define X86_BUG_SPECTRE_V2_USER X86_BUG( 1*32+ 5) /* "spectre_v2_user" CPU is affected by Spectre variant 2 attack between user processes */
537+
#define X86_BUG_OLD_MICROCODE X86_BUG( 1*32+ 6) /* "old_microcode" CPU has old microcode, it is surely vulnerable to something */
538+
537539
#endif /* _ASM_X86_CPUFEATURES_H */

arch/x86/kernel/cpu/bugs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,14 @@ static ssize_t rfds_show_state(char *buf)
29632963
return sysfs_emit(buf, "%s\n", rfds_strings[rfds_mitigation]);
29642964
}
29652965

2966+
static ssize_t old_microcode_show_state(char *buf)
2967+
{
2968+
if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
2969+
return sysfs_emit(buf, "Unknown: running under hypervisor");
2970+
2971+
return sysfs_emit(buf, "Vulnerable\n");
2972+
}
2973+
29662974
static char *stibp_state(void)
29672975
{
29682976
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
@@ -3144,6 +3152,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
31443152
case X86_BUG_RFDS:
31453153
return rfds_show_state(buf);
31463154

3155+
case X86_BUG_OLD_MICROCODE:
3156+
return old_microcode_show_state(buf);
3157+
31473158
default:
31483159
break;
31493160
}
@@ -3220,6 +3231,11 @@ ssize_t cpu_show_reg_file_data_sampling(struct device *dev, struct device_attrib
32203231
{
32213232
return cpu_show_common(dev, attr, buf, X86_BUG_RFDS);
32223233
}
3234+
3235+
ssize_t cpu_show_old_microcode(struct device *dev, struct device_attribute *attr, char *buf)
3236+
{
3237+
return cpu_show_common(dev, attr, buf, X86_BUG_OLD_MICROCODE);
3238+
}
32233239
#endif
32243240

32253241
void __warn_thunk(void)

arch/x86/kernel/cpu/common.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,52 @@ static bool __init vulnerable_to_rfds(u64 x86_arch_cap_msr)
13201320
return cpu_matches(cpu_vuln_blacklist, RFDS);
13211321
}
13221322

1323+
static struct x86_cpu_id cpu_latest_microcode[] = {
1324+
#include "microcode/intel-ucode-defs.h"
1325+
{}
1326+
};
1327+
1328+
static bool __init cpu_has_old_microcode(void)
1329+
{
1330+
const struct x86_cpu_id *m = x86_match_cpu(cpu_latest_microcode);
1331+
1332+
/* Give unknown CPUs a pass: */
1333+
if (!m) {
1334+
/* Intel CPUs should be in the list. Warn if not: */
1335+
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
1336+
pr_info("x86/CPU: Model not found in latest microcode list\n");
1337+
return false;
1338+
}
1339+
1340+
/*
1341+
* Hosts usually lie to guests with a super high microcode
1342+
* version. Just ignore what hosts tell guests:
1343+
*/
1344+
if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
1345+
return false;
1346+
1347+
/* Consider all debug microcode to be old: */
1348+
if (boot_cpu_data.microcode & BIT(31))
1349+
return true;
1350+
1351+
/* Give new microcode a pass: */
1352+
if (boot_cpu_data.microcode >= m->driver_data)
1353+
return false;
1354+
1355+
/* Uh oh, too old: */
1356+
return true;
1357+
}
1358+
13231359
static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
13241360
{
13251361
u64 x86_arch_cap_msr = x86_read_arch_cap_msr();
13261362

1363+
if (cpu_has_old_microcode()) {
1364+
pr_warn("x86/CPU: Running old microcode\n");
1365+
setup_force_cpu_bug(X86_BUG_OLD_MICROCODE);
1366+
add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
1367+
}
1368+
13271369
/* Set ITLB_MULTIHIT bug if cpu is not in the whitelist and not mitigated */
13281370
if (!cpu_matches(cpu_vuln_whitelist, NO_ITLB_MULTIHIT) &&
13291371
!(x86_arch_cap_msr & ARCH_CAP_PSCHANGE_MC_NO))

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ static bool verify_sha256_digest(u32 patch_id, u32 cur_rev, const u8 *data, unsi
217217
{
218218
struct patch_digest *pd = NULL;
219219
u8 digest[SHA256_DIGEST_SIZE];
220-
struct sha256_state s;
221220
int i;
222221

223222
if (x86_family(bsp_cpuid_1_eax) < 0x17)
@@ -235,9 +234,7 @@ static bool verify_sha256_digest(u32 patch_id, u32 cur_rev, const u8 *data, unsi
235234
return false;
236235
}
237236

238-
sha256_init(&s);
239-
sha256_update(&s, data, len);
240-
sha256_final(&s, digest);
237+
sha256(data, len, digest);
241238

242239
if (memcmp(digest, pd->sha256, sizeof(digest))) {
243240
pr_err("Patch 0x%x SHA256 digest mismatch!\n", patch_id);
@@ -1178,11 +1175,18 @@ static void microcode_fini_cpu_amd(int cpu)
11781175
uci->mc = NULL;
11791176
}
11801177

1178+
static void finalize_late_load_amd(int result)
1179+
{
1180+
if (result)
1181+
cleanup();
1182+
}
1183+
11811184
static struct microcode_ops microcode_amd_ops = {
11821185
.request_microcode_fw = request_microcode_amd,
11831186
.collect_cpu_info = collect_cpu_info_amd,
11841187
.apply_microcode = apply_microcode_amd,
11851188
.microcode_fini_cpu = microcode_fini_cpu_amd,
1189+
.finalize_late_load = finalize_late_load_amd,
11861190
.nmi_safe = true,
11871191
};
11881192

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ static int load_late_locked(void)
696696
return load_late_stop_cpus(true);
697697
case UCODE_NFOUND:
698698
return -ENOENT;
699+
case UCODE_OK:
700+
return 0;
699701
default:
700702
return -EBADFD;
701703
}

0 commit comments

Comments
 (0)