summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorMel Gorman <mgorman@techsingularity.net>2025-01-24 01:11:14 +0300
committerKees Cook <kees@kernel.org>2025-02-28 22:51:31 +0300
commit496d2d23886436f7c651bf4c14950eb002815c61 (patch)
tree523dfc03bdca78d94eb22f1b93e29d6f34b48f28 /include/linux
parentd2132f453e3308adc82ab7c101bd5220a9a34167 (diff)
downloadlinux-496d2d23886436f7c651bf4c14950eb002815c61.tar.xz
mm: security: Check early if HARDENED_USERCOPY is enabled
HARDENED_USERCOPY is checked within a function so even if disabled, the function overhead still exists. Move the static check inline. This is at best a micro-optimisation and any difference in performance was within noise but it is relatively consistent with the init_on_* implementations. Suggested-by: Kees Cook <kees@kernel.org> Signed-off-by: Mel Gorman <mgorman@techsingularity.net> Link: https://lore.kernel.org/r/20250123221115.19722-4-mgorman@techsingularity.net Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/ucopysize.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/linux/ucopysize.h b/include/linux/ucopysize.h
index b3e1b875d565..41c2d9720466 100644
--- a/include/linux/ucopysize.h
+++ b/include/linux/ucopysize.h
@@ -6,14 +6,21 @@
#include <linux/bug.h>
#ifdef CONFIG_HARDENED_USERCOPY
+#include <linux/jump_label.h>
extern void __check_object_size(const void *ptr, unsigned long n,
bool to_user);
+DECLARE_STATIC_KEY_MAYBE(CONFIG_HARDENED_USERCOPY_DEFAULT_ON,
+ validate_usercopy_range);
+
static __always_inline void check_object_size(const void *ptr, unsigned long n,
bool to_user)
{
- if (!__builtin_constant_p(n))
+ if (!__builtin_constant_p(n) &&
+ static_branch_maybe(CONFIG_HARDENED_USERCOPY_DEFAULT_ON,
+ &validate_usercopy_range)) {
__check_object_size(ptr, n, to_user);
+ }
}
#else
static inline void check_object_size(const void *ptr, unsigned long n,