Misc x86 fixes:
- Fix a kexec bug, - Fix an UML build bug, - Fix a handful of SRSO related bugs, - Fix a shadow stacks handling bug & robustify related code. Signed-off-by: Ingo Molnar <mingo@kernel.org> -----BEGIN PGP SIGNATURE----- iQJFBAABCgAvFiEEBpT5eoXrXCwVQwEKEnMQ0APhK1gFAmUNbQIRHG1pbmdvQGtl cm5lbC5vcmcACgkQEnMQ0APhK1jVIg/9EChW7qFTda8joR41Uayg07VIOpGirDLu 7hjzOnt4Ni93cfFNUBkKDKXoWxGAiOD+cRDnT6+zsJAvAZR26Y3UNVLYlAy+lFKK 9kRxeDM7nOEKqCC+zneinMFcIKmZRttMLpj8O901jB2S08x4UarnNx5SaWEcqYbn rf1XIEuEvlxqMfafNueS/TRadV52qVU8Y+2+inkDnM7dDNwt+rCs5tQ9ebJos8QO tsAoQes1G+0mjPrpqAgsIic5e3QCHliwVr8ASQrKZ9KR+fokEJRbSBNjgHUCNeVN 0bHBhuDJBSniC7QmAQGEizrZWmHl2HxwYYnCE0gd0g24b7sDTwWBFSXWratCrPdX e4qYq36xonWdQcbpVF8ijMXF/R810vDyis/yc/BTeo5EBWf6aM/cx1dmS9DUxRpA QsIW2amSCPVYwYE5MAC+K/DM9nq1tk8YnKi4Mob3L28+W3CmVwSwT9S86z2QLlZu +KgVV4yBtJY1FJqVur5w3awhFtqLfBdfIvs6uQCd9VZXVPbBfS8+rOQmmhFixEDu FSPlAChmXYTAM2R+UxcEvw1Zckrtd2BCOa8UrY2lq57mduBK1EymdpfjlrUAChLG x7fQBOGNgOTLwYcsurIdS5jAqiudpnJ/KDG8ZAmKsVoW96JCPp9B3tVZMp9tT30C 8HRwSPX4384= =58St -----END PGP SIGNATURE----- Merge tag 'x86-urgent-2023-09-22' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull misc x86 fixes from Ingo Molnar: - Fix a kexec bug - Fix an UML build bug - Fix a handful of SRSO related bugs - Fix a shadow stacks handling bug & robustify related code * tag 'x86-urgent-2023-09-22' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/shstk: Add warning for shadow stack double unmap x86/shstk: Remove useless clone error handling x86/shstk: Handle vfork clone failure correctly x86/srso: Fix SBPB enablement for spec_rstack_overflow=off x86/srso: Don't probe microcode in a guest x86/srso: Set CPUID feature bits independently of bug or mitigation status x86/srso: Fix srso_show_state() side effect x86/asm: Fix build of UML with KASAN x86/mm, kexec, ima: Use memblock_free_late() from ima_free_kexec_buffer()
This commit is contained in:
commit
e583bffeb8
|
@ -105,6 +105,13 @@
|
|||
CFI_POST_PADDING \
|
||||
SYM_FUNC_END(__cfi_##name)
|
||||
|
||||
/* UML needs to be able to override memcpy() and friends for KASAN. */
|
||||
#ifdef CONFIG_UML
|
||||
# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS_WEAK
|
||||
#else
|
||||
# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS
|
||||
#endif
|
||||
|
||||
/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
|
||||
#define SYM_TYPED_FUNC_START(name) \
|
||||
SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_F_ALIGN) \
|
||||
|
|
|
@ -186,7 +186,6 @@ do { \
|
|||
#else
|
||||
#define deactivate_mm(tsk, mm) \
|
||||
do { \
|
||||
if (!tsk->vfork_done) \
|
||||
shstk_free(tsk); \
|
||||
load_gs_index(0); \
|
||||
loadsegment(fs, 0); \
|
||||
|
|
|
@ -683,13 +683,11 @@ extern u16 get_llc_id(unsigned int cpu);
|
|||
#ifdef CONFIG_CPU_SUP_AMD
|
||||
extern u32 amd_get_nodes_per_socket(void);
|
||||
extern u32 amd_get_highest_perf(void);
|
||||
extern bool cpu_has_ibpb_brtype_microcode(void);
|
||||
extern void amd_clear_divider(void);
|
||||
extern void amd_check_microcode(void);
|
||||
#else
|
||||
static inline u32 amd_get_nodes_per_socket(void) { return 0; }
|
||||
static inline u32 amd_get_highest_perf(void) { return 0; }
|
||||
static inline bool cpu_has_ibpb_brtype_microcode(void) { return false; }
|
||||
static inline void amd_clear_divider(void) { }
|
||||
static inline void amd_check_microcode(void) { }
|
||||
#endif
|
||||
|
|
|
@ -766,6 +766,15 @@ static void early_init_amd(struct cpuinfo_x86 *c)
|
|||
|
||||
if (cpu_has(c, X86_FEATURE_TOPOEXT))
|
||||
smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1;
|
||||
|
||||
if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_IBPB_BRTYPE)) {
|
||||
if (c->x86 == 0x17 && boot_cpu_has(X86_FEATURE_AMD_IBPB))
|
||||
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
|
||||
else if (c->x86 >= 0x19 && !wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
|
||||
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
|
||||
setup_force_cpu_cap(X86_FEATURE_SBPB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_amd_k8(struct cpuinfo_x86 *c)
|
||||
|
@ -1301,25 +1310,6 @@ void amd_check_microcode(void)
|
|||
on_each_cpu(zenbleed_check_cpu, NULL, 1);
|
||||
}
|
||||
|
||||
bool cpu_has_ibpb_brtype_microcode(void)
|
||||
{
|
||||
switch (boot_cpu_data.x86) {
|
||||
/* Zen1/2 IBPB flushes branch type predictions too. */
|
||||
case 0x17:
|
||||
return boot_cpu_has(X86_FEATURE_AMD_IBPB);
|
||||
case 0x19:
|
||||
/* Poke the MSR bit on Zen3/4 to check its presence. */
|
||||
if (!wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
|
||||
setup_force_cpu_cap(X86_FEATURE_SBPB);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue a DIV 0/1 insn to clear any division data from previous DIV
|
||||
* operations.
|
||||
|
|
|
@ -2404,26 +2404,15 @@ early_param("spec_rstack_overflow", srso_parse_cmdline);
|
|||
|
||||
static void __init srso_select_mitigation(void)
|
||||
{
|
||||
bool has_microcode;
|
||||
bool has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE);
|
||||
|
||||
if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
|
||||
goto pred_cmd;
|
||||
|
||||
/*
|
||||
* The first check is for the kernel running as a guest in order
|
||||
* for guests to verify whether IBPB is a viable mitigation.
|
||||
*/
|
||||
has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) || cpu_has_ibpb_brtype_microcode();
|
||||
if (!has_microcode) {
|
||||
pr_warn("IBPB-extending microcode not applied!\n");
|
||||
pr_warn(SRSO_NOTICE);
|
||||
} else {
|
||||
/*
|
||||
* Enable the synthetic (even if in a real CPUID leaf)
|
||||
* flags for guests.
|
||||
*/
|
||||
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
|
||||
|
||||
/*
|
||||
* Zen1/2 with SMT off aren't vulnerable after the right
|
||||
* IBPB microcode has been applied.
|
||||
|
@ -2444,7 +2433,7 @@ static void __init srso_select_mitigation(void)
|
|||
|
||||
switch (srso_cmd) {
|
||||
case SRSO_CMD_OFF:
|
||||
return;
|
||||
goto pred_cmd;
|
||||
|
||||
case SRSO_CMD_MICROCODE:
|
||||
if (has_microcode) {
|
||||
|
@ -2717,7 +2706,7 @@ static ssize_t srso_show_state(char *buf)
|
|||
|
||||
return sysfs_emit(buf, "%s%s\n",
|
||||
srso_strings[srso_mitigation],
|
||||
(cpu_has_ibpb_brtype_microcode() ? "" : ", no microcode"));
|
||||
boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) ? "" : ", no microcode");
|
||||
}
|
||||
|
||||
static ssize_t gds_show_state(char *buf)
|
||||
|
|
|
@ -257,13 +257,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
|
|||
if (!ret && unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
|
||||
io_bitmap_share(p);
|
||||
|
||||
/*
|
||||
* If copy_thread() if failing, don't leak the shadow stack possibly
|
||||
* allocated in shstk_alloc_thread_stack() above.
|
||||
*/
|
||||
if (ret)
|
||||
shstk_free(p);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -358,15 +358,11 @@ static void __init add_early_ima_buffer(u64 phys_addr)
|
|||
#if defined(CONFIG_HAVE_IMA_KEXEC) && !defined(CONFIG_OF_FLATTREE)
|
||||
int __init ima_free_kexec_buffer(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!ima_kexec_buffer_size)
|
||||
return -ENOENT;
|
||||
|
||||
rc = memblock_phys_free(ima_kexec_buffer_phys,
|
||||
memblock_free_late(ima_kexec_buffer_phys,
|
||||
ima_kexec_buffer_size);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
ima_kexec_buffer_phys = 0;
|
||||
ima_kexec_buffer_size = 0;
|
||||
|
|
|
@ -205,10 +205,21 @@ unsigned long shstk_alloc_thread_stack(struct task_struct *tsk, unsigned long cl
|
|||
return 0;
|
||||
|
||||
/*
|
||||
* For CLONE_VM, except vfork, the child needs a separate shadow
|
||||
* For CLONE_VFORK the child will share the parents shadow stack.
|
||||
* Make sure to clear the internal tracking of the thread shadow
|
||||
* stack so the freeing logic run for child knows to leave it alone.
|
||||
*/
|
||||
if (clone_flags & CLONE_VFORK) {
|
||||
shstk->base = 0;
|
||||
shstk->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* For !CLONE_VM the child will use a copy of the parents shadow
|
||||
* stack.
|
||||
*/
|
||||
if ((clone_flags & (CLONE_VFORK | CLONE_VM)) != CLONE_VM)
|
||||
if (!(clone_flags & CLONE_VM))
|
||||
return 0;
|
||||
|
||||
size = adjust_shstk_size(stack_size);
|
||||
|
@ -408,7 +419,25 @@ void shstk_free(struct task_struct *tsk)
|
|||
if (!tsk->mm || tsk->mm != current->mm)
|
||||
return;
|
||||
|
||||
/*
|
||||
* If shstk->base is NULL, then this task is not managing its
|
||||
* own shadow stack (CLONE_VFORK). So skip freeing it.
|
||||
*/
|
||||
if (!shstk->base)
|
||||
return;
|
||||
|
||||
/*
|
||||
* shstk->base is NULL for CLONE_VFORK child tasks, and so is
|
||||
* normal. But size = 0 on a shstk->base is not normal and
|
||||
* indicated an attempt to free the thread shadow stack twice.
|
||||
* Warn about it.
|
||||
*/
|
||||
if (WARN_ON(!shstk->size))
|
||||
return;
|
||||
|
||||
unmap_shadow_stack(shstk->base, shstk->size);
|
||||
|
||||
shstk->size = 0;
|
||||
}
|
||||
|
||||
static int wrss_control(bool enable)
|
||||
|
|
|
@ -40,7 +40,7 @@ SYM_TYPED_FUNC_START(__memcpy)
|
|||
SYM_FUNC_END(__memcpy)
|
||||
EXPORT_SYMBOL(__memcpy)
|
||||
|
||||
SYM_FUNC_ALIAS(memcpy, __memcpy)
|
||||
SYM_FUNC_ALIAS_MEMFUNC(memcpy, __memcpy)
|
||||
EXPORT_SYMBOL(memcpy)
|
||||
|
||||
SYM_FUNC_START_LOCAL(memcpy_orig)
|
||||
|
|
|
@ -212,5 +212,5 @@ SYM_FUNC_START(__memmove)
|
|||
SYM_FUNC_END(__memmove)
|
||||
EXPORT_SYMBOL(__memmove)
|
||||
|
||||
SYM_FUNC_ALIAS(memmove, __memmove)
|
||||
SYM_FUNC_ALIAS_MEMFUNC(memmove, __memmove)
|
||||
EXPORT_SYMBOL(memmove)
|
||||
|
|
|
@ -40,7 +40,7 @@ SYM_FUNC_START(__memset)
|
|||
SYM_FUNC_END(__memset)
|
||||
EXPORT_SYMBOL(__memset)
|
||||
|
||||
SYM_FUNC_ALIAS(memset, __memset)
|
||||
SYM_FUNC_ALIAS_MEMFUNC(memset, __memset)
|
||||
EXPORT_SYMBOL(memset)
|
||||
|
||||
SYM_FUNC_START_LOCAL(memset_orig)
|
||||
|
|
Loading…
Reference in New Issue