Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Mar 2006 13:12:28 +0100 (CET)
From:      Frank Behrens <frank@pinky.sax.de>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/94730: jail(8) should not set login name for session [patch]
Message-ID:  <200603201212.k2KCCSok002035@moon.behrens>
Resent-Message-ID: <200603201220.k2KCKIeI090635@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         94730
>Category:       bin
>Synopsis:       jail(8) should not set login name for session [patch]
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 20 12:20:18 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Frank Behrens
>Release:        FreeBSD 6.1-PRERELEASE-200602270917 i386
>Organization:
>Environment:
>Description:
If in jail(8) a user is supplied, the user is switched to with
setusercontext() call (see LOGIN_CLASS(3)). The flags are
LOGIN_SETALL & ~LOGIN_SETGROUP, which implies LOGIN_SETLOGIN.
In that case the login name for the session is set
(including parent/sibling programs), although only the jail 
command is run with different user.

Observed problem:
In system startup (via rc.conf) a jail was configured with
a restricted user (argument -u). This changed the login name 
for the current session running rc(8) and all further child sessions. 
All messages sent via wall(1) and mail(1) from later started
system daemons had the restricted user as sender, not
root as expected. getlogin(2) from these daemons did not
return root, but the restricted user.

The attached patch fixes this problem, it excludes
the flag LOGIN_SETLOGIN from setusercontext() in jail(8).

>How-To-Repeat:
# id -u
0
# logname
frank
# jail -u www / test 192.168.99.99 /bin/sh
$ logname
www
$ exit
# logname
www
>Fix:

--- jailsetlogin.diff begins here ---
Index: jail.c
===================================================================
RCS file: /data/freebsd/src/usr.sbin/jail/jail.c,v
retrieving revision 1.20.2.1
diff -u -r1.20.2.1 jail.c
--- jail.c	30 Jan 2006 00:38:37 -0000	1.20.2.1
+++ jail.c	20 Mar 2006 11:36:20 -0000
@@ -142,7 +142,7 @@
 		if (setgid(pwd->pw_gid) != 0)
 			err(1, "setgid");
 		if (setusercontext(lcap, pwd, pwd->pw_uid,
-		    LOGIN_SETALL & ~LOGIN_SETGROUP) != 0)
+		    LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN) != 0)
 			err(1, "setusercontext");
 		login_close(lcap);
 	}
--- jailsetlogin.diff ends here ---


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200603201212.k2KCCSok002035>