drivers/misc/lkdtm/bugs.c
Source file repositories/reference/linux-study-clean/drivers/misc/lkdtm/bugs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/lkdtm/bugs.c- Extension
.c- Size
- 22101 bytes
- Lines
- 886
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
lkdtm.hlinux/cpu.hlinux/efi.hlinux/list.hlinux/hrtimer.hlinux/sched.hlinux/sched/signal.hlinux/sched/task_stack.hlinux/slab.hlinux/stop_machine.hlinux/uaccess.hasm/desc.h
Detected Declarations
struct lkdtm_liststruct array_bounds_flex_arraystruct array_boundsstruct lkdtm_cb_famstruct lkdtm_extrastruct lkdtm_cb_ptrfunction recursive_loopfunction lkdtm_bugs_initfunction lkdtm_PANICfunction panic_stop_irqoff_fnfunction lkdtm_PANIC_STOP_IRQOFFfunction panic_in_hardirqfunction lkdtm_PANIC_IN_HARDIRQfunction lkdtm_BUGfunction bug_in_hardirqfunction lkdtm_BUG_IN_HARDIRQfunction lkdtm_WARNINGfunction lkdtm_WARNING_MESSAGEfunction lkdtm_EXCEPTIONfunction lkdtm_LOOPfunction lkdtm_EXHAUST_STACKfunction __lkdtm_CORRUPT_STACKfunction lkdtm_CORRUPT_STACKfunction lkdtm_CORRUPT_STACK_STRONGfunction lkdtm_REPORT_STACKfunction __lkdtm_REPORT_STACK_CANARYfunction lkdtm_REPORT_STACK_CANARYfunction lkdtm_UNALIGNED_LOAD_STORE_WRITEfunction lkdtm_SOFTLOCKUPfunction lkdtm_HARDLOCKUPfunction __lkdtm_SMP_CALL_LOCKUPfunction lkdtm_SMP_CALL_LOCKUPfunction lkdtm_SPINLOCKUPfunction lkdtm_HUNG_TASKfunction lkdtm_OVERFLOW_SIGNEDfunction lkdtm_OVERFLOW_UNSIGNEDfunction lkdtm_ARRAY_BOUNDSfunction lkdtm_FAM_BOUNDSfunction check_ptr_lenfunction lkdtm_PTR_BOUNDSfunction lkdtm_CORRUPT_LIST_ADDfunction lkdtm_CORRUPT_LIST_DELfunction lkdtm_STACK_GUARD_PAGE_LEADINGfunction lkdtm_STACK_GUARD_PAGE_TRAILINGfunction lkdtm_UNSET_SMEPfunction lkdtm_DOUBLE_FAULTfunction change_pac_parametersfunction lkdtm_CORRUPT_PAC
Annotated Snippet
struct lkdtm_list {
struct list_head node;
};
/*
* Make sure our attempts to over run the kernel stack doesn't trigger
* a compiler warning when CONFIG_FRAME_WARN is set. Then make sure we
* recurse past the end of THREAD_SIZE by default.
*/
#if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
#define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
#else
#define REC_STACK_SIZE (THREAD_SIZE / 8UL)
#endif
#define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
static int recur_count = REC_NUM_DEFAULT;
static DEFINE_SPINLOCK(lock_me_up);
/*
* Make sure compiler does not optimize this function or stack frame away:
* - function marked noinline
* - stack variables are marked volatile
* - stack variables are written (memset()) and read (buf[..] passed as arg)
* - function may have external effects (memzero_explicit())
* - no tail recursion possible
*/
static int noinline recursive_loop(int remaining)
{
volatile char buf[REC_STACK_SIZE];
volatile int ret;
memset((void *)buf, remaining & 0xFF, sizeof(buf));
if (!remaining)
ret = 0;
else
ret = recursive_loop((int)buf[remaining % sizeof(buf)] - 1);
memzero_explicit((void *)buf, sizeof(buf));
return ret;
}
/* If the depth is negative, use the default, otherwise keep parameter. */
void __init lkdtm_bugs_init(int *recur_param)
{
if (*recur_param < 0)
*recur_param = recur_count;
else
recur_count = *recur_param;
}
static void lkdtm_PANIC(void)
{
panic("dumptest");
}
static int panic_stop_irqoff_fn(void *arg)
{
atomic_t *v = arg;
/*
* As stop_machine() disables interrupts, all CPUs within this function
* have interrupts disabled and cannot take a regular IPI.
*
* The last CPU which enters here will trigger a panic, and as all CPUs
* cannot take a regular IPI, we'll only be able to stop secondaries if
* smp_send_stop() or crash_smp_send_stop() uses an NMI.
*/
if (atomic_inc_return(v) == num_online_cpus())
panic("panic stop irqoff test");
for (;;)
cpu_relax();
}
static void lkdtm_PANIC_STOP_IRQOFF(void)
{
atomic_t v = ATOMIC_INIT(0);
stop_machine(panic_stop_irqoff_fn, &v, cpu_online_mask);
}
static bool wait_for_panic;
static enum hrtimer_restart panic_in_hardirq(struct hrtimer *timer)
{
panic("from hard IRQ context");
wait_for_panic = false;
return HRTIMER_NORESTART;
}
Annotation
- Immediate include surface: `lkdtm.h`, `linux/cpu.h`, `linux/efi.h`, `linux/list.h`, `linux/hrtimer.h`, `linux/sched.h`, `linux/sched/signal.h`, `linux/sched/task_stack.h`.
- Detected declarations: `struct lkdtm_list`, `struct array_bounds_flex_array`, `struct array_bounds`, `struct lkdtm_cb_fam`, `struct lkdtm_extra`, `struct lkdtm_cb_ptr`, `function recursive_loop`, `function lkdtm_bugs_init`, `function lkdtm_PANIC`, `function panic_stop_irqoff_fn`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: source implementation candidate.
- 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.