Skip to content

Commit eb972ea

Browse files
ardbiesheuvelctmarinas
authored andcommitted
lkdtm/bugs: Add cases for BUG and PANIC occurring in hardirq context
Add lkdtm cases to trigger a BUG() or panic() from hardirq context. This is useful for testing pstore behavior being invoked from such contexts. Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent b7737c3 commit eb972ea

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

drivers/misc/lkdtm/bugs.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "lkdtm.h"
99
#include <linux/cpu.h>
1010
#include <linux/list.h>
11+
#include <linux/hrtimer.h>
1112
#include <linux/sched.h>
1213
#include <linux/sched/signal.h>
1314
#include <linux/sched/task_stack.h>
@@ -100,11 +101,61 @@ static void lkdtm_PANIC_STOP_IRQOFF(void)
100101
stop_machine(panic_stop_irqoff_fn, &v, cpu_online_mask);
101102
}
102103

104+
static bool wait_for_panic;
105+
106+
static enum hrtimer_restart panic_in_hardirq(struct hrtimer *timer)
107+
{
108+
panic("from hard IRQ context");
109+
110+
wait_for_panic = false;
111+
return HRTIMER_NORESTART;
112+
}
113+
114+
static void lkdtm_PANIC_IN_HARDIRQ(void)
115+
{
116+
struct hrtimer timer;
117+
118+
wait_for_panic = true;
119+
hrtimer_setup_on_stack(&timer, panic_in_hardirq,
120+
CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
121+
hrtimer_start(&timer, us_to_ktime(100), HRTIMER_MODE_REL_HARD);
122+
123+
while (wait_for_panic)
124+
;
125+
126+
hrtimer_cancel(&timer);
127+
}
128+
103129
static void lkdtm_BUG(void)
104130
{
105131
BUG();
106132
}
107133

134+
static bool wait_for_bug;
135+
136+
static enum hrtimer_restart bug_in_hardirq(struct hrtimer *timer)
137+
{
138+
BUG();
139+
140+
wait_for_bug = false;
141+
return HRTIMER_NORESTART;
142+
}
143+
144+
static void lkdtm_BUG_IN_HARDIRQ(void)
145+
{
146+
struct hrtimer timer;
147+
148+
wait_for_bug = true;
149+
hrtimer_setup_on_stack(&timer, bug_in_hardirq,
150+
CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
151+
hrtimer_start(&timer, us_to_ktime(100), HRTIMER_MODE_REL_HARD);
152+
153+
while (wait_for_bug)
154+
;
155+
156+
hrtimer_cancel(&timer);
157+
}
158+
108159
static int warn_counter;
109160

110161
static void lkdtm_WARNING(void)
@@ -696,7 +747,9 @@ static noinline void lkdtm_CORRUPT_PAC(void)
696747
static struct crashtype crashtypes[] = {
697748
CRASHTYPE(PANIC),
698749
CRASHTYPE(PANIC_STOP_IRQOFF),
750+
CRASHTYPE(PANIC_IN_HARDIRQ),
699751
CRASHTYPE(BUG),
752+
CRASHTYPE(BUG_IN_HARDIRQ),
700753
CRASHTYPE(WARNING),
701754
CRASHTYPE(WARNING_MESSAGE),
702755
CRASHTYPE(EXCEPTION),

tools/testing/selftests/lkdtm/tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#PANIC
22
#PANIC_STOP_IRQOFF Crashes entire system
3+
#PANIC_IN_HARDIRQ Crashes entire system
34
BUG kernel BUG at
5+
#BUG_IN_HARDIRQ Crashes entire system
46
WARNING WARNING:
57
WARNING_MESSAGE message trigger
68
EXCEPTION

0 commit comments

Comments
 (0)