forked from raspberrypi/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib, include/linux: add usercopy failure capability
Patch series "add fault injection to user memory access", v3. The goal of this series is to improve testing of fault-tolerance in usages of user memory access functions, by adding support for fault injection. syzkaller/syzbot are using the existing fault injection modes and will use this particular feature also. The first patch adds failure injection capability for usercopy functions. The second changes usercopy functions to use this new failure capability (copy_from_user, ...). The third patch adds get/put/clear_user failures to x86. This patch (of 3): Add a failure injection capability to improve testing of fault-tolerance in usages of user memory access functions. Add CONFIG_FAULT_INJECTION_USERCOPY to enable faults in usercopy functions. The should_fail_usercopy function is to be called by these functions (copy_from_user, get_user, ...) in order to fail or not. Signed-off-by: Albert van der Linde <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Akinobu Mita <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Al Viro <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Marco Elver <[email protected]> Cc: Christoph Hellwig <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
1 parent
d9bc85d
commit 2c739ce
Showing
6 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef __LINUX_FAULT_INJECT_USERCOPY_H__ | ||
#define __LINUX_FAULT_INJECT_USERCOPY_H__ | ||
|
||
/* | ||
* This header provides a wrapper for injecting failures to user space memory | ||
* access functions. | ||
*/ | ||
|
||
#include <linux/types.h> | ||
|
||
#ifdef CONFIG_FAULT_INJECTION_USERCOPY | ||
|
||
bool should_fail_usercopy(void); | ||
|
||
#else | ||
|
||
static inline bool should_fail_usercopy(void) { return false; } | ||
|
||
#endif /* CONFIG_FAULT_INJECTION_USERCOPY */ | ||
|
||
#endif /* __LINUX_FAULT_INJECT_USERCOPY_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <linux/fault-inject.h> | ||
#include <linux/fault-inject-usercopy.h> | ||
|
||
static struct { | ||
struct fault_attr attr; | ||
} fail_usercopy = { | ||
.attr = FAULT_ATTR_INITIALIZER, | ||
}; | ||
|
||
static int __init setup_fail_usercopy(char *str) | ||
{ | ||
return setup_fault_attr(&fail_usercopy.attr, str); | ||
} | ||
__setup("fail_usercopy=", setup_fail_usercopy); | ||
|
||
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | ||
|
||
static int __init fail_usercopy_debugfs(void) | ||
{ | ||
struct dentry *dir; | ||
|
||
dir = fault_create_debugfs_attr("fail_usercopy", NULL, | ||
&fail_usercopy.attr); | ||
if (IS_ERR(dir)) | ||
return PTR_ERR(dir); | ||
|
||
return 0; | ||
} | ||
|
||
late_initcall(fail_usercopy_debugfs); | ||
|
||
#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ | ||
|
||
bool should_fail_usercopy(void) | ||
{ | ||
return should_fail(&fail_usercopy.attr, 1); | ||
} | ||
EXPORT_SYMBOL_GPL(should_fail_usercopy); |