1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_H_
3 #define _ASM_POWERPC_KUP_H_
7 #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE)
9 * For prevent_user_access() only.
10 * Use the current saved situation instead of the to/from/size params.
13 #define KUAP_CURRENT_READ 4
14 #define KUAP_CURRENT_WRITE 8
15 #define KUAP_CURRENT (KUAP_CURRENT_READ | KUAP_CURRENT_WRITE)
17 #ifdef CONFIG_PPC_BOOK3S_64
18 #include <asm/book3s/64/kup.h>
22 #include <asm/nohash/32/kup-8xx.h>
25 #ifdef CONFIG_PPC_BOOK3S_32
26 #include <asm/book3s/32/kup.h>
30 #ifndef CONFIG_PPC_KUAP
31 .macro kuap_save_and_lock sp
, thread
, gpr1
, gpr2
, gpr3
34 .macro kuap_restore sp
, current
, gpr1
, gpr2
, gpr3
37 .macro kuap_check current
, gpr
40 .macro kuap_check_amr gpr1
, gpr2
45 #else /* !__ASSEMBLY__ */
47 extern bool disable_kuep
;
48 extern bool disable_kuap
;
50 #include <linux/pgtable.h>
52 #ifdef CONFIG_PPC_KUEP
53 void setup_kuep(bool disabled
);
55 static inline void setup_kuep(bool disabled
) { }
56 #endif /* CONFIG_PPC_KUEP */
58 #ifdef CONFIG_PPC_KUAP
59 void setup_kuap(bool disabled
);
61 static inline void setup_kuap(bool disabled
) { }
64 bad_kuap_fault(struct pt_regs
*regs
, unsigned long address
, bool is_write
)
69 static inline void kuap_check_amr(void) { }
72 * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
73 * the L1D cache after user accesses. Only include the empty stubs for other
76 #ifndef CONFIG_PPC_BOOK3S_64
77 static inline void allow_user_access(void __user
*to
, const void __user
*from
,
78 unsigned long size
, unsigned long dir
) { }
79 static inline void prevent_user_access(void __user
*to
, const void __user
*from
,
80 unsigned long size
, unsigned long dir
) { }
81 static inline unsigned long prevent_user_access_return(void) { return 0UL; }
82 static inline void restore_user_access(unsigned long flags
) { }
83 #endif /* CONFIG_PPC_BOOK3S_64 */
84 #endif /* CONFIG_PPC_KUAP */
86 static __always_inline
void setup_kup(void)
88 setup_kuep(disable_kuep
);
89 setup_kuap(disable_kuap
);
92 static inline void allow_read_from_user(const void __user
*from
, unsigned long size
)
94 allow_user_access(NULL
, from
, size
, KUAP_READ
);
97 static inline void allow_write_to_user(void __user
*to
, unsigned long size
)
99 allow_user_access(to
, NULL
, size
, KUAP_WRITE
);
102 static inline void allow_read_write_user(void __user
*to
, const void __user
*from
,
105 allow_user_access(to
, from
, size
, KUAP_READ_WRITE
);
108 static inline void prevent_read_from_user(const void __user
*from
, unsigned long size
)
110 prevent_user_access(NULL
, from
, size
, KUAP_READ
);
113 static inline void prevent_write_to_user(void __user
*to
, unsigned long size
)
115 prevent_user_access(to
, NULL
, size
, KUAP_WRITE
);
118 static inline void prevent_read_write_user(void __user
*to
, const void __user
*from
,
121 prevent_user_access(to
, from
, size
, KUAP_READ_WRITE
);
124 static inline void prevent_current_access_user(void)
126 prevent_user_access(NULL
, NULL
, ~0UL, KUAP_CURRENT
);
129 static inline void prevent_current_read_from_user(void)
131 prevent_user_access(NULL
, NULL
, ~0UL, KUAP_CURRENT_READ
);
134 static inline void prevent_current_write_to_user(void)
136 prevent_user_access(NULL
, NULL
, ~0UL, KUAP_CURRENT_WRITE
);
139 #endif /* !__ASSEMBLY__ */
141 #endif /* _ASM_POWERPC_KUAP_H_ */