Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/m68k/m68k Forbid to set odd address to PC in proces...



details:   https://anonhg.NetBSD.org/src/rev/2a9085c4a10c
branches:  trunk
changeset: 1012802:2a9085c4a10c
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Aug 10 09:38:48 2020 +0000

description:
Forbid to set odd address to PC in process_write_regs() and process_set_pc().

Otherwise, address error occurs in kernel at rte instruction when returning
to the user level.

Found by tests/lib/libc/t_ptrace_*:access_regs_set_unaligned_pc_0x[137].

diffstat:

 sys/arch/m68k/m68k/process_machdep.c |  23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)

diffs (53 lines):

diff -r f1bb3d398942 -r 2a9085c4a10c sys/arch/m68k/m68k/process_machdep.c
--- a/sys/arch/m68k/m68k/process_machdep.c      Mon Aug 10 09:30:21 2020 +0000
+++ b/sys/arch/m68k/m68k/process_machdep.c      Mon Aug 10 09:38:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: process_machdep.c,v 1.30 2014/01/04 00:10:02 dsl Exp $ */
+/*     $NetBSD: process_machdep.c,v 1.31 2020/08/10 09:38:48 rin Exp $ */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.30 2014/01/04 00:10:02 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.31 2020/08/10 09:38:48 rin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -114,13 +114,10 @@
        struct frame *frame = process_frame(l);
 
        /*
-        * in the hp300 machdep.c _write_regs, PC alignment wasn't
-        * checked.  If an odd address is placed in the PC and the
-        * program is allowed to run, it will cause an Address Error
-        * which will be transmitted to the process by a SIGBUS.
-        * No reasonable debugger would let this happen, but
-        * it's not our problem.
+        * Avoid kernel address error at rte instruction.
         */
+       if (regs->r_pc & 1)
+               return EINVAL;
 
        /*
         * XXX
@@ -171,14 +168,10 @@
        struct frame *frame = process_frame(l);
 
        /*
-        * in the hp300 machdep.c _set_pc, PC alignment is guaranteed
-        * by chopping off the low order bit of the new pc.
-        * If an odd address was placed in the PC and the program
-        * is allowed to run, it will cause an Address Error
-        * which will be transmitted to the process by a SIGBUS.
-        * No reasonable debugger would let this happen, but
-        * it's not our problem.
+        * Avoid kernel address error at rte instruction.
         */
+       if ((u_int)addr & 1)
+               return EINVAL;
        frame->f_pc = (u_int)addr;
 
        return 0;



Home | Main Index | Thread Index | Old Index