Skip to contentSkip to conversation

fault-inject: support systematic fault injection

PATCH Superseded Dmitry Vyukov 2 participants 3 messages Mar 24, 2017 – Mar 28, 2017

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fault-inject: support systematic fault injection

Add /sys/kernel/debug/fail_once file that allows failing 0-th, 1-st, 2-nd and so on calls systematically. Excerpt from the added documentation:

===
Write to this file of integer N makes N-th call in the current task fail (N is 0-based). Read from this file returns a single char 'Y' or 'N' that says if the fault setup with a previous write to this file was injected or not, and disables the fault if it wasn't yet injected. Note that this file enables all types of faults (slab, futex, etc). This setting takes precedence over all other generic settings like probability, interval, times, etc. But per-capability settings (e.g. fail_futex/ignore-private) take precedence over it. This feature is intended for systematic testing of faults in a single system call. See an example below.
===

Why adding new setting:
1. Existing settings are global rather than per-task.
So parallel testing is not possible.
2. attr->interval is close but it depends on attr->count which is non reset to 0, so interval does not work as expected.
3. Trying to model this with existing settings requires manipulations of all of probability, interval, times, space, task-filter and unexposed count and per-task make-it-fail files.
4. Existing settings are per-failure-type, and the set of failure types is potentially expanding.
5. make-it-fail can't be changed by unprivileged user and aggressive stress testing better be done from an unprivileged user. Similarly, this would require opening the debugfs files to the unprivileged user, as he would need to reopen at least times file (not possible to pre-open before dropping privs).

The proposed interface solves all of the above (see the example).

---

We want to integrate this into syzkaller fuzzer.
A prototype has found 10 bugs in kernel in first day of usage:
https://groups.google.com/forum/#!searchin/syzkaller/%22FAULT_INJECTION%22%7Csort:relevance

---
 Documentation/fault-injection/fault-injection.txt | 74 +++++++++++++++++++++++
 include/linux/sched.h                             |  1 +
 kernel/fork.c                                     |  4 ++
 lib/fault-inject.c                                | 49 +++++++++++++++
 4 files changed, 128 insertions(+)
Documentation/fault-injection/fault-injection.txt +74 -0
index 415484f3d59a..593ad33c76c2 100644
@@ -99,6 +99,20 @@ configuration of fault-injection capabilities.
 	for a caller within [require-start,require-end) OR
 	[reject-start,reject-end).
 
+- /sys/kernel/debug/fail_once:
+
+	Write to this file of integer N makes N-th call in the current task fail
+	(N is 0-based). Read from this file returns a single char 'Y' or 'N'
+	that says if the fault setup with a previous write to this file was
+	injected or not, and disables the fault if it wasn't yet injected.
+	Note that this file enables all types of faults (slab, futex, etc).
+	This setting takes precedence over all other generic settings like
+	probability, interval, times, etc. But per-capability settings
+	(e.g. fail_futex/ignore-private) take precedence over it.
+
+	This feature is intended for systematic testing of faults in a single
+	system call. See an example below.
+
 - /sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem:
 
 	Format: { 'Y' | 'N' }
@@ -278,3 +292,63 @@ allocation failure.
 	# env FAILCMD_TYPE=fail_page_alloc \
 		./tools/testing/fault-injection/failcmd.sh --times=100 \
                 -- make -C tools/testing/selftests/ run_tests
+
+Systematic faults using fail_once
+---------------------------------
+
+The following code systematically faults 0-th, 1-st, 2-nd and so on
+capabilities in the socketpair() system call.
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+int main()
+{
+	int i, err, res, once, fds[2];
+	char buf[16];
+
+	system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait");
+	once = open("/sys/kernel/debug/fail_once", O_RDWR);
+	for (i = 0;; i++) {
+		sprintf(buf, "%d", i);
+		write(once, buf, strlen(buf));
+		res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
+		err = errno;
+		read(once, buf, 1);
+		if (res == 0) {
+			close(fds[0]);
+			close(fds[1]);
+		}
+		printf("%d-th fault %c: res=%d/%d\n", i, buf[0], res, err);
+		if (buf[0] != 'Y')
+			break;
+	}
+	return 0;
+}
+
+An example output:
+
+0-th fault Y: res=-1/23
+1-th fault Y: res=-1/23
+2-th fault Y: res=-1/23
+3-th fault Y: res=-1/12
+4-th fault Y: res=-1/12
+5-th fault Y: res=-1/23
+6-th fault Y: res=-1/23
+7-th fault Y: res=-1/23
+8-th fault Y: res=-1/12
+9-th fault Y: res=-1/12
+10-th fault Y: res=-1/12
+11-th fault Y: res=-1/12
+12-th fault Y: res=-1/12
+13-th fault Y: res=-1/12
+14-th fault Y: res=-1/12
+15-th fault Y: res=-1/12
+16-th fault N: res=0/12
include/linux/sched.h +1 -0
index 543e0ea82684..7b50221fea51 100644
@@ -1897,6 +1897,7 @@ struct task_struct {
 #endif
 #ifdef CONFIG_FAULT_INJECTION
 	int make_it_fail;
+	int fail_nth;
 #endif
 	/*
 	 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
kernel/fork.c +4 -0
index 61284d8122fa..869c97a0a930 100644
@@ -545,6 +545,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
 
 	kcov_task_init(tsk);
 
+#ifdef CONFIG_FAULT_INJECTION
+	tsk->fail_nth = 0;
+#endif
+
 	return tsk;
 
 free_stack:
lib/fault-inject.c +49 -0

71 lines not on this page · raw message

Signature · 7 lines
2.12.1.578.ge9c3154ca4-goog

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw

2017-03-25 5:08 GMT+09:00 Dmitry Vyukov <[email protected]>:

Quoted 15 lines

Add /sys/kernel/debug/fail_once file that allows failing 0-th, 1-st, 2-nd and so on calls systematically. Excerpt from the added documentation:

===
Write to this file of integer N makes N-th call in the current task fail (N is 0-based). Read from this file returns a single char 'Y' or 'N' that says if the fault setup with a previous write to this file was injected or not, and disables the fault if it wasn't yet injected. Note that this file enables all types of faults (slab, futex, etc). This setting takes precedence over all other generic settings like probability, interval, times, etc. But per-capability settings (e.g. fail_futex/ignore-private) take precedence over it. This feature is intended for systematic testing of faults in a single system call. See an example below.
===

The "/sys/kernel/debug/fail_once" contains per-task data.

Should we introduce new per-task file like "/proc/<pid>/fail-nth" instead of adding a single global debugfs file?

Quoted 16 lines

Why adding new setting:
1. Existing settings are global rather than per-task.
So parallel testing is not possible.
2. attr->interval is close but it depends on attr->count which is non reset to 0, so interval does not work as expected.
3. Trying to model this with existing settings requires manipulations of all of probability, interval, times, space, task-filter and unexposed count and per-task make-it-fail files.
4. Existing settings are per-failure-type, and the set of failure types is potentially expanding.
5. make-it-fail can't be changed by unprivileged user and aggressive stress testing better be done from an unprivileged user. Similarly, this would require opening the debugfs files to the unprivileged user, as he would need to reopen at least times file (not possible to pre-open before dropping privs).

Quoted 1 line

The proposed interface solves all of the above (see the example).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 17 lines · Akinobu Mita

2017-03-25 5:08 GMT+09:00 Dmitry Vyukov <[email protected]>:

Quoted 15 lines

Add /sys/kernel/debug/fail_once file that allows failing 0-th, 1-st, 2-nd and so on calls systematically. Excerpt from the added documentation:

===
Write to this file of integer N makes N-th call in the current task fail (N is 0-based). Read from this file returns a single char 'Y' or 'N' that says if the fault setup with a previous write to this file was injected or not, and disables the fault if it wasn't yet injected. Note that this file enables all types of faults (slab, futex, etc). This setting takes precedence over all other generic settings like probability, interval, times, etc. But per-capability settings (e.g. fail_futex/ignore-private) take precedence over it. This feature is intended for systematic testing of faults in a single system call. See an example below.
===

Quoted 4 lines

The "/sys/kernel/debug/fail_once" contains per-task data.

Should we introduce new per-task file like "/proc/<pid>/fail-nth" instead of adding a single global debugfs file?

Mailed v2 that uses /proc/self/task/tid/fail-nth.

Quoted 16 lines
Quoted 16 lines

Why adding new setting:
1. Existing settings are global rather than per-task.
So parallel testing is not possible.
2. attr->interval is close but it depends on attr->count which is non reset to 0, so interval does not work as expected.
3. Trying to model this with existing settings requires manipulations of all of probability, interval, times, space, task-filter and unexposed count and per-task make-it-fail files.
4. Existing settings are per-failure-type, and the set of failure types is potentially expanding.
5. make-it-fail can't be changed by unprivileged user and aggressive stress testing better be done from an unprivileged user. Similarly, this would require opening the debugfs files to the unprivileged user, as he would need to reopen at least times file (not possible to pre-open before dropping privs).

Quoted 1 line
Quoted 1 line

The proposed interface solves all of the above (see the example).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>