Commit 2c739ced authored by Albert van der Linde's avatar Albert van der Linde Committed by Linus Torvalds

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: default avatarAlbert van der Linde <alinde@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Christoph Hellwig <hch@lst.de>
Link: http://lkml.kernel.org/r/20200831171733.955393-1-alinde@google.com
Link: http://lkml.kernel.org/r/20200831171733.955393-2-alinde@google.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d9bc85de
...@@ -1343,6 +1343,7 @@ ...@@ -1343,6 +1343,7 @@
current integrity status. current integrity status.
failslab= failslab=
fail_usercopy=
fail_page_alloc= fail_page_alloc=
fail_make_request=[KNL] fail_make_request=[KNL]
General fault injection mechanism. General fault injection mechanism.
......
...@@ -16,6 +16,10 @@ Available fault injection capabilities ...@@ -16,6 +16,10 @@ Available fault injection capabilities
injects page allocation failures. (alloc_pages(), get_free_pages(), ...) injects page allocation failures. (alloc_pages(), get_free_pages(), ...)
- fail_usercopy
injects failures in user memory access functions. (copy_from_user(), get_user(), ...)
- fail_futex - fail_futex
injects futex deadlock and uaddr fault errors. injects futex deadlock and uaddr fault errors.
...@@ -177,6 +181,7 @@ use the boot option:: ...@@ -177,6 +181,7 @@ use the boot option::
failslab= failslab=
fail_page_alloc= fail_page_alloc=
fail_usercopy=
fail_make_request= fail_make_request=
fail_futex= fail_futex=
mmc_core.fail_request=<interval>,<probability>,<space>,<times> mmc_core.fail_request=<interval>,<probability>,<space>,<times>
...@@ -222,7 +227,7 @@ How to add new fault injection capability ...@@ -222,7 +227,7 @@ How to add new fault injection capability
- debugfs entries - debugfs entries
failslab, fail_page_alloc, and fail_make_request use this way. failslab, fail_page_alloc, fail_usercopy, and fail_make_request use this way.
Helper functions: Helper functions:
fault_create_debugfs_attr(name, parent, attr); fault_create_debugfs_attr(name, parent, attr);
......
/* 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__ */
...@@ -1768,6 +1768,13 @@ config FAIL_PAGE_ALLOC ...@@ -1768,6 +1768,13 @@ config FAIL_PAGE_ALLOC
help help
Provide fault-injection capability for alloc_pages(). Provide fault-injection capability for alloc_pages().
config FAULT_INJECTION_USERCOPY
bool "Fault injection capability for usercopy functions"
depends on FAULT_INJECTION
help
Provides fault-injection capability to inject failures
in usercopy functions (copy_from_user(), get_user(), ...).
config FAIL_MAKE_REQUEST config FAIL_MAKE_REQUEST
bool "Fault-injection capability for disk IO" bool "Fault-injection capability for disk IO"
depends on FAULT_INJECTION && BLOCK depends on FAULT_INJECTION && BLOCK
......
...@@ -210,6 +210,7 @@ obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o ...@@ -210,6 +210,7 @@ obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o
obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
obj-$(CONFIG_FAULT_INJECTION_USERCOPY) += fault-inject-usercopy.o
obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o
obj-$(CONFIG_PM_NOTIFIER_ERROR_INJECT) += pm-notifier-error-inject.o obj-$(CONFIG_PM_NOTIFIER_ERROR_INJECT) += pm-notifier-error-inject.o
obj-$(CONFIG_NETDEV_NOTIFIER_ERROR_INJECT) += netdev-notifier-error-inject.o obj-$(CONFIG_NETDEV_NOTIFIER_ERROR_INJECT) += netdev-notifier-error-inject.o
......
// 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);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment