Skip to content

Commit 2f662d1

Browse files
keesgregkh
authored andcommitted
lkdtm: Make arch-specific tests always available
[ Upstream commit ae56942 ] I'd like arch-specific tests to XFAIL when on a mismatched architecture so that we can more easily compare test coverage across all systems. Lacking kernel configs or CPU features count as a FAIL, not an XFAIL. Additionally fixes a build failure under 32-bit UML. Fixes: b09511c ("lkdtm: Add a DOUBLE_FAULT crash type on x86") Fixes: cea23ef ("lkdtm/bugs: Make double-fault test always available") Fixes: 6cb6982 ("lkdtm: arm64: test kernel pointer authentication") Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20200625203704.317097-5-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ccc2f5b commit 2f662d1

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

‎drivers/misc/lkdtm/bugs.c‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/uaccess.h>
1414
#include <linux/slab.h>
1515

16-
#ifdef CONFIG_X86_32
16+
#if IS_ENABLED(CONFIG_X86_32) && !IS_ENABLED(CONFIG_UML)
1717
#include <asm/desc.h>
1818
#endif
1919

@@ -418,7 +418,7 @@ void lkdtm_UNSET_SMEP(void)
418418

419419
void lkdtm_DOUBLE_FAULT(void)
420420
{
421-
#ifdef CONFIG_X86_32
421+
#if IS_ENABLED(CONFIG_X86_32) && !IS_ENABLED(CONFIG_UML)
422422
/*
423423
* Trigger #DF by setting the stack limit to zero. This clobbers
424424
* a GDT TLS slot, which is okay because the current task will die
@@ -453,38 +453,42 @@ void lkdtm_DOUBLE_FAULT(void)
453453
#endif
454454
}
455455

456-
#ifdef CONFIG_ARM64_PTR_AUTH
456+
#ifdef CONFIG_ARM64
457457
static noinline void change_pac_parameters(void)
458458
{
459-
/* Reset the keys of current task */
460-
ptrauth_thread_init_kernel(current);
461-
ptrauth_thread_switch_kernel(current);
459+
if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH)) {
460+
/* Reset the keys of current task */
461+
ptrauth_thread_init_kernel(current);
462+
ptrauth_thread_switch_kernel(current);
463+
}
462464
}
465+
#endif
463466

464-
#define CORRUPT_PAC_ITERATE 10
465467
noinline void lkdtm_CORRUPT_PAC(void)
466468
{
469+
#ifdef CONFIG_ARM64
470+
#define CORRUPT_PAC_ITERATE 10
467471
int i;
468472

473+
if (!IS_ENABLED(CONFIG_ARM64_PTR_AUTH))
474+
pr_err("FAIL: kernel not built with CONFIG_ARM64_PTR_AUTH\n");
475+
469476
if (!system_supports_address_auth()) {
470-
pr_err("FAIL: arm64 pointer authentication feature not present\n");
477+
pr_err("FAIL: CPU lacks pointer authentication feature\n");
471478
return;
472479
}
473480

474-
pr_info("Change the PAC parameters to force function return failure\n");
481+
pr_info("changing PAC parameters to force function return failure...\n");
475482
/*
476-
* Pac is a hash value computed from input keys, return address and
483+
* PAC is a hash value computed from input keys, return address and
477484
* stack pointer. As pac has fewer bits so there is a chance of
478485
* collision, so iterate few times to reduce the collision probability.
479486
*/
480487
for (i = 0; i < CORRUPT_PAC_ITERATE; i++)
481488
change_pac_parameters();
482489

483-
pr_err("FAIL: %s test failed. Kernel may be unstable from here\n", __func__);
484-
}
485-
#else /* !CONFIG_ARM64_PTR_AUTH */
486-
noinline void lkdtm_CORRUPT_PAC(void)
487-
{
488-
pr_err("FAIL: arm64 pointer authentication config disabled\n");
489-
}
490+
pr_err("FAIL: survived PAC changes! Kernel may be unstable from here\n");
491+
#else
492+
pr_err("XFAIL: this test is arm64-only\n");
490493
#endif
494+
}

‎drivers/misc/lkdtm/lkdtm.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ void lkdtm_CORRUPT_USER_DS(void);
3131
void lkdtm_STACK_GUARD_PAGE_LEADING(void);
3232
void lkdtm_STACK_GUARD_PAGE_TRAILING(void);
3333
void lkdtm_UNSET_SMEP(void);
34-
#ifdef CONFIG_X86_32
3534
void lkdtm_DOUBLE_FAULT(void);
36-
#endif
3735
void lkdtm_CORRUPT_PAC(void);
3836

3937
/* lkdtm_heap.c */

‎tools/testing/selftests/lkdtm/tests.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ STACK_GUARD_PAGE_LEADING
1414
STACK_GUARD_PAGE_TRAILING
1515
UNSET_SMEP CR4 bits went missing
1616
DOUBLE_FAULT
17+
CORRUPT_PAC
1718
UNALIGNED_LOAD_STORE_WRITE
1819
#OVERWRITE_ALLOCATION Corrupts memory on failure
1920
#WRITE_AFTER_FREE Corrupts memory on failure

0 commit comments

Comments
 (0)