linux/drivers/misc/lkdtm/core.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Linux Kernel Dump Test Module for testing kernel crashes conditions:
 * induces system failures at predefined crashpoints and under predefined
 * operational conditions in order to evaluate the reliability of kernel
 * sanity checking and crash dumps obtained using different dumping
 * solutions.
 *
 * Copyright (C) IBM Corporation, 2006
 *
 * Author: Ankita Garg <[email protected]>
 *
 * It is adapted from the Linux Kernel Dump Test Tool by
 * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net>
 *
 * Debugfs support added by Simon Kagstrom <[email protected]>
 *
 * See Documentation/fault-injection/provoke-crashes.rst for instructions
 */
#include "lkdtm.h"
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/buffer_head.h>
#include <linux/kprobes.h>
#include <linux/list.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/debugfs.h>
#include <linux/utsname.h>

#define DEFAULT_COUNT

static int lkdtm_debugfs_open(struct inode *inode, struct file *file);
static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
		size_t count, loff_t *off);
static ssize_t direct_entry(struct file *f, const char __user *user_buf,
			    size_t count, loff_t *off);

#ifdef CONFIG_KPROBES
static int lkdtm_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
static ssize_t lkdtm_debugfs_entry(struct file *f,
				   const char __user *user_buf,
				   size_t count, loff_t *off);
#define CRASHPOINT_KPROBE(_symbol)
#define CRASHPOINT_WRITE(_symbol)
#else
#define CRASHPOINT_KPROBE
#define CRASHPOINT_WRITE
#endif

/* Crash points */
struct crashpoint {};

#define CRASHPOINT(_name, _symbol)

/* Define the possible places where we can trigger a crash point. */
static struct crashpoint crashpoints[] =;

/* List of possible types for crashes that can be triggered. */
static const struct crashtype_category *crashtype_categories[] =;

/* 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 =;
module_param(recur_count, int, 0644);
MODULE_PARM_DESC();

static char* cpoint_name;
module_param(cpoint_name, charp, 0444);
MODULE_PARM_DESC();

static char* cpoint_type;
module_param(cpoint_type, charp, 0444);
MODULE_PARM_DESC();

static int cpoint_count =;
module_param(cpoint_count, int, 0644);
MODULE_PARM_DESC();

/*
 * 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)
{}

/*
 * This is forced noinline just so it distinctly shows up in the stackdump
 * which makes validation of expected lkdtm crashes easier.
 *
 * NOTE: having a valid return value helps prevent the compiler from doing
 * tail call optimizations and taking this out of the stack trace.
 */
static noinline int lkdtm_do_action(const struct crashtype *crashtype)
{}

static int lkdtm_register_cpoint(struct crashpoint *crashpoint,
				 const struct crashtype *crashtype)
{}

#ifdef CONFIG_KPROBES
/* Global crash counter and spinlock. */
static int crash_count =;
static DEFINE_SPINLOCK(crash_count_lock);

/* Called by kprobe entry points. */
static int lkdtm_kprobe_handler(struct kprobe *kp, struct pt_regs *regs)
{}

static ssize_t lkdtm_debugfs_entry(struct file *f,
				   const char __user *user_buf,
				   size_t count, loff_t *off)
{}
#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)
{}

static int lkdtm_debugfs_open(struct inode *inode, struct file *file)
{}

/* 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)
{}

#ifndef MODULE
/*
 * To avoid needing to export parse_args(), just don't use this code
 * when LKDTM is built as a module.
 */
struct check_cmdline_args {};

static int lkdtm_parse_one(char *param, char *val,
			   const char *unused, void *arg)
{}

int lkdtm_check_bool_cmdline(const char *param)
{}
#endif

static struct dentry *lkdtm_debugfs_root;

static int __init lkdtm_module_init(void)
{}

static void __exit lkdtm_module_exit(void)
{}

module_init();
module_exit(lkdtm_module_exit);

MODULE_LICENSE();
MODULE_DESCRIPTION();