Patch "module/retpoline: Warn about missing retpoline in module" has been added to the 4.15-stable tree
Subsystems (5)
This is a note to let you know that I've just added the patch titled
module/retpoline: Warn about missing retpoline in module
to the 4.15-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
moduleretpoline_Warn_about_missing_retpoline_in_module.patch
and it can be found in the queue-4.15 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Subject: module/retpoline: Warn about missing retpoline in module
From: Andi Kleen [email protected]
Date: Thu Jan 25 15:50:28 2018 -0800
From: Andi Kleen [email protected]
commit caf7501a1b4ec964190f31f9c3f163de252273b8
There's a risk that a kernel which has full retpoline mitigations becomes vulnerable when a module gets loaded that hasn't been compiled with the right compiler or the right option.
To enable detection of that mismatch at module load time, add a module info string "retpoline" at build time when the module was compiled with retpoline support. This only covers compiled C source, but assembler source or prebuilt object files are not checked.
If a retpoline enabled kernel detects a non retpoline protected module at load time, print a warning and report it in the sysfs vulnerability file.
[ tglx: Massaged changelog ]
--- arch/x86/kernel/cpu/bugs.c | 17 ++++++++++++++++- include/linux/module.h | 9 +++++++++ kernel/module.c | 11 +++++++++++ scripts/mod/modpost.c | 9 +++++++++ 4 files changed, 45 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +16 -1
@@ -11,6 +11,7 @@#include <linux/init.h> #include <linux/utsname.h> #include <linux/cpu.h> +#include <linux/module.h> #include <asm/nospec-branch.h> #include <asm/cmdline.h>
@@ -93,6 +94,19 @@ static const char *spectre_v2_strings[]#define pr_fmt (fmt) "Spectre V2 mitigation: " fmtstatic enum spectre_v2_mitigation spectre_v2_enabled =SPECTRE_V2_NONE ; +static bool spectre_v2_bad_module; + +#ifdef RETPOLINE +bool retpoline_module_ok (bool has_retpoline) +{ +if (spectre_v2_enabled ==SPECTRE_V2_NONE || has_retpoline) +return true; + +pr_err ("System may be vunerable to spectre v2\n" ); + spectre_v2_bad_module = true; +return false; +} +#endif static void __init spec2_print_if_insecure (const char *reason) {
@@ -278,6 +292,7 @@ ssize_t cpu_show_spectre_v2(struct devicif (!boot_cpu_has_bug (X86_BUG_SPECTRE_V2 ))return sprintf (buf,"Not affected\n" ); - return sprintf(buf, "%s\n", spectre_v2_strings[spectre_v2_enabled]); +return sprintf (buf,"%s%s\n" , spectre_v2_strings[spectre_v2_enabled], + spectre_v2_bad_module ? " - vulnerable module loaded" : ""); }#endif
include/linux/module.h +9 -0
@@ -801,6 +801,15 @@ static inline void module_bug_finalize(cstatic inline void module_bug_cleanup (struct module *mod) {}#endif /* CONFIG_GENERIC_BUG */ +#ifdef RETPOLINE +extern bool retpoline_module_ok (bool has_retpoline); +#else +static inline bool retpoline_module_ok (bool has_retpoline) +{ +return true; +} +#endif +#ifdef CONFIG_MODULE_SIG static inline bool module_sig_ok (struct module *module) {
kernel/module.c +11 -0
@@ -2863,6 +2863,15 @@ static int check_modinfo_livepatch(struc }#endif /* CONFIG_LIVEPATCH */ +static void check_modinfo_retpoline (struct module *mod,struct load_info *info) +{ +if (retpoline_module_ok (get_modinfo (info,"retpoline" ))) +return ; + +pr_warn ("%s: loading module not compiled with retpoline compiler.\n" , + mod->name); +} +/* Sets info->hdr and info->len. */ static int copy_module_from_user (const void __user *umod,unsigned long len,struct load_info *info)
@@ -3029,6 +3038,8 @@ static int check_modinfo(struct module *add_taint_module (mod,TAINT_OOT_MODULE ,LOCKDEP_STILL_OK ); } +check_modinfo_retpoline (mod, info); +if (get_modinfo (info,"staging" )) {add_taint_module (mod,TAINT_CRAP ,LOCKDEP_STILL_OK ); pr_warn("%s: module is from the staging directory, the quality "
scripts/mod/modpost.c +9 -0
@@ -2165,6 +2165,14 @@ static void add_intree_flag(struct buffebuf_printf (b,"\nMODULE_INFO(intree, \"Y\");\n" ); } +/* Cannot check for assembler */ +static void add_retpoline (struct buffer *b) +{ +buf_printf (b,"\n#ifdef RETPOLINE\n" ); +buf_printf (b,"MODULE_INFO(retpoline, \"Y\");\n" ); +buf_printf (b,"#endif\n" ); +} +static void add_staging_flag (struct buffer *b,const char *name) {static const char *staging_dir ="drivers/staging" ;
@@ -2506,6 +2514,7 @@ int main(int argc, char **argv) err |=check_modname_len (mod);add_header (&buf, mod);add_intree_flag (&buf, !external_module); +add_retpoline (&buf);add_staging_flag (&buf, mod->name); err |=add_versions (&buf, mod);add_depends (&buf, mod, modules);
Patches currently in stable-queue which might be from [email protected] are
queue-4.15/x86pti_Do_not_enable_PTI_on_CPUs_which_are_not_vulnerable_to_Meltdown.patch queue-4.15/x86cpufeature_Blacklist_SPEC_CTRLPRED_CMD_on_early_Spectre_v2_microcodes.patch queue-4.15/x86cpufeatures_Add_Intel_feature_bits_for_Speculation_Control.patch queue-4.15/KVM_VMX_Make_indirect_call_speculation_safe.patch queue-4.15/x86msr_Add_definitions_for_new_speculation_control_MSRs.patch queue-4.15/x86alternative_Print_unadorned_pointers.patch queue-4.15/x86cpubugs_Make_retpoline_module_warning_conditional.patch queue-4.15/x86cpufeatures_Add_CPUID_7_EDX_CPUID_leaf.patch queue-4.15/x86bugs_Drop_one_mitigation_from_dmesg.patch queue-4.15/x86cpufeatures_Add_AMD_feature_bits_for_Speculation_Control.patch queue-4.15/moduleretpoline_Warn_about_missing_retpoline_in_module.patch queue-4.15/x86speculation_Add_basic_IBPB_(Indirect_Branch_Prediction_Barrier)_support.patch queue-4.15/x86speculation_Simplify_indirect_branch_prediction_barrier().patch queue-4.15/x86nospec_Fix_header_guards_names.patch queue-4.15/KVM_x86_Make_indirect_calls_in_emulator_speculation_safe.patch queue-4.15/x86retpoline_Simplify_vmexit_fill_RSB().patch queue-4.15/x86cpufeatures_Clean_up_Spectre_v2_related_CPUID_flags.patch