blob: ff28bd03a9e836793d7b1119c3ae38e14da6c074 [file] [log] [blame]
Ankita Garg8bb31b92006-10-02 02:17:36 -07001/*
Kees Cook426f3a52016-06-03 11:16:32 -07002 * Linux Kernel Dump Test Module for testing kernel crashes conditions:
3 * induces system failures at predefined crashpoints and under predefined
4 * operational conditions in order to evaluate the reliability of kernel
5 * sanity checking and crash dumps obtained using different dumping
6 * solutions.
Ankita Garg8bb31b92006-10-02 02:17:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 * Copyright (C) IBM Corporation, 2006
23 *
24 * Author: Ankita Garg <ankita@in.ibm.com>
25 *
Ankita Garg8bb31b92006-10-02 02:17:36 -070026 * It is adapted from the Linux Kernel Dump Test Tool by
27 * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net>
28 *
Simon Kagstrom0347af42010-03-05 13:42:49 -080029 * Debugfs support added by Simon Kagstrom <simon.kagstrom@netinsight.net>
Ankita Garg8bb31b92006-10-02 02:17:36 -070030 *
Simon Kagstrom0347af42010-03-05 13:42:49 -080031 * See Documentation/fault-injection/provoke-crashes.txt for instructions
Ankita Garg8bb31b92006-10-02 02:17:36 -070032 */
Kees Cook426f3a52016-06-03 11:16:32 -070033#define pr_fmt(fmt) "lkdtm: " fmt
Ankita Garg8bb31b92006-10-02 02:17:36 -070034
35#include <linux/kernel.h>
Randy Dunlap5d861d92006-11-02 22:07:06 -080036#include <linux/fs.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070037#include <linux/module.h>
Randy Dunlap5d861d92006-11-02 22:07:06 -080038#include <linux/buffer_head.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070039#include <linux/kprobes.h>
Randy Dunlap5d861d92006-11-02 22:07:06 -080040#include <linux/list.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070041#include <linux/init.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070042#include <linux/interrupt.h>
Randy Dunlap5d861d92006-11-02 22:07:06 -080043#include <linux/hrtimer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070045#include <scsi/scsi_cmnd.h>
Simon Kagstrom0347af42010-03-05 13:42:49 -080046#include <linux/debugfs.h>
Ankita Garg8bb31b92006-10-02 02:17:36 -070047
48#ifdef CONFIG_IDE
49#include <linux/ide.h>
50#endif
51
Kees Cook9a49a522016-02-22 14:09:29 -080052#include "lkdtm.h"
53
Kees Cookd87c9782016-06-29 08:07:11 -070054#define DEFAULT_COUNT 10
55
56static int lkdtm_parse_commandline(void);
57static void lkdtm_handler(void);
58
Ankita Garg8bb31b92006-10-02 02:17:36 -070059enum cname {
Namhyung Kim93e2f582010-10-26 14:22:40 -070060 CN_INVALID,
61 CN_INT_HARDWARE_ENTRY,
62 CN_INT_HW_IRQ_EN,
63 CN_INT_TASKLET_ENTRY,
64 CN_FS_DEVRW,
65 CN_MEM_SWAPOUT,
66 CN_TIMERADD,
67 CN_SCSI_DISPATCH_CMD,
68 CN_IDE_CORE_CP,
69 CN_DIRECT,
Ankita Garg8bb31b92006-10-02 02:17:36 -070070};
71
72enum ctype {
Namhyung Kim93e2f582010-10-26 14:22:40 -070073 CT_NONE,
74 CT_PANIC,
75 CT_BUG,
Kees Cook65892722013-07-08 10:01:31 -070076 CT_WARNING,
Namhyung Kim93e2f582010-10-26 14:22:40 -070077 CT_EXCEPTION,
78 CT_LOOP,
79 CT_OVERFLOW,
80 CT_CORRUPT_STACK,
81 CT_UNALIGNED_LOAD_STORE_WRITE,
82 CT_OVERWRITE_ALLOCATION,
83 CT_WRITE_AFTER_FREE,
Laura Abbottbc0b8cc2016-02-25 16:36:42 -080084 CT_READ_AFTER_FREE,
Laura Abbott920d4512016-02-25 16:36:44 -080085 CT_WRITE_BUDDY_AFTER_FREE,
86 CT_READ_BUDDY_AFTER_FREE,
Namhyung Kim93e2f582010-10-26 14:22:40 -070087 CT_SOFTLOCKUP,
88 CT_HARDLOCKUP,
Kees Cook274a5852013-07-08 10:01:32 -070089 CT_SPINLOCKUP,
Namhyung Kim93e2f582010-10-26 14:22:40 -070090 CT_HUNG_TASK,
Kees Cookcc33c5372013-07-08 10:01:33 -070091 CT_EXEC_DATA,
92 CT_EXEC_STACK,
93 CT_EXEC_KMALLOC,
94 CT_EXEC_VMALLOC,
Kees Cook9a49a522016-02-22 14:09:29 -080095 CT_EXEC_RODATA,
Kees Cook9ae113c2013-10-24 09:25:57 -070096 CT_EXEC_USERSPACE,
97 CT_ACCESS_USERSPACE,
98 CT_WRITE_RO,
Kees Cook7cca0712016-02-17 14:41:16 -080099 CT_WRITE_RO_AFTER_INIT,
Kees Cookdc2b9e92014-02-09 13:48:48 -0800100 CT_WRITE_KERN,
Kees Cookb5484522016-06-07 14:27:02 -0700101 CT_ATOMIC_UNDERFLOW,
102 CT_ATOMIC_OVERFLOW,
Kees Cookaa981a62016-06-03 12:06:52 -0700103 CT_USERCOPY_HEAP_SIZE_TO,
104 CT_USERCOPY_HEAP_SIZE_FROM,
105 CT_USERCOPY_HEAP_FLAG_TO,
106 CT_USERCOPY_HEAP_FLAG_FROM,
107 CT_USERCOPY_STACK_FRAME_TO,
108 CT_USERCOPY_STACK_FRAME_FROM,
109 CT_USERCOPY_STACK_BEYOND,
Kees Cook6c352142016-06-23 22:01:26 -0700110 CT_USERCOPY_KERNEL,
Ankita Garg8bb31b92006-10-02 02:17:36 -0700111};
112
113static char* cp_name[] = {
Kees Cook329d4162016-06-26 22:26:11 -0700114 "INVALID",
Ankita Garg8bb31b92006-10-02 02:17:36 -0700115 "INT_HARDWARE_ENTRY",
116 "INT_HW_IRQ_EN",
117 "INT_TASKLET_ENTRY",
118 "FS_DEVRW",
119 "MEM_SWAPOUT",
120 "TIMERADD",
121 "SCSI_DISPATCH_CMD",
Simon Kagstrom0347af42010-03-05 13:42:49 -0800122 "IDE_CORE_CP",
123 "DIRECT",
Ankita Garg8bb31b92006-10-02 02:17:36 -0700124};
125
126static char* cp_type[] = {
Kees Cook329d4162016-06-26 22:26:11 -0700127 "NONE",
Ankita Garg8bb31b92006-10-02 02:17:36 -0700128 "PANIC",
129 "BUG",
Kees Cook65892722013-07-08 10:01:31 -0700130 "WARNING",
Ankita Garg8bb31b92006-10-02 02:17:36 -0700131 "EXCEPTION",
132 "LOOP",
Simon Kagstrom0347af42010-03-05 13:42:49 -0800133 "OVERFLOW",
134 "CORRUPT_STACK",
135 "UNALIGNED_LOAD_STORE_WRITE",
136 "OVERWRITE_ALLOCATION",
137 "WRITE_AFTER_FREE",
Laura Abbottbc0b8cc2016-02-25 16:36:42 -0800138 "READ_AFTER_FREE",
Laura Abbott920d4512016-02-25 16:36:44 -0800139 "WRITE_BUDDY_AFTER_FREE",
140 "READ_BUDDY_AFTER_FREE",
Frederic Weisbeckera48223f2010-05-26 14:44:29 -0700141 "SOFTLOCKUP",
142 "HARDLOCKUP",
Kees Cook274a5852013-07-08 10:01:32 -0700143 "SPINLOCKUP",
Frederic Weisbeckera48223f2010-05-26 14:44:29 -0700144 "HUNG_TASK",
Kees Cookcc33c5372013-07-08 10:01:33 -0700145 "EXEC_DATA",
146 "EXEC_STACK",
147 "EXEC_KMALLOC",
148 "EXEC_VMALLOC",
Kees Cook9a49a522016-02-22 14:09:29 -0800149 "EXEC_RODATA",
Kees Cook9ae113c2013-10-24 09:25:57 -0700150 "EXEC_USERSPACE",
151 "ACCESS_USERSPACE",
152 "WRITE_RO",
Kees Cook7cca0712016-02-17 14:41:16 -0800153 "WRITE_RO_AFTER_INIT",
Kees Cookdc2b9e92014-02-09 13:48:48 -0800154 "WRITE_KERN",
Kees Cookb5484522016-06-07 14:27:02 -0700155 "ATOMIC_UNDERFLOW",
156 "ATOMIC_OVERFLOW",
Kees Cookaa981a62016-06-03 12:06:52 -0700157 "USERCOPY_HEAP_SIZE_TO",
158 "USERCOPY_HEAP_SIZE_FROM",
159 "USERCOPY_HEAP_FLAG_TO",
160 "USERCOPY_HEAP_FLAG_FROM",
161 "USERCOPY_STACK_FRAME_TO",
162 "USERCOPY_STACK_FRAME_FROM",
163 "USERCOPY_STACK_BEYOND",
Kees Cook6c352142016-06-23 22:01:26 -0700164 "USERCOPY_KERNEL",
Ankita Garg8bb31b92006-10-02 02:17:36 -0700165};
166
Kees Cookd87c9782016-06-29 08:07:11 -0700167/* Global jprobe entry and crashtype. */
Kees Cook38f95fe2016-06-29 08:02:32 -0700168static struct jprobe lkdtm_jprobe;
Kees Cook38f95fe2016-06-29 08:02:32 -0700169static enum cname lkdtm_crashpoint = CN_INVALID;
170static enum ctype lkdtm_crashtype = CT_NONE;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700171
Kees Cookd87c9782016-06-29 08:07:11 -0700172/* Global crash counter and spinlock. */
173static int crash_count = DEFAULT_COUNT;
174static DEFINE_SPINLOCK(crash_count_lock);
175
176/* Module parameters */
177static int recur_count = -1;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700178module_param(recur_count, int, 0644);
Kees Cook7d196ac2013-10-24 09:25:39 -0700179MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
Kees Cookd87c9782016-06-29 08:07:11 -0700180
181static char* cpoint_name;
Rusty Russelldca41302010-08-11 23:04:21 -0600182module_param(cpoint_name, charp, 0444);
Randy Dunlap5d861d92006-11-02 22:07:06 -0800183MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
Kees Cookd87c9782016-06-29 08:07:11 -0700184
185static char* cpoint_type;
Rusty Russelldca41302010-08-11 23:04:21 -0600186module_param(cpoint_type, charp, 0444);
Randy Dunlap5d861d92006-11-02 22:07:06 -0800187MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\
188 "hitting the crash point");
Kees Cookd87c9782016-06-29 08:07:11 -0700189
190static int cpoint_count = DEFAULT_COUNT;
Randy Dunlap5d861d92006-11-02 22:07:06 -0800191module_param(cpoint_count, int, 0644);
192MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
193 "crash point is to be hit to trigger action");
Ankita Garg8bb31b92006-10-02 02:17:36 -0700194
Adrian Bunk21181162008-02-06 01:36:50 -0800195static unsigned int jp_do_irq(unsigned int irq)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700196{
197 lkdtm_handler();
198 jprobe_return();
199 return 0;
200}
201
Adrian Bunk21181162008-02-06 01:36:50 -0800202static irqreturn_t jp_handle_irq_event(unsigned int irq,
203 struct irqaction *action)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700204{
205 lkdtm_handler();
206 jprobe_return();
207 return 0;
208}
209
Adrian Bunk21181162008-02-06 01:36:50 -0800210static void jp_tasklet_action(struct softirq_action *a)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700211{
212 lkdtm_handler();
213 jprobe_return();
214}
215
Adrian Bunk21181162008-02-06 01:36:50 -0800216static void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
Ankita Garg8bb31b92006-10-02 02:17:36 -0700217{
218 lkdtm_handler();
219 jprobe_return();
220}
221
222struct scan_control;
223
Adrian Bunk21181162008-02-06 01:36:50 -0800224static unsigned long jp_shrink_inactive_list(unsigned long max_scan,
225 struct zone *zone,
226 struct scan_control *sc)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700227{
228 lkdtm_handler();
229 jprobe_return();
230 return 0;
231}
232
Adrian Bunk21181162008-02-06 01:36:50 -0800233static int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
234 const enum hrtimer_mode mode)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700235{
236 lkdtm_handler();
237 jprobe_return();
238 return 0;
239}
240
Adrian Bunk21181162008-02-06 01:36:50 -0800241static int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700242{
243 lkdtm_handler();
244 jprobe_return();
245 return 0;
246}
247
248#ifdef CONFIG_IDE
Rashika Kheria44629432013-12-13 12:29:42 +0530249static int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file,
Ankita Garg8bb31b92006-10-02 02:17:36 -0700250 struct block_device *bdev, unsigned int cmd,
251 unsigned long arg)
252{
253 lkdtm_handler();
254 jprobe_return();
255 return 0;
256}
257#endif
258
Simon Kagstrom0347af42010-03-05 13:42:49 -0800259/* Return the crashpoint number or NONE if the name is invalid */
260static enum ctype parse_cp_type(const char *what, size_t count)
261{
262 int i;
263
264 for (i = 0; i < ARRAY_SIZE(cp_type); i++) {
265 if (!strcmp(what, cp_type[i]))
Kees Cook329d4162016-06-26 22:26:11 -0700266 return i;
Simon Kagstrom0347af42010-03-05 13:42:49 -0800267 }
268
Namhyung Kim93e2f582010-10-26 14:22:40 -0700269 return CT_NONE;
Simon Kagstrom0347af42010-03-05 13:42:49 -0800270}
271
272static const char *cp_type_to_str(enum ctype type)
273{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700274 if (type == CT_NONE || type < 0 || type > ARRAY_SIZE(cp_type))
Kees Cook329d4162016-06-26 22:26:11 -0700275 return "NONE";
Simon Kagstrom0347af42010-03-05 13:42:49 -0800276
Kees Cook329d4162016-06-26 22:26:11 -0700277 return cp_type[type];
Simon Kagstrom0347af42010-03-05 13:42:49 -0800278}
279
280static const char *cp_name_to_str(enum cname name)
281{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700282 if (name == CN_INVALID || name < 0 || name > ARRAY_SIZE(cp_name))
Simon Kagstrom0347af42010-03-05 13:42:49 -0800283 return "INVALID";
284
Kees Cook329d4162016-06-26 22:26:11 -0700285 return cp_name[name];
Simon Kagstrom0347af42010-03-05 13:42:49 -0800286}
287
288
Ankita Garg8bb31b92006-10-02 02:17:36 -0700289static int lkdtm_parse_commandline(void)
290{
291 int i;
Josh Huntaa2c96d2011-06-27 16:18:08 -0700292 unsigned long flags;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700293
Simon Kagstrom0347af42010-03-05 13:42:49 -0800294 if (cpoint_count < 1 || recur_count < 1)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700295 return -EINVAL;
296
Kees Cook76a10e22016-06-26 22:40:13 -0700297 spin_lock_irqsave(&crash_count_lock, flags);
298 crash_count = cpoint_count;
299 spin_unlock_irqrestore(&crash_count_lock, flags);
Ankita Garg8bb31b92006-10-02 02:17:36 -0700300
Simon Kagstrom0347af42010-03-05 13:42:49 -0800301 /* No special parameters */
302 if (!cpoint_type && !cpoint_name)
303 return 0;
304
305 /* Neither or both of these need to be set */
306 if (!cpoint_type || !cpoint_name)
307 return -EINVAL;
308
Kees Cook38f95fe2016-06-29 08:02:32 -0700309 lkdtm_crashtype = parse_cp_type(cpoint_type, strlen(cpoint_type));
310 if (lkdtm_crashtype == CT_NONE)
Simon Kagstrom0347af42010-03-05 13:42:49 -0800311 return -EINVAL;
312
Kees Cook329d4162016-06-26 22:26:11 -0700313 /* Refuse INVALID as a selectable crashpoint name. */
314 if (!strcmp(cpoint_name, "INVALID"))
315 return -EINVAL;
316
Simon Kagstrom0347af42010-03-05 13:42:49 -0800317 for (i = 0; i < ARRAY_SIZE(cp_name); i++) {
318 if (!strcmp(cpoint_name, cp_name[i])) {
Kees Cook38f95fe2016-06-29 08:02:32 -0700319 lkdtm_crashpoint = i;
Simon Kagstrom0347af42010-03-05 13:42:49 -0800320 return 0;
321 }
322 }
323
324 /* Could not find a valid crash point */
325 return -EINVAL;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700326}
327
Simon Kagstrom0347af42010-03-05 13:42:49 -0800328static void lkdtm_do_action(enum ctype which)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700329{
Simon Kagstrom0347af42010-03-05 13:42:49 -0800330 switch (which) {
Namhyung Kim93e2f582010-10-26 14:22:40 -0700331 case CT_PANIC:
Kees Cook00f496c2016-06-26 22:17:25 -0700332 lkdtm_PANIC();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800333 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700334 case CT_BUG:
Kees Cook00f496c2016-06-26 22:17:25 -0700335 lkdtm_BUG();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800336 break;
Kees Cook65892722013-07-08 10:01:31 -0700337 case CT_WARNING:
Kees Cook00f496c2016-06-26 22:17:25 -0700338 lkdtm_WARNING();
Kees Cook65892722013-07-08 10:01:31 -0700339 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700340 case CT_EXCEPTION:
Kees Cook00f496c2016-06-26 22:17:25 -0700341 lkdtm_EXCEPTION();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800342 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700343 case CT_LOOP:
Kees Cook00f496c2016-06-26 22:17:25 -0700344 lkdtm_LOOP();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800345 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700346 case CT_OVERFLOW:
Kees Cook00f496c2016-06-26 22:17:25 -0700347 lkdtm_OVERFLOW();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800348 break;
Kees Cook629c66a2013-10-24 18:05:42 -0700349 case CT_CORRUPT_STACK:
Kees Cook00f496c2016-06-26 22:17:25 -0700350 lkdtm_CORRUPT_STACK();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800351 break;
Kees Cook00f496c2016-06-26 22:17:25 -0700352 case CT_UNALIGNED_LOAD_STORE_WRITE:
353 lkdtm_UNALIGNED_LOAD_STORE_WRITE();
354 break;
Kees Cookffc514f2016-06-26 21:45:23 -0700355 case CT_OVERWRITE_ALLOCATION:
356 lkdtm_OVERWRITE_ALLOCATION();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800357 break;
Kees Cookffc514f2016-06-26 21:45:23 -0700358 case CT_WRITE_AFTER_FREE:
359 lkdtm_WRITE_AFTER_FREE();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800360 break;
Kees Cookffc514f2016-06-26 21:45:23 -0700361 case CT_READ_AFTER_FREE:
362 lkdtm_READ_AFTER_FREE();
Laura Abbottbc0b8cc2016-02-25 16:36:42 -0800363 break;
Kees Cookffc514f2016-06-26 21:45:23 -0700364 case CT_WRITE_BUDDY_AFTER_FREE:
365 lkdtm_WRITE_BUDDY_AFTER_FREE();
Laura Abbott920d4512016-02-25 16:36:44 -0800366 break;
Kees Cookffc514f2016-06-26 21:45:23 -0700367 case CT_READ_BUDDY_AFTER_FREE:
368 lkdtm_READ_BUDDY_AFTER_FREE();
Simon Kagstrom0347af42010-03-05 13:42:49 -0800369 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700370 case CT_SOFTLOCKUP:
Kees Cook00f496c2016-06-26 22:17:25 -0700371 lkdtm_SOFTLOCKUP();
Frederic Weisbeckera48223f2010-05-26 14:44:29 -0700372 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700373 case CT_HARDLOCKUP:
Kees Cook00f496c2016-06-26 22:17:25 -0700374 lkdtm_HARDLOCKUP();
Frederic Weisbeckera48223f2010-05-26 14:44:29 -0700375 break;
Kees Cook274a5852013-07-08 10:01:32 -0700376 case CT_SPINLOCKUP:
Kees Cook00f496c2016-06-26 22:17:25 -0700377 lkdtm_SPINLOCKUP();
Kees Cook274a5852013-07-08 10:01:32 -0700378 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700379 case CT_HUNG_TASK:
Kees Cook00f496c2016-06-26 22:17:25 -0700380 lkdtm_HUNG_TASK();
Frederic Weisbeckera48223f2010-05-26 14:44:29 -0700381 break;
Kees Cookcc33c5372013-07-08 10:01:33 -0700382 case CT_EXEC_DATA:
Kees Cook0d9eb292016-06-26 15:12:31 -0700383 lkdtm_EXEC_DATA();
Kees Cookcc33c5372013-07-08 10:01:33 -0700384 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700385 case CT_EXEC_STACK:
386 lkdtm_EXEC_STACK();
Kees Cookcc33c5372013-07-08 10:01:33 -0700387 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700388 case CT_EXEC_KMALLOC:
389 lkdtm_EXEC_KMALLOC();
Kees Cookcc33c5372013-07-08 10:01:33 -0700390 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700391 case CT_EXEC_VMALLOC:
392 lkdtm_EXEC_VMALLOC();
Kees Cookcc33c5372013-07-08 10:01:33 -0700393 break;
Kees Cook9a49a522016-02-22 14:09:29 -0800394 case CT_EXEC_RODATA:
Kees Cook0d9eb292016-06-26 15:12:31 -0700395 lkdtm_EXEC_RODATA();
Kees Cook9a49a522016-02-22 14:09:29 -0800396 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700397 case CT_EXEC_USERSPACE:
398 lkdtm_EXEC_USERSPACE();
Kees Cook9ae113c2013-10-24 09:25:57 -0700399 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700400 case CT_ACCESS_USERSPACE:
401 lkdtm_ACCESS_USERSPACE();
Kees Cook9ae113c2013-10-24 09:25:57 -0700402 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700403 case CT_WRITE_RO:
404 lkdtm_WRITE_RO();
Kees Cook7cca0712016-02-17 14:41:16 -0800405 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700406 case CT_WRITE_RO_AFTER_INIT:
407 lkdtm_WRITE_RO_AFTER_INIT();
Kees Cook9ae113c2013-10-24 09:25:57 -0700408 break;
Kees Cook0d9eb292016-06-26 15:12:31 -0700409 case CT_WRITE_KERN:
410 lkdtm_WRITE_KERN();
Kees Cookdc2b9e92014-02-09 13:48:48 -0800411 break;
Kees Cook00f496c2016-06-26 22:17:25 -0700412 case CT_ATOMIC_UNDERFLOW:
413 lkdtm_ATOMIC_UNDERFLOW();
Kees Cookb5484522016-06-07 14:27:02 -0700414 break;
Kees Cook00f496c2016-06-26 22:17:25 -0700415 case CT_ATOMIC_OVERFLOW:
416 lkdtm_ATOMIC_OVERFLOW();
417 break;
Kees Cookaa981a62016-06-03 12:06:52 -0700418 case CT_USERCOPY_HEAP_SIZE_TO:
Kees Cooka3dff712016-06-26 08:46:23 -0700419 lkdtm_USERCOPY_HEAP_SIZE_TO();
Kees Cookaa981a62016-06-03 12:06:52 -0700420 break;
421 case CT_USERCOPY_HEAP_SIZE_FROM:
Kees Cooka3dff712016-06-26 08:46:23 -0700422 lkdtm_USERCOPY_HEAP_SIZE_FROM();
Kees Cookaa981a62016-06-03 12:06:52 -0700423 break;
424 case CT_USERCOPY_HEAP_FLAG_TO:
Kees Cooka3dff712016-06-26 08:46:23 -0700425 lkdtm_USERCOPY_HEAP_FLAG_TO();
Kees Cookaa981a62016-06-03 12:06:52 -0700426 break;
427 case CT_USERCOPY_HEAP_FLAG_FROM:
Kees Cooka3dff712016-06-26 08:46:23 -0700428 lkdtm_USERCOPY_HEAP_FLAG_FROM();
Kees Cookaa981a62016-06-03 12:06:52 -0700429 break;
430 case CT_USERCOPY_STACK_FRAME_TO:
Kees Cooka3dff712016-06-26 08:46:23 -0700431 lkdtm_USERCOPY_STACK_FRAME_TO();
Kees Cookaa981a62016-06-03 12:06:52 -0700432 break;
433 case CT_USERCOPY_STACK_FRAME_FROM:
Kees Cooka3dff712016-06-26 08:46:23 -0700434 lkdtm_USERCOPY_STACK_FRAME_FROM();
Kees Cookaa981a62016-06-03 12:06:52 -0700435 break;
436 case CT_USERCOPY_STACK_BEYOND:
Kees Cooka3dff712016-06-26 08:46:23 -0700437 lkdtm_USERCOPY_STACK_BEYOND();
Kees Cookaa981a62016-06-03 12:06:52 -0700438 break;
Kees Cook6c352142016-06-23 22:01:26 -0700439 case CT_USERCOPY_KERNEL:
Kees Cooka3dff712016-06-26 08:46:23 -0700440 lkdtm_USERCOPY_KERNEL();
Kees Cook6c352142016-06-23 22:01:26 -0700441 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700442 case CT_NONE:
Simon Kagstrom0347af42010-03-05 13:42:49 -0800443 default:
444 break;
445 }
446
447}
448
449static void lkdtm_handler(void)
450{
Josh Huntaa2c96d2011-06-27 16:18:08 -0700451 unsigned long flags;
Cong Wang92618182012-02-03 15:37:15 -0800452 bool do_it = false;
Josh Huntaa2c96d2011-06-27 16:18:08 -0700453
Kees Cook76a10e22016-06-26 22:40:13 -0700454 spin_lock_irqsave(&crash_count_lock, flags);
455 crash_count--;
Kees Cookfeac6e22014-02-09 13:48:46 -0800456 pr_info("Crash point %s of type %s hit, trigger in %d rounds\n",
Kees Cook38f95fe2016-06-29 08:02:32 -0700457 cp_name_to_str(lkdtm_crashpoint),
458 cp_type_to_str(lkdtm_crashtype), crash_count);
Ankita Garg8bb31b92006-10-02 02:17:36 -0700459
Kees Cook76a10e22016-06-26 22:40:13 -0700460 if (crash_count == 0) {
Cong Wang92618182012-02-03 15:37:15 -0800461 do_it = true;
Kees Cook76a10e22016-06-26 22:40:13 -0700462 crash_count = cpoint_count;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700463 }
Kees Cook76a10e22016-06-26 22:40:13 -0700464 spin_unlock_irqrestore(&crash_count_lock, flags);
Cong Wang92618182012-02-03 15:37:15 -0800465
466 if (do_it)
Kees Cook38f95fe2016-06-29 08:02:32 -0700467 lkdtm_do_action(lkdtm_crashtype);
Ankita Garg8bb31b92006-10-02 02:17:36 -0700468}
469
Simon Kagstrom0347af42010-03-05 13:42:49 -0800470static int lkdtm_register_cpoint(enum cname which)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700471{
472 int ret;
473
Kees Cook38f95fe2016-06-29 08:02:32 -0700474 lkdtm_crashpoint = CN_INVALID;
475 if (lkdtm_jprobe.entry != NULL)
476 unregister_jprobe(&lkdtm_jprobe);
Ankita Garg8bb31b92006-10-02 02:17:36 -0700477
Simon Kagstrom0347af42010-03-05 13:42:49 -0800478 switch (which) {
Namhyung Kim93e2f582010-10-26 14:22:40 -0700479 case CN_DIRECT:
Kees Cook38f95fe2016-06-29 08:02:32 -0700480 lkdtm_do_action(lkdtm_crashtype);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800481 return 0;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700482 case CN_INT_HARDWARE_ENTRY:
Kees Cook38f95fe2016-06-29 08:02:32 -0700483 lkdtm_jprobe.kp.symbol_name = "do_IRQ";
484 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_do_irq;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700485 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700486 case CN_INT_HW_IRQ_EN:
Kees Cook38f95fe2016-06-29 08:02:32 -0700487 lkdtm_jprobe.kp.symbol_name = "handle_IRQ_event";
488 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_handle_irq_event;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700489 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700490 case CN_INT_TASKLET_ENTRY:
Kees Cook38f95fe2016-06-29 08:02:32 -0700491 lkdtm_jprobe.kp.symbol_name = "tasklet_action";
492 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_tasklet_action;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700493 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700494 case CN_FS_DEVRW:
Kees Cook38f95fe2016-06-29 08:02:32 -0700495 lkdtm_jprobe.kp.symbol_name = "ll_rw_block";
496 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_ll_rw_block;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700497 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700498 case CN_MEM_SWAPOUT:
Kees Cook38f95fe2016-06-29 08:02:32 -0700499 lkdtm_jprobe.kp.symbol_name = "shrink_inactive_list";
500 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_shrink_inactive_list;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700501 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700502 case CN_TIMERADD:
Kees Cook38f95fe2016-06-29 08:02:32 -0700503 lkdtm_jprobe.kp.symbol_name = "hrtimer_start";
504 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_hrtimer_start;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700505 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700506 case CN_SCSI_DISPATCH_CMD:
Kees Cook38f95fe2016-06-29 08:02:32 -0700507 lkdtm_jprobe.kp.symbol_name = "scsi_dispatch_cmd";
508 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_scsi_dispatch_cmd;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700509 break;
Namhyung Kim93e2f582010-10-26 14:22:40 -0700510 case CN_IDE_CORE_CP:
Ankita Garg8bb31b92006-10-02 02:17:36 -0700511#ifdef CONFIG_IDE
Kees Cook38f95fe2016-06-29 08:02:32 -0700512 lkdtm_jprobe.kp.symbol_name = "generic_ide_ioctl";
513 lkdtm_jprobe.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700514#else
Kees Cookfeac6e22014-02-09 13:48:46 -0800515 pr_info("Crash point not available\n");
Simon Kagstrom0347af42010-03-05 13:42:49 -0800516 return -EINVAL;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700517#endif
518 break;
519 default:
Kees Cookfeac6e22014-02-09 13:48:46 -0800520 pr_info("Invalid Crash Point\n");
Simon Kagstrom0347af42010-03-05 13:42:49 -0800521 return -EINVAL;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700522 }
523
Kees Cook38f95fe2016-06-29 08:02:32 -0700524 lkdtm_crashpoint = which;
525 if ((ret = register_jprobe(&lkdtm_jprobe)) < 0) {
Kees Cookfeac6e22014-02-09 13:48:46 -0800526 pr_info("Couldn't register jprobe\n");
Kees Cook38f95fe2016-06-29 08:02:32 -0700527 lkdtm_crashpoint = CN_INVALID;
Ankita Garg8bb31b92006-10-02 02:17:36 -0700528 }
529
Simon Kagstrom0347af42010-03-05 13:42:49 -0800530 return ret;
531}
532
533static ssize_t do_register_entry(enum cname which, struct file *f,
534 const char __user *user_buf, size_t count, loff_t *off)
535{
536 char *buf;
537 int err;
538
539 if (count >= PAGE_SIZE)
540 return -EINVAL;
541
542 buf = (char *)__get_free_page(GFP_KERNEL);
543 if (!buf)
544 return -ENOMEM;
545 if (copy_from_user(buf, user_buf, count)) {
546 free_page((unsigned long) buf);
547 return -EFAULT;
548 }
549 /* NULL-terminate and remove enter */
550 buf[count] = '\0';
551 strim(buf);
552
Kees Cook38f95fe2016-06-29 08:02:32 -0700553 lkdtm_crashtype = parse_cp_type(buf, count);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800554 free_page((unsigned long) buf);
555
Kees Cook38f95fe2016-06-29 08:02:32 -0700556 if (lkdtm_crashtype == CT_NONE)
Simon Kagstrom0347af42010-03-05 13:42:49 -0800557 return -EINVAL;
558
559 err = lkdtm_register_cpoint(which);
560 if (err < 0)
561 return err;
562
563 *off += count;
564
565 return count;
566}
567
568/* Generic read callback that just prints out the available crash types */
569static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
570 size_t count, loff_t *off)
571{
572 char *buf;
573 int i, n, out;
574
575 buf = (char *)__get_free_page(GFP_KERNEL);
Alan Cox086ff4b2012-07-30 14:43:24 -0700576 if (buf == NULL)
577 return -ENOMEM;
Simon Kagstrom0347af42010-03-05 13:42:49 -0800578
579 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
580 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
581 n += snprintf(buf + n, PAGE_SIZE - n, "%s\n", cp_type[i]);
582 buf[n] = '\0';
583
584 out = simple_read_from_buffer(user_buf, count, off,
585 buf, n);
586 free_page((unsigned long) buf);
587
588 return out;
589}
590
591static int lkdtm_debugfs_open(struct inode *inode, struct file *file)
592{
Ankita Garg8bb31b92006-10-02 02:17:36 -0700593 return 0;
594}
595
Simon Kagstrom0347af42010-03-05 13:42:49 -0800596
597static ssize_t int_hardware_entry(struct file *f, const char __user *buf,
598 size_t count, loff_t *off)
599{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700600 return do_register_entry(CN_INT_HARDWARE_ENTRY, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800601}
602
603static ssize_t int_hw_irq_en(struct file *f, const char __user *buf,
604 size_t count, loff_t *off)
605{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700606 return do_register_entry(CN_INT_HW_IRQ_EN, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800607}
608
609static ssize_t int_tasklet_entry(struct file *f, const char __user *buf,
610 size_t count, loff_t *off)
611{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700612 return do_register_entry(CN_INT_TASKLET_ENTRY, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800613}
614
615static ssize_t fs_devrw_entry(struct file *f, const char __user *buf,
616 size_t count, loff_t *off)
617{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700618 return do_register_entry(CN_FS_DEVRW, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800619}
620
621static ssize_t mem_swapout_entry(struct file *f, const char __user *buf,
622 size_t count, loff_t *off)
623{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700624 return do_register_entry(CN_MEM_SWAPOUT, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800625}
626
627static ssize_t timeradd_entry(struct file *f, const char __user *buf,
628 size_t count, loff_t *off)
629{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700630 return do_register_entry(CN_TIMERADD, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800631}
632
633static ssize_t scsi_dispatch_cmd_entry(struct file *f,
634 const char __user *buf, size_t count, loff_t *off)
635{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700636 return do_register_entry(CN_SCSI_DISPATCH_CMD, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800637}
638
639static ssize_t ide_core_cp_entry(struct file *f, const char __user *buf,
640 size_t count, loff_t *off)
641{
Namhyung Kim93e2f582010-10-26 14:22:40 -0700642 return do_register_entry(CN_IDE_CORE_CP, f, buf, count, off);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800643}
644
645/* Special entry to just crash directly. Available without KPROBEs */
646static ssize_t direct_entry(struct file *f, const char __user *user_buf,
647 size_t count, loff_t *off)
648{
649 enum ctype type;
650 char *buf;
651
652 if (count >= PAGE_SIZE)
653 return -EINVAL;
654 if (count < 1)
655 return -EINVAL;
656
657 buf = (char *)__get_free_page(GFP_KERNEL);
658 if (!buf)
659 return -ENOMEM;
660 if (copy_from_user(buf, user_buf, count)) {
661 free_page((unsigned long) buf);
662 return -EFAULT;
663 }
664 /* NULL-terminate and remove enter */
665 buf[count] = '\0';
666 strim(buf);
667
668 type = parse_cp_type(buf, count);
669 free_page((unsigned long) buf);
Namhyung Kim93e2f582010-10-26 14:22:40 -0700670 if (type == CT_NONE)
Simon Kagstrom0347af42010-03-05 13:42:49 -0800671 return -EINVAL;
672
Kees Cookfeac6e22014-02-09 13:48:46 -0800673 pr_info("Performing direct entry %s\n", cp_type_to_str(type));
Simon Kagstrom0347af42010-03-05 13:42:49 -0800674 lkdtm_do_action(type);
675 *off += count;
676
677 return count;
678}
679
680struct crash_entry {
681 const char *name;
682 const struct file_operations fops;
683};
684
685static const struct crash_entry crash_entries[] = {
686 {"DIRECT", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200687 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800688 .open = lkdtm_debugfs_open,
689 .write = direct_entry} },
690 {"INT_HARDWARE_ENTRY", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200691 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800692 .open = lkdtm_debugfs_open,
693 .write = int_hardware_entry} },
694 {"INT_HW_IRQ_EN", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200695 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800696 .open = lkdtm_debugfs_open,
697 .write = int_hw_irq_en} },
698 {"INT_TASKLET_ENTRY", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200699 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800700 .open = lkdtm_debugfs_open,
701 .write = int_tasklet_entry} },
702 {"FS_DEVRW", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200703 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800704 .open = lkdtm_debugfs_open,
705 .write = fs_devrw_entry} },
706 {"MEM_SWAPOUT", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200707 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800708 .open = lkdtm_debugfs_open,
709 .write = mem_swapout_entry} },
710 {"TIMERADD", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200711 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800712 .open = lkdtm_debugfs_open,
713 .write = timeradd_entry} },
714 {"SCSI_DISPATCH_CMD", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200715 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800716 .open = lkdtm_debugfs_open,
717 .write = scsi_dispatch_cmd_entry} },
718 {"IDE_CORE_CP", {.read = lkdtm_debugfs_read,
Arnd Bergmann05271ec2010-07-06 19:10:26 +0200719 .llseek = generic_file_llseek,
Simon Kagstrom0347af42010-03-05 13:42:49 -0800720 .open = lkdtm_debugfs_open,
721 .write = ide_core_cp_entry} },
722};
723
724static struct dentry *lkdtm_debugfs_root;
725
726static int __init lkdtm_module_init(void)
727{
728 int ret = -EINVAL;
729 int n_debugfs_entries = 1; /* Assume only the direct entry */
730 int i;
731
Kees Cooka3dff712016-06-26 08:46:23 -0700732 /* Handle test-specific initialization. */
Kees Cook00f496c2016-06-26 22:17:25 -0700733 lkdtm_bugs_init(&recur_count);
Kees Cook0d9eb292016-06-26 15:12:31 -0700734 lkdtm_perms_init();
Kees Cooka3dff712016-06-26 08:46:23 -0700735 lkdtm_usercopy_init();
736
Simon Kagstrom0347af42010-03-05 13:42:49 -0800737 /* Register debugfs interface */
738 lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
739 if (!lkdtm_debugfs_root) {
Kees Cookfeac6e22014-02-09 13:48:46 -0800740 pr_err("creating root dir failed\n");
Simon Kagstrom0347af42010-03-05 13:42:49 -0800741 return -ENODEV;
742 }
743
744#ifdef CONFIG_KPROBES
745 n_debugfs_entries = ARRAY_SIZE(crash_entries);
746#endif
747
748 for (i = 0; i < n_debugfs_entries; i++) {
749 const struct crash_entry *cur = &crash_entries[i];
750 struct dentry *de;
751
752 de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
753 NULL, &cur->fops);
754 if (de == NULL) {
Kees Cookfeac6e22014-02-09 13:48:46 -0800755 pr_err("could not create %s\n", cur->name);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800756 goto out_err;
757 }
758 }
759
760 if (lkdtm_parse_commandline() == -EINVAL) {
Kees Cookfeac6e22014-02-09 13:48:46 -0800761 pr_info("Invalid command\n");
Simon Kagstrom0347af42010-03-05 13:42:49 -0800762 goto out_err;
763 }
764
Kees Cook38f95fe2016-06-29 08:02:32 -0700765 if (lkdtm_crashpoint != CN_INVALID && lkdtm_crashtype != CT_NONE) {
766 ret = lkdtm_register_cpoint(lkdtm_crashpoint);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800767 if (ret < 0) {
Kees Cook38f95fe2016-06-29 08:02:32 -0700768 pr_info("Invalid crash point %d\n", lkdtm_crashpoint);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800769 goto out_err;
770 }
Kees Cookfeac6e22014-02-09 13:48:46 -0800771 pr_info("Crash point %s of type %s registered\n",
772 cpoint_name, cpoint_type);
Simon Kagstrom0347af42010-03-05 13:42:49 -0800773 } else {
Kees Cookfeac6e22014-02-09 13:48:46 -0800774 pr_info("No crash points registered, enable through debugfs\n");
Simon Kagstrom0347af42010-03-05 13:42:49 -0800775 }
776
777 return 0;
778
779out_err:
780 debugfs_remove_recursive(lkdtm_debugfs_root);
781 return ret;
782}
783
Adrian Bunk21181162008-02-06 01:36:50 -0800784static void __exit lkdtm_module_exit(void)
Ankita Garg8bb31b92006-10-02 02:17:36 -0700785{
Simon Kagstrom0347af42010-03-05 13:42:49 -0800786 debugfs_remove_recursive(lkdtm_debugfs_root);
787
Kees Cooka3dff712016-06-26 08:46:23 -0700788 /* Handle test-specific clean-up. */
789 lkdtm_usercopy_exit();
Kees Cookaa981a62016-06-03 12:06:52 -0700790
Kees Cook38f95fe2016-06-29 08:02:32 -0700791 unregister_jprobe(&lkdtm_jprobe);
Kees Cookfeac6e22014-02-09 13:48:46 -0800792 pr_info("Crash point unregistered\n");
Ankita Garg8bb31b92006-10-02 02:17:36 -0700793}
794
795module_init(lkdtm_module_init);
796module_exit(lkdtm_module_exit);
797
798MODULE_LICENSE("GPL");
Terry Chiada869202014-07-02 21:02:25 +0800799MODULE_DESCRIPTION("Kprobe module for testing crash dumps");