-----BEGIN PGP SIGNED MESSAGE----- [ For Public Release ] __________________________________________________________ The U.S. Department of Energy Computer Incident Advisory Capability ___ __ __ _ ___ / | /_\ / \___ __|__ / \ \___ __________________________________________________________ INFORMATION BULLETIN FreeBSD procfs Vulnerability August 26, 1997 23:00 GMT Number H-101 ______________________________________________________________________________ PROBLEM: A vulnerability exists in the procfs kernel code that allows processes to write to the memory space of other processes where it should have been prohibited. PLATFORM: FreeBSD 2.1.*, FreeBSD 2.2.*, FreeBSD-stable and FreeBSD-current before 1997/08/12. DAMAGE: Any users may gain root privileges. SOLUTION: Apply patches or workaround. ______________________________________________________________________________ VULNERABILITY CIAC recommends that you apply the patches in Section V if you ASSESSMENT: are running any of the affected versions of FreeBSD. ______________________________________________________________________________ [ Start FreeBSD Advisory ] ============================================================================= FreeBSD-SA-97:04 Security Advisory FreeBSD, Inc. Topic: security compromise via procfs Category: core Module: procfs Announced: 1997-08-19 Affects: FreeBSD 2.1.*, FreeBSD 2.2.*, FreeBSD-stable and FreeBSD-current before 1997/08/12 suffer from this problem. Corrected: FreeBSD-current as of 1997/08/12 FreeBSD-stable as of 1997/08/12 FreeBSD 2.1-stable as of 1997/08/25 FreeBSD only: no (also other BSD systems may be affected) Patches: ftp://freebsd.org/pub/CERT/patches/SA-97:04/ ============================================================================= I. Background Procfs provides a filesystem interface to processes on a system. Among others it is used by ps(1) and gdb(1). II. Problem Description A problem exists in the procfs kernel code that allows processes to write memory of other processes where it should have been prohibited. III. Impact The hole can be used by any user on the system to gain root privileges. IV. Workaround A workaround is to disable the mounting of procfs. To achieve this, edit the file /etc/fstab and put a '#' in front of the line proc /proc procfs rw 0 0 Note that when you do that, some utilities may either not work anymore or have a limited functionality. V. Solution Apply one of the following patches in /usr/src/sys/miscfs/procfs, rebuild your kernel, install it and reboot your system. For 2.1 and 2.2 systems: Index: procfs_regs.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_regs.c,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -u -r1.3 -r1.3.4.1 --- procfs_regs.c 1996/01/24 18:41:25 1.3 +++ procfs_regs.c 1997/08/12 04:45:25 1.3.4.1 @@ -36,7 +36,7 @@ * * @(#)procfs_regs.c 8.3 (Berkeley) 1/27/94 * - * $Id: procfs_regs.c,v 1.3 1996/01/24 18:41:25 peter Exp $ + * $Id: procfs_regs.c,v 1.3.4.1 1997/08/12 04:45:25 sef Exp $ */ #include @@ -62,6 +62,8 @@ char *kv; int kl; + if (!CHECKIO(curp, p)) + return EPERM; kl = sizeof(r); kv = (char *) &r; Index: procfs.h =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs.h,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- procfs.h 1996/07/02 13:38:07 1.12 +++ procfs.h 1997/08/12 04:45:20 1.12.2.1 @@ -36,7 +36,7 @@ * * @(#)procfs.h 8.6 (Berkeley) 2/3/94 * - * $Id: procfs.h,v 1.12 1996/07/02 13:38:07 dyson Exp $ + * $Id: procfs.h,v 1.12.2.1 1997/08/12 04:45:20 sef Exp $ */ /* @@ -83,6 +83,18 @@ (bcmp((s), (cnp)->cn_nameptr, (len)) == 0)) #define KMEM_GROUP 2 + +/* + * Check to see whether access to target process is allowed + * Evaluates to 1 if access is allowed. + */ +#define CHECKIO(p1, p2) \ + ((((p1)->p_cred->pc_ucred->cr_uid == (p2)->p_cred->p_ruid) && \ + ((p1)->p_cred->p_ruid == (p2)->p_cred->p_ruid) && \ + ((p1)->p_cred->p_svuid == (p2)->p_cred->p_ruid) && \ + ((p2)->p_flag & P_SUGID) == 0) || \ + (suser((p1)->p_cred->pc_ucred, &(p1)->p_acflag) == 0)) + /* * Format of a directory entry in /proc, ... * This must map onto struct dirent (see ) Index: procfs_mem.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_mem.c,v retrieving revision 1.20 retrieving revision 1.20.2.1 diff -u -r1.20 -r1.20.2.1 --- procfs_mem.c 1996/10/24 02:47:05 1.20 +++ procfs_mem.c 1997/08/12 04:45:23 1.20.2.1 @@ -37,7 +37,7 @@ * * @(#)procfs_mem.c 8.4 (Berkeley) 1/21/94 * - * $Id: procfs_mem.c,v 1.20 1996/10/24 02:47:05 dyson Exp $ + * $Id: procfs_mem.c,v 1.20.2.1 1997/08/12 04:45:23 sef Exp $ */ /* @@ -300,6 +300,23 @@ if (uio->uio_resid == 0) return (0); + /* + * XXX + * We need to check for KMEM_GROUP because ps is sgid kmem; + * not allowing it here causes ps to not work properly. Arguably, + * this is a bug with what ps does. We only need to do this + * for Pmem nodes, and only if it's reading. This is still not + * good, as it may still be possible to grab illicit data if + * a process somehow gets to be KMEM_GROUP. Note that this also + * means that KMEM_GROUP can't change without editing procfs.h! + * All in all, quite yucky. + */ + + if (!CHECKIO(curp, p) && + !(curp->p_cred->pc_ucred->cr_gid == KMEM_GROUP && + uio->uio_rw == UIO_READ)) + return EPERM; + error = procfs_rwmem(p, uio); return (error); Index: procfs_vnops.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_vnops.c,v retrieving revision 1.24 retrieving revision 1.24.2.1 diff -u -r1.24 -r1.24.2.1 --- procfs_vnops.c 1996/09/03 14:23:10 1.24 +++ procfs_vnops.c 1997/08/12 04:45:27 1.24.2.1 @@ -36,7 +36,7 @@ * * @(#)procfs_vnops.c 8.6 (Berkeley) 2/7/94 * - * $Id: procfs_vnops.c,v 1.24 1996/09/03 14:23:10 bde Exp $ + * $Id: procfs_vnops.c,v 1.24.2.1 1997/08/12 04:45:27 sef Exp $ */ /* @@ -120,16 +120,21 @@ struct vop_open_args *ap; { struct pfsnode *pfs = VTOPFS(ap->a_vp); + struct proc *p1 = ap->a_p, *p2 = PFIND(pfs->pfs_pid); + + if (p2 == NULL) + return ENOENT; switch (pfs->pfs_type) { case Pmem: - if (PFIND(pfs->pfs_pid) == 0) - return (ENOENT); /* was ESRCH, jsp */ - if (((pfs->pfs_flags & FWRITE) && (ap->a_mode & O_EXCL)) || ((pfs->pfs_flags & O_EXCL) && (ap->a_mode & FWRITE))) return (EBUSY); + if (!CHECKIO(p1, p2) && + (p1->p_cred->pc_ucred->cr_gid != KMEM_GROUP)) + return EPERM; + if (ap->a_mode & FWRITE) pfs->pfs_flags = ap->a_mode & (FWRITE|O_EXCL); @@ -176,7 +181,6 @@ procfs_ioctl(ap) struct vop_ioctl_args *ap; { - return (ENOTTY); } Index: procfs_fpregs.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_fpregs.c,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -u -r1.3 -r1.3.4.1 --- procfs_fpregs.c 1996/01/24 18:40:56 1.3 +++ procfs_fpregs.c 1997/08/12 05:24:20 1.3.4.1 @@ -36,7 +36,7 @@ * * @(#)procfs_fpregs.c 8.1 (Berkeley) 1/27/94 * - * $Id: procfs_fpregs.c,v 1.3 1996/01/24 18:40:56 peter Exp $ + * $Id: procfs_fpregs.c,v 1.3.4.1 1997/08/12 05:24:20 sef Exp $ */ #include @@ -62,6 +62,8 @@ char *kv; int kl; + if (!CHECKIO(curp, p)) + return EPERM; kl = sizeof(r); kv = (char *) &r; For FreeBSd-current systems: Index: procfs_regs.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_regs.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- procfs_regs.c 1997/08/02 14:32:16 1.7 +++ procfs_regs.c 1997/08/12 04:34:29 1.8 @@ -37,7 +37,7 @@ * @(#)procfs_regs.c 8.4 (Berkeley) 6/15/94 * * From: - * $Id: procfs_regs.c,v 1.7 1997/08/02 14:32:16 bde Exp $ + * $Id: procfs_regs.c,v 1.8 1997/08/12 04:34:29 sef Exp $ */ #include @@ -60,6 +60,8 @@ char *kv; int kl; + if (!CHECKIO(curp, p)) + return EPERM; kl = sizeof(r); kv = (char *) &r; Index: procfs.h =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- procfs.h 1997/02/22 09:40:26 1.15 +++ procfs.h 1997/08/12 04:34:27 1.16 @@ -37,7 +37,7 @@ * @(#)procfs.h 8.9 (Berkeley) 5/14/95 * * From: - * $Id: procfs.h,v 1.15 1997/02/22 09:40:26 peter Exp $ + * $Id: procfs.h,v 1.16 1997/08/12 04:34:27 sef Exp $ */ /* @@ -85,6 +85,18 @@ (bcmp((s), (cnp)->cn_nameptr, (len)) == 0)) #define KMEM_GROUP 2 + +/* + * Check to see whether access to target process is allowed + * Evaluates to 1 if access is allowed. + */ +#define CHECKIO(p1, p2) \ + ((((p1)->p_cred->pc_ucred->cr_uid == (p2)->p_cred->p_ruid) && \ + ((p1)->p_cred->p_ruid == (p2)->p_cred->p_ruid) && \ + ((p1)->p_cred->p_svuid == (p2)->p_cred->p_ruid) && \ + ((p2)->p_flag & P_SUGID) == 0) || \ + (suser((p1)->p_cred->pc_ucred, &(p1)->p_acflag) == 0)) + /* * Format of a directory entry in /proc, ... * This must map onto struct dirent (see ) Index: procfs_mem.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_mem.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- procfs_mem.c 1997/08/02 14:32:14 1.26 +++ procfs_mem.c 1997/08/12 04:34:28 1.27 @@ -37,7 +37,7 @@ * * @(#)procfs_mem.c 8.5 (Berkeley) 6/15/94 * - * $Id: procfs_mem.c,v 1.26 1997/08/02 14:32:14 bde Exp $ + * $Id: procfs_mem.c,v 1.27 1997/08/12 04:34:28 sef Exp $ */ /* @@ -276,6 +276,23 @@ if (uio->uio_resid == 0) return (0); + + /* + * XXX + * We need to check for KMEM_GROUP because ps is sgid kmem; + * not allowing it here causes ps to not work properly. Arguably, + * this is a bug with what ps does. We only need to do this + * for Pmem nodes, and only if it's reading. This is still not + * good, as it may still be possible to grab illicit data if + * a process somehow gets to be KMEM_GROUP. Note that this also + * means that KMEM_GROUP can't change without editing procfs.h! + * All in all, quite yucky. + */ + + if (!CHECKIO(curp, p) && + !(curp->p_cred->pc_ucred->cr_gid == KMEM_GROUP && + uio->uio_rw == UIO_READ)) + return EPERM; return (procfs_rwmem(p, uio)); } Index: procfs_vnops.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_vnops.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- procfs_vnops.c 1997/08/02 14:32:20 1.30 +++ procfs_vnops.c 1997/08/12 04:34:30 1.31 @@ -36,7 +36,7 @@ * * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 * - * $Id: procfs_vnops.c,v 1.30 1997/08/02 14:32:20 bde Exp $ + * $Id: procfs_vnops.c,v 1.31 1997/08/12 04:34:30 sef Exp $ */ /* @@ -127,16 +127,21 @@ } */ *ap; { struct pfsnode *pfs = VTOPFS(ap->a_vp); + struct proc *p1 = ap->a_p, *p2 = PFIND(pfs->pfs_pid); + + if (p2 == NULL) + return ENOENT; switch (pfs->pfs_type) { case Pmem: - if (PFIND(pfs->pfs_pid) == 0) - return (ENOENT); /* was ESRCH, jsp */ - if ((pfs->pfs_flags & FWRITE) && (ap->a_mode & O_EXCL) || (pfs->pfs_flags & O_EXCL) && (ap->a_mode & FWRITE)) return (EBUSY); + if (!CHECKIO(p1, p2) && + (p1->p_cred->pc_ucred->cr_gid != KMEM_GROUP)) + return EPERM; + if (ap->a_mode & FWRITE) pfs->pfs_flags = ap->a_mode & (FWRITE|O_EXCL); @@ -194,7 +199,6 @@ struct proc *a_p; } */ *ap; { - return (ENOTTY); } Index: procfs_fpregs.c =================================================================== RCS file: /home/cvsup/freebsd/CVS/src/sys/miscfs/procfs/procfs_fpregs.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- procfs_fpregs.c 1997/08/02 14:32:11 1.7 +++ procfs_fpregs.c 1997/08/12 05:23:51 1.8 @@ -37,7 +37,7 @@ * @(#)procfs_fpregs.c 8.2 (Berkeley) 6/15/94 * * From: - * $Id: procfs_fpregs.c,v 1.7 1997/08/02 14:32:11 bde Exp $ + * $Id: procfs_fpregs.c,v 1.8 1997/08/12 05:23:51 sef Exp $ */ #include @@ -60,6 +60,8 @@ char *kv; int kl; + if (!CHECKIO(curp, p)) + return EPERM; kl = sizeof(r); kv = (char *) &r; (These patches can also be found on ftp://freebsd.org/pub/CERT/patches/SA-97:04/) VI. Thanks This problem was brought to light by Brian Mitchell ============================================================================= FreeBSD, Inc. Web Site: http://www.freebsd.org/ Confidential contacts: security-officer@freebsd.org PGP Key: ftp://freebsd.org/pub/CERT/public_key.asc Security notifications: security-notifications@freebsd.org Security public discussion: security@freebsd.org 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. [ End FreeBSD Advisory ] ______________________________________________________________________________ CIAC wishes to acknowledge the contributions of FreeBSD for the information contained in this bulletin. ______________________________________________________________________________ CIAC, the Computer Incident Advisory Capability, is the computer security incident response team for the U.S. Department of Energy (DOE) and the emergency backup response team for the National Institutes of Health (NIH). CIAC is located at the Lawrence Livermore National Laboratory in Livermore, California. CIAC is also a founding member of FIRST, the Forum of Incident Response and Security Teams, a global organization established to foster cooperation and coordination among computer security teams worldwide. CIAC services are available to DOE, DOE contractors, and the NIH. CIAC can be contacted at: Voice: +1 510-422-8193 FAX: +1 510-423-8002 STU-III: +1 510-423-2604 E-mail: ciac@llnl.gov For emergencies and off-hour assistance, DOE, DOE contractor sites, and the NIH may contact CIAC 24-hours a day. During off hours (5PM - 8AM PST), call the CIAC voice number 510-422-8193 and leave a message, or call 800-759-7243 (800-SKY-PAGE) to send a Sky Page. CIAC has two Sky Page PIN numbers, the primary PIN number, 8550070, is for the CIAC duty person, and the secondary PIN number, 8550074 is for the CIAC Project Leader. Previous CIAC notices, anti-virus software, and other information are available from the CIAC Computer Security Archive. World Wide Web: http://ciac.llnl.gov/ Anonymous FTP: ciac.llnl.gov (198.128.39.53) Modem access: +1 (510) 423-4753 (28.8K baud) +1 (510) 423-3331 (28.8K baud) CIAC has several self-subscribing mailing lists for electronic publications: 1. CIAC-BULLETIN for Advisories, highest priority - time critical information and Bulletins, important computer security information; 2. CIAC-NOTES for Notes, a collection of computer security articles; 3. SPI-ANNOUNCE for official news about Security Profile Inspector (SPI) software updates, new features, distribution and availability; 4. SPI-NOTES, for discussion of problems and solutions regarding the use of SPI products. Our mailing lists are managed by a public domain software package called Majordomo, which ignores E-mail header subject lines. To subscribe (add yourself) to one of our mailing lists, send the following request as the E-mail message body, substituting ciac-bulletin, ciac-notes, spi-announce OR spi-notes for list-name: E-mail to ciac-listproc@llnl.gov or majordomo@tholia.llnl.gov: subscribe list-name e.g., subscribe ciac-notes You will receive an acknowledgment email immediately with a confirmation that you will need to mail back to the addresses above, as per the instructions in the email. This is a partial protection to make sure you are really the one who asked to be signed up for the list in question. If you include the word 'help' in the body of an email to the above address, it will also send back an information file on how to subscribe/unsubscribe, get past issues of CIAC bulletins via email, etc. PLEASE NOTE: Many users outside of the DOE, ESnet, and NIH computing communities receive CIAC bulletins. If you are not part of these communities, please contact your agency's response team to report incidents. Your agency's team will coordinate with CIAC. The Forum of Incident Response and Security Teams (FIRST) is a world-wide organization. A list of FIRST member organizations and their constituencies can be obtained via WWW at http://www.first.org/. This document was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government nor the University of California nor any of their employees, makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately owned rights. Reference herein to any specific commercial products, process, or service by trade name, trademark, manufacturer, or otherwise, does not necessarily constitute or imply its endorsement, recommendation or favoring by the United States Government or the University of California. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or the University of California, and shall not be used for advertising or product endorsement purposes. LAST 10 CIAC BULLETINS ISSUED (Previous bulletins available from CIAC) H-92: HP-UX X11/Motif Lib & Novell Netware Vulerabilities H-93: SGI IRIX ordist Buffer Overrun Vulnerability H-94: Vulnerability in ps H-95: Vulnerability in x-lock H-96: Vulnerability in Bind H-92a: HP-UX X11/Motif Lib and Novell Netware Vulnerabilities H-97: SGI IRIX ftpd Signal Handling Vulnerability H-98: SunOS automounter Vulnerability H-99: SunOS, Solaris ifconfig ioctls Vulnerability H-100: SunOS, Solaris libXt Vulnerability -----BEGIN PGP SIGNATURE----- Version: 4.0 Business Edition iQCVAwUBNAcO07nzJzdsy3QZAQEh/wP/ZPLWf9TqWShp/v+gHlJo9oySFAgtgsVR UqP14B5TsJKc9L6UXP2RO2znAiNppwrpoY7XFghFUfx9jbhLkXXsQheJYXl0h6Aj 6KfA7wVQQj1Hv00TznUfEPksBX2wNtPhEe+pcau+PlQbxT7J3DaVabUYTkfq3gc7 FJmR7+4/LTw= =rwi7 -----END PGP SIGNATURE-----