Operating System:

Published:

04 January 1998

Protect yourself against future threats.

-----BEGIN PGP SIGNED MESSAGE-----

===========================================================================
              AUSCERT External Security Bulletin Redistribution

                             
       ESB-98.087 -- FreeBSD Security Advisory - FreeBSD-SA-98:04.mmap
                        security compromise via mmap
                              05 Jun 1998

===========================================================================

The FreeBSD Security Team has released the following advisory concerning a 
security compromise via mmap which makes it possible to change the contents of 
append-only files.

The following security bulletin is provided as a service to AusCERT's
members.  As AusCERT did not write this document, AusCERT has had no
control over its content.  As such, the decision to use any or all of this
information is the responsibility of each user or organisation, and should
be done so in accordance with site policies and procedures.

NOTE: This is only the original release of the security bulletin.  It will
not be updated when the original bulletin is.  If downloading at a later
date, it is recommended that the bulletin is retrieved from the original
authors to ensure that the information is still current.

Contact information for FreeBSD is included in the Security Bulletin below.  
If you have any questions or need further information, please contact them 
directly.

Previous advisories and external security bulletins can be retrieved from:

	http://www.auscert.org.au/Information/advisories.html

If you believe that your system has been compromised, contact AusCERT or
your representative in FIRST (Forum of Incident Response and Security
Teams).

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 emergencies.


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

- -----BEGIN PGP SIGNED MESSAGE-----

=============================================================================
FreeBSD-SA-98:04                                            Security Advisory
                                                                FreeBSD, Inc.

Topic:          security compromise via mmap

Category:       core
Module:         kernel
Announced:      1998-06-02
Affects:        FreeBSD 2.2.*, FreeBSD-stable before 1998/05/24
		and FreeBSD-current before 1998/05/19 suffer from
		this problem.
Corrected:      FreeBSD-current as of 1998/05/19
		FreeBSD-stable as of 1998/05/24
FreeBSD only:   no (also other 4.4BSD based systems may be affected)

Patches:        ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-98:04/

=============================================================================
IMPORTANT MESSAGE: The FreeBSD security officer now uses the policy
ftp://freebsd.org/pub/CERT to ftp://ftp.freebsd.org/pub/FreeBSD/POLICY
for sending out advisories.
=============================================================================

I.   Background    

     The 4.4BSD VM system allows files to be "memory mapped", which
     causes the specified contents of a file to be made available
     to a process via its address space. Manipulations of that file
     can then be performed simply by manipulating memory, rather
     than using filesystem I/O calls.  This technique is used to
     simplify code, speed up access to files, and provide interprocess
     communication.

     In 4.4BSD, 4 new FFS flags were added that give the possibility
     to mark files as append-only or immutable.

II.  Problem Description

     It is possible for a process to open an append-only file
     according to the limitations of the flags, and then mmap the
     file shared with write permission even when the file is marked
     as append-only or immutable. This circumvents the concept of
     the the append-only flag.

III. Impact
     
     It is possible to change the contents of append-only files.

IV.  Workaround

     No workaround is known.

V.   Solution


     Apply one of the following patches, rebuild your kernel,
     install it and reboot your system.

     The patches below can be found on
	ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-98:04/

     NOTE: Users of FreeBSD 2.2.5 or FreeBSD-current or FreeBSD-stable
     dated before 1998/03/12 will need to apply the patch mentioned in
     FreeBSD advisory SA-98:02.


     Patch for 3.0-current systems:

  Index: vm_mmap.c
  ===================================================================
  RCS file: /home/cvsup/freebsd/CVS/src/sys/vm/vm_mmap.c,v
  retrieving revision 1.75
  retrieving revision 1.77
  diff -u -r1.75 -r1.77
  --- vm_mmap.c	1998/03/12 19:36:18	1.75
  +++ vm_mmap.c	1998/05/19 07:13:21	1.77
  @@ -58,6 +58,7 @@
   #include <sys/file.h>
   #include <sys/mman.h>
   #include <sys/conf.h>
  +#include <sys/stat.h>
   #include <sys/vmmeter.h>
   
   #include <miscfs/specfs/specdev.h>
  @@ -295,12 +296,25 @@
   			 * we're at securelevel < 1, to allow the XIG X server
   			 * to continue to work.
   			 */
  -			if (((flags & MAP_SHARED) != 0 ||
  -				(vp->v_type == VCHR && disablexworkaround)) &&
  -				(fp->f_flag & FWRITE) == 0 && (prot & PROT_WRITE) != 0)
  -				return (EACCES);
  -			else
  +
  +			if ((flags & MAP_SHARED) != 0 ||
  +			    (vp->v_type == VCHR && disablexworkaround)) {
  +				if ((fp->f_flag & FWRITE) != 0) {
  +					struct vattr va;
  +					if ((error =
  +					    VOP_GETATTR(vp, &va,
  +						        p->p_ucred, p)))
  +						return (error);
  +					if ((va.va_flags &
  +					    (IMMUTABLE|APPEND)) == 0)
  +						maxprot |= VM_PROT_WRITE;
  +					else if (prot & PROT_WRITE)
  +						return (EPERM);
  +				} else if ((prot & PROT_WRITE) != 0)
  +					return (EACCES);
  +			} else
   				maxprot |= VM_PROT_WRITE;
  +
   			handle = (void *)vp;
   		}
   	}

     Patch for 2.2 systems:

  Index: vm_mmap.c
  ===================================================================
  RCS file: /home/cvsup/freebsd/CVS/src/sys/vm/vm_mmap.c,v
  retrieving revision 1.53.2.3
  retrieving revision 1.53.2.4
  diff -u -r1.53.2.3 -r1.53.2.4
  --- vm_mmap.c	1998/03/12 19:36:50	1.53.2.3
  +++ vm_mmap.c	1998/05/24 19:47:02	1.53.2.4
  @@ -57,6 +57,7 @@
   #include <sys/file.h>
   #include <sys/mman.h>
   #include <sys/conf.h>
  +#include <sys/stat.h>
   #include <sys/vmmeter.h>
   
   #include <miscfs/specfs/specdev.h>
  @@ -275,12 +276,26 @@
   			 * we're at securelevel < 1, to allow the XIG X server
   			 * to continue to work.
   			 */
  -			if (((flags & MAP_SHARED) != 0 ||
  -				(vp->v_type == VCHR && disablexworkaround)) &&
  -				(fp->f_flag & FWRITE) == 0 && (prot & PROT_WRITE) != 0)
  -				return (EACCES);
  -			else
  +
  +			if ((flags & MAP_SHARED) != 0 ||
  +			    (vp->v_type == VCHR && disablexworkaround)) {
  +				if ((fp->f_flag & FWRITE) != 0) {
  +					struct vattr va;
  +
  +					if ((error =
  +					    VOP_GETATTR(vp, &va,
  +						        p->p_ucred, p)))
  +						return (error);
  +					if ((va.va_flags &
  +					    (IMMUTABLE|APPEND)) == 0)
  +						maxprot |= VM_PROT_WRITE;
  +					else if (prot & PROT_WRITE)
  +						return (EPERM);
  +				} else if ((prot & PROT_WRITE) != 0)
  +					return (EACCES);
  +			} else
   				maxprot |= VM_PROT_WRITE;
  +
   			handle = (caddr_t) vp;
   		}
   	}

VI.   Thanks

     This advisory is based on NetBSD Security Advisory 1998-003.
     In porting the NetBSD patch, we accidentally mentioned that we
     obtained the patch from OpenBSD, which was evidently wrong.
     
=============================================================================
FreeBSD, Inc.

Web Site:                       http://www.freebsd.org/
Confidential contacts:          security-officer@freebsd.org
Security notifications:         security-notifications@freebsd.org
Security public discussion:     freebsd-security@freebsd.org
PGP Key:                ftp://ftp.freebsd.org/pub/FreeBSD/CERT/public_key.asc

Notice: Any patches in this document may not apply cleanly due to
        modifications caused by digital signature or mailer software.
        Please reference the URL listed at the top of this document
        for original copies of all patches if necessary.
=============================================================================

- -----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBNXWJC1UuHi5z0oilAQG3nAP9GjmOtlc1WxPJjcbRwvXmKzhRInCfuVTL
f5k7dAyFmUmo6wnyQwsBoQUsa7d/kS0YCnfTIkFYrGkFvBa8hnw/i9VVdMFaUFFV
kTo6YLQfgG35znTxftACAs4uzjeRbh/6dr1YsERYxWNW0PabKbYfjMQapmY5GUVm
px3WF/jRI5k=
=Umgx
- -----END PGP SIGNATURE-----

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

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: noconv
Comment: ftp://ftp.auscert.org.au/pub/auscert/AUSCERT_PGP.key

iQCVAwUBNX5tuCh9+71yA2DNAQERoQP/TgfalF3gomwxus5BOLt2He+pE38xXmos
lgEypqKxUYaVYM7BWfIWuXU+tQQPWGjwAvFDGgGrexVtY9FI95/AZ4jCI+ZBSCEM
BaNHyx7Kxvs8uEU9x5fTEGr9V8D5DHhR36nn2OfV5Cu6Z1WNL/U6ikO6J4viJdCG
JfQS+mPNbyA=
=LvdP
-----END PGP SIGNATURE-----