Subject: bin/18222: patch to allow a uid or gid of (-2) matching default NFS mapping for remote root users
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 09/07/2002 14:03:06
>Number:         18222
>Category:       bin
>Synopsis:       patch to allow a uid or gid of (-2) matching default NFS mapping for remote root users
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 07 11:04:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Greg A. Woods
>Release:        2002/09/06
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD
>Description:

	Mountd(8) uses the vaule '-2' as the default "maroot" user-ID
	and group-ID (i.e. it is the UID and GID that root users from
	remote clients are mapped into when they access files on the NFS
	server).  Unfortunately due to checks in pw_scan(3) it's
	impossible for the NFS server administrator to add a user with
	this user-ID to the local password file (eg. so that files
	created by remote NFS client root users will show up with a
	meaningful local username).

	This is due to the current artificial ceiling on the values of
	UID_MAX and GID_MAX, used by the checks imposed in pw-scan(3).

	Given that uid_t and gid_t are defined as u_int32_t I believe
	the only integer value that is actually invalid for a user-ID or
	group-ID is UINT_MAX (i.e. -1 when converted to an int32_t).

	(even -1 may not be strictly necessary to reserve, but it's used
	as an error value in so many places that not reserving it is
	only an invitation to problems)

>How-To-Repeat:
	
	Attempt to add a line like the following to /etc/master.passwd
	using vipw(8):

	nfsnbody:*:4294967294:4294967294::0:0:NFS unprivileged (default maproot) user:/nonexistant:/sbin/nologin

>Fix:

	increase UID_MAX and GID_MAX to (UINT_MAX-1)

Index: syslimits.h
===================================================================
RCS file: /cvs/NetBSD/src/sys/sys/syslimits.h,v
retrieving revision 1.1.1.7
diff -c -r1.1.1.7 syslimits.h
*** syslimits.h	13 Jun 2001 07:04:40 -0000	1.1.1.7
--- syslimits.h	7 Sep 2002 17:35:12 -0000
***************
*** 43,55 ****
  #if !defined(_ANSI_SOURCE)
  #define	ARG_MAX		 (256 * 1024)	/* max bytes for an exec function */
  #define	CHILD_MAX		  160	/* max simultaneous processes */
! #define	GID_MAX		   2147483647U	/* max value for a gid_t (2^31-2) */
  #define	LINK_MAX		32767	/* max file link count */
  #define	MAX_CANON		  255	/* max bytes in term canon input line */
  #define	MAX_INPUT		  255	/* max bytes in terminal input */
  #define	NAME_MAX		  255	/* max bytes in a file name */
  #define	NGROUPS_MAX		   16	/* max supplemental group id's */
! #define	UID_MAX		   2147483647U	/* max value for a uid_t (2^31-2) */
  #define	OPEN_MAX		   64	/* max open files per process */
  #define	PATH_MAX		 1024	/* max bytes in pathname */
  #define	PIPE_BUF		  512	/* max bytes for atomic pipe writes */
--- 43,55 ----
  #if !defined(_ANSI_SOURCE)
  #define	ARG_MAX		 (256 * 1024)	/* max bytes for an exec function */
  #define	CHILD_MAX		  160	/* max simultaneous processes */
! #define	GID_MAX		 (UINT_MAX-1)	/* max value for a gid_t (2^32-1) */
  #define	LINK_MAX		32767	/* max file link count */
  #define	MAX_CANON		  255	/* max bytes in term canon input line */
  #define	MAX_INPUT		  255	/* max bytes in terminal input */
  #define	NAME_MAX		  255	/* max bytes in a file name */
  #define	NGROUPS_MAX		   16	/* max supplemental group id's */
! #define	UID_MAX		 (UINT_MAX-1)	/* max value for a uid_t (2^32-1) */
  #define	OPEN_MAX		   64	/* max open files per process */
  #define	PATH_MAX		 1024	/* max bytes in pathname */
  #define	PIPE_BUF		  512	/* max bytes for atomic pipe writes */
>Release-Note:
>Audit-Trail:
>Unformatted: