34 #include <linux/kernel.h>
36 #include <linux/module.h>
39 #include <linux/list.h>
42 #include <linux/hrtimer.h>
43 #include <linux/slab.h>
51 #define DEFAULT_COUNT 10
52 #define REC_NUM_DEFAULT 10
83 static char* cp_name[] = {
95 static char* cp_type[] = {
102 "UNALIGNED_LOAD_STORE_WRITE",
103 "OVERWRITE_ALLOCATION",
110 static struct jprobe lkdtm;
112 static int lkdtm_parse_commandline(
void);
113 static void lkdtm_handler(
void);
115 static char* cpoint_name;
116 static char* cpoint_type;
126 MODULE_PARM_DESC(recur_count,
" Recursion level for the stack overflow test, "\
129 MODULE_PARM_DESC(cpoint_name,
" Crash Point, where kernel is to be crashed");
132 "hitting the crash point");
135 "crash point is to be hit to trigger action");
137 static unsigned int jp_do_irq(
unsigned int irq)
144 static irqreturn_t jp_handle_irq_event(
unsigned int irq,
158 static void jp_ll_rw_block(
int rw,
int nr,
struct buffer_head *bhs[])
166 static unsigned long jp_shrink_inactive_list(
unsigned long max_scan,
207 if (!
strcmp(what, cp_type[i]))
214 static const char *cp_type_to_str(
enum ctype type)
219 return cp_type[type - 1];
222 static const char *cp_name_to_str(
enum cname name)
227 return cp_name[name - 1];
231 static int lkdtm_parse_commandline(
void)
236 if (cpoint_count < 1 || recur_count < 1)
240 count = cpoint_count;
241 spin_unlock_irqrestore(&count_lock, flags);
244 if (!cpoint_type && !cpoint_name)
248 if (!cpoint_type || !cpoint_name)
251 cptype = parse_cp_type(cpoint_type,
strlen(cpoint_type));
256 if (!
strcmp(cpoint_name, cp_name[i])) {
266 static int recursive_loop(
int a)
275 return recursive_loop(a);
278 static void lkdtm_do_action(
enum ctype which)
295 (
void) recursive_loop(0);
320 data[1024 /
sizeof(
u32)] = 0x12345678;
354 static void lkdtm_handler(
void)
361 printk(
KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n",
362 cp_name_to_str(cpoint), cp_type_to_str(cptype), count);
366 count = cpoint_count;
368 spin_unlock_irqrestore(&count_lock, flags);
371 lkdtm_do_action(cptype);
374 static int lkdtm_register_cpoint(
enum cname which)
379 if (lkdtm.entry !=
NULL)
384 lkdtm_do_action(cptype);
387 lkdtm.kp.symbol_name =
"do_IRQ";
391 lkdtm.kp.symbol_name =
"handle_IRQ_event";
395 lkdtm.kp.symbol_name =
"tasklet_action";
399 lkdtm.kp.symbol_name =
"ll_rw_block";
403 lkdtm.kp.symbol_name =
"shrink_inactive_list";
407 lkdtm.kp.symbol_name =
"hrtimer_start";
411 lkdtm.kp.symbol_name =
"scsi_dispatch_cmd";
416 lkdtm.kp.symbol_name =
"generic_ide_ioctl";
438 const char __user *user_buf,
size_t count, loff_t *off)
457 cptype = parse_cp_type(buf, count);
463 err = lkdtm_register_cpoint(which);
473 static ssize_t lkdtm_debugfs_read(
struct file *f,
char __user *user_buf,
474 size_t count, loff_t *off)
501 static ssize_t int_hardware_entry(
struct file *f,
const char __user *buf,
502 size_t count, loff_t *off)
507 static ssize_t int_hw_irq_en(
struct file *f,
const char __user *buf,
508 size_t count, loff_t *off)
513 static ssize_t int_tasklet_entry(
struct file *f,
const char __user *buf,
514 size_t count, loff_t *off)
519 static ssize_t fs_devrw_entry(
struct file *f,
const char __user *buf,
520 size_t count, loff_t *off)
522 return do_register_entry(
CN_FS_DEVRW, f, buf, count, off);
525 static ssize_t mem_swapout_entry(
struct file *f,
const char __user *buf,
526 size_t count, loff_t *off)
531 static ssize_t timeradd_entry(
struct file *f,
const char __user *buf,
532 size_t count, loff_t *off)
534 return do_register_entry(
CN_TIMERADD, f, buf, count, off);
537 static ssize_t scsi_dispatch_cmd_entry(
struct file *f,
538 const char __user *buf,
size_t count, loff_t *off)
543 static ssize_t ide_core_cp_entry(
struct file *f,
const char __user *buf,
544 size_t count, loff_t *off)
550 static ssize_t direct_entry(
struct file *f,
const char __user *user_buf,
551 size_t count, loff_t *off)
572 type = parse_cp_type(buf, count);
578 cp_type_to_str(type));
579 lkdtm_do_action(type);
590 static const struct crash_entry crash_entries[] = {
591 {
"DIRECT", {.read = lkdtm_debugfs_read,
593 .open = lkdtm_debugfs_open,
594 .write = direct_entry} },
595 {
"INT_HARDWARE_ENTRY", {.read = lkdtm_debugfs_read,
597 .open = lkdtm_debugfs_open,
598 .write = int_hardware_entry} },
599 {
"INT_HW_IRQ_EN", {.read = lkdtm_debugfs_read,
601 .open = lkdtm_debugfs_open,
602 .write = int_hw_irq_en} },
603 {
"INT_TASKLET_ENTRY", {.read = lkdtm_debugfs_read,
605 .open = lkdtm_debugfs_open,
606 .write = int_tasklet_entry} },
607 {
"FS_DEVRW", {.read = lkdtm_debugfs_read,
609 .open = lkdtm_debugfs_open,
610 .write = fs_devrw_entry} },
611 {
"MEM_SWAPOUT", {.read = lkdtm_debugfs_read,
613 .open = lkdtm_debugfs_open,
614 .write = mem_swapout_entry} },
615 {
"TIMERADD", {.read = lkdtm_debugfs_read,
617 .open = lkdtm_debugfs_open,
618 .write = timeradd_entry} },
619 {
"SCSI_DISPATCH_CMD", {.read = lkdtm_debugfs_read,
621 .open = lkdtm_debugfs_open,
622 .write = scsi_dispatch_cmd_entry} },
623 {
"IDE_CORE_CP", {.read = lkdtm_debugfs_read,
625 .open = lkdtm_debugfs_open,
626 .write = ide_core_cp_entry} },
629 static struct dentry *lkdtm_debugfs_root;
631 static int __init lkdtm_module_init(
void)
634 int n_debugfs_entries = 1;
639 if (!lkdtm_debugfs_root) {
644 #ifdef CONFIG_KPROBES
645 n_debugfs_entries =
ARRAY_SIZE(crash_entries);
648 for (i = 0; i < n_debugfs_entries; i++) {
661 if (lkdtm_parse_commandline() == -
EINVAL) {
667 ret = lkdtm_register_cpoint(cpoint);
674 cpoint_name, cpoint_type);
676 printk(
KERN_INFO "lkdtm: No crash points registered, enable through debugfs\n");
686 static void __exit lkdtm_module_exit(
void)