2019-06-13 01:52:44 +08:00
|
|
|
===========================================
|
2006-12-08 18:39:42 +08:00
|
|
|
Fault injection capabilities infrastructure
|
|
|
|
===========================================
|
|
|
|
|
2017-12-23 00:41:21 +08:00
|
|
|
See also drivers/md/md-faulty.c and "every_nth" module option for scsi_debug.
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
Available fault injection capabilities
|
|
|
|
--------------------------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- failslab
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
injects slab allocation failures. (kmalloc(), kmem_cache_alloc(), ...)
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- fail_page_alloc
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
injects page allocation failures. (alloc_pages(), get_free_pages(), ...)
|
|
|
|
|
2020-10-16 11:13:46 +08:00
|
|
|
- fail_usercopy
|
|
|
|
|
|
|
|
injects failures in user memory access functions. (copy_from_user(), get_user(), ...)
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- fail_futex
|
2015-06-30 14:26:02 +08:00
|
|
|
|
|
|
|
injects futex deadlock and uaddr fault errors.
|
|
|
|
|
2021-08-10 02:01:50 +08:00
|
|
|
- fail_sunrpc
|
|
|
|
|
|
|
|
injects kernel RPC client and server failures.
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- fail_make_request
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
injects disk IO errors on devices permitted by setting
|
2006-12-08 18:39:42 +08:00
|
|
|
/sys/block/<device>/make-it-fail or
|
2020-07-01 16:59:44 +08:00
|
|
|
/sys/block/<device>/<partition>/make-it-fail. (submit_bio_noacct())
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- fail_mmc_request
|
2011-08-19 20:52:38 +08:00
|
|
|
|
|
|
|
injects MMC data errors on devices permitted by setting
|
|
|
|
debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- fail_function
|
2018-01-13 01:56:03 +08:00
|
|
|
|
|
|
|
injects error return on specific functions, which are marked by
|
|
|
|
ALLOW_ERROR_INJECTION() macro, by setting debugfs entries
|
|
|
|
under /sys/kernel/debug/fail_function. No boot option supported.
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- NVMe fault injection
|
2018-02-09 02:38:30 +08:00
|
|
|
|
|
|
|
inject NVMe status code and retry flag on devices permitted by setting
|
|
|
|
debugfs entries under /sys/kernel/debug/nvme*/fault_inject. The default
|
|
|
|
status code is NVME_SC_INVALID_OPCODE with no retry. The status code and
|
|
|
|
retry flag can be set via the debugfs.
|
|
|
|
|
2023-03-27 22:37:33 +08:00
|
|
|
- Null test block driver fault injection
|
|
|
|
|
|
|
|
inject IO timeouts by setting config items under
|
|
|
|
/sys/kernel/config/nullb/<disk>/timeout_inject,
|
|
|
|
inject requeue requests by setting config items under
|
|
|
|
/sys/kernel/config/nullb/<disk>/requeue_inject, and
|
|
|
|
inject init_hctx() errors by setting config items under
|
|
|
|
/sys/kernel/config/nullb/<disk>/init_hctx_fault_inject.
|
2018-02-09 02:38:30 +08:00
|
|
|
|
2006-12-08 18:39:42 +08:00
|
|
|
Configure fault-injection capabilities behavior
|
|
|
|
-----------------------------------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
debugfs entries
|
|
|
|
^^^^^^^^^^^^^^^
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
fault-inject-debugfs kernel module provides some debugfs entries for runtime
|
|
|
|
configuration of fault-injection capabilities.
|
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/probability:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
likelihood of failure injection, in percent.
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2006-12-08 18:39:42 +08:00
|
|
|
Format: <percent>
|
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
Note that one-failure-per-hundred is a very high error rate
|
|
|
|
for some testcases. Consider setting probability=100 and configure
|
2009-06-02 14:01:37 +08:00
|
|
|
/sys/kernel/debug/fail*/interval for such testcases.
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/interval:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
specifies the interval between failures, for calls to
|
|
|
|
should_fail() that pass all the other tests.
|
|
|
|
|
|
|
|
Note that if you enable this, by setting interval>1, you will
|
|
|
|
probably want to set probability=100.
|
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/times:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2021-06-03 20:58:41 +08:00
|
|
|
specifies how many times failures may happen at most. A value of -1
|
2022-09-20 01:24:18 +08:00
|
|
|
means "no limit".
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/space:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
specifies an initial resource "budget", decremented by "size"
|
|
|
|
on each call to should_fail(,size). Failure injection is
|
|
|
|
suppressed until "space" reaches zero.
|
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/verbose
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
Format: { 0 | 1 | 2 }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
specifies the verbosity of the messages when failure is
|
|
|
|
injected. '0' means no messages; '1' will print only a single
|
|
|
|
log line per failure; '2' will print a call trace too -- useful
|
|
|
|
to debug the problems revealed by fault injection.
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/task-filter:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
Format: { 'Y' | 'N' }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
A value of 'N' disables filtering by process (default).
|
2006-12-08 18:39:42 +08:00
|
|
|
Any positive value limits failures to only processes indicated by
|
|
|
|
/proc/<pid>/make-it-fail==1.
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- /sys/kernel/debug/fail*/require-start,
|
|
|
|
/sys/kernel/debug/fail*/require-end,
|
|
|
|
/sys/kernel/debug/fail*/reject-start,
|
|
|
|
/sys/kernel/debug/fail*/reject-end:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
specifies the range of virtual addresses tested during
|
|
|
|
stacktrace walking. Failure is injected only if some caller
|
2006-12-08 18:39:48 +08:00
|
|
|
in the walked stacktrace lies within the required range, and
|
|
|
|
none lies within the rejected range.
|
|
|
|
Default required range is [0,ULONG_MAX) (whole of virtual address space).
|
|
|
|
Default rejected range is [0,0).
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail*/stacktrace-depth:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
specifies the maximum stacktrace depth walked during search
|
2006-12-08 18:39:50 +08:00
|
|
|
for a caller within [require-start,require-end) OR
|
|
|
|
[reject-start,reject-end).
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
Format: { 'Y' | 'N' }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2022-04-05 17:54:14 +08:00
|
|
|
default is 'Y', setting it to 'N' will also inject failures into
|
|
|
|
highmem/user allocations (__GFP_HIGHMEM allocations).
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/failslab/ignore-gfp-wait:
|
|
|
|
- /sys/kernel/debug/fail_page_alloc/ignore-gfp-wait:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
Format: { 'Y' | 'N' }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2022-04-05 17:54:14 +08:00
|
|
|
default is 'Y', setting it to 'N' will also inject failures
|
|
|
|
into allocations that can sleep (__GFP_DIRECT_RECLAIM allocations).
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2009-06-02 14:01:37 +08:00
|
|
|
- /sys/kernel/debug/fail_page_alloc/min-order:
|
2007-07-16 14:40:23 +08:00
|
|
|
|
|
|
|
specifies the minimum page allocation order to be injected
|
|
|
|
failures.
|
|
|
|
|
2015-06-30 14:26:02 +08:00
|
|
|
- /sys/kernel/debug/fail_futex/ignore-private:
|
|
|
|
|
|
|
|
Format: { 'Y' | 'N' }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2015-06-30 14:26:02 +08:00
|
|
|
default is 'N', setting it to 'Y' will disable failure injections
|
|
|
|
when dealing with private (address space) futexes.
|
|
|
|
|
2021-08-10 02:01:50 +08:00
|
|
|
- /sys/kernel/debug/fail_sunrpc/ignore-client-disconnect:
|
|
|
|
|
|
|
|
Format: { 'Y' | 'N' }
|
|
|
|
|
|
|
|
default is 'N', setting it to 'Y' will disable disconnect
|
|
|
|
injection on the RPC client.
|
|
|
|
|
|
|
|
- /sys/kernel/debug/fail_sunrpc/ignore-server-disconnect:
|
|
|
|
|
|
|
|
Format: { 'Y' | 'N' }
|
|
|
|
|
|
|
|
default is 'N', setting it to 'Y' will disable disconnect
|
|
|
|
injection on the RPC server.
|
|
|
|
|
2022-07-01 22:37:15 +08:00
|
|
|
- /sys/kernel/debug/fail_sunrpc/ignore-cache-wait:
|
|
|
|
|
|
|
|
Format: { 'Y' | 'N' }
|
|
|
|
|
|
|
|
default is 'N', setting it to 'Y' will disable cache wait
|
|
|
|
injection on the RPC server.
|
|
|
|
|
2018-01-13 01:56:03 +08:00
|
|
|
- /sys/kernel/debug/fail_function/inject:
|
|
|
|
|
|
|
|
Format: { 'function-name' | '!function-name' | '' }
|
2019-06-13 01:52:44 +08:00
|
|
|
|
2018-01-13 01:56:03 +08:00
|
|
|
specifies the target function of error injection by name.
|
|
|
|
If the function name leads '!' prefix, given function is
|
|
|
|
removed from injection list. If nothing specified ('')
|
|
|
|
injection list is cleared.
|
|
|
|
|
|
|
|
- /sys/kernel/debug/fail_function/injectable:
|
|
|
|
|
|
|
|
(read only) shows error injectable functions and what type of
|
|
|
|
error values can be specified. The error type will be one of
|
|
|
|
below;
|
|
|
|
- NULL: retval must be 0.
|
|
|
|
- ERRNO: retval must be -1 to -MAX_ERRNO (-4096).
|
|
|
|
- ERR_NULL: retval must be 0 or -1 to -MAX_ERRNO (-4096).
|
|
|
|
|
2021-06-03 20:58:41 +08:00
|
|
|
- /sys/kernel/debug/fail_function/<function-name>/retval:
|
2018-01-13 01:56:03 +08:00
|
|
|
|
2021-06-03 20:58:41 +08:00
|
|
|
specifies the "error" return value to inject to the given function.
|
|
|
|
This will be created when the user specifies a new injection entry.
|
|
|
|
Note that this file only accepts unsigned values. So, if you want to
|
|
|
|
use a negative errno, you better use 'printf' instead of 'echo', e.g.:
|
|
|
|
$ printf %#x -12 > retval
|
2018-01-13 01:56:03 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
Boot option
|
|
|
|
^^^^^^^^^^^
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
In order to inject faults while debugfs is not available (early boot time),
|
2019-06-13 01:52:44 +08:00
|
|
|
use the boot option::
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
failslab=
|
|
|
|
fail_page_alloc=
|
2020-10-16 11:13:46 +08:00
|
|
|
fail_usercopy=
|
2011-08-19 20:52:38 +08:00
|
|
|
fail_make_request=
|
2015-06-30 14:26:02 +08:00
|
|
|
fail_futex=
|
2011-09-14 05:03:30 +08:00
|
|
|
mmc_core.fail_request=<interval>,<probability>,<space>,<times>
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
proc entries
|
|
|
|
^^^^^^^^^^^^
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- /proc/<pid>/fail-nth,
|
|
|
|
/proc/self/task/<tid>/fail-nth:
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
|
2017-07-15 05:49:52 +08:00
|
|
|
Write to this file of integer N makes N-th call in the task fail.
|
2017-07-15 05:49:54 +08:00
|
|
|
Read from this file returns a integer value. A value of '0' indicates
|
|
|
|
that the fault setup with a previous write to this file was injected.
|
|
|
|
A positive integer N indicates that the fault wasn't yet injected.
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
Note that this file enables all types of faults (slab, futex, etc).
|
|
|
|
This setting takes precedence over all other generic debugfs 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.
|
|
|
|
|
2022-12-12 10:46:54 +08:00
|
|
|
|
|
|
|
Error Injectable Functions
|
|
|
|
--------------------------
|
|
|
|
|
2023-08-15 05:28:22 +08:00
|
|
|
This part is for the kernel developers considering to add a function to
|
2022-12-12 10:46:54 +08:00
|
|
|
ALLOW_ERROR_INJECTION() macro.
|
|
|
|
|
|
|
|
Requirements for the Error Injectable Functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Since the function-level error injection forcibly changes the code path
|
|
|
|
and returns an error even if the input and conditions are proper, this can
|
|
|
|
cause unexpected kernel crash if you allow error injection on the function
|
|
|
|
which is NOT error injectable. Thus, you (and reviewers) must ensure;
|
|
|
|
|
|
|
|
- The function returns an error code if it fails, and the callers must check
|
|
|
|
it correctly (need to recover from it).
|
|
|
|
|
|
|
|
- The function does not execute any code which can change any state before
|
|
|
|
the first error return. The state includes global or local, or input
|
|
|
|
variable. For example, clear output address storage (e.g. `*ret = NULL`),
|
|
|
|
increments/decrements counter, set a flag, preempt/irq disable or get
|
|
|
|
a lock (if those are recovered before returning error, that will be OK.)
|
|
|
|
|
|
|
|
The first requirement is important, and it will result in that the release
|
|
|
|
(free objects) functions are usually harder to inject errors than allocate
|
|
|
|
functions. If errors of such release functions are not correctly handled
|
|
|
|
it will cause a memory leak easily (the caller will confuse that the object
|
|
|
|
has been released or corrupted.)
|
|
|
|
|
|
|
|
The second one is for the caller which expects the function should always
|
|
|
|
does something. Thus if the function error injection skips whole of the
|
|
|
|
function, the expectation is betrayed and causes an unexpected error.
|
|
|
|
|
|
|
|
Type of the Error Injectable Functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Each error injectable functions will have the error type specified by the
|
|
|
|
ALLOW_ERROR_INJECTION() macro. You have to choose it carefully if you add
|
|
|
|
a new error injectable function. If the wrong error type is chosen, the
|
|
|
|
kernel may crash because it may not be able to handle the error.
|
|
|
|
There are 4 types of errors defined in include/asm-generic/error-injection.h
|
|
|
|
|
|
|
|
EI_ETYPE_NULL
|
|
|
|
This function will return `NULL` if it fails. e.g. return an allocateed
|
|
|
|
object address.
|
|
|
|
|
|
|
|
EI_ETYPE_ERRNO
|
|
|
|
This function will return an `-errno` error code if it fails. e.g. return
|
|
|
|
-EINVAL if the input is wrong. This will include the functions which will
|
|
|
|
return an address which encodes `-errno` by ERR_PTR() macro.
|
|
|
|
|
|
|
|
EI_ETYPE_ERRNO_NULL
|
|
|
|
This function will return an `-errno` or `NULL` if it fails. If the caller
|
|
|
|
of this function checks the return value with IS_ERR_OR_NULL() macro, this
|
|
|
|
type will be appropriate.
|
|
|
|
|
|
|
|
EI_ETYPE_TRUE
|
|
|
|
This function will return `true` (non-zero positive value) if it fails.
|
|
|
|
|
|
|
|
If you specifies a wrong type, for example, EI_TYPE_ERRNO for the function
|
|
|
|
which returns an allocated object, it may cause a problem because the returned
|
|
|
|
value is not an object address and the caller can not access to the address.
|
|
|
|
|
|
|
|
|
2006-12-08 18:39:42 +08:00
|
|
|
How to add new fault injection capability
|
|
|
|
-----------------------------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- #include <linux/fault-inject.h>
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- define the fault attributes
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-01-05 07:08:34 +08:00
|
|
|
DECLARE_FAULT_ATTR(name);
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
Please see the definition of struct fault_attr in fault-inject.h
|
|
|
|
for details.
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- provide a way to configure fault attributes
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
- boot option
|
|
|
|
|
|
|
|
If you need to enable the fault injection capability from boot time, you can
|
2006-12-08 18:39:50 +08:00
|
|
|
provide boot option to configure it. There is a helper function for it:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
setup_fault_attr(attr, str);
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
- debugfs entries
|
|
|
|
|
2020-10-16 11:13:46 +08:00
|
|
|
failslab, fail_page_alloc, fail_usercopy, and fail_make_request use this way.
|
2006-12-08 18:39:50 +08:00
|
|
|
Helper functions:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2011-08-04 07:21:01 +08:00
|
|
|
fault_create_debugfs_attr(name, parent, attr);
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
- module parameters
|
|
|
|
|
|
|
|
If the scope of the fault injection capability is limited to a
|
|
|
|
single kernel module, it is better to provide module parameters to
|
|
|
|
configure the fault attributes.
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- add a hook to insert failures
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
Upon should_fail() returning true, client code should inject a failure:
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2006-12-08 18:39:50 +08:00
|
|
|
should_fail(attr, size);
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
Application Examples
|
|
|
|
--------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- Inject slab allocation failures into module init/exit code::
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
#!/bin/bash
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
FAILTYPE=failslab
|
|
|
|
echo Y > /sys/kernel/debug/$FAILTYPE/task-filter
|
|
|
|
echo 10 > /sys/kernel/debug/$FAILTYPE/probability
|
|
|
|
echo 100 > /sys/kernel/debug/$FAILTYPE/interval
|
2022-09-20 01:24:18 +08:00
|
|
|
echo -1 > /sys/kernel/debug/$FAILTYPE/times
|
2019-06-13 01:52:44 +08:00
|
|
|
echo 0 > /sys/kernel/debug/$FAILTYPE/space
|
|
|
|
echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
|
2022-04-05 17:54:14 +08:00
|
|
|
echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
faulty_system()
|
|
|
|
{
|
2007-07-16 14:40:24 +08:00
|
|
|
bash -c "echo 1 > /proc/self/make-it-fail && exec $*"
|
2019-06-13 01:52:44 +08:00
|
|
|
}
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
2007-07-16 14:40:24 +08:00
|
|
|
echo "Usage: $0 modulename [ modulename ... ]"
|
|
|
|
exit 1
|
2019-06-13 01:52:44 +08:00
|
|
|
fi
|
2007-07-16 14:40:24 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
for m in $*
|
|
|
|
do
|
2007-07-16 14:40:24 +08:00
|
|
|
echo inserting $m...
|
|
|
|
faulty_system modprobe $m
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2007-07-16 14:40:24 +08:00
|
|
|
echo removing $m...
|
|
|
|
faulty_system modprobe -r $m
|
2019-06-13 01:52:44 +08:00
|
|
|
done
|
2006-12-08 18:39:42 +08:00
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- Inject page allocation failures only for a specific module::
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
#!/bin/bash
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
FAILTYPE=fail_page_alloc
|
|
|
|
module=$1
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
if [ -z $module ]
|
|
|
|
then
|
2007-07-16 14:40:24 +08:00
|
|
|
echo "Usage: $0 <modulename>"
|
|
|
|
exit 1
|
2019-06-13 01:52:44 +08:00
|
|
|
fi
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
modprobe $module
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
if [ ! -d /sys/module/$module/sections ]
|
|
|
|
then
|
2007-07-16 14:40:24 +08:00
|
|
|
echo Module $module is not loaded
|
|
|
|
exit 1
|
2019-06-13 01:52:44 +08:00
|
|
|
fi
|
2007-07-16 14:40:24 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
cat /sys/module/$module/sections/.text > /sys/kernel/debug/$FAILTYPE/require-start
|
|
|
|
cat /sys/module/$module/sections/.data > /sys/kernel/debug/$FAILTYPE/require-end
|
2007-07-16 14:40:24 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
echo N > /sys/kernel/debug/$FAILTYPE/task-filter
|
|
|
|
echo 10 > /sys/kernel/debug/$FAILTYPE/probability
|
|
|
|
echo 100 > /sys/kernel/debug/$FAILTYPE/interval
|
2022-09-20 01:24:18 +08:00
|
|
|
echo -1 > /sys/kernel/debug/$FAILTYPE/times
|
2019-06-13 01:52:44 +08:00
|
|
|
echo 0 > /sys/kernel/debug/$FAILTYPE/space
|
|
|
|
echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
|
2022-04-05 17:54:14 +08:00
|
|
|
echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
|
|
|
|
echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-highmem
|
2019-06-13 01:52:44 +08:00
|
|
|
echo 10 > /sys/kernel/debug/$FAILTYPE/stacktrace-depth
|
2007-07-16 14:40:24 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT
|
2007-07-16 14:40:24 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
echo "Injecting errors into the module $module... (interrupt to stop)"
|
|
|
|
sleep 1000000
|
2006-12-08 18:39:42 +08:00
|
|
|
|
2018-01-13 01:56:03 +08:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
- Inject open_ctree error while btrfs mount::
|
|
|
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
rm -f testfile.img
|
|
|
|
dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1
|
|
|
|
DEVICE=$(losetup --show -f testfile.img)
|
|
|
|
mkfs.btrfs -f $DEVICE
|
|
|
|
mkdir -p tmpmnt
|
|
|
|
|
|
|
|
FAILTYPE=fail_function
|
|
|
|
FAILFUNC=open_ctree
|
|
|
|
echo $FAILFUNC > /sys/kernel/debug/$FAILTYPE/inject
|
2021-06-03 20:58:41 +08:00
|
|
|
printf %#x -12 > /sys/kernel/debug/$FAILTYPE/$FAILFUNC/retval
|
2019-06-13 01:52:44 +08:00
|
|
|
echo N > /sys/kernel/debug/$FAILTYPE/task-filter
|
|
|
|
echo 100 > /sys/kernel/debug/$FAILTYPE/probability
|
|
|
|
echo 0 > /sys/kernel/debug/$FAILTYPE/interval
|
2022-09-20 01:24:18 +08:00
|
|
|
echo -1 > /sys/kernel/debug/$FAILTYPE/times
|
2019-06-13 01:52:44 +08:00
|
|
|
echo 0 > /sys/kernel/debug/$FAILTYPE/space
|
|
|
|
echo 1 > /sys/kernel/debug/$FAILTYPE/verbose
|
|
|
|
|
|
|
|
mount -t btrfs $DEVICE tmpmnt
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2018-01-13 01:56:03 +08:00
|
|
|
echo "SUCCESS!"
|
2019-06-13 01:52:44 +08:00
|
|
|
else
|
2018-01-13 01:56:03 +08:00
|
|
|
echo "FAILED!"
|
|
|
|
umount tmpmnt
|
2019-06-13 01:52:44 +08:00
|
|
|
fi
|
2018-01-13 01:56:03 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
echo > /sys/kernel/debug/$FAILTYPE/inject
|
2018-01-13 01:56:03 +08:00
|
|
|
|
2019-06-13 01:52:44 +08:00
|
|
|
rmdir tmpmnt
|
|
|
|
losetup -d $DEVICE
|
|
|
|
rm testfile.img
|
2018-01-13 01:56:03 +08:00
|
|
|
|
|
|
|
|
2012-07-31 05:43:20 +08:00
|
|
|
Tool to run command with failslab or fail_page_alloc
|
|
|
|
----------------------------------------------------
|
|
|
|
In order to make it easier to accomplish the tasks mentioned above, we can use
|
|
|
|
tools/testing/fault-injection/failcmd.sh. Please run a command
|
|
|
|
"./tools/testing/fault-injection/failcmd.sh --help" for more information and
|
|
|
|
see the following examples.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
Run a command "make -C tools/testing/selftests/ run_tests" with injecting slab
|
2019-06-13 01:52:44 +08:00
|
|
|
allocation failure::
|
2012-07-31 05:43:20 +08:00
|
|
|
|
|
|
|
# ./tools/testing/fault-injection/failcmd.sh \
|
|
|
|
-- make -C tools/testing/selftests/ run_tests
|
|
|
|
|
|
|
|
Same as above except to specify 100 times failures at most instead of one time
|
2019-06-13 01:52:44 +08:00
|
|
|
at most by default::
|
2012-07-31 05:43:20 +08:00
|
|
|
|
|
|
|
# ./tools/testing/fault-injection/failcmd.sh --times=100 \
|
|
|
|
-- make -C tools/testing/selftests/ run_tests
|
|
|
|
|
|
|
|
Same as above except to inject page allocation failure instead of slab
|
2019-06-13 01:52:44 +08:00
|
|
|
allocation failure::
|
2012-07-31 05:43:20 +08:00
|
|
|
|
|
|
|
# env FAILCMD_TYPE=fail_page_alloc \
|
|
|
|
./tools/testing/fault-injection/failcmd.sh --times=100 \
|
2019-06-13 01:52:44 +08:00
|
|
|
-- make -C tools/testing/selftests/ run_tests
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
|
|
|
|
Systematic faults using fail-nth
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
The following code systematically faults 0-th, 1-st, 2-nd and so on
|
2019-06-13 01:52:44 +08:00
|
|
|
capabilities in the socketpair() system call::
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
int i, err, res, fail_nth, fds[2];
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait");
|
|
|
|
sprintf(buf, "/proc/self/task/%ld/fail-nth", syscall(SYS_gettid));
|
|
|
|
fail_nth = open(buf, O_RDWR);
|
2017-07-15 05:49:52 +08:00
|
|
|
for (i = 1;; i++) {
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
sprintf(buf, "%d", i);
|
|
|
|
write(fail_nth, buf, strlen(buf));
|
|
|
|
res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
|
|
|
|
err = errno;
|
2017-07-15 05:49:54 +08:00
|
|
|
pread(fail_nth, buf, sizeof(buf), 0);
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
if (res == 0) {
|
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
|
|
|
}
|
2017-07-15 05:49:54 +08:00
|
|
|
printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y',
|
|
|
|
res, err);
|
|
|
|
if (atoi(buf))
|
fault-inject: support systematic fault injection
Add /proc/self/task/<current-tid>/fail-nth 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 add a 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
I've made the current interface work with all types of our sandboxes.
For setuid the secret sauce was prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) to
make /proc entries non-root owned. So I am fine with the current
version of the code.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170328130128.101773-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-13 05:34:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
2019-06-13 01:52:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
An example output::
|
|
|
|
|
|
|
|
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
|