[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250712192202.707192-6-gatlin.newhouse@gmail.com>
Date: Sat, 12 Jul 2025 19:21:50 +0000
From: Gatlin Newhouse <gatlin.newhouse@...il.com>
To: linux-hardening@...r.kernel.org
Cc: Gatlin Newhouse <gatlin.newhouse@...il.com>
Subject: [RFC v1 05/17] uaccess: add non-caching copy_from_user functions
---
include/linux/uaccess.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 7c06f4795670..d6d80bb9e0fa 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -186,6 +186,26 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
extern __must_check unsigned long
_copy_from_user(void *, const void __user *, unsigned long);
+#ifdef CONFIG_SAFEFETCH
+static inline __must_check unsigned long
+_copy_from_user_no_dfcache(void *to, const void __user *from, unsigned long n)
+{
+ unsigned long res = n;
+
+ might_fault();
+ if (!should_fail_usercopy() && likely(access_ok(from, n))) {
+ instrument_copy_from_user_before(to, from, n);
+ res = raw_copy_from_user_no_dfcache(to, from, n);
+ instrument_copy_from_user_after(to, from, n, res);
+ }
+ if (unlikely(res))
+ memset(to + (n - res), 0, res);
+ return res;
+}
+extern __must_check unsigned long
+_copy_from_user_no_dfcache(void *, const void __user *, unsigned long);
+#endif
+
static inline __must_check unsigned long
_inline_copy_to_user(void __user *to, const void *from, unsigned long n)
{
@@ -213,6 +233,16 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
#endif
}
+#ifdef CONFIG_SAFEFETCH
+static __always_inline unsigned long __must_check
+copy_from_user_no_dfcache(void *to, const void __user *from, unsigned long n)
+{
+ if (likely(check_copy_size(to, n, false)))
+ n = _copy_from_user_no_dfcache(to, from, n);
+ return n;
+}
+#endif
+
static __always_inline unsigned long __must_check
copy_to_user(void __user *to, const void *from, unsigned long n)
{
--
2.25.1
Powered by blists - more mailing lists