Subject: kern/2340: Make mapping of page zero possible in SVR4 emulation
To: None <gnats-bugs@NetBSD.ORG>
From: Niklas Hallqvist <>
List: netbsd-bugs
Date: 04/18/1996 18:59:27
>Number:         2340
>Category:       kern
>Synopsis:       Make mapping of page zero possible in SVR4 emulation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 18 13:05:01 1996
>Originator:     Niklas Hallqvist
>Release:        960317
System: OpenBSD 1.2 OpenBSD 1.2 (FILIPPA) #65: Sun Mar 24 13:12:13 MET 1996 amiga

	In at least one SVR4 implementation (Dell) page zero was mapped
	readonly making NULL dereferences non-fatal.  Therefore binaries
	that "work" on Dell SVR4 might fail in NetBSD's SVR4 emulation.
	Compile this program with a SVR4 compiler:

	main() { return *(int *)0; }

	On Dell SVR4, it will run to a normal end, in NetBSD's SVR4
	emulation it will abort with a segmentation fault.
	I agree the bug is really in Dell SVR4, but as some binaries actually
	rely on this behaviour it can be of importance to provide a kernel
	that accepts NULL dereferences no matter how bad they are seen upon.
	Emulation of bugs can also be important.

	This patch makes it possible to get the desired behaviour if


	is used in the kernel config file.  I'm aware that this also affects
	Linux/ELF, but as this change is slackening the rules, no working
	Linux/ELF binaries will stop work with this patch in.  I might cook up
	a better patch later, which only touches the SVR4 emulation, but this
	will have to do for now.

Index: src/sys/kern/exec_elf.c
diff -c src/sys/kern/exec_elf.c:1.3 src/sys/kern/exec_elf.c:1.4
*** 530,535 ****
--- 530,541 ----
  		epp->ep_emul_arg = ap;
  	} else
  		epp->ep_entry = eh->e_entry;
+ 	/* Dell SVR4 maps page zero, yeuch! */
+ 	NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, NBPG, 0, epp->ep_vp, 0,
+ 	    VM_PROT_READ);
+ #endif
  	free((char *) ph, M_TEMP);
  	epp->ep_vp->v_flag |= VTEXT;