Gennady Sharapov | ea2ba7d | 2006-01-08 01:01:31 -0800 | [diff] [blame] | 1 | /* |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 6 | #include <linux/mm.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 7 | #include <linux/sched/signal.h> |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 8 | #include <linux/hardirq.h> |
Al Viro | 73395a0 | 2011-08-18 20:14:10 +0100 | [diff] [blame] | 9 | #include <linux/module.h> |
Peter Zijlstra | fbc9f16 | 2015-05-19 13:53:29 +0200 | [diff] [blame] | 10 | #include <linux/uaccess.h> |
Ingo Molnar | b17b015 | 2017-02-08 18:51:35 +0100 | [diff] [blame] | 11 | #include <linux/sched/debug.h> |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 12 | #include <asm/current.h> |
| 13 | #include <asm/pgtable.h> |
| 14 | #include <asm/tlbflush.h> |
Al Viro | 37185b3 | 2012-10-08 03:27:32 +0100 | [diff] [blame] | 15 | #include <arch.h> |
| 16 | #include <as-layout.h> |
| 17 | #include <kern_util.h> |
| 18 | #include <os.h> |
| 19 | #include <skas.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 21 | /* |
| 22 | * Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by |
| 23 | * segv(). |
| 24 | */ |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 25 | int handle_page_fault(unsigned long address, unsigned long ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | int is_write, int is_user, int *code_out) |
| 27 | { |
| 28 | struct mm_struct *mm = current->mm; |
| 29 | struct vm_area_struct *vma; |
| 30 | pgd_t *pgd; |
| 31 | pud_t *pud; |
| 32 | pmd_t *pmd; |
| 33 | pte_t *pte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int err = -EFAULT; |
Johannes Weiner | 759496b | 2013-09-12 15:13:39 -0700 | [diff] [blame] | 35 | unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | *code_out = SEGV_MAPERR; |
Paolo 'Blaisorblade' Giarrusso | fea03cb | 2005-09-22 21:44:20 -0700 | [diff] [blame] | 38 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 39 | /* |
David Hildenbrand | 70ffdb9 | 2015-05-11 17:52:11 +0200 | [diff] [blame] | 40 | * If the fault was with pagefaults disabled, don't take the fault, just |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 41 | * fail. |
| 42 | */ |
David Hildenbrand | 70ffdb9 | 2015-05-11 17:52:11 +0200 | [diff] [blame] | 43 | if (faulthandler_disabled()) |
Paolo 'Blaisorblade' Giarrusso | fea03cb | 2005-09-22 21:44:20 -0700 | [diff] [blame] | 44 | goto out_nosemaphore; |
| 45 | |
Johannes Weiner | 759496b | 2013-09-12 15:13:39 -0700 | [diff] [blame] | 46 | if (is_user) |
| 47 | flags |= FAULT_FLAG_USER; |
Kautuk Consul | 1cefe28 | 2012-05-31 16:26:03 -0700 | [diff] [blame] | 48 | retry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | down_read(&mm->mmap_sem); |
| 50 | vma = find_vma(mm, address); |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 51 | if (!vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | goto out; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 53 | else if (vma->vm_start <= address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | goto good_area; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 55 | else if (!(vma->vm_flags & VM_GROWSDOWN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | goto out; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 57 | else if (is_user && !ARCH_IS_STACKGROW(address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | goto out; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 59 | else if (expand_stack(vma, address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | goto out; |
| 61 | |
Paolo 'Blaisorblade' Giarrusso | 3b52166 | 2005-09-03 15:57:26 -0700 | [diff] [blame] | 62 | good_area: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | *code_out = SEGV_ACCERR; |
Johannes Weiner | 759496b | 2013-09-12 15:13:39 -0700 | [diff] [blame] | 64 | if (is_write) { |
| 65 | if (!(vma->vm_flags & VM_WRITE)) |
| 66 | goto out; |
| 67 | flags |= FAULT_FLAG_WRITE; |
| 68 | } else { |
| 69 | /* Don't require VM_READ|VM_EXEC for write faults! */ |
| 70 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
| 71 | goto out; |
| 72 | } |
Jeff Dike | 13479d5 | 2005-05-20 13:59:08 -0700 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | do { |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 75 | int fault; |
Nick Piggin | 1c0fe6e | 2009-01-06 14:38:59 -0800 | [diff] [blame] | 76 | |
Kirill A. Shutemov | dcddffd | 2016-07-26 15:25:18 -0700 | [diff] [blame] | 77 | fault = handle_mm_fault(vma, address, flags); |
Kautuk Consul | 1cefe28 | 2012-05-31 16:26:03 -0700 | [diff] [blame] | 78 | |
| 79 | if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) |
| 80 | goto out_nosemaphore; |
| 81 | |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 82 | if (unlikely(fault & VM_FAULT_ERROR)) { |
| 83 | if (fault & VM_FAULT_OOM) { |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 84 | goto out_of_memory; |
Linus Torvalds | 33692f2 | 2015-01-29 10:51:32 -0800 | [diff] [blame] | 85 | } else if (fault & VM_FAULT_SIGSEGV) { |
| 86 | goto out; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 87 | } else if (fault & VM_FAULT_SIGBUS) { |
| 88 | err = -EACCES; |
| 89 | goto out; |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | BUG(); |
| 92 | } |
Kautuk Consul | 1cefe28 | 2012-05-31 16:26:03 -0700 | [diff] [blame] | 93 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
| 94 | if (fault & VM_FAULT_MAJOR) |
| 95 | current->maj_flt++; |
| 96 | else |
| 97 | current->min_flt++; |
| 98 | if (fault & VM_FAULT_RETRY) { |
| 99 | flags &= ~FAULT_FLAG_ALLOW_RETRY; |
Shaohua Li | 45cac65 | 2012-10-08 16:32:19 -0700 | [diff] [blame] | 100 | flags |= FAULT_FLAG_TRIED; |
Kautuk Consul | 1cefe28 | 2012-05-31 16:26:03 -0700 | [diff] [blame] | 101 | |
| 102 | goto retry; |
| 103 | } |
| 104 | } |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 105 | |
Paolo 'Blaisorblade' Giarrusso | 3b52166 | 2005-09-03 15:57:26 -0700 | [diff] [blame] | 106 | pgd = pgd_offset(mm, address); |
| 107 | pud = pud_offset(pgd, address); |
| 108 | pmd = pmd_offset(pud, address); |
| 109 | pte = pte_offset_kernel(pmd, address); |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 110 | } while (!pte_present(*pte)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | err = 0; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 112 | /* |
| 113 | * The below warning was added in place of |
Paolo 'Blaisorblade' Giarrusso | cbc24af | 2005-11-13 16:07:04 -0800 | [diff] [blame] | 114 | * pte_mkyoung(); if (is_write) pte_mkdirty(); |
| 115 | * If it's triggered, we'd see normally a hang here (a clean pte is |
| 116 | * marked read-only to emulate the dirty bit). |
| 117 | * However, the generic code can mark a PTE writable but clean on a |
| 118 | * concurrent read fault, triggering this harmlessly. So comment it out. |
| 119 | */ |
| 120 | #if 0 |
Paolo 'Blaisorblade' Giarrusso | 16b0367 | 2005-09-10 19:44:58 +0200 | [diff] [blame] | 121 | WARN_ON(!pte_young(*pte) || (is_write && !pte_dirty(*pte))); |
Paolo 'Blaisorblade' Giarrusso | cbc24af | 2005-11-13 16:07:04 -0800 | [diff] [blame] | 122 | #endif |
Paolo 'Blaisorblade' Giarrusso | 3b52166 | 2005-09-03 15:57:26 -0700 | [diff] [blame] | 123 | flush_tlb_page(vma, address); |
| 124 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | up_read(&mm->mmap_sem); |
Paolo 'Blaisorblade' Giarrusso | fea03cb | 2005-09-22 21:44:20 -0700 | [diff] [blame] | 126 | out_nosemaphore: |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 127 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | out_of_memory: |
Nick Piggin | 1c0fe6e | 2009-01-06 14:38:59 -0800 | [diff] [blame] | 130 | /* |
| 131 | * We ran out of memory, call the OOM killer, and return the userspace |
| 132 | * (which will retry the fault, or kill us if we got oom-killed). |
| 133 | */ |
| 134 | up_read(&mm->mmap_sem); |
Johannes Weiner | 8713410 | 2013-09-12 15:13:38 -0700 | [diff] [blame] | 135 | if (!is_user) |
| 136 | goto out_nosemaphore; |
Nick Piggin | 1c0fe6e | 2009-01-06 14:38:59 -0800 | [diff] [blame] | 137 | pagefault_out_of_memory(); |
| 138 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Al Viro | 73395a0 | 2011-08-18 20:14:10 +0100 | [diff] [blame] | 140 | EXPORT_SYMBOL(handle_page_fault); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Richard Weinberger | 3ef6130 | 2011-05-24 17:13:03 -0700 | [diff] [blame] | 142 | static void show_segv_info(struct uml_pt_regs *regs) |
| 143 | { |
| 144 | struct task_struct *tsk = current; |
| 145 | struct faultinfo *fi = UPT_FAULTINFO(regs); |
| 146 | |
| 147 | if (!unhandled_signal(tsk, SIGSEGV)) |
| 148 | return; |
| 149 | |
| 150 | if (!printk_ratelimit()) |
| 151 | return; |
| 152 | |
Kees Cook | 10a7e9d | 2017-12-19 13:52:23 -0800 | [diff] [blame] | 153 | printk("%s%s[%d]: segfault at %lx ip %px sp %px error %x", |
Richard Weinberger | 3ef6130 | 2011-05-24 17:13:03 -0700 | [diff] [blame] | 154 | task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, |
| 155 | tsk->comm, task_pid_nr(tsk), FAULT_ADDRESS(*fi), |
| 156 | (void *)UPT_IP(regs), (void *)UPT_SP(regs), |
| 157 | fi->error_code); |
| 158 | |
| 159 | print_vma_addr(KERN_CONT " in ", UPT_IP(regs)); |
| 160 | printk(KERN_CONT "\n"); |
| 161 | } |
| 162 | |
Jeff Dike | 27aa6ef | 2007-02-10 01:44:14 -0800 | [diff] [blame] | 163 | static void bad_segv(struct faultinfo fi, unsigned long ip) |
| 164 | { |
Jeff Dike | 27aa6ef | 2007-02-10 01:44:14 -0800 | [diff] [blame] | 165 | current->thread.arch.faultinfo = fi; |
Eric W. Biederman | bc08c07 | 2018-04-15 19:50:48 -0500 | [diff] [blame^] | 166 | force_sig_fault(SIGSEGV, SEGV_ACCERR, (void __user *) FAULT_ADDRESS(fi), |
| 167 | current); |
Jeff Dike | 27aa6ef | 2007-02-10 01:44:14 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 170 | void fatal_sigsegv(void) |
| 171 | { |
| 172 | force_sigsegv(SIGSEGV, current); |
Ingo Molnar | ccaee5f | 2015-07-03 12:44:20 -0700 | [diff] [blame] | 173 | do_signal(¤t->thread.regs); |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 174 | /* |
| 175 | * This is to tell gcc that we're not returning - do_signal |
| 176 | * can, in general, return, but in this case, it's not, since |
| 177 | * we just got a fatal SIGSEGV queued. |
| 178 | */ |
| 179 | os_dump_core(); |
| 180 | } |
| 181 | |
Thomas Meyer | 88af233 | 2017-07-06 00:34:04 +0200 | [diff] [blame] | 182 | /** |
| 183 | * segv_handler() - the SIGSEGV handler |
| 184 | * @sig: the signal number |
| 185 | * @unused_si: the signal info struct; unused in this handler |
| 186 | * @regs: the ptrace register information |
| 187 | * |
| 188 | * The handler first extracts the faultinfo from the UML ptrace regs struct. |
| 189 | * If the userfault did not happen in an UML userspace process, bad_segv is called. |
| 190 | * Otherwise the signal did happen in a cloned userspace process, handle it. |
| 191 | */ |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 192 | void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) |
Gennady Sharapov | c66fdd5 | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 193 | { |
| 194 | struct faultinfo * fi = UPT_FAULTINFO(regs); |
| 195 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 196 | if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) { |
Richard Weinberger | 3ef6130 | 2011-05-24 17:13:03 -0700 | [diff] [blame] | 197 | show_segv_info(regs); |
Gennady Sharapov | c66fdd5 | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 198 | bad_segv(*fi, UPT_IP(regs)); |
| 199 | return; |
| 200 | } |
| 201 | segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs); |
| 202 | } |
| 203 | |
Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 204 | /* |
| 205 | * We give a *copy* of the faultinfo in the regs to segv. |
| 206 | * This must be done, since nesting SEGVs could overwrite |
| 207 | * the info in the regs. A pointer to the info then would |
| 208 | * give us bad data! |
| 209 | */ |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 210 | unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 211 | struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 213 | jmp_buf *catcher; |
Eric W. Biederman | bc08c07 | 2018-04-15 19:50:48 -0500 | [diff] [blame^] | 214 | int si_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | int err; |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 216 | int is_write = FAULT_WRITE(fi); |
| 217 | unsigned long address = FAULT_ADDRESS(fi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Richard Weinberger | bb6a1b2 | 2014-07-20 13:39:27 +0200 | [diff] [blame] | 219 | if (!is_user && regs) |
Richard Weinberger | f72c22e | 2013-09-23 17:38:02 +0200 | [diff] [blame] | 220 | current->thread.segv_regs = container_of(regs, struct pt_regs, regs); |
| 221 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 222 | if (!is_user && (address >= start_vm) && (address < end_vm)) { |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 223 | flush_tlb_kernel_vm(); |
Richard Weinberger | f72c22e | 2013-09-23 17:38:02 +0200 | [diff] [blame] | 224 | goto out; |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 225 | } |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 226 | else if (current->mm == NULL) { |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 227 | show_regs(container_of(regs, struct pt_regs, regs)); |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 228 | panic("Segfault with no mm"); |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 229 | } |
Richard Weinberger | 56b88a3 | 2015-08-09 22:26:33 +0200 | [diff] [blame] | 230 | else if (!is_user && address > PAGE_SIZE && address < TASK_SIZE) { |
Richard Weinberger | d231308 | 2015-05-31 19:21:51 +0200 | [diff] [blame] | 231 | show_regs(container_of(regs, struct pt_regs, regs)); |
| 232 | panic("Kernel tried to access user memory at addr 0x%lx, ip 0x%lx", |
| 233 | address, ip); |
| 234 | } |
Paolo 'Blaisorblade' Giarrusso | 546fe1c | 2005-09-22 21:44:16 -0700 | [diff] [blame] | 235 | |
Richard Weinberger | d0b5e15 | 2015-03-18 21:31:27 +0100 | [diff] [blame] | 236 | if (SEGV_IS_FIXABLE(&fi)) |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 237 | err = handle_page_fault(address, ip, is_write, is_user, |
Eric W. Biederman | bc08c07 | 2018-04-15 19:50:48 -0500 | [diff] [blame^] | 238 | &si_code); |
Paolo 'Blaisorblade' Giarrusso | 546fe1c | 2005-09-22 21:44:16 -0700 | [diff] [blame] | 239 | else { |
| 240 | err = -EFAULT; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 241 | /* |
| 242 | * A thread accessed NULL, we get a fault, but CR2 is invalid. |
| 243 | * This code is used in __do_copy_from_user() of TT mode. |
| 244 | * XXX tt mode is gone, so maybe this isn't needed any more |
| 245 | */ |
Paolo 'Blaisorblade' Giarrusso | 546fe1c | 2005-09-22 21:44:16 -0700 | [diff] [blame] | 246 | address = 0; |
| 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | catcher = current->thread.fault_catcher; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 250 | if (!err) |
Richard Weinberger | f72c22e | 2013-09-23 17:38:02 +0200 | [diff] [blame] | 251 | goto out; |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 252 | else if (catcher != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | current->thread.fault_addr = (void *) address; |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 254 | UML_LONGJMP(catcher, 1); |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 255 | } |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 256 | else if (current->thread.fault_addr != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | panic("fault_addr set but no fault catcher"); |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 258 | else if (!is_user && arch_fixup(ip, regs)) |
Richard Weinberger | f72c22e | 2013-09-23 17:38:02 +0200 | [diff] [blame] | 259 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 261 | if (!is_user) { |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 262 | show_regs(container_of(regs, struct pt_regs, regs)); |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 263 | panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | address, ip); |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Richard Weinberger | 3ef6130 | 2011-05-24 17:13:03 -0700 | [diff] [blame] | 267 | show_segv_info(regs); |
| 268 | |
Paolo 'Blaisorblade' Giarrusso | 3b52166 | 2005-09-03 15:57:26 -0700 | [diff] [blame] | 269 | if (err == -EACCES) { |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 270 | current->thread.arch.faultinfo = fi; |
Eric W. Biederman | bc08c07 | 2018-04-15 19:50:48 -0500 | [diff] [blame^] | 271 | force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, |
| 272 | current); |
Paolo 'Blaisorblade' Giarrusso | 3b52166 | 2005-09-03 15:57:26 -0700 | [diff] [blame] | 273 | } else { |
| 274 | BUG_ON(err != -EFAULT); |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 275 | current->thread.arch.faultinfo = fi; |
Eric W. Biederman | bc08c07 | 2018-04-15 19:50:48 -0500 | [diff] [blame^] | 276 | force_sig_fault(SIGSEGV, si_code, (void __user *) address, |
| 277 | current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
Richard Weinberger | f72c22e | 2013-09-23 17:38:02 +0200 | [diff] [blame] | 279 | |
| 280 | out: |
| 281 | if (regs) |
| 282 | current->thread.segv_regs = NULL; |
| 283 | |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 284 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 287 | void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 289 | struct faultinfo *fi; |
| 290 | struct siginfo clean_si; |
| 291 | |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 292 | if (!UPT_IS_USER(regs)) { |
| 293 | if (sig == SIGBUS) |
| 294 | printk(KERN_ERR "Bus error - the host /dev/shm or /tmp " |
| 295 | "mount likely just ran out of space\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | panic("Kernel mode signal %d", sig); |
Jeff Dike | 6edf428 | 2006-09-25 23:33:03 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 299 | arch_examine_signal(sig, regs); |
| 300 | |
Eric W. Biederman | 3b10db2b | 2017-08-18 19:56:27 -0500 | [diff] [blame] | 301 | clear_siginfo(&clean_si); |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 302 | clean_si.si_signo = si->si_signo; |
| 303 | clean_si.si_errno = si->si_errno; |
| 304 | clean_si.si_code = si->si_code; |
| 305 | switch (sig) { |
| 306 | case SIGILL: |
| 307 | case SIGFPE: |
| 308 | case SIGSEGV: |
| 309 | case SIGBUS: |
| 310 | case SIGTRAP: |
| 311 | fi = UPT_FAULTINFO(regs); |
| 312 | clean_si.si_addr = (void __user *) FAULT_ADDRESS(*fi); |
| 313 | current->thread.arch.faultinfo = *fi; |
| 314 | #ifdef __ARCH_SI_TRAPNO |
| 315 | clean_si.si_trapno = si->si_trapno; |
| 316 | #endif |
| 317 | break; |
| 318 | default: |
| 319 | printk(KERN_ERR "Attempted to relay unknown signal %d (si_code = %d)\n", |
| 320 | sig, si->si_code); |
| 321 | } |
| 322 | |
| 323 | force_sig_info(sig, &clean_si, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 326 | void bus_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Jeff Dike | 4c9e138 | 2007-10-16 01:26:54 -0700 | [diff] [blame] | 328 | if (current->thread.fault_catcher != NULL) |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 329 | UML_LONGJMP(current->thread.fault_catcher, 1); |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 330 | else |
| 331 | relay_signal(sig, si, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Martin Pärtel | d3c1cfc | 2012-08-02 00:49:17 +0200 | [diff] [blame] | 334 | void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | do_IRQ(WINCH_IRQ, regs); |
| 337 | } |
| 338 | |
| 339 | void trap_init(void) |
| 340 | { |
| 341 | } |