Message ID | 20190606200646.3951-24-yu-cheng.yu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Control-flow Enforcement: Shadow Stack | expand |
On Thu, Jun 06, 2019 at 01:06:42PM -0700, Yu-cheng Yu wrote: > +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY > +int arch_setup_property(void *ehdr, void *phdr, struct file *f, bool inter) > +{ > + int r; > + uint32_t property; Flip those two lines around. > + > + r = get_gnu_property(ehdr, phdr, f, GNU_PROPERTY_X86_FEATURE_1_AND, > + &property); > + > + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); It seems to me that memset would be better placed before get_gnu_property(). > + if (r) > + return r; > + > + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { if (r || !cpu_feature_enabled()) return r; > + if (property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) > + r = cet_setup_shstk(); > + if (r < 0) > + return r; > + } > + return r; and loose the indent. > +} > +#endif > -- > 2.17.1 >
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1664918c2c1c..df8b57de75b2 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1928,6 +1928,7 @@ config X86_INTEL_SHADOW_STACK_USER select ARCH_USES_HIGH_VMA_FLAGS select X86_INTEL_CET select ARCH_HAS_SHSTK + select ARCH_USE_GNU_PROPERTY ---help--- Shadow stack provides hardware protection against program stack corruption. Only when all the following are true will an application diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 250e4c4ac6d9..c51df5b4e116 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -828,3 +828,27 @@ unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } + +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY +int arch_setup_property(void *ehdr, void *phdr, struct file *f, bool inter) +{ + int r; + uint32_t property; + + r = get_gnu_property(ehdr, phdr, f, GNU_PROPERTY_X86_FEATURE_1_AND, + &property); + + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); + + if (r) + return r; + + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { + if (property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + r = cet_setup_shstk(); + if (r < 0) + return r; + } + return r; +} +#endif