hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/include/asm-generic/uaccess.h
....@@ -9,8 +9,94 @@
99 */
1010 #include <linux/string.h>
1111
12
-#include <asm/segment.h>
12
+#ifdef CONFIG_UACCESS_MEMCPY
13
+#include <asm/unaligned.h>
1314
15
+static __always_inline int
16
+__get_user_fn(size_t size, const void __user *from, void *to)
17
+{
18
+ BUILD_BUG_ON(!__builtin_constant_p(size));
19
+
20
+ switch (size) {
21
+ case 1:
22
+ *(u8 *)to = get_unaligned((u8 __force *)from);
23
+ return 0;
24
+ case 2:
25
+ *(u16 *)to = get_unaligned((u16 __force *)from);
26
+ return 0;
27
+ case 4:
28
+ *(u32 *)to = get_unaligned((u32 __force *)from);
29
+ return 0;
30
+ case 8:
31
+ *(u64 *)to = get_unaligned((u64 __force *)from);
32
+ return 0;
33
+ default:
34
+ BUILD_BUG();
35
+ return 0;
36
+ }
37
+
38
+}
39
+#define __get_user_fn(sz, u, k) __get_user_fn(sz, u, k)
40
+
41
+static __always_inline int
42
+__put_user_fn(size_t size, void __user *to, void *from)
43
+{
44
+ BUILD_BUG_ON(!__builtin_constant_p(size));
45
+
46
+ switch (size) {
47
+ case 1:
48
+ put_unaligned(*(u8 *)from, (u8 __force *)to);
49
+ return 0;
50
+ case 2:
51
+ put_unaligned(*(u16 *)from, (u16 __force *)to);
52
+ return 0;
53
+ case 4:
54
+ put_unaligned(*(u32 *)from, (u32 __force *)to);
55
+ return 0;
56
+ case 8:
57
+ put_unaligned(*(u64 *)from, (u64 __force *)to);
58
+ return 0;
59
+ default:
60
+ BUILD_BUG();
61
+ return 0;
62
+ }
63
+}
64
+#define __put_user_fn(sz, u, k) __put_user_fn(sz, u, k)
65
+
66
+#define __get_kernel_nofault(dst, src, type, err_label) \
67
+do { \
68
+ *((type *)dst) = get_unaligned((type *)(src)); \
69
+ if (0) /* make sure the label looks used to the compiler */ \
70
+ goto err_label; \
71
+} while (0)
72
+
73
+#define __put_kernel_nofault(dst, src, type, err_label) \
74
+do { \
75
+ put_unaligned(*((type *)src), (type *)(dst)); \
76
+ if (0) /* make sure the label looks used to the compiler */ \
77
+ goto err_label; \
78
+} while (0)
79
+
80
+#define HAVE_GET_KERNEL_NOFAULT 1
81
+
82
+static inline __must_check unsigned long
83
+raw_copy_from_user(void *to, const void __user * from, unsigned long n)
84
+{
85
+ memcpy(to, (const void __force *)from, n);
86
+ return 0;
87
+}
88
+
89
+static inline __must_check unsigned long
90
+raw_copy_to_user(void __user *to, const void *from, unsigned long n)
91
+{
92
+ memcpy((void __force *)to, from, n);
93
+ return 0;
94
+}
95
+#define INLINE_COPY_FROM_USER
96
+#define INLINE_COPY_TO_USER
97
+#endif /* CONFIG_UACCESS_MEMCPY */
98
+
99
+#ifdef CONFIG_SET_FS
14100 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
15101
16102 #ifndef KERNEL_DS
....@@ -22,7 +108,6 @@
22108 #endif
23109
24110 #ifndef get_fs
25
-#define get_ds() (KERNEL_DS)
26111 #define get_fs() (current_thread_info()->addr_limit)
27112
28113 static inline void set_fs(mm_segment_t fs)
....@@ -31,11 +116,12 @@
31116 }
32117 #endif
33118
34
-#ifndef segment_eq
35
-#define segment_eq(a, b) ((a).seg == (b).seg)
119
+#ifndef uaccess_kernel
120
+#define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg)
36121 #endif
122
+#endif /* CONFIG_SET_FS */
37123
38
-#define access_ok(type, addr, size) __access_ok((unsigned long)(addr),(size))
124
+#define access_ok(addr, size) __access_ok((unsigned long)(addr),(size))
39125
40126 /*
41127 * The architecture should really override this if possible, at least
....@@ -78,7 +164,7 @@
78164 ({ \
79165 void __user *__p = (ptr); \
80166 might_fault(); \
81
- access_ok(VERIFY_WRITE, __p, sizeof(*ptr)) ? \
167
+ access_ok(__p, sizeof(*ptr)) ? \
82168 __put_user((x), ((__typeof__(*(ptr)) __user *)__p)) : \
83169 -EFAULT; \
84170 })
....@@ -140,7 +226,7 @@
140226 ({ \
141227 const void __user *__p = (ptr); \
142228 might_fault(); \
143
- access_ok(VERIFY_READ, __p, sizeof(*ptr)) ? \
229
+ access_ok(__p, sizeof(*ptr)) ? \
144230 __get_user((x), (__typeof__(*(ptr)) __user *)__p) :\
145231 ((x) = (__typeof__(*(ptr)))0,-EFAULT); \
146232 })
....@@ -175,7 +261,7 @@
175261 static inline long
176262 strncpy_from_user(char *dst, const char __user *src, long count)
177263 {
178
- if (!access_ok(VERIFY_READ, src, 1))
264
+ if (!access_ok(src, 1))
179265 return -EFAULT;
180266 return __strncpy_from_user(dst, src, count);
181267 }
....@@ -196,7 +282,7 @@
196282 */
197283 static inline long strnlen_user(const char __user *src, long n)
198284 {
199
- if (!access_ok(VERIFY_READ, src, 1))
285
+ if (!access_ok(src, 1))
200286 return 0;
201287 return __strnlen_user(src, n);
202288 }
....@@ -217,7 +303,7 @@
217303 clear_user(void __user *to, unsigned long n)
218304 {
219305 might_fault();
220
- if (!access_ok(VERIFY_WRITE, to, n))
306
+ if (!access_ok(to, n))
221307 return n;
222308
223309 return __clear_user(to, n);