aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fault-inject.c
diff options
context:
space:
mode:
authorAkinobu Mita <[email protected]>2017-07-14 21:49:57 +0000
committerLinus Torvalds <[email protected]>2017-07-14 22:05:13 +0000
commit1203c8e6fb0aa1e9c39d2323607a74c3adc34fd8 (patch)
tree67fc0c8911aec1b7c4bfdfc90305c2ff72b081a0 /lib/fault-inject.c
parentfault-inject: make fail-nth read/write interface symmetric (diff)
downloadkernel-1203c8e6fb0aa1e9c39d2323607a74c3adc34fd8.tar.gz
kernel-1203c8e6fb0aa1e9c39d2323607a74c3adc34fd8.zip
fault-inject: simplify access check for fail-nth
The fail-nth file is created with 0666 and the access is permitted if and only if the task is current. This file is owned by the currnet user. So we can create it with 0644 and allow the owner to write it. This enables to watch the status of task->fail_nth from another processes. [[email protected]: don't convert unsigned type value as signed int] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: avoid unwanted data race to task->fail_nth] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Akinobu Mita <[email protected]> Acked-by: Dmitry Vyukov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'lib/fault-inject.c')
-rw-r--r--lib/fault-inject.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 09ac73c177fd..7d315fdb9f13 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -107,9 +107,12 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
bool should_fail(struct fault_attr *attr, ssize_t size)
{
- if (in_task() && current->fail_nth) {
- if (--current->fail_nth == 0)
+ if (in_task()) {
+ unsigned int fail_nth = READ_ONCE(current->fail_nth);
+
+ if (fail_nth && !WRITE_ONCE(current->fail_nth, fail_nth - 1))
goto fail;
+
return false;
}