Subject: siginfo & no-exec permission - please test
To: None <port-powerpc@netbsd.org>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: port-powerpc
Date: 02/19/2004 19:19:42
This is a multipart MIME message.

--==_Exmh_66457698933210
Content-Type: text/plain; charset=us-ascii


Hi -
I don't have a ppc box to test with atm, but I've done
related fixes to other architectures, and from code
inspection it appears to me that a little fix should be
applied to the powerpc port as well:
Desired behaviour is that a SIGSEGV is delivered to a
process, with a siginfo si_code of SEGV_ACCERR if code
execution is attempted from virtual memory mapped without
execution permission (especially the stack).
The appended patched should implement this.

Unfortunately I don't have a test program ready to verify
this -- the regression test in regress/sys/uvm/stack_noexec
probably doesn't work because gcc's ppc target doesn't
use stack trampolines afaics.
Perhaps you've got another idea;-)

While we are here, 2 observations:
-powerpc/ibm4xx/trap.c appears to leave ksi.ksi_code
 uninitialized at a number of places
-it also calls trapsignal() directly, without the
 emulation hook

best regards
Matthias



--==_Exmh_66457698933210
Content-Type: text/plain ; name="ppcnox.txt"; charset=us-ascii
Content-Description: ppcnox.txt
Content-Disposition: attachment; filename="ppcnox.txt"

Index: powerpc/ibm4xx/trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/ibm4xx/trap.c,v
retrieving revision 1.20
diff -u -r1.20 trap.c
--- powerpc/ibm4xx/trap.c	31 Oct 2003 16:44:35 -0000	1.20
+++ powerpc/ibm4xx/trap.c	19 Feb 2004 17:28:14 -0000
@@ -293,6 +293,7 @@
 		ksi.ksi_signo = SIGSEGV;
 		ksi.ksi_trap = EXC_ISI;
 		ksi.ksi_addr = (void *)frame->srr0;
+		ksi.ksi_code = (rv == EACCES ? SEGV_ACC : SEGV_MAP);
 		trapsignal(l, &ksi);
 		l->l_flag &= ~L_SA_PAGEFAULT;
 		KERNEL_PROC_UNLOCK(l);
Index: powerpc/powerpc/trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/trap.c,v
retrieving revision 1.96
diff -u -r1.96 trap.c
--- powerpc/powerpc/trap.c	21 Nov 2003 22:57:14 -0000	1.96
+++ powerpc/powerpc/trap.c	19 Feb 2004 17:28:14 -0000
@@ -334,7 +334,7 @@
 		ksi.ksi_signo = SIGSEGV;
 		ksi.ksi_trap = EXC_ISI;
 		ksi.ksi_addr = (void *)frame->srr0;
-		ksi.ksi_code = SEGV_MAPERR;
+		ksi.ksi_code = (rv == EACCES ? SEGV_ACCERR : SEGV_MAPERR);
 		(*p->p_emul->e_trapsignal)(l, &ksi);
 		l->l_flag &= ~L_SA_PAGEFAULT;
 		KERNEL_PROC_UNLOCK(l);

--==_Exmh_66457698933210--