blob: 19c5dbd46770bf9db115b447014c672fc4aee244 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Richard Weinberger548f0a42011-07-25 17:12:53 -07002/*
3 * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
Richard Weinberger548f0a42011-07-25 17:12:53 -07004 */
5
6#include <linux/mm.h>
Richard Weinberger27795672015-05-12 00:07:07 +02007#include <asm/elf.h>
Richard Weinberger548f0a42011-07-25 17:12:53 -07008
9static struct vm_area_struct gate_vma;
10
11static int __init gate_vma_init(void)
12{
13 if (!FIXADDR_USER_START)
14 return 0;
15
Kirill A. Shutemov2c4541e2018-07-26 16:37:30 -070016 vma_init(&gate_vma, NULL);
Richard Weinberger548f0a42011-07-25 17:12:53 -070017 gate_vma.vm_start = FIXADDR_USER_START;
18 gate_vma.vm_end = FIXADDR_USER_END;
19 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
20 gate_vma.vm_page_prot = __P101;
21
Richard Weinberger548f0a42011-07-25 17:12:53 -070022 return 0;
23}
24__initcall(gate_vma_init);
25
26struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27{
28 return FIXADDR_USER_START ? &gate_vma : NULL;
29}
30
31int in_gate_area_no_mm(unsigned long addr)
32{
33 if (!FIXADDR_USER_START)
34 return 0;
35
36 if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))
37 return 1;
38
39 return 0;
40}
41
42int in_gate_area(struct mm_struct *mm, unsigned long addr)
43{
44 struct vm_area_struct *vma = get_gate_vma(mm);
45
46 if (!vma)
47 return 0;
48
49 return (addr >= vma->vm_start) && (addr < vma->vm_end);
50}