diff options
author | Douglas Anderson <dianders@chromium.org> | 2024-01-23 01:49:35 +0100 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2024-02-01 18:44:07 +0100 |
commit | 6dde3569b867e2af2a9576c2f3ca1aa9b87d39fd (patch) | |
tree | eb4199d75493af8e690f60e0b1d2b3be77fca1a4 /drivers/misc/lkdtm/bugs.c | |
parent | lkdtm: Make lkdtm_do_action() return to avoid tail call optimization (diff) | |
download | linux-6dde3569b867e2af2a9576c2f3ca1aa9b87d39fd.tar.xz linux-6dde3569b867e2af2a9576c2f3ca1aa9b87d39fd.zip |
lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid tail call optimization
When testing with lkdtm_HUNG_TASK() and looking at the output, I
expected to see lkdtm_HUNG_TASK() in the stack crawl but it wasn't
there. Instead, the top function on at least some devices was
schedule() due to tail call optimization.
Let's do two things to help here:
1. We'll mark this as "__noreturn". On GCC at least this is documented
to prevent tail call optimization. The docs [1] say "In order to
preserve backtraces, GCC will never turn calls to noreturn
functions into tail calls."
2. We'll add a BUG_ON(1) at the end which means that schedule() is no
longer a tail call. Note that this is potentially important because
if we _did_ end up returning from schedule() due to some weird
issue then we'd potentially be violating the "noreturn" that we
told the compiler about. BUG is the right thing to do here.
[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20240122164935.2.I26e8f68c312824fcc80c19d4e91de2d2bef958f0@changeid
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to '')
-rw-r--r-- | drivers/misc/lkdtm/bugs.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index b080eb2335eb..d1222d3eda2f 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -294,10 +294,11 @@ static void lkdtm_SPINLOCKUP(void) __release(&lock_me_up); } -static void lkdtm_HUNG_TASK(void) +static void __noreturn lkdtm_HUNG_TASK(void) { set_current_state(TASK_UNINTERRUPTIBLE); schedule(); + BUG_ON(1); } static volatile unsigned int huge = INT_MAX - 2; |