]>
Commit | Line | Data |
---|---|---|
69795cab CL |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _ASM_POWERPC_KUP_H_ | |
3 | #define _ASM_POWERPC_KUP_H_ | |
4 | ||
1d8f739b CL |
5 | #define KUAP_READ 1 |
6 | #define KUAP_WRITE 2 | |
7 | #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE) | |
bedb4dbe CL |
8 | /* |
9 | * For prevent_user_access() only. | |
10 | * Use the current saved situation instead of the to/from/size params. | |
11 | * Used on book3s/32 | |
12 | */ | |
4fe5cda9 CL |
13 | #define KUAP_CURRENT_READ 4 |
14 | #define KUAP_CURRENT_WRITE 8 | |
15 | #define KUAP_CURRENT (KUAP_CURRENT_READ | KUAP_CURRENT_WRITE) | |
1d8f739b | 16 | |
890274c2 ME |
17 | #ifdef CONFIG_PPC64 |
18 | #include <asm/book3s/64/kup-radix.h> | |
19 | #endif | |
2679f9bd CL |
20 | #ifdef CONFIG_PPC_8xx |
21 | #include <asm/nohash/32/kup-8xx.h> | |
22 | #endif | |
31ed2b13 CL |
23 | #ifdef CONFIG_PPC_BOOK3S_32 |
24 | #include <asm/book3s/32/kup.h> | |
25 | #endif | |
890274c2 | 26 | |
e2fb9f54 CL |
27 | #ifdef __ASSEMBLY__ |
28 | #ifndef CONFIG_PPC_KUAP | |
29 | .macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3 | |
30 | .endm | |
31 | ||
32 | .macro kuap_restore sp, current, gpr1, gpr2, gpr3 | |
33 | .endm | |
34 | ||
35 | .macro kuap_check current, gpr | |
36 | .endm | |
37 | ||
38 | #endif | |
39 | ||
40 | #else /* !__ASSEMBLY__ */ | |
69795cab | 41 | |
ca5999fd | 42 | #include <linux/pgtable.h> |
de78a9c4 | 43 | |
69795cab CL |
44 | void setup_kup(void); |
45 | ||
0fb1c25a CL |
46 | #ifdef CONFIG_PPC_KUEP |
47 | void setup_kuep(bool disabled); | |
48 | #else | |
49 | static inline void setup_kuep(bool disabled) { } | |
50 | #endif /* CONFIG_PPC_KUEP */ | |
51 | ||
de78a9c4 CL |
52 | #ifdef CONFIG_PPC_KUAP |
53 | void setup_kuap(bool disabled); | |
54 | #else | |
55 | static inline void setup_kuap(bool disabled) { } | |
56 | static inline void allow_user_access(void __user *to, const void __user *from, | |
1d8f739b | 57 | unsigned long size, unsigned long dir) { } |
de78a9c4 | 58 | static inline void prevent_user_access(void __user *to, const void __user *from, |
1d8f739b | 59 | unsigned long size, unsigned long dir) { } |
3d7dfd63 CL |
60 | static inline unsigned long prevent_user_access_return(void) { return 0UL; } |
61 | static inline void restore_user_access(unsigned long flags) { } | |
6ec20aa2 CL |
62 | static inline bool |
63 | bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) | |
64 | { | |
65 | return false; | |
66 | } | |
de78a9c4 CL |
67 | #endif /* CONFIG_PPC_KUAP */ |
68 | ||
69 | static inline void allow_read_from_user(const void __user *from, unsigned long size) | |
70 | { | |
1d8f739b | 71 | allow_user_access(NULL, from, size, KUAP_READ); |
de78a9c4 CL |
72 | } |
73 | ||
74 | static inline void allow_write_to_user(void __user *to, unsigned long size) | |
75 | { | |
1d8f739b CL |
76 | allow_user_access(to, NULL, size, KUAP_WRITE); |
77 | } | |
78 | ||
79 | static inline void allow_read_write_user(void __user *to, const void __user *from, | |
80 | unsigned long size) | |
81 | { | |
82 | allow_user_access(to, from, size, KUAP_READ_WRITE); | |
de78a9c4 CL |
83 | } |
84 | ||
85 | static inline void prevent_read_from_user(const void __user *from, unsigned long size) | |
86 | { | |
1d8f739b | 87 | prevent_user_access(NULL, from, size, KUAP_READ); |
de78a9c4 CL |
88 | } |
89 | ||
90 | static inline void prevent_write_to_user(void __user *to, unsigned long size) | |
91 | { | |
1d8f739b CL |
92 | prevent_user_access(to, NULL, size, KUAP_WRITE); |
93 | } | |
94 | ||
95 | static inline void prevent_read_write_user(void __user *to, const void __user *from, | |
96 | unsigned long size) | |
97 | { | |
98 | prevent_user_access(to, from, size, KUAP_READ_WRITE); | |
de78a9c4 CL |
99 | } |
100 | ||
bedb4dbe CL |
101 | static inline void prevent_current_access_user(void) |
102 | { | |
103 | prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT); | |
104 | } | |
105 | ||
4fe5cda9 CL |
106 | static inline void prevent_current_read_from_user(void) |
107 | { | |
108 | prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_READ); | |
109 | } | |
110 | ||
111 | static inline void prevent_current_write_to_user(void) | |
112 | { | |
113 | prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_WRITE); | |
114 | } | |
115 | ||
69795cab CL |
116 | #endif /* !__ASSEMBLY__ */ |
117 | ||
1d8f739b | 118 | #endif /* _ASM_POWERPC_KUAP_H_ */ |