hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/misc/lkdtm/core.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Linux Kernel Dump Test Module for testing kernel crashes conditions:
34 * induces system failures at predefined crashpoints and under predefined
45 * operational conditions in order to evaluate the reliability of kernel
56 * sanity checking and crash dumps obtained using different dumping
67 * solutions.
7
- *
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.
218 *
229 * Copyright (C) IBM Corporation, 2006
2310 *
....@@ -28,7 +15,7 @@
2815 *
2916 * Debugfs support added by Simon Kagstrom <simon.kagstrom@netinsight.net>
3017 *
31
- * See Documentation/fault-injection/provoke-crashes.txt for instructions
18
+ * See Documentation/fault-injection/provoke-crashes.rst for instructions
3219 */
3320 #include "lkdtm.h"
3421 #include <linux/fs.h>
....@@ -37,15 +24,8 @@
3724 #include <linux/kprobes.h>
3825 #include <linux/list.h>
3926 #include <linux/init.h>
40
-#include <linux/interrupt.h>
41
-#include <linux/hrtimer.h>
4227 #include <linux/slab.h>
43
-#include <scsi/scsi_cmnd.h>
4428 #include <linux/debugfs.h>
45
-
46
-#ifdef CONFIG_IDE
47
-#include <linux/ide.h>
48
-#endif
4929
5030 #define DEFAULT_COUNT 10
5131
....@@ -101,10 +81,8 @@
10181 CRASHPOINT("FS_DEVRW", "ll_rw_block"),
10282 CRASHPOINT("MEM_SWAPOUT", "shrink_inactive_list"),
10383 CRASHPOINT("TIMERADD", "hrtimer_start"),
104
- CRASHPOINT("SCSI_DISPATCH_CMD", "scsi_dispatch_cmd"),
105
-# ifdef CONFIG_IDE
84
+ CRASHPOINT("SCSI_QUEUE_RQ", "scsi_queue_rq"),
10685 CRASHPOINT("IDE_CORE_CP", "generic_ide_ioctl"),
107
-# endif
10886 #endif
10987 };
11088
....@@ -126,26 +104,34 @@
126104 CRASHTYPE(PANIC),
127105 CRASHTYPE(BUG),
128106 CRASHTYPE(WARNING),
107
+ CRASHTYPE(WARNING_MESSAGE),
129108 CRASHTYPE(EXCEPTION),
130109 CRASHTYPE(LOOP),
131
- CRASHTYPE(OVERFLOW),
132
- CRASHTYPE(CORRUPT_LIST_ADD),
133
- CRASHTYPE(CORRUPT_LIST_DEL),
134
- CRASHTYPE(CORRUPT_USER_DS),
110
+ CRASHTYPE(EXHAUST_STACK),
135111 CRASHTYPE(CORRUPT_STACK),
136112 CRASHTYPE(CORRUPT_STACK_STRONG),
113
+ CRASHTYPE(CORRUPT_LIST_ADD),
114
+ CRASHTYPE(CORRUPT_LIST_DEL),
137115 CRASHTYPE(STACK_GUARD_PAGE_LEADING),
138116 CRASHTYPE(STACK_GUARD_PAGE_TRAILING),
117
+ CRASHTYPE(UNSET_SMEP),
118
+ CRASHTYPE(CORRUPT_PAC),
139119 CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE),
140120 CRASHTYPE(OVERWRITE_ALLOCATION),
141121 CRASHTYPE(WRITE_AFTER_FREE),
142122 CRASHTYPE(READ_AFTER_FREE),
143123 CRASHTYPE(WRITE_BUDDY_AFTER_FREE),
144124 CRASHTYPE(READ_BUDDY_AFTER_FREE),
125
+ CRASHTYPE(SLAB_FREE_DOUBLE),
126
+ CRASHTYPE(SLAB_FREE_CROSS),
127
+ CRASHTYPE(SLAB_FREE_PAGE),
145128 CRASHTYPE(SOFTLOCKUP),
146129 CRASHTYPE(HARDLOCKUP),
147130 CRASHTYPE(SPINLOCKUP),
148131 CRASHTYPE(HUNG_TASK),
132
+ CRASHTYPE(OVERFLOW_SIGNED),
133
+ CRASHTYPE(OVERFLOW_UNSIGNED),
134
+ CRASHTYPE(ARRAY_BOUNDS),
149135 CRASHTYPE(EXEC_DATA),
150136 CRASHTYPE(EXEC_STACK),
151137 CRASHTYPE(EXEC_KMALLOC),
....@@ -185,6 +171,9 @@
185171 CRASHTYPE(USERCOPY_STACK_FRAME_FROM),
186172 CRASHTYPE(USERCOPY_STACK_BEYOND),
187173 CRASHTYPE(USERCOPY_KERNEL),
174
+ CRASHTYPE(STACKLEAK_ERASING),
175
+ CRASHTYPE(CFI_FORWARD_PROTO),
176
+ CRASHTYPE(DOUBLE_FAULT),
188177 };
189178
190179
....@@ -347,9 +336,9 @@
347336 if (buf == NULL)
348337 return -ENOMEM;
349338
350
- n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
339
+ n = scnprintf(buf, PAGE_SIZE, "Available crash types:\n");
351340 for (i = 0; i < ARRAY_SIZE(crashtypes); i++) {
352
- n += snprintf(buf + n, PAGE_SIZE - n, "%s\n",
341
+ n += scnprintf(buf + n, PAGE_SIZE - n, "%s\n",
353342 crashtypes[i].name);
354343 }
355344 buf[n] = '\0';
....@@ -407,7 +396,7 @@
407396 {
408397 struct crashpoint *crashpoint = NULL;
409398 const struct crashtype *crashtype = NULL;
410
- int ret = -EINVAL;
399
+ int ret;
411400 int i;
412401
413402 /* Neither or both of these need to be set */
....@@ -446,25 +435,17 @@
446435 lkdtm_bugs_init(&recur_count);
447436 lkdtm_perms_init();
448437 lkdtm_usercopy_init();
438
+ lkdtm_heap_init();
449439
450440 /* Register debugfs interface */
451441 lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
452
- if (!lkdtm_debugfs_root) {
453
- pr_err("creating root dir failed\n");
454
- return -ENODEV;
455
- }
456442
457443 /* Install debugfs trigger files. */
458444 for (i = 0; i < ARRAY_SIZE(crashpoints); i++) {
459445 struct crashpoint *cur = &crashpoints[i];
460
- struct dentry *de;
461446
462
- de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
463
- cur, &cur->fops);
464
- if (de == NULL) {
465
- pr_err("could not create crashpoint %s\n", cur->name);
466
- goto out_err;
467
- }
447
+ debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, cur,
448
+ &cur->fops);
468449 }
469450
470451 /* Install crashpoint if one was selected. */
....@@ -492,6 +473,7 @@
492473 debugfs_remove_recursive(lkdtm_debugfs_root);
493474
494475 /* Handle test-specific clean-up. */
476
+ lkdtm_heap_exit();
495477 lkdtm_usercopy_exit();
496478
497479 if (lkdtm_kprobe != NULL)