kup.h 2.5 KB
Newer Older
1 2 3 4
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_POWERPC_KUP_H_
#define _ASM_POWERPC_KUP_H_

5 6 7
#define KUAP_READ	1
#define KUAP_WRITE	2
#define KUAP_READ_WRITE	(KUAP_READ | KUAP_WRITE)
8 9 10 11 12 13
/*
 * For prevent_user_access() only.
 * Use the current saved situation instead of the to/from/size params.
 * Used on book3s/32
 */
#define KUAP_CURRENT	4
14

15 16 17
#ifdef CONFIG_PPC64
#include <asm/book3s/64/kup-radix.h>
#endif
18 19 20
#ifdef CONFIG_PPC_8xx
#include <asm/nohash/32/kup-8xx.h>
#endif
21 22 23
#ifdef CONFIG_PPC_BOOK3S_32
#include <asm/book3s/32/kup.h>
#endif
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38
#ifdef __ASSEMBLY__
#ifndef CONFIG_PPC_KUAP
.macro kuap_save_and_lock	sp, thread, gpr1, gpr2, gpr3
.endm

.macro kuap_restore	sp, current, gpr1, gpr2, gpr3
.endm

.macro kuap_check	current, gpr
.endm

#endif

#else /* !__ASSEMBLY__ */
39

40 41
#include <asm/pgtable.h>

42 43
void setup_kup(void);

44 45 46 47 48 49
#ifdef CONFIG_PPC_KUEP
void setup_kuep(bool disabled);
#else
static inline void setup_kuep(bool disabled) { }
#endif /* CONFIG_PPC_KUEP */

50 51 52 53 54
#ifdef CONFIG_PPC_KUAP
void setup_kuap(bool disabled);
#else
static inline void setup_kuap(bool disabled) { }
static inline void allow_user_access(void __user *to, const void __user *from,
55
				     unsigned long size, unsigned long dir) { }
56
static inline void prevent_user_access(void __user *to, const void __user *from,
57
				       unsigned long size, unsigned long dir) { }
58 59 60 61 62
static inline bool
bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
{
	return false;
}
63 64 65 66
#endif /* CONFIG_PPC_KUAP */

static inline void allow_read_from_user(const void __user *from, unsigned long size)
{
67
	allow_user_access(NULL, from, size, KUAP_READ);
68 69 70 71
}

static inline void allow_write_to_user(void __user *to, unsigned long size)
{
72 73 74 75 76 77 78
	allow_user_access(to, NULL, size, KUAP_WRITE);
}

static inline void allow_read_write_user(void __user *to, const void __user *from,
					 unsigned long size)
{
	allow_user_access(to, from, size, KUAP_READ_WRITE);
79 80 81 82
}

static inline void prevent_read_from_user(const void __user *from, unsigned long size)
{
83
	prevent_user_access(NULL, from, size, KUAP_READ);
84 85 86 87
}

static inline void prevent_write_to_user(void __user *to, unsigned long size)
{
88 89 90 91 92 93 94
	prevent_user_access(to, NULL, size, KUAP_WRITE);
}

static inline void prevent_read_write_user(void __user *to, const void __user *from,
					   unsigned long size)
{
	prevent_user_access(to, from, size, KUAP_READ_WRITE);
95 96
}

97 98 99 100 101
static inline void prevent_current_access_user(void)
{
	prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT);
}

102 103
#endif /* !__ASSEMBLY__ */

104
#endif /* _ASM_POWERPC_KUAP_H_ */