/* Define the possible places where we can trigger a crash point. */ staticstruct crashpoint crashpoints[] = {
CRASHPOINT("DIRECT", NULL), #ifdef CONFIG_KPROBES
CRASHPOINT("INT_HARDWARE_ENTRY", "do_IRQ"),
CRASHPOINT("INT_HW_IRQ_EN", "handle_irq_event"),
CRASHPOINT("INT_TASKLET_ENTRY", "tasklet_action"),
CRASHPOINT("FS_SUBMIT_BH", "submit_bh"),
CRASHPOINT("MEM_SWAPOUT", "shrink_inactive_list"),
CRASHPOINT("TIMERADD", "hrtimer_start"),
CRASHPOINT("SCSI_QUEUE_RQ", "scsi_queue_rq"), #endif
};
/* List of possible types for crashes that can be triggered. */ staticconststruct crashtype_category *crashtype_categories[] = {
&bugs_crashtypes,
&heap_crashtypes,
&perms_crashtypes,
&refcount_crashtypes,
&usercopy_crashtypes,
&stackleak_crashtypes,
&cfi_crashtypes,
&fortify_crashtypes, #ifdef CONFIG_PPC_64S_HASH_MMU
&powerpc_crashtypes, #endif
};
/* Global kprobe entry and crashtype. */ staticstruct kprobe *lkdtm_kprobe; staticstruct crashpoint *lkdtm_crashpoint; staticconststruct crashtype *lkdtm_crashtype;
/* Module parameters */ staticint recur_count = -1;
module_param(recur_count, int, 0644);
MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
staticchar* cpoint_name;
module_param(cpoint_name, charp, 0444);
MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
staticchar* cpoint_type;
module_param(cpoint_type, charp, 0444);
MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\ "hitting the crash point");
staticint cpoint_count = DEFAULT_COUNT;
module_param(cpoint_count, int, 0644);
MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ "crash point is to be hit to trigger action");
if (WARN_ON(!lkdtm_crashpoint || !lkdtm_crashtype)) return0;
spin_lock_irqsave(&crash_count_lock, flags);
crash_count--;
pr_info("Crash point %s of type %s hit, trigger in %d rounds\n",
lkdtm_crashpoint->name, lkdtm_crashtype->name, crash_count);
err = lkdtm_register_cpoint(crashpoint, crashtype); if (err < 0) return err;
*off += count;
return count;
} #endif
/* Generic read callback that just prints out the available crash types */ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
size_t count, loff_t *off)
{ int n, cat, idx;
ssize_t out; char *buf;
buf = (char *)__get_free_page(GFP_KERNEL); if (buf == NULL) return -ENOMEM;
n = scnprintf(buf, PAGE_SIZE, "Available crash types:\n");
/* short circuit if we already found a value. */ if (args->value != -ESRCH) return0; if (strncmp(param, args->param, strlen(args->param)) == 0) { bool bool_result; int ret;
ret = kstrtobool(val, &bool_result); if (ret == 0)
args->value = bool_result;
} return0;
}
staticint __init lkdtm_module_init(void)
{ struct crashpoint *crashpoint = NULL; conststruct crashtype *crashtype = NULL; int ret; int i;
/* Neither or both of these need to be set */ if ((cpoint_type || cpoint_name) && !(cpoint_type && cpoint_name)) {
pr_err("Need both cpoint_type and cpoint_name or neither\n"); return -EINVAL;
}
if (cpoint_type) {
crashtype = find_crashtype(cpoint_type); if (!crashtype) {
pr_err("Unknown crashtype '%s'\n", cpoint_type); return -EINVAL;
}
}
if (cpoint_name) { for (i = 0; i < ARRAY_SIZE(crashpoints); i++) { if (!strcmp(cpoint_name, crashpoints[i].name))
crashpoint = &crashpoints[i];
}
/* Install crashpoint if one was selected. */ if (crashpoint) {
ret = lkdtm_register_cpoint(crashpoint, crashtype); if (ret < 0) {
pr_info("Invalid crashpoint %s\n", crashpoint->name); goto out_err;
}
pr_info("Crash point %s of type %s registered\n",
crashpoint->name, cpoint_type);
} else {
pr_info("No crash points registered, enable through debugfs\n");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.