-----BEGIN PGP SIGNED MESSAGE----- =============================================================================== Security Advisory CERT-NL =============================================================================== Author/Source : Gert Meijerink Index : S-98-34 Distribution : World Page : 1 Classification: External Version: 1 Subject : FreeBSD security compromise via mmap Date : 05-Jun-98 =============================================================================== By courtesy of FreeBSD, Inc. we received information on a security compromise via mmap. It is possible to change the contents op append-only files. CERT-NL recommends to follow the FreeBSD recommendation, which is to apply the patch. ============================================================================== ============================================================================= 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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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. ============================================================================= ============================================================================== CERT-NL is the Computer Emergency Response Team for SURFnet customers. SURFnet is the Dutch network for educational, research and related institutes. CERT-NL is a member of the Forum of Incident Response and Security Teams (FIRST). All CERT-NL material is available under: http://www.surfnet.nl/surfnet/security/cert-nl.html ftp://ftp.surfnet.nl/surfnet/net-security In case of computer or network security problems please contact your local CERT/security-team or CERT-NL (if your institute is NOT a SURFnet customer please address the appropriate (local) CERT/security-team). CERT-NL is one/two hour(s) ahead of UTC (GMT) in winter/summer, i.e. UTC+0100 in winter and UTC+0200 in summer (DST). Email: cert-nl@surfnet.nl ATTENDED REGULARLY ALL DAYS Phone: +31 302 305 305 BUSINESS HOURS ONLY Fax: +31 302 305 329 BUSINESS HOURS ONLY Snailmail: SURFnet bv Attn. CERT-NL P.O. Box 19035 NL - 3501 DA UTRECHT The Netherlands NOODGEVALLEN: 06 52 87 92 82 ALTIJD BEREIKBAAR EMERGENCIES : +31 6 52 87 92 82 ATTENDED AT ALL TIMES CERT-NL'S EMERGENCY PHONENUMBER IS ONLY TO BE USED IN CASE OF EMERGENCIES: THE SURFNET HELPDESK OPERATING THE EMERGENCY NUMBER HAS A *FIXED* PROCEDURE FOR DEALING WITH YOUR ALERT AND WILL IN REGULAR CASES RELAY IT TO CERT-NL IN AN APPROPRIATE MANNER. CERT-NL WILL THEN CONTACT YOU. ============================================================================== -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: cp850 iQCVAwUBNXgEEVpSTqmIRWKVAQHwyQP+JmEAKiDPSc+6UC/SMdBw6YgJpyiDaBQ9 qIrjU8TVvvCSTfJIxQvNJVD/9iAC5Ob3XI9NEUl7WYv8lEA8y1aGqvgZnN99Oy+w Bd4cA13XRQwAcGTylHN9KgOkyvG3fRS3cJnepFt6DLruJLyC12dgSy49PexAzpnU 4dBtcOxZe2U= =qsis -----END PGP SIGNATURE-----