Skip to content

Commit b845f31

Browse files
Dave Kleikampozbenh
authored andcommitted
mm: Allow architectures to define additional protection bits
This patch allows architectures to define functions to deal with additional protections bits for mmap() and mprotect(). arch_calc_vm_prot_bits() maps additonal protection bits to vm_flags arch_vm_get_page_prot() maps additional vm_flags to the vma's vm_page_prot arch_validate_prot() checks for valid values of the protection bits Note: vm_get_page_prot() is now pretty ugly, but the generated code should be identical for architectures that don't define additional protection bits. Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com> Acked-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Hugh Dickins <hugh@veritas.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent e5093ff commit b845f31

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎include/linux/mman.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ static inline void vm_unacct_memory(long pages)
3333
vm_acct_memory(-pages);
3434
}
3535

36+
/*
37+
* Allow architectures to handle additional protection bits
38+
*/
39+
40+
#ifndef arch_calc_vm_prot_bits
41+
#define arch_calc_vm_prot_bits(prot) 0
42+
#endif
43+
44+
#ifndef arch_vm_get_page_prot
45+
#define arch_vm_get_page_prot(vm_flags) __pgprot(0)
46+
#endif
47+
48+
#ifndef arch_validate_prot
49+
/*
50+
* This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have
51+
* already been masked out.
52+
*
53+
* Returns true if the prot flags are valid
54+
*/
55+
static inline int arch_validate_prot(unsigned long prot)
56+
{
57+
return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0;
58+
}
59+
#define arch_validate_prot arch_validate_prot
60+
#endif
61+
3662
/*
3763
* Optimisation macro. It is equivalent to:
3864
* (x & bit1) ? bit2 : 0
@@ -51,7 +77,8 @@ calc_vm_prot_bits(unsigned long prot)
5177
{
5278
return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
5379
_calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
54-
_calc_vm_trans(prot, PROT_EXEC, VM_EXEC );
80+
_calc_vm_trans(prot, PROT_EXEC, VM_EXEC) |
81+
arch_calc_vm_prot_bits(prot);
5582
}
5683

5784
/*

‎mm/mmap.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ pgprot_t protection_map[16] = {
7272

7373
pgprot_t vm_get_page_prot(unsigned long vm_flags)
7474
{
75-
return protection_map[vm_flags &
76-
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
75+
return __pgprot(pgprot_val(protection_map[vm_flags &
76+
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
77+
pgprot_val(arch_vm_get_page_prot(vm_flags)));
7778
}
7879
EXPORT_SYMBOL(vm_get_page_prot);
7980

‎mm/mprotect.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ sys_mprotect(unsigned long start, size_t len, unsigned long prot)
239239
end = start + len;
240240
if (end <= start)
241241
return -ENOMEM;
242-
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM))
242+
if (!arch_validate_prot(prot))
243243
return -EINVAL;
244244

245245
reqprot = prot;

0 commit comments

Comments
 (0)