Subject: kern/2340: Make mapping of page zero possible in SVR4 emulation
To: None <gnats-bugs@NetBSD.ORG>
From: Niklas Hallqvist <niklas@filippa.appli.se>
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
>Last-Modified:
>Originator:     Niklas Hallqvist
>Organization:
	
>Release:        960317
>Environment:
	
System: OpenBSD filippa.appli.se 1.2 OpenBSD 1.2 (FILIPPA) #65: Sun Mar 24 13:12:13 MET 1996 niklas@filippa.appli.se:/u3/OpenBSD/src/sys/arch/amiga/compile/FILIPPA amiga


>Description:
	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.
>How-To-Repeat:
	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.
>Fix:
	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

	options	ELF_MAP_PAGE_ZERO

	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;
+ 
+ #ifdef ELF_MAP_PAGE_ZERO
+ 	/* 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;

>Audit-Trail:
>Unformatted: