drivers/misc/lkdtm/core.c
Source file repositories/reference/linux-study-clean/drivers/misc/lkdtm/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/lkdtm/core.c- Extension
.c- Size
- 12510 bytes
- Lines
- 495
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
lkdtm.hlinux/fs.hlinux/module.hlinux/buffer_head.hlinux/kprobes.hlinux/list.hlinux/init.hlinux/slab.hlinux/debugfs.hlinux/utsname.h
Detected Declarations
struct crashpointstruct check_cmdline_argsfunction lkdtm_do_actionfunction lkdtm_register_cpointfunction lkdtm_kprobe_handlerfunction lkdtm_debugfs_entryfunction lkdtm_debugfs_readfunction lkdtm_debugfs_openfunction direct_entryfunction lkdtm_parse_onefunction lkdtm_check_bool_cmdlinefunction lkdtm_module_initfunction lkdtm_module_exitmodule init lkdtm_module_init
Annotated Snippet
const struct file_operations fops;
struct kprobe kprobe;
};
#define CRASHPOINT(_name, _symbol) \
{ \
.name = _name, \
.fops = { \
.read = lkdtm_debugfs_read, \
.llseek = generic_file_llseek, \
.open = lkdtm_debugfs_open, \
.write = CRASHPOINT_WRITE(_symbol) \
}, \
CRASHPOINT_KPROBE(_symbol) \
}
/* Define the possible places where we can trigger a crash point. */
static struct 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. */
static const struct crashtype_category *crashtype_categories[] = {
&bugs_crashtypes,
&heap_crashtypes,
&perms_crashtypes,
&refcount_crashtypes,
&usercopy_crashtypes,
&stackleak_crashtypes,
&cfi_crashtypes,
&fortify_crashtypes,
#ifdef CONFIG_PPC_BOOK3S_64
&powerpc_crashtypes,
#endif
};
/* Global kprobe entry and crashtype. */
static struct kprobe *lkdtm_kprobe;
static struct crashpoint *lkdtm_crashpoint;
static const struct crashtype *lkdtm_crashtype;
/* Module parameters */
static int recur_count = -1;
module_param(recur_count, int, 0644);
MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
static char* cpoint_name;
module_param(cpoint_name, charp, 0444);
MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
static char* 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");
static int 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");
/*
* For test debug reporting when CI systems provide terse summaries.
* TODO: Remove this once reasonable reporting exists in most CI systems:
* https://lore.kernel.org/lkml/CAHk-=wiFvfkoFixTapvvyPMN9pq5G-+Dys2eSyBa1vzDGAO5+A@mail.gmail.com
*/
char *lkdtm_kernel_info;
/* Return the crashtype number or NULL if the name is invalid */
static const struct crashtype *find_crashtype(const char *name)
{
int cat, idx;
for (cat = 0; cat < ARRAY_SIZE(crashtype_categories); cat++) {
for (idx = 0; idx < crashtype_categories[cat]->len; idx++) {
struct crashtype *crashtype;
crashtype = &crashtype_categories[cat]->crashtypes[idx];
if (!strcmp(name, crashtype->name))
return crashtype;
}
}
Annotation
- Immediate include surface: `lkdtm.h`, `linux/fs.h`, `linux/module.h`, `linux/buffer_head.h`, `linux/kprobes.h`, `linux/list.h`, `linux/init.h`, `linux/slab.h`.
- Detected declarations: `struct crashpoint`, `struct check_cmdline_args`, `function lkdtm_do_action`, `function lkdtm_register_cpoint`, `function lkdtm_kprobe_handler`, `function lkdtm_debugfs_entry`, `function lkdtm_debugfs_read`, `function lkdtm_debugfs_open`, `function direct_entry`, `function lkdtm_parse_one`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.