Tue Mar 3 13:23:49 2015 UTC ()
Handle EINVAL in the fault path and send SIGBUS on mmap'd access past EOF


(martin)
diff -r1.132 -r1.133 src/sys/arch/vax/vax/trap.c

cvs diff -r1.132 -r1.133 src/sys/arch/vax/vax/trap.c (expand / switch to unified diff)

--- src/sys/arch/vax/vax/trap.c 2013/10/25 16:30:52 1.132
+++ src/sys/arch/vax/vax/trap.c 2015/03/03 13:23:48 1.133
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: trap.c,v 1.132 2013/10/25 16:30:52 martin Exp $ */ 1/* $NetBSD: trap.c,v 1.133 2015/03/03 13:23:48 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994 Ludd, University of Lule}, Sweden. 4 * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 /* All bugs are subject to removal without further notice */ 33 /* All bugs are subject to removal without further notice */
34  34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.132 2013/10/25 16:30:52 martin Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.133 2015/03/03 13:23:48 martin Exp $");
37 37
38#include "opt_ddb.h" 38#include "opt_ddb.h"
39#include "opt_multiprocessor.h" 39#include "opt_multiprocessor.h"
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/cpu.h> 43#include <sys/cpu.h>
44#include <sys/exec.h> 44#include <sys/exec.h>
45#include <sys/kauth.h> 45#include <sys/kauth.h>
46#include <sys/proc.h> 46#include <sys/proc.h>
47#include <sys/signalvar.h> 47#include <sys/signalvar.h>
48 48
49#include <uvm/uvm_extern.h> 49#include <uvm/uvm_extern.h>
@@ -234,38 +234,48 @@ if(faultdebug)printf("trap accflt type % @@ -234,38 +234,48 @@ if(faultdebug)printf("trap accflt type %
234 printf("r0=%08lx r1=%08lx r2=%08lx r3=%08lx ", 234 printf("r0=%08lx r1=%08lx r2=%08lx r3=%08lx ",
235 tf->tf_r0, tf->tf_r1, tf->tf_r2, tf->tf_r3); 235 tf->tf_r0, tf->tf_r1, tf->tf_r2, tf->tf_r3);
236 printf("r4=%08lx r5=%08lx r6=%08lx r7=%08lx\n", 236 printf("r4=%08lx r5=%08lx r6=%08lx r7=%08lx\n",
237 tf->tf_r4, tf->tf_r5, tf->tf_r6, tf->tf_r7); 237 tf->tf_r4, tf->tf_r5, tf->tf_r6, tf->tf_r7);
238 printf( 238 printf(
239 "r8=%08lx r9=%08lx r10=%08lx r11=%08lx\n", 239 "r8=%08lx r9=%08lx r10=%08lx r11=%08lx\n",
240 tf->tf_r8, tf->tf_r9, tf->tf_r10, 240 tf->tf_r8, tf->tf_r9, tf->tf_r10,
241 tf->tf_r11); 241 tf->tf_r11);
242 printf("ap=%08lx fp=%08lx sp=%08lx pc=%08lx\n", 242 printf("ap=%08lx fp=%08lx sp=%08lx pc=%08lx\n",
243 tf->tf_ap, tf->tf_fp, tf->tf_sp, tf->tf_pc); 243 tf->tf_ap, tf->tf_fp, tf->tf_sp, tf->tf_pc);
244 panic("SEGV in kernel mode: pc %#lx addr %#lx", 244 panic("SEGV in kernel mode: pc %#lx addr %#lx",
245 tf->tf_pc, tf->tf_code); 245 tf->tf_pc, tf->tf_code);
246 } 246 }
247 code = SEGV_ACCERR; 247 switch (rv) {
248 if (rv == ENOMEM) { 248 case ENOMEM:
249 printf("UVM: pid %d (%s), uid %d killed: " 249 printf("UVM: pid %d (%s), uid %d killed: "
250 "out of swap\n", 250 "out of swap\n",
251 p->p_pid, p->p_comm, 251 p->p_pid, p->p_comm,
252 l->l_cred ? 252 l->l_cred ?
253 kauth_cred_geteuid(l->l_cred) : -1); 253 kauth_cred_geteuid(l->l_cred) : -1);
254 sig = SIGKILL; 254 sig = SIGKILL;
255 } else { 255 code = SI_NOINFO;
 256 break;
 257 case EINVAL:
 258 code = BUS_ADRERR;
 259 sig = SIGBUS;
 260 break;
 261 case EACCES:
 262 code = SEGV_ACCERR;
256 sig = SIGSEGV; 263 sig = SIGSEGV;
257 if (rv != EACCES) 264 break;
258 code = SEGV_MAPERR; 265 default:
 266 code = SEGV_MAPERR;
 267 sig = SIGSEGV;
 268 break;
259 } 269 }
260 } else { 270 } else {
261 trapsig = false; 271 trapsig = false;
262 if (map != kernel_map && addr > 0 272 if (map != kernel_map && addr > 0
263 && (void *)addr >= vm->vm_maxsaddr) 273 && (void *)addr >= vm->vm_maxsaddr)
264 uvm_grow(p, addr); 274 uvm_grow(p, addr);
265 } 275 }
266 break; 276 break;
267 277
268 case T_BPTFLT|T_USER: 278 case T_BPTFLT|T_USER:
269 sig = SIGTRAP; 279 sig = SIGTRAP;
270 code = TRAP_BRKPT; 280 code = TRAP_BRKPT;
271 break; 281 break;