Skip to content

Commit 01c0514

Browse files
a13xp0p0vgregkh
authored andcommitted
lkdtm/stackleak: Make the test more verbose
Make the stack erasing test more verbose about the errors that it can detect. Signed-off-by: Alexander Popov <alex.popov@linux.com> Cc: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20200102234907.585508-1-alex.popov@linux.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff5cd9a commit 01c0514

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎drivers/misc/lkdtm/stackleak.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void lkdtm_STACKLEAK_ERASING(void)
1616
unsigned long *sp, left, found, i;
1717
const unsigned long check_depth =
1818
STACKLEAK_SEARCH_DEPTH / sizeof(unsigned long);
19+
bool test_failed = false;
1920

2021
/*
2122
* For the details about the alignment of the poison values, see
@@ -34,7 +35,8 @@ void lkdtm_STACKLEAK_ERASING(void)
3435
left--;
3536
} else {
3637
pr_err("FAIL: not enough stack space for the test\n");
37-
return;
38+
test_failed = true;
39+
goto end;
3840
}
3941

4042
pr_info("checking unused part of the thread stack (%lu bytes)...\n",
@@ -52,22 +54,29 @@ void lkdtm_STACKLEAK_ERASING(void)
5254
}
5355

5456
if (found <= check_depth) {
55-
pr_err("FAIL: thread stack is not erased (checked %lu bytes)\n",
57+
pr_err("FAIL: the erased part is not found (checked %lu bytes)\n",
5658
i * sizeof(unsigned long));
57-
return;
59+
test_failed = true;
60+
goto end;
5861
}
5962

60-
pr_info("first %lu bytes are unpoisoned\n",
63+
pr_info("the erased part begins after %lu not poisoned bytes\n",
6164
(i - found) * sizeof(unsigned long));
6265

6366
/* The rest of thread stack should be erased */
6467
for (; i < left; i++) {
6568
if (*(sp - i) != STACKLEAK_POISON) {
66-
pr_err("FAIL: thread stack is NOT properly erased\n");
67-
return;
69+
pr_err("FAIL: bad value number %lu in the erased part: 0x%lx\n",
70+
i, *(sp - i));
71+
test_failed = true;
6872
}
6973
}
7074

71-
pr_info("OK: the rest of the thread stack is properly erased\n");
72-
return;
75+
end:
76+
if (test_failed) {
77+
pr_err("FAIL: the thread stack is NOT properly erased\n");
78+
dump_stack();
79+
} else {
80+
pr_info("OK: the rest of the thread stack is properly erased\n");
81+
}
7382
}

0 commit comments

Comments
 (0)