lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250730183327.1001875-1-vishistriker@gmail.com>
Date: Thu, 31 Jul 2025 00:03:27 +0530
From: Vishal Parmar <vishistriker@...il.com>
To: skhan@...uxfoundation.org
Cc: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Vishal Parmar <vishistriker@...il.com>
Subject: [PATCH v2] Subject: [PATCH] selftests: panic: Add test module to trigger kernel panic

This patch adds a new test module under tools/testing/selftests/panic
that intentionally triggers a kernel panic for test and diagnostic
purposes. The goal is to provide a reproducible and isolated kernel
panic event for testing crash dump mechanisms or validating kernel
panic handling behavior.

The test includes:
- A kernel module that calls panic() in init.
- A Makefile to build the kernel module.
- A run.sh script to load the module and capture panic logs.

Changes in v2:
- Added run.sh
- Added reference output log of run.sh

Signed-off-by: Vishal Parmar <vishistriker@...il.com>
---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/panic/Makefile        | 13 +++++++++
 .../selftests/panic/panic_trigger_test.c      | 26 +++++++++++++++++
 .../selftests/panic/reference_output_log.txt  | 29 +++++++++++++++++++
 tools/testing/selftests/panic/run.sh          | 17 +++++++++++
 5 files changed, 86 insertions(+)
 create mode 100644 tools/testing/selftests/panic/Makefile
 create mode 100644 tools/testing/selftests/panic/panic_trigger_test.c
 create mode 100644 tools/testing/selftests/panic/reference_output_log.txt
 create mode 100755 tools/testing/selftests/panic/run.sh

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 339b31e6a6b5..7b824470a9b3 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -78,6 +78,7 @@ TARGETS += net/packetdrill
 TARGETS += net/rds
 TARGETS += net/tcp_ao
 TARGETS += nsfs
+TARGETS += panic
 TARGETS += pci_endpoint
 TARGETS += pcie_bwctrl
 TARGETS += perf_events
diff --git a/tools/testing/selftests/panic/Makefile b/tools/testing/selftests/panic/Makefile
new file mode 100644
index 000000000000..e4a1b88a63b2
--- /dev/null
+++ b/tools/testing/selftests/panic/Makefile
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-m := panic_trigger_test.o
+
+KDIR := $(abspath ../../../../)
+PWD  := $(shell pwd)
+
+all:
+	$(MAKE) -C $(KDIR) M=$(PWD) modules
+
+clean:
+	$(MAKE) -C $(KDIR) M=$(PWD) clean
+	rm -f *.mod.c *.o *.ko *.order *.symvers
diff --git a/tools/testing/selftests/panic/panic_trigger_test.c b/tools/testing/selftests/panic/panic_trigger_test.c
new file mode 100644
index 000000000000..4e2e043fe3ad
--- /dev/null
+++ b/tools/testing/selftests/panic/panic_trigger_test.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * panic_test.c - Module to test kernel panic
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+
+static int __init panic_test_init(void)
+{
+    pr_info("Triggering a deliberate kernel panic now.\n");
+    panic("Triggered by panic_test module.");
+    return 0;
+}
+
+static void __exit panic_test_exit(void)
+{
+    pr_info("This should not be printed, as system panics on init.\n");
+}
+
+module_init(panic_test_init);
+module_exit(panic_test_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Vishal Parmar");
+MODULE_DESCRIPTION("Module to trigger kernel panic for testing");
diff --git a/tools/testing/selftests/panic/reference_output_log.txt b/tools/testing/selftests/panic/reference_output_log.txt
new file mode 100644
index 000000000000..2c8143bf6c4a
--- /dev/null
+++ b/tools/testing/selftests/panic/reference_output_log.txt
@@ -0,0 +1,29 @@
+[*] Inserting module: panic_trigger_test.ko
+[   30.377307] panic_trigger_test: loading out-of-tree module taints kernel.
+[   30.380328] Triggering a deliberate kernel panic now.
+[   30.382369] Kernel panic - not syncing: Triggered by panic_test module.
+[   30.383349] CPU: 1 UID: 0 PID: 99 Comm: insmod Tainted: G           O        6.16.0-rc7-00140-gec2df4364666 #1 PREEMPT(voluntary) 
+[   30.383349] Tainted: [O]=OOT_MODULE
+[   30.383349] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
+[   30.383349] Call Trace:
+[   30.383349]  <TASK>
+[   30.383349]  panic+0x325/0x380
+[   30.383349]  ? __pfx_panic_test_init+0x10/0x10 [panic_trigger_test]
+[   30.383349]  panic_test_init+0x1c/0xff0 [panic_trigger_test]
+[   30.383349]  do_one_initcall+0x55/0x220
+[   30.383349]  do_init_module+0x5b/0x230
+[   30.383349]  __do_sys_init_module+0x150/0x180
+[   30.383349]  do_syscall_64+0xa4/0x260
+[   30.383349]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
+[   30.383349] RIP: 0033:0x7f88f09177d9
+[   30.383349] Code: 08 89 e8 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d f7 05 8
+[   30.383349] RSP: 002b:00007ffc16317848 EFLAGS: 00000206 ORIG_RAX: 00000000000000af
+[   30.383349] RAX: ffffffffffffffda RBX: 000055a4a84b0eae RCX: 00007f88f09177d9
+[   30.383349] RDX: 000055a4a84b0eae RSI: 00000000000019e8 RDI: 000055a4c9b4b370
+[   30.383349] RBP: 00007ffc16317bd0 R08: 000055a4c9b4b310 R09: 00000000000019e8
+[   30.383349] R10: 0000000000000007 R11: 0000000000000206 R12: 00007ffc16317bd8
+[   30.383349] R13: 00007ffc16317be0 R14: 000055a4a84b0eae R15: 00007f88f0b25020
+[   30.383349]  </TASK>
+[   30.383349] Kernel Offset: 0x10000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
+[   30.383349] ---[ end Kernel panic - not syncing: Triggered by panic_test module. ]---
+
diff --git a/tools/testing/selftests/panic/run.sh b/tools/testing/selftests/panic/run.sh
new file mode 100755
index 000000000000..ffa20dc22708
--- /dev/null
+++ b/tools/testing/selftests/panic/run.sh
@@ -0,0 +1,17 @@
+# tools/testing/selftests/panic/run.sh
+
+#!/bin/sh
+set -e
+
+MOD_NAME="panic_trigger_test.ko"
+LOG_FILE="panic_log.txt"
+
+echo "[*] Clearing dmesg..."
+dmesg -c
+
+echo "[*] Inserting module: $MOD_NAME"
+insmod ./$MOD_NAME
+
+echo "[*] Capturing dmesg..."
+dmesg > "$LOG_FILE"
+
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ