~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/include/asm/kup.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _ASM_POWERPC_KUP_H_
  3 #define _ASM_POWERPC_KUP_H_
  4 
  5 #define KUAP_READ       1
  6 #define KUAP_WRITE      2
  7 #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE)
  8 
  9 #ifndef __ASSEMBLY__
 10 #include <linux/types.h>
 11 
 12 static __always_inline bool kuap_is_disabled(void);
 13 #endif
 14 
 15 #ifdef CONFIG_PPC_BOOK3S_64
 16 #include <asm/book3s/64/kup.h>
 17 #endif
 18 
 19 #ifdef CONFIG_PPC_8xx
 20 #include <asm/nohash/32/kup-8xx.h>
 21 #endif
 22 
 23 #ifdef CONFIG_BOOKE
 24 #include <asm/nohash/kup-booke.h>
 25 #endif
 26 
 27 #ifdef CONFIG_PPC_BOOK3S_32
 28 #include <asm/book3s/32/kup.h>
 29 #endif
 30 
 31 #ifdef __ASSEMBLY__
 32 #ifndef CONFIG_PPC_KUAP
 33 .macro kuap_check_amr   gpr1, gpr2
 34 .endm
 35 
 36 #endif
 37 
 38 #else /* !__ASSEMBLY__ */
 39 
 40 extern bool disable_kuep;
 41 extern bool disable_kuap;
 42 
 43 #include <linux/pgtable.h>
 44 
 45 void setup_kup(void);
 46 void setup_kuep(bool disabled);
 47 
 48 #ifdef CONFIG_PPC_KUAP
 49 void setup_kuap(bool disabled);
 50 
 51 static __always_inline bool kuap_is_disabled(void)
 52 {
 53         return !mmu_has_feature(MMU_FTR_KUAP);
 54 }
 55 #else
 56 static inline void setup_kuap(bool disabled) { }
 57 
 58 static __always_inline bool kuap_is_disabled(void) { return true; }
 59 
 60 static __always_inline bool
 61 __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
 62 {
 63         return false;
 64 }
 65 
 66 static __always_inline void kuap_user_restore(struct pt_regs *regs) { }
 67 static __always_inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { }
 68 
 69 /*
 70  * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
 71  * the L1D cache after user accesses. Only include the empty stubs for other
 72  * platforms.
 73  */
 74 #ifndef CONFIG_PPC_BOOK3S_64
 75 static __always_inline void allow_user_access(void __user *to, const void __user *from,
 76                                               unsigned long size, unsigned long dir) { }
 77 static __always_inline void prevent_user_access(unsigned long dir) { }
 78 static __always_inline unsigned long prevent_user_access_return(void) { return 0UL; }
 79 static __always_inline void restore_user_access(unsigned long flags) { }
 80 #endif /* CONFIG_PPC_BOOK3S_64 */
 81 #endif /* CONFIG_PPC_KUAP */
 82 
 83 static __always_inline bool
 84 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
 85 {
 86         if (kuap_is_disabled())
 87                 return false;
 88 
 89         return __bad_kuap_fault(regs, address, is_write);
 90 }
 91 
 92 static __always_inline void kuap_lock(void)
 93 {
 94 #ifdef __kuap_lock
 95         if (kuap_is_disabled())
 96                 return;
 97 
 98         __kuap_lock();
 99 #endif
100 }
101 
102 static __always_inline void kuap_save_and_lock(struct pt_regs *regs)
103 {
104 #ifdef __kuap_save_and_lock
105         if (kuap_is_disabled())
106                 return;
107 
108         __kuap_save_and_lock(regs);
109 #endif
110 }
111 
112 static __always_inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long amr)
113 {
114         if (kuap_is_disabled())
115                 return;
116 
117         __kuap_kernel_restore(regs, amr);
118 }
119 
120 static __always_inline unsigned long kuap_get_and_assert_locked(void)
121 {
122 #ifdef __kuap_get_and_assert_locked
123         if (!kuap_is_disabled())
124                 return __kuap_get_and_assert_locked();
125 #endif
126         return 0;
127 }
128 
129 static __always_inline void kuap_assert_locked(void)
130 {
131         if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG))
132                 kuap_get_and_assert_locked();
133 }
134 
135 static __always_inline void allow_read_from_user(const void __user *from, unsigned long size)
136 {
137         barrier_nospec();
138         allow_user_access(NULL, from, size, KUAP_READ);
139 }
140 
141 static __always_inline void allow_write_to_user(void __user *to, unsigned long size)
142 {
143         allow_user_access(to, NULL, size, KUAP_WRITE);
144 }
145 
146 static __always_inline void allow_read_write_user(void __user *to, const void __user *from,
147                                                   unsigned long size)
148 {
149         barrier_nospec();
150         allow_user_access(to, from, size, KUAP_READ_WRITE);
151 }
152 
153 static __always_inline void prevent_read_from_user(const void __user *from, unsigned long size)
154 {
155         prevent_user_access(KUAP_READ);
156 }
157 
158 static __always_inline void prevent_write_to_user(void __user *to, unsigned long size)
159 {
160         prevent_user_access(KUAP_WRITE);
161 }
162 
163 static __always_inline void prevent_read_write_user(void __user *to, const void __user *from,
164                                                     unsigned long size)
165 {
166         prevent_user_access(KUAP_READ_WRITE);
167 }
168 
169 static __always_inline void prevent_current_access_user(void)
170 {
171         prevent_user_access(KUAP_READ_WRITE);
172 }
173 
174 static __always_inline void prevent_current_read_from_user(void)
175 {
176         prevent_user_access(KUAP_READ);
177 }
178 
179 static __always_inline void prevent_current_write_to_user(void)
180 {
181         prevent_user_access(KUAP_WRITE);
182 }
183 
184 #endif /* !__ASSEMBLY__ */
185 
186 #endif /* _ASM_POWERPC_KUAP_H_ */
187 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php