Skip to content

Commit f171d69

Browse files
mrutland-armkees
authored andcommitted
lkdtm/stackleak: check stack boundaries
The stackleak code relies upon the current SP and lowest recorded SP falling within expected task stack boundaries. Check this at the start of the test. Signed-off-by: Mark Rutland <[email protected]> Cc: Alexander Popov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Kees Cook <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f03a509 commit f171d69

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/misc/lkdtm/stackleak.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ static void noinstr check_stackleak_irqoff(void)
3535
unsigned long poison_high, poison_low;
3636
bool test_failed = false;
3737

38+
/*
39+
* Check that the current and lowest recorded stack pointer values fall
40+
* within the expected task stack boundaries. These tests should never
41+
* fail unless the boundaries are incorrect or we're clobbering the
42+
* STACK_END_MAGIC, and in either casee something is seriously wrong.
43+
*/
44+
if (current_sp < task_stack_low || current_sp >= task_stack_high) {
45+
pr_err("FAIL: current_stack_pointer (0x%lx) outside of task stack bounds [0x%lx..0x%lx]\n",
46+
current_sp, task_stack_low, task_stack_high - 1);
47+
test_failed = true;
48+
goto out;
49+
}
50+
if (lowest_sp < task_stack_low || lowest_sp >= task_stack_high) {
51+
pr_err("FAIL: current->lowest_stack (0x%lx) outside of task stack bounds [0x%lx..0x%lx]\n",
52+
lowest_sp, task_stack_low, task_stack_high - 1);
53+
test_failed = true;
54+
goto out;
55+
}
56+
3857
/*
3958
* Depending on what has run prior to this test, the lowest recorded
4059
* stack pointer could be above or below the current stack pointer.
@@ -87,6 +106,7 @@ static void noinstr check_stackleak_irqoff(void)
87106
poison_high - task_stack_low,
88107
task_stack_low - task_stack_base);
89108

109+
out:
90110
if (test_failed) {
91111
pr_err("FAIL: the thread stack is NOT properly erased!\n");
92112
pr_expected_config(CONFIG_GCC_PLUGIN_STACKLEAK);

0 commit comments

Comments
 (0)