lkdtm: Make UNSET_SMEP built-in-only and unexport native_write_cr4()
Subsystems (3)
PATCH 1/1 lkdtm: Make UNSET_SMEP built-in-only and unexport native_write_cr4()
native_write_cr4 should not be exported to modules. Commit 21953ee5013d ("x86/cpu: Export native_write_cr4() only when CONFIG_LKTDM=m") restricted the export somewhat, but native_write_cr4() is still exposed to all GPL-compatible modules when CONFIG_LKDTM=m.
UNSET_SMEP is the only module user of native_write_cr4(). Restrict the test to CONFIG_LKDTM=y and remove the export. When LKDTM is built as a module, report XFAIL for UNSET_SMEP.
--- arch/x86/kernel/cpu/common.c | 3 --- drivers/misc/lkdtm/bugs.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/common.c +0 -3
@@ -490,9 +490,6 @@ void __no_profile native_write_cr4(unsigned long val) bits_changed); } } -#if IS_MODULE (CONFIG_LKDTM ) -EXPORT_SYMBOL_GPL (native_write_cr4); -#endif void cr4_update_irqsoff (unsigned long set,unsigned long clear) {
drivers/misc/lkdtm/bugs.c +2 -2
@@ -676,7 +676,7 @@ static void lkdtm_STACK_GUARD_PAGE_TRAILING(void)static void lkdtm_UNSET_SMEP (void ) { -#if IS_ENABLED (CONFIG_X86_64 ) && !IS_ENABLED (CONFIG_UML ) +#if IS_ENABLED (CONFIG_X86_64 ) && !IS_ENABLED (CONFIG_UML ) &&IS_BUILTIN (CONFIG_LKDTM )#define MOV_CR4_DEPTH 64void (*direct_write_cr4)(unsigned long val);unsigned char *insn;
@@ -737,7 +737,7 @@ static void lkdtm_UNSET_SMEP(void) native_write_cr4(cr4); }#else -pr_err ("XFAIL: this test is x86_64-only\n" ); +pr_err ("XFAIL: this test is x86_64-only and requires CONFIG_LKDTM=y\n" );#endif }
Signature · 1 line
2.56.0
Quoted 10 lines · Dennis Chen
native_write_cr4should not be exported to modules. Commit21953ee5013d("x86/cpu: Exportnative_write_cr4()only whenCONFIG_LKTDM=m") restricted the export somewhat, butnative_write_cr4()is still exposed to all GPL-compatible modules whenCONFIG_LKDTM=m.
UNSET_SMEPis the only module user ofnative_write_cr4(). Restrict the test toCONFIG_LKDTM=yand remove the export. When LKDTM is built as a module, report XFAIL forUNSET_SMEP.[...]
Applied to for-next/hardening, thanks!
[1/1] lkdtm: Make UNSET_SMEP built-in-only and unexport native_write_cr4()
https://git.kernel.org/kees/c/e2cd253cb31b
Take care,
Signature · 1 line
Kees Cook
Looks good: