Subject: kern/28458: shmat(2) shmaddr argument is not honored as intended.
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <makoto@haun.org>
List: netbsd-bugs
Date: 11/29/2004 13:12:00
>Number:         28458
>Category:       kern
>Synopsis:       shmat(2) shmaddr argument is not honored as intended.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 29 13:12:00 +0000 2004
>Originator:     Minoura Makoto
>Release:        NetBSD 2.0_RC4
>Organization:
>Environment:
System: NetBSD dumbo 2.0_RC4 NetBSD 2.0_RC4 (DUMBO) #5: Tue Nov 23 19:11:36 JST 2004 root@dumbo:/usr/src/sys/arch/i386/compile/DUMBO i386
Architecture: i386
Machine: i386
>Description:
	In sys_shmat() in sys/kern/sysv_shm.c,
	 - local variable flags is set but not used.
	 - UVM_FLAG_FIXED should be passed to uvm_map() when
	  shmaddr != 0.
>How-To-Repeat:
>Fix:
Index: sysv_shm.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sysv_shm.c,v
retrieving revision 1.76.2.1
diff -u -p -r1.76.2.1 sysv_shm.c
--- sysv_shm.c	4 Oct 2004 05:19:09 -0000	1.76.2.1
+++ sysv_shm.c	29 Nov 2004 12:58:36 -0000
@@ -351,9 +351,9 @@ sys_shmat(l, v, retval)
 	prot = VM_PROT_READ;
 	if ((SCARG(uap, shmflg) & SHM_RDONLY) == 0)
 		prot |= VM_PROT_WRITE;
-	flags = MAP_ANON | MAP_SHARED;
+	flags = 0;
 	if (SCARG(uap, shmaddr)) {
-		flags |= MAP_FIXED;
+		flags |= UVM_FLAG_FIXED;
 		if (SCARG(uap, shmflg) & SHM_RND)
 			attach_va =
 			    (vaddr_t)SCARG(uap, shmaddr) & ~(SHMLBA-1);
@@ -369,7 +369,7 @@ sys_shmat(l, v, retval)
 	(*uobj->pgops->pgo_reference)(uobj);
 	error = uvm_map(&p->p_vmspace->vm_map, &attach_va, size,
 	    uobj, 0, 0,
-	    UVM_MAPFLAG(prot, prot, UVM_INH_SHARE, UVM_ADV_RANDOM, 0));
+	    UVM_MAPFLAG(prot, prot, UVM_INH_SHARE, UVM_ADV_RANDOM, flags));
 	if (error) {
 		(*uobj->pgops->pgo_detach)(uobj);
 		return error;