Operating System:



12 January 2007

Protect yourself against future threats.

Hash: SHA1

             AUSCERT External Security Bulletin Redistribution

                        ESB-2007.0026 -- [FreeBSD]
                   Jail rc.d script privilege escalation
                              12 January 2007


        AusCERT Security Bulletin Summary

Product:              jail(2)
Publisher:            FreeBSD
Operating System:     FreeBSD
Impact:               Increased Privileges
                      Root Compromise
Access:               Existing Account
CVE Names:            CVE-2007-0166

Original Bulletin:    

Revision History:  August   7 2007: New corrected patch for FreeBSD 5.x
                   January 12 2007: Initial Release

- --------------------------BEGIN INCLUDED TEXT--------------------

Hash: SHA1

FreeBSD-SA-07:01.jail                                       Security Advisory
                                                          The FreeBSD Project

Topic:          Jail rc.d script privilege escalation

Category:       core
Module:         etc_rc.d
Announced:      2007-01-11
Credits:        Dirk Engling
Affects:        All FreeBSD releases since 5.3
Corrected:      2007-01-11 18:16:58 UTC (RELENG_6, 6.2-STABLE)
                2007-01-11 18:17:24 UTC (RELENG_6_2, 6.2-RELEASE)
                2007-01-11 18:18:08 UTC (RELENG_6_1, 6.1-RELEASE-p12)
                2007-01-11 18:18:35 UTC (RELENG_6_0, 6.0-RELEASE-p17)
                2007-08-01 20:47:13 UTC (RELENG_5, 5.5-STABLE)
                2007-08-01 20:48:19 UTC (RELENG_5_5, 5.5-RELEASE-p15)
CVE Name:       CVE-2007-0166

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

0.   Revision History

v1.0 2007-01-11  Initial release.
v1.1 2007-08-01  Corrected patch for FreeBSD 5.5.

I.   Background

The jail(2) system call allows a system administrator to lock a process
and all of its descendants inside an environment with a very limited
ability to affect the system outside that environment, even for
processes with superuser privileges.  It is an extension of, but
far more powerful than, the traditional UNIX chroot(2) system call.

The host's jail rc.d(8) script can be used to start and stop jails
automatically on system boot/shutdown.

II.  Problem Description

In multiple situations the host's jail rc.d(8) script does not check if
a path inside the jail file system structure is a symbolic link before
using the path.  In particular this is the case when writing the
output from the jail start-up to /var/log/console.log and when
mounting and unmounting file systems inside the jail directory

III. Impact

Due to the lack of handling of potential symbolic links the host's jail
rc.d(8) script is vulnerable to "symlink attacks".  By replacing
/var/log/console.log inside the jail with a symbolic link it is
possible for the superuser (root) inside the jail to overwrite files
on the host system outside the jail with arbitrary content.  This in
turn can be used to execute arbitrary commands with non-jailed
superuser privileges.

Similarly, by changing directory mount points inside the jail file
system structure into symbolic links, it may be possible for a jailed
attacker to mount file systems which were meant to be mounted inside
the jail at arbitrary points in the host file system structure, or to
unmount arbitrary file systems on the host system.

NOTE WELL: The above vulnerabilities occur only when a jail is being
started or stopped using the host's jail rc.d(8) script; once started
(and until stopped), running jails cannot exploit this.

IV.  Workaround

If the sysctl(8) variable security.jail.chflags_allowed is set to 0
(the default), setting the "sunlnk" system flag on /var, /var/log,
/var/log/console.log, and all file system mount points and their
parent directories inside the jail(s) will ensure that the console
log file and mount points are not replaced by symbolic links.  If
this is done while jails are running, the administrator must check
that an attacker has not replaced any directories with symlinks
after setting the "sunlnk" flag.

V.   Solution

NOTE WELL: The solution described changes the default location of the
"console.log" for jails from /var/log/console.log inside each jail to
/var/log/jail_${jail_name}_console.log on host system.  If this is a
problem, it may be possible to create a hard link from the new position
of the console log file to a location inside the jail.  A new rc.conf(5)
variable, jail_${jail_name}_consolelog, can be used to change the
location of console.log files on a per-jail basis.

In addition, the solution described below does not fully secure jail
configurations where two jails have overlapping directory trees and a
file system is mounted inside the overlap.  Overlapping directory
trees can occur when jails share the same root directory; when a jail
has a root directory which is a subdirectory of another jail's root
directory; or when a part of the file system space of one jail is
mounted inside the file system space of another jail, e.g., using
nullfs or unionfs.

To handle overlapping jails safely the administrator must set the
sysctl(8) variable security.jail.chflags_allowed to 0 (the default)
and manually set the "sunlnk" file/directory flag on all mount points
and all parent directories of mount points.  If this is done while
jails are running, the adminstrator must check that an attacker has
not replaced any directories with symlinks after setting the "sunlnk"

Perform one of the following:

1) Upgrade your vulnerable system to 5-STABLE, or 6-STABLE, or to the
RELENG_6_1, RELENG_6_0, or RELENG_5_5 security branch dated after the
correction date.

2) To patch your present system:

The following patches have been verified to apply to FreeBSD 5.5, 6.0,
and 6.1 systems.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

[FreeBSD 5.5]
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail5.patch
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail5.patch.asc

[FreeBSD 6.0]
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail60.patch
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail60.patch.asc

[FreeBSD 6.1]
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail61.patch
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail61.patch.asc

NOTE: The patch distributed at the time of the original advisory was
incorrect for FreeBSD 5.5 (both RELENG_5 and RELENG_5_5).  Systems to
which the original patch was applied should be patched with the
following corrective patch, which contains only the changes between
the original and updated patch:

# fetch http://security.FreeBSD.org/patches/SA-07:01/jail5-correction.patch
# fetch http://security.FreeBSD.org/patches/SA-07:01/jail5-correction.patch.asc

b) Execute the following commands as root:

# cd /usr/src
# patch < /path/to/patch
# install -o root -g wheel -m 555 etc/rc.d/jail /etc/rc.d

VI.  Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

Branch                                                           Revision
- - -------------------------------------------------------------------------
  src/UPDATING                                            1.342.
  src/UPDATING                                             1.416.
  src/UPDATING                                            1.416.
  src/UPDATING                                             1.416.
- - -------------------------------------------------------------------------

VII. References


The latest revision of this advisory is available at
Version: GnuPG v1.4.7 (FreeBSD)


- --------------------------END INCLUDED TEXT--------------------

You have received this e-mail bulletin as a result of your organisation's
registration with AusCERT. The mailing list you are subscribed to is
maintained within your organisation, so if you do not wish to continue
receiving these bulletins you should contact your local IT manager. If
you do not know who that is, please send an email to auscert@auscert.org.au
and we will forward your request to the appropriate person.

NOTE: Third Party Rights
This security bulletin is provided as a service to AusCERT's members.  As
AusCERT did not write the document quoted above, AusCERT has had no control
over its content. The decision to follow or act on information or advice
contained in this security bulletin is the responsibility of each user or
organisation, and should be considered in accordance with your organisation's
site policies and procedures. AusCERT takes no responsibility for consequences
which may arise from following or acting on information or advice contained in
this security bulletin.

NOTE: This is only the original release of the security bulletin.  It may
not be updated when updates to the original are made.  If downloading at
a later date, it is recommended that the bulletin is retrieved directly
from the author's website to ensure that the information is still current.

Contact information for the authors of the original document is included
in the Security Bulletin above.  If you have any questions or need further
information, please contact them directly.

Previous advisories and external security bulletins can be retrieved from:


If you believe that your computer system has been compromised or attacked in 
any way, we encourage you to let us know by completing the secure National IT 
Incident Reporting Form at:


Australian Computer Emergency Response Team
The University of Queensland
Qld 4072

Internet Email: auscert@auscert.org.au
Facsimile:      (07) 3365 7031
Telephone:      (07) 3365 4417 (International: +61 7 3365 4417)
                AusCERT personnel answer during Queensland business hours
                which are GMT+10:00 (AEST).
                On call after hours for member emergencies only.

Comment: http://www.auscert.org.au/render.html?it=1967