Skip to contentSkip to conversation

Provide ways of crashing the kernel through debugfs

PATCH In review Simon Kagstrom 5 participants 13 messages Jan 26, 2010 – Feb 4, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Provide ways of crashing the kernel through debugfs

For development and testing it's sometimes useful to crash or injure the kernel in various ways. This patch adds a debugfs interface to provoke null-pointer dereferences, stack corruption, panics, bugons etc. For example:

mount -t debugfs debugfs /mnt
echo 1 > /mnt/provoke-crash/null_dereference

---
Obviously this feature is for debugging and testing only, and of interest to fairly few people. I've used it for testing the kmsg_dump stuff (hence the CC:s above) and kdump, and have found it fairly useful.

If it's not of interest, at least this mail will be in the archives if someone else needs something like it :-)

 lib/Kconfig.debug   |    8 +++
 lib/Makefile        |    2 +
 lib/provoke-crash.c |  163 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+), 0 deletions(-)
 create mode 100644 lib/provoke-crash.c
lib/Kconfig.debug +8 -0
index 25c3ed5..8c82a1d 100644
@@ -1054,6 +1054,14 @@ config DMA_API_DEBUG
 	  This option causes a performance degredation.  Use only if you want
 	  to debug device drivers. If unsure, say N.
 
+config PROVOKE_CRASH
+	tristate "Provoke kernel crashes through a debugfs interface"
+	depends on DEBUG_FS
+	help
+	  Enable the kernel to crash in different ways through a debugfs interface.
+	  NOTE: This feature is dangerous!
+	  If unsure, say N.
+
 source "samples/Kconfig"
 
 source "lib/Kconfig.kgdb"
lib/Makefile +2 -0
index 3b0b4a6..6018057 100644
@@ -100,6 +100,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o
 
 obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
 
+obj-$(CONFIG_PROVOKE_CRASH) += provoke-crash.o
+
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/provoke-crash.c new file +163 -0

163 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 8 lines · Simon Kagstrom

For development and testing it's sometimes useful to crash or injure the kernel in various ways. This patch adds a debugfs interface to provoke null-pointer dereferences, stack corruption, panics, bugons etc. For example:

 mount -t debugfs debugfs /mnt
 echo 1 > /mnt/provoke-crash/null_dereference

Quoted 9 lines

---
Obviously this feature is for debugging and testing only, and of interest to fairly few people. I've used it for testing the kmsg_dump stuff (hence the CC:s above) and kdump, and have found it fairly useful.

If it's not of interest, at least this mail will be in the archives if someone else needs something like it :-)

Hey, we already have /proc/sysrq-trigger, you need to state why it is better than using /proc/sysrq-trigger.

Thanks.

#2 lore raw

Hi Americo!

Quoted 16 lines · On Tue, 26 Jan 2010 18:08:28 +0800 Américo Wang <[email protected]>…
Quoted 14 lines · Simon Kagstrom

For development and testing it's sometimes useful to crash or injure the kernel in various ways. This patch adds a debugfs interface to provoke null-pointer dereferences, stack corruption, panics, bugons etc. For example:

 mount -t debugfs debugfs /mnt
 echo 1 > /mnt/provoke-crash/null_dereference

---
Obviously this feature is for debugging and testing only, and of interest to fairly few people. I've used it for testing the kmsg_dump stuff (hence the CC:s above) and kdump, and have found it fairly useful.

Quoted 5 lines
Quoted 2 lines

If it's not of interest, at least this mail will be in the archives if someone else needs something like it :-)

Hey, we already have /proc/sysrq-trigger, you need to state why it is better than using /proc/sysrq-trigger.

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

// Simon

#3 lore raw
Quoted 21 lines · Simon Kagstrom

Hi Americo!

Quoted 16 lines · On Tue, 26 Jan 2010 18:08:28 +0800 Américo Wang <[email protected]>…
Quoted 14 lines · Simon Kagstrom

For development and testing it's sometimes useful to crash or injure the kernel in various ways. This patch adds a debugfs interface to provoke null-pointer dereferences, stack corruption, panics, bugons etc. For example:

 mount -t debugfs debugfs /mnt
 echo 1 > /mnt/provoke-crash/null_dereference

---
Obviously this feature is for debugging and testing only, and of interest to fairly few people. I've used it for testing the kmsg_dump stuff (hence the CC:s above) and kdump, and have found it fairly useful.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

If it's not of interest, at least this mail will be in the archives if someone else needs something like it :-)

Hey, we already have /proc/sysrq-trigger, you need to state why it is better than using /proc/sysrq-trigger.

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

Thanks.

#4 lore raw
Quoted 8 lines · On Wed, 27 Jan 2010 10:53:23 +0800 Américo Wang <[email protected]>…
Quoted 5 lines
Quoted 2 lines

Hey, we already have /proc/sysrq-trigger, you need to state why it is better than using /proc/sysrq-trigger.

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

I understand what you mean, and I'm fine if this doesn't get merged.

Thanks for the comments!

// Simon

#5 lore raw
In reply to Américo Wang
Quoted 29 lines · Américo Wang
Quoted 27 lines · Simon Kagstrom

Hi Americo!

Quoted 21 lines · On Tue, 26 Jan 2010 18:08:28 +0800 Américo Wang <[email protected]>…
Quoted 8 lines · Simon Kagstrom

For development and testing it's sometimes useful to crash or injure the kernel in various ways. This patch adds a debugfs interface to provoke null-pointer dereferences, stack corruption, panics, bugons etc. For example:

mount -t debugfs debugfs /mnt
echo 1 > /mnt/provoke-crash/null_dereference

Quoted 8 lines

---
Obviously this feature is for debugging and testing only, and of interest to fairly few people. I've used it for testing the kmsg_dump stuff (hence the CC:s above) and kdump, and have found it fairly useful.

If it's not of interest, at least this mail will be in the archives if someone else needs something like it :-)

Hey, we already have /proc/sysrq-trigger, you need to state why it is better than using /proc/sysrq-trigger.

Quoted 6 lines
Quoted 3 lines

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

But Simon did explain in his first e-mail why he cares. You or others might care for similar reasons.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#6 lore raw
Quoted 9 lines · On Thu, 28 Jan 2010 16:38:02 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 5 lines · Américo Wang
Quoted 2 lines

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

But Simon did explain in his first e-mail why he cares. You or others might care for similar reasons.

Another argument for the patch is that it's simple and well-contained, it doesn't touch any other code apart from the driver itself.

It is also easy to extend with other tests, e.g., provoking kernel hangs to test watchdogs and so on.

// Simon

maintainer
#7 lore raw
Quoted 10 lines · On Fri, 29 Jan 2010 07:13:24 +0100 Simon Kagstrom…
Quoted 7 lines · On Thu, 28 Jan 2010 16:38:02 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 5 lines · Am__rico Wang
Quoted 2 lines

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

Quoted 9 lines
Quoted 2 lines

But Simon did explain in his first e-mail why he cares. You or others might care for similar reasons.

Another argument for the patch is that it's simple and well-contained, it doesn't touch any other code apart from the driver itself.

It is also easy to extend with other tests, e.g., provoking kernel hangs to test watchdogs and so on.

Yes, it's the sort of thing which lots of people have written throw-away ad-hoc versions of. It probably makes sense to do it once, do it right to save people from having to rererereinvent that wheel.

What do others think?

#8 lore raw
Quoted 22 lines · Andrew Morton
Quoted 10 lines · On Fri, 29 Jan 2010 07:13:24 +0100 Simon Kagstrom…
Quoted 7 lines · On Thu, 28 Jan 2010 16:38:02 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 5 lines · Am__rico Wang
Quoted 2 lines

Well, it provides a few more ways of crashing the kernel. That's basically the only additional feature you'll get.

Yeah, I can see that, but why do I need to care how I crash the kernel as long as I can crash it in a way.

Quoted 9 lines
Quoted 2 lines

But Simon did explain in his first e-mail why he cares. You or others might care for similar reasons.

Another argument for the patch is that it's simple and well-contained, it doesn't touch any other code apart from the driver itself.

It is also easy to extend with other tests, e.g., provoking kernel hangs to test watchdogs and so on.

Quoted 5 lines

Yes, it's the sort of thing which lots of people have written throw-away ad-hoc versions of. It probably makes sense to do it once, do it right to save people from having to rererereinvent that wheel.

What do others think?

I think it makes sense, and in fact we have already merged one attempt at doing this generically. drivers/misc/lkdtm.c

I think Simon's patch adds some additional interesting failure modes. write_after_free, corrupt_stack_write, unaligned_load_store.

Simon is there any chance you can change your patch to an enhancement of lkdtm?

lkdtm actually digs into the interesting failure points with a jprobe to trigger the harder to reproduce scenarios. Like stack overflow in an interrupt handler.

Eric

#9 lore raw
Quoted 10 lines · On Mon, 01 Feb 2010 20:16:46 -0800 [email protected] (Eric W. Biederman)…
Quoted 5 lines · Andrew Morton

Yes, it's the sort of thing which lots of people have written throw-away ad-hoc versions of. It probably makes sense to do it once, do it right to save people from having to rererereinvent that wheel.

What do others think?

I think it makes sense, and in fact we have already merged one attempt at doing this generically. drivers/misc/lkdtm.c

So this functionality was already there - it would appear that I didn't do my research good enough then (I did actually look for this kind of thing). If something, I guess it shows that the kernel source is getting big!

To add to the irony, I work for a company that works on "DTM", although it's not related to this functionality :-)

Quoted 8 lines

I think Simon's patch adds some additional interesting failure modes. write_after_free, corrupt_stack_write, unaligned_load_store.

Simon is there any chance you can change your patch to an enhancement of lkdtm?

lkdtm actually digs into the interesting failure points with a jprobe to trigger the harder to reproduce scenarios. Like stack overflow in an interrupt handler.

Yes, this would be a better way of supporting the crash functionality. I'll take a look on integrating the extra tests into lkdtm.

I think it would also be good to provide a debugfs interface to lkdtm similar to what provoke-crash has. Right now you have to set it up via module parameters, and for some tests (write_after_free) I think that's a limitation since it often doesn't crash immediately.

// Simon

#10 lore raw

PATCH 1/1 lkdtm: Add debugfs access and loosen KPROBE ties

In reply to Eric W. Biederman

This patch adds a debugfs interface and additional failure modes to LKDTM to provide similar functionality to the provoke-crash driver submitted here:

http://lwn.net/Articles/371208/

Crashes can now be induced either through module parameters (as before) or through the debugfs interface as in provoke-crash.

The patch also provides a new "direct" interface, where KPROBES are not used, i.e., the crash is invoked directly upon write to the debugfs file. When built without KPROBES configured, only this mode is available.

---
I reused the debugfs directory name from provoke-crash since I think the name is more descriptive than "lkdtm".

I also put some documentation in Documentation/fault-injection. While I know that the fault-injection framework isn't used for this driver, I think the name make sense (that's where I'd look for functionality like this).

 Documentation/fault-injection/provoke-crashes.txt |   38 ++
 drivers/misc/lkdtm.c                              |  457 +++++++++++++++++----
 lib/Kconfig.debug                                 |    5 +-
 3 files changed, 419 insertions(+), 81 deletions(-)
 create mode 100644 Documentation/fault-injection/provoke-crashes.txt
Documentation/fault-injection/provoke-crashes.txt new file +38 -0
new file mode 100644
index 0000000..7a9d3d8
@@ -0,0 +1,38 @@
+The lkdtm module provides an interface to crash or injure the kernel at
+predefined crashpoints to evaluate the reliability of crash dumps obtained
+using different dumping solutions. The module uses KPROBEs to instrument
+crashing points, but can also crash the kernel directly without KRPOBE
+support.
+
+
+You can provide the way either through module arguments when inserting
+the module, or through a debugfs interface.
+
+Usage: insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<>
+				[cpoint_count={>0}]
+
+  recur_count : Recursion level for the stack overflow test. Default is 10.
+
+  cpoint_name : Crash point where the kernel is to be crashed. It can be
+	 one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
+	 FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
+	 IDE_CORE_CP, DIRECT
+
+  cpoint_type : Indicates the action to be taken on hitting the crash point.
+     It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW,
+     CORRUPT_STACK, UNALIGNED_LOAD_STORE_WRITE, OVERWRITE_ALLOCATION,
+     WRITE_AFTER_FREE,
+
+  cpoint_count : Indicates the number of times the crash point is to be hit
+    to trigger an action. The default is 10.
+
+You can also induce failures by mounting debugfs and writing the type to
+<mountpoint>/provoke-crash/<crashpoint>. E.g.,
+
+  mount -t debugfs debugfs /mnt
+  echo EXCEPTION > /mnt/provoke-crash/INT_HARDWARE_ENTRY
+
+
+A special file is `DIRECT' which will induce the crash directly without
+KPROBE instrumentation. This mode is the only one available when the module
+is built on a kernel without KPROBEs support.
drivers/misc/lkdtm.c +379 -78

555 lines not on this page · raw message

lib/Kconfig.debug +2 -3
index 8c82a1d..67b1799 100644
@@ -840,8 +840,7 @@ config DEBUG_FORCE_WEAK_PER_CPU
 
 config LKDTM
 	tristate "Linux Kernel Dump Test Tool Module"
-	depends on DEBUG_KERNEL
-	depends on KPROBES
+	depends on DEBUG_FS
 	depends on BLOCK
 	default n
 	help
@@ -852,7 +851,7 @@ config LKDTM
 	called lkdtm.
 
 	Documentation on how to use the module can be found in
-	drivers/misc/lkdtm.c
+	Documentation/fault-injection/provoke-crashes.txt
 
 config FAULT_INJECTION
 	bool "Fault-injection framework"
Signature · 1 line
1.6.0.4
maintainer
#11 lore raw

Re: [PATCH] lkdtm: Add debugfs access and loosen KPROBE ties

Quoted 32 lines · On Wed, 3 Feb 2010 09:52:24 +0100 Simon Kagstrom…

This patch adds a debugfs interface and additional failure modes to LKDTM to provide similar functionality to the provoke-crash driver submitted here:

http://lwn.net/Articles/371208/

Crashes can now be induced either through module parameters (as before) or through the debugfs interface as in provoke-crash.

The patch also provides a new "direct" interface, where KPROBES are not used, i.e., the crash is invoked directly upon write to the debugfs file. When built without KPROBES configured, only this mode is available.

---
I reused the debugfs directory name from provoke-crash since I think the name is more descriptive than "lkdtm".

I also put some documentation in Documentation/fault-injection. While I know that the fault-injection framework isn't used for this driver, I think the name make sense (that's where I'd look for functionality like this).

...

drivers/misc/lkdtm.c +3 -2
+static void lkdtm_do_action(enum ctype which)
 {
-	printk(KERN_INFO "lkdtm : Crash point %s of type %s hit\n",
-					 cpoint_name, cpoint_type);
+	switch (which) {
+	case PANIC:

drivers/misc/lkdtm.c static int recursive_loop(int a) · line 280

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+		panic("dumptest");
+		break;
+	case BUG:
+		BUG();
+		break;
+	case EXCEPTION:
+		*((int *) 0) = 0;
+		break;
+	case LOOP:
+		for (;;);

Please feed the patch through scripts/checkpatch.pl and contemplate the resulting report.

drivers/misc/lkdtm.c static int recursive_loop(int a) · line 291

Quoted 11 lines
drivers/misc/lkdtm.c +11 -0
+		break;
+	case OVERFLOW:
+		(void) recursive_loop(0);
+		break;
+	case CORRUPT_STACK:
+	{
+		volatile u32 data[8];
+		volatile u32 *p = data;
+
+		p[12] = 0x12345678;
+	} break;

Like this:

	case CORRUPT_STACK: {
		volatile u32 data[8];
		volatile u32 *p = data;

		p[12] = 0x12345678;
		break;
	}
Quoted 38 lines
drivers/misc/lkdtm.c +35 -0
+	case UNALIGNED_LOAD_STORE_WRITE:
+	{
+		static u8 data[5] __attribute__((aligned(4))) = {1,2,3,4,5};
+		u32 *p;
+		u32 val = 0x12345678;
+
+		p = (u32*)(data + 1);
+		if (*p == 0)
+			val = 0x87654321;
+		*p = val;
+	} break;
+	case OVERWRITE_ALLOCATION:
+	{
+		size_t len = 1020;
+		u32 *data = kmalloc(len, GFP_KERNEL);
+
+		data[1024 / sizeof(u32)] = 0x12345678;
+		kfree(data);
+	} break;
+	case WRITE_AFTER_FREE:
+	{
+		size_t len = 1024;
+		u32 *data = kmalloc(len, GFP_KERNEL);
+
+		kfree(data);
+		schedule();
+		memset(data, 0x78, len);
+	} break;
+	case NONE:
+	default:
+		break;
+	}
+
+}
+
 
...
 

drivers/misc/lkdtm.c static int recursive_loop(int a)

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+static ssize_t do_register_entry(enum cname which, struct file *f,
+		const char __user *user_buf, size_t count, loff_t *off)
+{
+	char *buf;
+	int err;
+
+	if (count >= PAGE_SIZE)
+		return -EINVAL;
+
+	buf = (char *)__get_free_page(GFP_TEMPORARY);

Someone ought to write

static inline void *__get_free_page_ptr(gfp_t flags)

{
	return (void *)__get_free_page(flags);
}

and then delete 100000000 typecasts.

The use of GFP_TEMPORARY is incorrect. This page is not reclaimable.

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 421

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+	if (!buf)
+		return -ENOMEM;
+	if (copy_from_user(buf, user_buf, count)) {
+		free_page((unsigned long) buf);
+		return -EFAULT;
+	}
+	/* NULL-terminate and remove enter */
+	buf[count] = '\0';
+	if (buf[count - 1] == '\r' || buf[count - 1] == '\n')
+		buf[count - 1] = '\0';

Use strim().

Review

Quoted 2 lines
(quoted diff) +2 -0
+	cptype = parse_cp_type(buf, count);
+	free_page((unsigned long) buf);

Write free_page_ptr() and delete another 100000000.

Quoted 19 lines
drivers/misc/lkdtm.c +16 -0
+
+	if (cptype == NONE)
+		return -EINVAL;
+
+	err = lkdtm_register_cpoint(which);
+	if (err < 0)
+		return err;
+
+	*off += count;
+
+	return count;
+}
+
 
...
 
+/* Special entry to just crash directly. Available without KPROBEs */
+static ssize_t direct_entry(struct file *f, const char __user *user_buf,
+		size_t count, loff_t *off)

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 525

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+{
+	enum ctype type;
+	char *buf;
+
+	if (count >= PAGE_SIZE)
+		return -EINVAL;
+	if (count < 1)
+		return -EINVAL;
+
+	buf = (char *)__get_free_page(GFP_TEMPORARY);

GFP_KERNEL

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 421

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+	if (!buf)
+		return -ENOMEM;
+	if (copy_from_user(buf, user_buf, count)) {
+		free_page((unsigned long) buf);
+		return -EFAULT;
+	}
+	/* NULL-terminate and remove enter */
+	buf[count] = '\0';
+	if (buf[count - 1] == '\r' || buf[count - 1] == '\n')
+		buf[count - 1] = '\0';

strim().

Quoted 5 lines
drivers/misc/lkdtm.c +5 -0
+	type = parse_cp_type(buf, count);
+	free_page((unsigned long) buf);
+	if (type == NONE)
+		return -EINVAL;
+

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 551

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+	printk(KERN_INFO "lkdtm : Performing direct entry %s\n",
+			cp_type_to_str(type));
+	lkdtm_do_action(type);
+	*off += count;
+
+	return count;
+}
+
+struct crash_entry
+{

struct crash_entry {

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 556

Quoted 5 lines
drivers/misc/lkdtm.c +5 -0
+	const char *name;
+	struct file_operations fops;
+};
+
+static struct crash_entry crash_entries[] = {

const, perhaps.

Quoted 26 lines
drivers/misc/lkdtm.c +26 -0
+	{"DIRECT",		{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = direct_entry}},
+	{"INT_HARDWARE_ENTRY",	{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = int_hardware_entry}},
+	{"INT_HW_IRQ_EN",	{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = int_hw_irq_en}},
+	{"INT_TASKLET_ENTRY",	{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = int_tasklet_entry}},
+	{"FS_DEVRW",		{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = fs_devrw_entry}},
+	{"MEM_SWAPOUT",		{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = mem_swapout_entry}},
+	{"TIMERADD",		{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = timeradd_entry}},
+	{"SCSI_DISPATCH_CMD",	{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = scsi_dispatch_cmd_entry}},
+	{"IDE_CORE_CP",		{.read = lkdtm_debugfs_read,
+			.open = lkdtm_debugfs_open, .write = ide_core_cp_entry}},
+};
+
+static struct dentry *lkdtm_debugfs_root;
+
+static int __init lkdtm_module_init(void)
+{
+	int ret = -EINVAL;
+	int n_debugfs_entries = 1; /* Assume only the direct entry */

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 592

Quoted 10 lines
drivers/misc/lkdtm.c +10 -0
+	int i;
+
+	/* Register debugfs interface */
+	lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
+	if (!lkdtm_debugfs_root) {
+		printk(KERN_ERR "lkdtm: creating root dir failed\n");
+		return -ENODEV;
+	}
+
+#if defined(CONFIG_KPROBES)

#ifdef will suffice

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 596

Quoted 4 lines
drivers/misc/lkdtm.c +4 -0
+	n_debugfs_entries = ARRAY_SIZE(crash_entries);
+#endif
+
+	for (i = 0; i < n_debugfs_entries; i++) {

Sometimes you do

	for (i = ..., i < ...; i++)

and sometimes

	for (i = ..., i < ...; ++i)

The former is more typical.

Quoted 11 lines
drivers/misc/lkdtm.c +11 -0
+		struct crash_entry *cur = &crash_entries[i];
+		struct dentry *de;
+
+		de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
+				NULL, &cur->fops);
+		if (de == NULL) {
+			printk(KERN_ERR "lkdtm: could not create %s\n",
+					cur->name);
+			goto out_err;
+		}
+	}

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 615

Quoted 10 lines
drivers/misc/lkdtm.c +6 -2
+
+	if (lkdtm_parse_commandline() == -EINVAL) {
+		printk(KERN_INFO "lkdtm : Invalid command\n");
+		goto out_err;
 	}
 
-	printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
-						cpoint_name, cpoint_type);
+	if (cpoint != INVALID && cptype != NONE)
+	{
	if (cpoint != INVALID && cptype != NONE) {

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 618

Quoted 3 lines
drivers/misc/lkdtm.c +3 -0
+		ret = lkdtm_register_cpoint(cpoint);
+		if (ret < 0)
+		{

ditto

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 623

Quoted 5 lines
drivers/misc/lkdtm.c +5 -0
+			printk(KERN_INFO "lkdtm : Invalid crash point %d\n", cpoint);
+			goto out_err;
+		}
+		printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
+				cpoint_name, cpoint_type);

Please do s/lkdtm :/lkdtm:/ in all printks.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	}
+	else
	} else {

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 627

Quoted 2 lines
drivers/misc/lkdtm.c +2 -0
+		printk(KERN_INFO "lkdtm : No crash points registered, enable through debugfs\n");
+
	}
Quoted 5 lines
drivers/misc/lkdtm.c +4 -0
 	return 0;
+
+out_err:
+	debugfs_remove_recursive(lkdtm_debugfs_root);
+	return ret;

drivers/misc/lkdtm.c static int __init lkdtm_module_init(void) · line 640

Quoted 10 lines
drivers/misc/lkdtm.c +4 -2
 }
 
 static void __exit lkdtm_module_exit(void)
 {
-        unregister_jprobe(&lkdtm);
-        printk(KERN_INFO "lkdtm : Crash point unregistered\n");
+	debugfs_remove_recursive(lkdtm_debugfs_root);
+
+	unregister_jprobe(&lkdtm);
+	printk(KERN_INFO "lkdtm : Crash point unregistered\n");

A colon does not terminate a sentence, so "lkdtm: crash point unregistered" would be better (applies to whole patch).

Quoted 28 lines

}

module_init(lkdtm_module_init);

lib/Kconfig.debug +2 -3
index 8c82a1d..67b1799 100644
@@ -840,8 +840,7 @@ config DEBUG_FORCE_WEAK_PER_CPU
 
 config LKDTM
 	tristate "Linux Kernel Dump Test Tool Module"
-	depends on DEBUG_KERNEL
-	depends on KPROBES
+	depends on DEBUG_FS
 	depends on BLOCK
 	default n
 	help
@@ -852,7 +851,7 @@ config LKDTM
 	called lkdtm.
 
 	Documentation on how to use the module can be found in
-	drivers/misc/lkdtm.c
+	Documentation/fault-injection/provoke-crashes.txt
 
 config FAULT_INJECTION
 	bool "Fault-injection framework"
Signature · 1 line
1.6.0.4
#12 lore raw

PATCH v2 1/1 lkdtm: Add debugfs access and loosen KPROBE ties

This patch adds a debugfs interface and additional failure modes to LKDTM to provide similar functionality to the provoke-crash driver submitted here:

http://lwn.net/Articles/371208/

Crashes can now be induced either through module parameters (as before) or through the debugfs interface as in provoke-crash.

The patch also provides a new "direct" interface, where KPROBES are not used, i.e., the crash is invoked directly upon write to the debugfs file. When built without KPROBES configured, only this mode is available.

--
ChangeLog: (Fixes from Andrew Mortons review)
* Fix checkpatch errors and warnings (except volatile)
* Move break; inside braces in switch statements
* GFP_TEMPORARY -> GFP_KERNEL
* Use strim()
* Constify struct crash_entry
* #if defined -> #ifdef
* Use i++/i-- throughout
* lkdtm : -> lkdtm:

 Documentation/fault-injection/provoke-crashes.txt |   38 ++
 drivers/misc/lkdtm.c                              |  472 +++++++++++++++++----
 lib/Kconfig.debug                                 |    5 +-
 3 files changed, 430 insertions(+), 85 deletions(-)
 create mode 100644 Documentation/fault-injection/provoke-crashes.txt
Documentation/fault-injection/provoke-crashes.txt new file +38 -0
new file mode 100644
index 0000000..7a9d3d8
@@ -0,0 +1,38 @@
+The lkdtm module provides an interface to crash or injure the kernel at
+predefined crashpoints to evaluate the reliability of crash dumps obtained
+using different dumping solutions. The module uses KPROBEs to instrument
+crashing points, but can also crash the kernel directly without KRPOBE
+support.
+
+
+You can provide the way either through module arguments when inserting
+the module, or through a debugfs interface.
+
+Usage: insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<>
+				[cpoint_count={>0}]
+
+  recur_count : Recursion level for the stack overflow test. Default is 10.
+
+  cpoint_name : Crash point where the kernel is to be crashed. It can be
+	 one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
+	 FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
+	 IDE_CORE_CP, DIRECT
+
+  cpoint_type : Indicates the action to be taken on hitting the crash point.
+     It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW,
+     CORRUPT_STACK, UNALIGNED_LOAD_STORE_WRITE, OVERWRITE_ALLOCATION,
+     WRITE_AFTER_FREE,
+
+  cpoint_count : Indicates the number of times the crash point is to be hit
+    to trigger an action. The default is 10.
+
+You can also induce failures by mounting debugfs and writing the type to
+<mountpoint>/provoke-crash/<crashpoint>. E.g.,
+
+  mount -t debugfs debugfs /mnt
+  echo EXCEPTION > /mnt/provoke-crash/INT_HARDWARE_ENTRY
+
+
+A special file is `DIRECT' which will induce the crash directly without
+KPROBE instrumentation. This mode is the only one available when the module
+is built on a kernel without KPROBEs support.
drivers/misc/lkdtm.c +390 -82

567 lines not on this page · raw message

lib/Kconfig.debug +2 -3
index 8c82a1d..67b1799 100644
@@ -840,8 +840,7 @@ config DEBUG_FORCE_WEAK_PER_CPU
 
 config LKDTM
 	tristate "Linux Kernel Dump Test Tool Module"
-	depends on DEBUG_KERNEL
-	depends on KPROBES
+	depends on DEBUG_FS
 	depends on BLOCK
 	default n
 	help
@@ -852,7 +851,7 @@ config LKDTM
 	called lkdtm.
 
 	Documentation on how to use the module can be found in
-	drivers/misc/lkdtm.c
+	Documentation/fault-injection/provoke-crashes.txt
 
 config FAULT_INJECTION
 	bool "Fault-injection framework"
Signature · 1 line
1.6.0.4