NetBSD Problem Report #14880

Received: (qmail 16575 invoked from network); 9 Dec 2001 02:55:44 -0000
Message-Id: <200112090350.fB93o9T01225@excalibur.reed.wattle.id.au>
Date: Sun, 9 Dec 2001 14:50:09 +1100 (EST)
From: darrenr@reed.wattle.id.au
Reply-To: darrenr@reed.wattle.id.au
To: gnats-bugs@gnats.netbsd.org
Subject: rlogind doesn't work properly with home directory on NFS
X-Send-Pr-Version: 3.95

>Number:         14880
>Category:       bin
>Synopsis:       rlogind doesn't work properly with home directory on NFS
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 09 02:56:00 +0000 2001
>Closed-Date:    Tue Jan 27 11:48:26 +0000 2004
>Last-Modified:  Fri Aug 29 07:53:41 +0000 2014
>Originator:     Darren Reed
>Release:        NetBSD 1.5R
>Organization:
>Environment:
System: NetBSD excalibur 1.5R NetBSD 1.5R (EXCALIBUR) #7: Sun Nov 25 14:23:53 EST 2001 darrenr@excalibur:/usr/src/sys/arch/i386/compile/EXCALIBUR i386
Architecture: i386
Machine: i386
>Description:
/home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
to the exported partition.
rlogin will not work if ~darrenr/.rhosts is mode 600.
>How-To-Repeat:
See above.
>Fix:

>Release-Note:
>Audit-Trail:

From: woods@weird.com (Greg A. Woods)
To: darrenr@reed.wattle.id.au
Cc: gnats-bugs@gnats.netbsd.org (NetBSD GNATS submissions and followups)
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Sat,  8 Dec 2001 23:06:05 -0500 (EST)

 [ On Sunday, December 9, 2001 at 14:50:09 (+1100), darrenr@reed.wattle.id.au wrote: ]
 > Subject: bin/14880: rlogind doesn't work properly with home directory on NFS
 >
 > /home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
 > to the exported partition.
 > rlogin will not work if ~darrenr/.rhosts is mode 600.

 As a half-assed work-around you might allow root to be root on your
 /home (exportfs with '-maproot=root'), but make sure you always mount it
 on the server with 'nodev,nosuid'.  It's an accident waiting to happen,
 and it might not protect you from some of the things you may be
 concerned about, but at least then rlogind works!  ;-)  [auditing should
 find any traps a foreign root might create, hopefully before they get a
 chance to be activated...]

 A real fix might be for rlogind to first try to open ~/.rhosts as the
 target user, and only open it as root if it is owned by root (and of
 course to always do an fstat() comparison after opening to be sure you
 get what you think you're getting).  That may raise the ugly openas()
 debate again though!  ;-)

 I've been through all the same issues with mailers reading ~/.forward,
 though at least with a mailer you don't have to allow root to own the
 file (though some folks might like the option).

 -- 
 								Greg A. Woods

 +1 416 218-0098;  <gwoods@acm.org>;  <g.a.woods@ieee.org>;  <woods@robohack.ca>
 Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>

From: Luke Mewburn <lukem@wasabisystems.com>
To: darrenr@reed.wattle.id.au
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Sun, 9 Dec 2001 15:50:37 +1100

 On Sun, Dec 09, 2001 at 02:50:09PM +1100, darrenr@reed.wattle.id.au wrote:
 > /home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
 > to the exported partition.
 > rlogin will not work if ~darrenr/.rhosts is mode 600.

 If I recall correctly, that has always been the behaviour of rlogind,
 even on non-NetBSD platforms.

From: Darren Reed <darrenr@reed.wattle.id.au>
To: lukem@wasabisystems.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Sun, 9 Dec 2001 16:45:06 +1100 (EST)

 In some email I received from Luke Mewburn, sie wrote:
 > On Sun, Dec 09, 2001 at 02:50:09PM +1100, darrenr@reed.wattle.id.au wrote:
 > > /home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
 > > to the exported partition.
 > > rlogin will not work if ~darrenr/.rhosts is mode 600.
 > 
 > If I recall correctly, that has always been the behaviour of rlogind,
 > even on non-NetBSD platforms.

 Of course.  rlogind never runs as the user, always as root. doh!

 Is this something which we should "fix" or in "fixing it", do we introduce
 a security risk that otherwise isn't there and one which may surprise ppl?

 Darren

From: Luke Mewburn <lukem@wasabisystems.com>
To: Darren Reed <darrenr@reed.wattle.id.au>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Sun, 9 Dec 2001 17:01:19 +1100

 On Sun, Dec 09, 2001 at 04:45:06PM +1100, Darren Reed wrote:
 > In some email I received from Luke Mewburn, sie wrote:
 > > On Sun, Dec 09, 2001 at 02:50:09PM +1100, darrenr@reed.wattle.id.au wrote:
 > > > /home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
 > > > to the exported partition.
 > > > rlogin will not work if ~darrenr/.rhosts is mode 600.
 > > 
 > > If I recall correctly, that has always been the behaviour of rlogind,
 > > even on non-NetBSD platforms.
 > 
 > Of course.  rlogind never runs as the user, always as root. doh!
 > 
 > Is this something which we should "fix" or in "fixing it", do we introduce
 > a security risk that otherwise isn't there and one which may surprise ppl?

 I would argue that we leave the semantics alone.

From: Darren Reed <darrenr@reed.wattle.id.au>
To: lukem@wasabisystems.com
Cc: darrenr@reed.wattle.id.au, gnats-bugs@gnats.netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Sun, 9 Dec 2001 17:25:52 +1100 (EST)

 In some email I received from Luke Mewburn, sie wrote:
 > On Sun, Dec 09, 2001 at 04:45:06PM +1100, Darren Reed wrote:
 > > In some email I received from Luke Mewburn, sie wrote:
 > > > On Sun, Dec 09, 2001 at 02:50:09PM +1100, darrenr@reed.wattle.id.au wrote:
 > > > > /home is mounted via NFS, rw from a SunOS4 box and doesn't have root access
 > > > > to the exported partition.
 > > > > rlogin will not work if ~darrenr/.rhosts is mode 600.
 > > > 
 > > > If I recall correctly, that has always been the behaviour of rlogind,
 > > > even on non-NetBSD platforms.
 > > 
 > > Of course.  rlogind never runs as the user, always as root. doh!
 > > 
 > > Is this something which we should "fix" or in "fixing it", do we introduce
 > > a security risk that otherwise isn't there and one which may surprise ppl?
 > 
 > I would argue that we leave the semantics alone.

 Just to through some contraversy into this, it works on Solaris.

 That is:
 * /home exported without root privs to a Solaris 2.6 box
 * rlogin from "trusted host" (correct entry in .rhosts)
 * .rhosts is 0600

 Checking the trace on this box:
 ...
 908:    setgroups(5, 0x00126A78)                        = 0
 908:    seteuid(darrenr's euid)                         = 0
 908:    open("/home/darrenr/.rhosts", O_RDONLY)         = 4
 ...

 Darren

From: Darren Reed <darrenr@reed.wattle.id.au>
To: darrenr@reed.wattle.id.au (Darren Reed)
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Wed, 12 Dec 2001 21:17:33 +1100 (EST)

 further investigation reveals that .rhosts is opened as the user, or at
 least the code does do a seteuid() to that effect.


From: Brian Ginsbach <ginsbach@cray.com>
To: darrenr@netbsd.org
Cc: gnats-bugs@netbsd.org, lukem@netbsd.org
Subject: Re: bin/14880: rlogind doesn't work properly with home directory on NFS
Date: Fri, 5 Dec 2003 10:48:43 -0600

 --tThc/1wpZn/ma/RB
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 This appears to be caused by trying to read the .rhost file as root
 when root is mapped to a user that doesn't have read permissions
 on the remote.  The file is opened as the user but then read as
 root.  The effective uid is being restored to root too soon in
 iruserok_sa.  It needs to remain as the user until after
 __ivaliduser_sa() is called.

 Note, most of the implementations of iruserok* that I've looked
 at that were originally based on BSD code do not give up
 the user uid as euid until after __ivaliduser* is called.  That
 is a NFS home directory with a 600 .rhosts file works fine
 with Linux, Solaris, IRIX, and the Cray UNICOS family.

 Patch for current attached.
 -- 
 Brian Ginsbach                          Cray Inc.

 --tThc/1wpZn/ma/RB
 Content-Type: text/plain; charset=us-ascii
 Content-Description: rcmd.patch
 Content-Disposition: attachment; filename="rcmd.patch"

 Index: rcmd.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/net/rcmd.c,v
 retrieving revision 1.54
 diff -u -r1.54 rcmd.c
 --- rcmd.c	2003/10/13 14:22:20	1.54
 +++ rcmd.c	2003/12/05 16:21:11
 @@ -655,13 +655,12 @@
  	const char *ruser, *luser;
  {
  	struct sockaddr *sa;
 -	register char *cp;
  	struct stat sbuf;
  	struct passwd *pwd;
  	FILE *hostf;
  	uid_t uid;
  	gid_t gid;
 -	int first;
 +	int isvaliduser;
  	char pbuf[MAXPATHLEN];

  	_DIAGASSERT(raddr != NULL);
 @@ -671,9 +670,10 @@
  	/*LINTED const castaway*/
  	sa = (struct sockaddr *)(void *)raddr;

 -	first = 1;
 +	__rcmd_errstr = NULL;
 +
  	hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
 -again:
 +
  	if (hostf) {
  		if (__ivaliduser_sa(hostf, sa, (socklen_t)rlen, luser,
  		    ruser) == 0) {
 @@ -682,17 +682,19 @@
  		}
  		(void)fclose(hostf);
  	}
 -	if (first == 1 && (__check_rhosts_file || superuser)) {
 -		first = 0;
 +
 +	isvaliduser = -1;
 +	if (__check_rhosts_file || superuser) {
 +
  		if ((pwd = getpwnam(luser)) == NULL)
  			return (-1);
  		(void)strlcpy(pbuf, pwd->pw_dir, sizeof(pbuf));
  		(void)strlcat(pbuf, "/.rhosts", sizeof(pbuf));

  		/*
 -		 * Change effective uid while opening .rhosts.  If root and
 -		 * reading an NFS mounted file system, can't read files that
 -		 * are protected read/write owner only.
 +		 * Change effective uid while opening and reading .rhosts.
 +		 * If root and reading an NFS mounted file system, can't
 +		 * read files that are protected read/write owner only.
  		 */
  		uid = geteuid();
  		gid = getegid();
 @@ -700,35 +702,36 @@
  		initgroups(pwd->pw_name, pwd->pw_gid);
  		(void)seteuid(pwd->pw_uid);
  		hostf = fopen(pbuf, "r");
 -		(void)seteuid(uid);
 -		(void)setegid(gid);

 -		if (hostf == NULL)
 -			return (-1);
 -		/*
 -		 * If not a regular file, or is owned by someone other than
 -		 * user or root or if writable by anyone but the owner, quit.
 -		 */
 -		cp = NULL;
 -		if (lstat(pbuf, &sbuf) < 0)
 -			cp = ".rhosts lstat failed";
 -		else if (!S_ISREG(sbuf.st_mode))
 -			cp = ".rhosts not regular file";
 -		else if (fstat(fileno(hostf), &sbuf) < 0)
 -			cp = ".rhosts fstat failed";
 -		else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
 -			cp = "bad .rhosts owner";
 -		else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
 -			cp = ".rhosts writable by other than owner";
 -		/* If there were any problems, quit. */
 -		if (cp) {
 -			__rcmd_errstr = cp;
 +		if (hostf != NULL) {
 +			/*
 +			 * If not a regular file, or is owned by someone other
 +			 * than user or root or if writable by anyone but the
 +			 * owner, quit.
 +			 */
 +			if (lstat(pbuf, &sbuf) < 0)
 +				__rcmd_errstr = ".rhosts lstat failed";
 +			else if (!S_ISREG(sbuf.st_mode))
 +				__rcmd_errstr = ".rhosts not regular file";
 +			else if (fstat(fileno(hostf), &sbuf) < 0)
 +				__rcmd_errstr = ".rhosts fstat failed";
 +			else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
 +				__rcmd_errstr = "bad .rhosts owner";
 +			else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
 +				__rcmd_errstr =
 +					".rhosts writable by other than owner";
 +			else 
 +				isvaliduser =
 +				    __ivaliduser_sa(hostf, sa, (socklen_t)rlen,
 +						    luser, ruser);
 +
  			(void)fclose(hostf);
 -			return (-1);
  		}
 -		goto again;
 +		(void)seteuid(uid);
 +		(void)setegid(gid);
 +
  	}
 -	return (-1);
 +	return (isvaliduser);
  }

  /*

 --tThc/1wpZn/ma/RB--
State-Changed-From-To: open->closed 
State-Changed-By: lukem 
State-Changed-When: Tue Jan 27 11:47:58 UTC 2004 
State-Changed-Why:  
Patch from Brian Ginsbach <ginsbach@cray.com> appears to fix the problem, 
as confirmed by Darren (the submitter) 

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.