Subject: kern/17765: PF_LOCAL sockets should take notice of umask
To: None <gnats-bugs@gnats.netbsd.org>
From: None <xs@kittenz.org>
List: netbsd-bugs
Date: 07/30/2002 15:50:35
>Number:         17765
>Category:       kern
>Synopsis:       PF_LOCAL sockets should take notice of umask
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 30 07:51:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        NetBSD 1.6D
>Organization:
>Environment:
/sys/kern/uipc_usrreq.c:
     $NetBSD: uipc_usrreq.c,v 1.53 2001/11/12 15:25:34 lukem Exp $
System: NetBSD stasis 1.6D NetBSD 1.6D (STASIS) #29: Wed Jul 17 17:55:51 BST 2002 xs@stasis:/usr/src/sys/arch/i386/compile/STASIS i386
Architecture: i386
Machine: i386
>Description:

	Currently PF_LOCAL sockets are always created with ACCESSPERMS (0777)
	because bind() does not honour the process' umask.
	There is always a race condition wrt socket permissions.

>How-To-Repeat:
	umask(some_mask);
	Call bind() on a PF_LOCAL socket.
>Fix:

Note: FreeBSD and OpenBSD do this already.
Index: uipc_usrreq.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/uipc_usrreq.c,v
retrieving revision 1.53
diff -u -r1.53 uipc_usrreq.c
--- uipc_usrreq.c	2001/11/12 15:25:34	1.53
+++ uipc_usrreq.c	2002/07/30 13:58:00
@@ -597,7 +597,7 @@
 	}
 	VATTR_NULL(&vattr);
 	vattr.va_type = VSOCK;
-	vattr.va_mode = ACCESSPERMS;
+	vattr.va_mode = ACCESSPERMS &~ p->p_cwdi->cwdi_cmask;
 	VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
 	error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
 	if (error)

>Release-Note:
>Audit-Trail:
>Unformatted: