Published:
15 September 1999
Protect yourself against future threats.
-----BEGIN PGP SIGNED MESSAGE----- ========================================================================== AUSCERT External Security Bulletin Redistribution ESB-1999.145 -- FreeBSD-SA-99:05 fts library routine vulnerability 16 September 1999 =========================================================================== The FreeBSD Security Team has released the following advisory concerning a vulnerability in the fts library routine which causes it to produce a core file. A root process using the fts library may be coerced into producing a core file in a predictable location. If the kernel follows symlinks when producing a core (the vulnerability described in the FreeBSD-SA-99:04 [AusCERT ESB-1999.144] advisory), a user may create or overwrite an arbitrary file on the system. This vulnerability may allow local users to gain root access. - --------------------------BEGIN INCLUDED TEXT-------------------- - -----BEGIN PGP SIGNED MESSAGE----- ============================================================================= FreeBSD-SA-99:05 Security Advisory FreeBSD, Inc. Topic: fts library routine vulnerability Category: core Module: kernel Announced: 1999-09-15 Affects: FreeBSD 3.2 (and earlier) FreeBSD-current before the correction date. FreeBSD 3.2-stable before the correction date. Corrected: FreeBSD-3.3 RELEASE FreeBSD-current as of 1999/08/26 FreeBSD-3.2-stable as of 1999/08/26 The FreeBSD-3.3-RC series of releases are not affected. FreeBSD only: NO Patches: ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-99:05/ I. Background The fts library routines provide a convenient way for a program to walk a hierarchy of files. II. Problem Description The fts library functions had a buffer overflow in them where which would lead to a core dump when periodic ran the security checking scripts (or other scripts which traverse trees that can be controlled by users). periodic(3) should limit core size to zero to disable core dumps while it is executing commands, but does not do so. In addition, the kernel should not follow symbolic links. All three of these problems caused a situation where it was possible for an attacker could create or overwrite an arbitrary file on the system with a moderate degree of controll of its contents to cause a problem. III. Impact Local users could gain root access. IV. Workaround One can workaround this problem by preventing core dumps for periodic. This solution is less than completely satisfying, since it only plugs the known exploit hole. None the less, this may provide a short term stopgap solution until a new kernel and userland can be installed. # mv /usr/sbin/periodic /usr/sbin/periodic.bin # cat > /usr/sbin/periodic #!/bin/sh ulimit -c 0 /usr/sbin/periodic.bin $* ^D # chmod 555 /usr/sbin/periodic V. Solution Apply the following patches to libc and do a make world. Please also see the companion advisory FreeBSD-SA-99:04.core.asc in the advisories directory of our ftp site for details on the kernel portions of this fix. Index: lib/libc/gen/fts.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/gen/fts.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- fts.c 1999/08/15 19:21:29 1.10 +++ fts.c 1999/09/02 07:45:07 1.11 @@ -963,6 +963,24 @@ return (sp->fts_path == NULL); } +static void +ADJUST(p, addr) + FTSENT *p; + void *addr; +{ + if ((p)->fts_accpath >= (p)->fts_path && + (p)->fts_accpath < (p)->fts_path + (p)->fts_pathlen) { + if (p->fts_accpath != p->fts_path) + errx(1, "fts ADJUST: accpath %p path %p", + p->fts_accpath, p->fts_path); + if (p->fts_level != 0) + errx(1, "fts ADJUST: level %d not 0", p->fts_level); + (p)->fts_accpath = + (char *)addr + ((p)->fts_accpath - (p)->fts_path); + } + (p)->fts_path = addr; +} + /* * When the path is realloc'd, have to fix all of the pointers in structures * already returned. @@ -974,18 +992,18 @@ { FTSENT *p; -#define ADJUST(p) { - (p)->fts_accpath = - (char *)addr + ((p)->fts_accpath - (p)->fts_path); +#define ADJUST1(p) { + if ((p)->fts_accpath == (p)->fts_path) + (p)->fts_accpath = (addr); (p)->fts_path = addr; } /* Adjust the current set of children. */ for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); + ADJUST(p, addr); /* Adjust the rest of the tree. */ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); + ADJUST(p, addr); p = p->fts_link ? p->fts_link : p->fts_parent; } } ============================================================================= 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 Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface iQCVAwUBN+B9rFUuHi5z0oilAQHGYgP+IwrmdUBtCw1r8J/lt/wBrxH5wug70K1V t2graun2wIWvtkh+kmwKJP4tonzlxi/YhyqqATh4pFIZb5CUEtCR2/gcpHPwB4NX oNuIGGBtKftrrFnPf9aArFu/XFjrxyUPetYoXtfgGc5y6VlI6mupDnwt9oj34EeY VIb92qSfH+c= =tPng - -----END PGP SIGNATURE----- - --------------------------END INCLUDED TEXT-------------------- 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 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 updates to the original are made. If downloading at a later date, it is recommended that the bulletin is retrieved directly from the original authors 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: 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 PGP SIGNATURE----- Version: 2.6.3i Charset: noconv Comment: ftp://ftp.auscert.org.au/pub/auscert/AUSCERT_PGP.key iQCVAwUBN+dwOih9+71yA2DNAQG+WwQAlHa3NsHZfrvGda9or0Pdf5dbncQeAyG+ CMnmExKr+D+/ArLN6Jfss8h2iqYeOw7Z2jGy6QfQS5db4JRpyznku8qwq0ZT6Ebe HjEB4L7ivxp+H4vqQjq9t5g0F1M/BqXBTPfdmOyqQBuHjYaUPdg++KQBz69JcIo9 ufr0zepmUmE= =3YVB -----END PGP SIGNATURE-----