Skip to content

Commit d410b62

Browse files
committed
Merge tag 'x86_urgent_for_v6.5_rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: - AMD's automatic IBRS doesn't enable cross-thread branch target injection protection (STIBP) for user processes. Enable STIBP on such systems. - Do not delete (but put the ref instead) of AMD MCE error thresholding sysfs kobjects when destroying them in order not to delete the kernfs pointer prematurely - Restore annotation in ret_from_fork_asm() in order to fix kthread stack unwinding from being marked as unreliable and thus breaking livepatching * tag 'x86_urgent_for_v6.5_rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled x86/MCE/AMD: Decrement threshold_bank refcount when removing threshold blocks x86: Fix kthread unwind
2 parents eb9fe17 + fd470a8 commit d410b62

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,14 @@ Spectre variant 2
484484

485485
Systems which support enhanced IBRS (eIBRS) enable IBRS protection once at
486486
boot, by setting the IBRS bit, and they're automatically protected against
487-
Spectre v2 variant attacks, including cross-thread branch target injections
488-
on SMT systems (STIBP). In other words, eIBRS enables STIBP too.
487+
Spectre v2 variant attacks.
489488

490-
Legacy IBRS systems clear the IBRS bit on exit to userspace and
491-
therefore explicitly enable STIBP for that
489+
On Intel's enhanced IBRS systems, this includes cross-thread branch target
490+
injections on SMT systems (STIBP). In other words, Intel eIBRS enables
491+
STIBP, too.
492+
493+
AMD Automatic IBRS does not protect userspace, and Legacy IBRS systems clear
494+
the IBRS bit on exit to userspace, therefore both explicitly enable STIBP.
492495

493496
The retpoline mitigation is turned on by default on vulnerable
494497
CPUs. It can be forced on or off by the administrator

arch/x86/entry/entry_64.S

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,15 @@ SYM_FUNC_END(__switch_to_asm)
285285
*/
286286
.pushsection .text, "ax"
287287
SYM_CODE_START(ret_from_fork_asm)
288-
UNWIND_HINT_REGS
288+
/*
289+
* This is the start of the kernel stack; even through there's a
290+
* register set at the top, the regset isn't necessarily coherent
291+
* (consider kthreads) and one cannot unwind further.
292+
*
293+
* This ensures stack unwinds of kernel threads terminate in a known
294+
* good state.
295+
*/
296+
UNWIND_HINT_END_OF_STACK
289297
ANNOTATE_NOENDBR // copy_thread
290298
CALL_DEPTH_ACCOUNT
291299

@@ -295,6 +303,12 @@ SYM_CODE_START(ret_from_fork_asm)
295303
movq %r12, %rcx /* fn_arg */
296304
call ret_from_fork
297305

306+
/*
307+
* Set the stack state to what is expected for the target function
308+
* -- at this point the register set should be a valid user set
309+
* and unwind should work normally.
310+
*/
311+
UNWIND_HINT_REGS
298312
jmp swapgs_restore_regs_and_return_to_usermode
299313
SYM_CODE_END(ret_from_fork_asm)
300314
.popsection

arch/x86/kernel/cpu/bugs.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,19 +1150,21 @@ spectre_v2_user_select_mitigation(void)
11501150
}
11511151

11521152
/*
1153-
* If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP
1153+
* If no STIBP, Intel enhanced IBRS is enabled, or SMT impossible, STIBP
11541154
* is not required.
11551155
*
1156-
* Enhanced IBRS also protects against cross-thread branch target
1156+
* Intel's Enhanced IBRS also protects against cross-thread branch target
11571157
* injection in user-mode as the IBRS bit remains always set which
11581158
* implicitly enables cross-thread protections. However, in legacy IBRS
11591159
* mode, the IBRS bit is set only on kernel entry and cleared on return
1160-
* to userspace. This disables the implicit cross-thread protection,
1161-
* so allow for STIBP to be selected in that case.
1160+
* to userspace. AMD Automatic IBRS also does not protect userspace.
1161+
* These modes therefore disable the implicit cross-thread protection,
1162+
* so allow for STIBP to be selected in those cases.
11621163
*/
11631164
if (!boot_cpu_has(X86_FEATURE_STIBP) ||
11641165
!smt_possible ||
1165-
spectre_v2_in_eibrs_mode(spectre_v2_enabled))
1166+
(spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
1167+
!boot_cpu_has(X86_FEATURE_AUTOIBRS)))
11661168
return;
11671169

11681170
/*
@@ -2294,7 +2296,8 @@ static ssize_t mmio_stale_data_show_state(char *buf)
22942296

22952297
static char *stibp_state(void)
22962298
{
2297-
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))
2299+
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
2300+
!boot_cpu_has(X86_FEATURE_AUTOIBRS))
22982301
return "";
22992302

23002303
switch (spectre_v2_user_stibp) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,10 @@ static void __threshold_remove_blocks(struct threshold_bank *b)
12611261
struct threshold_block *pos = NULL;
12621262
struct threshold_block *tmp = NULL;
12631263

1264-
kobject_del(b->kobj);
1264+
kobject_put(b->kobj);
12651265

12661266
list_for_each_entry_safe(pos, tmp, &b->blocks->miscj, miscj)
1267-
kobject_del(&pos->kobj);
1267+
kobject_put(b->kobj);
12681268
}
12691269

12701270
static void threshold_remove_bank(struct threshold_bank *bank)

0 commit comments

Comments
 (0)