From owner-svn-src-head@freebsd.org Fri Feb 21 01:40:22 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 045C924D0F3; Fri, 21 Feb 2020 01:40:22 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48NvKd5GQjz3JjX; Fri, 21 Feb 2020 01:40:21 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5DEBA30C8; Fri, 21 Feb 2020 01:40:21 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01L1eLMT059176; Fri, 21 Feb 2020 01:40:21 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01L1eLah059175; Fri, 21 Feb 2020 01:40:21 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202002210140.01L1eLah059175@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 21 Feb 2020 01:40:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358190 - head/sys/security/audit X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/security/audit X-SVN-Commit-Revision: 358190 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Feb 2020 01:40:22 -0000 Author: mjg Date: Fri Feb 21 01:40:20 2020 New Revision: 358190 URL: https://svnweb.freebsd.org/changeset/base/358190 Log: audit: simplify path resolving logic Modified: head/sys/security/audit/audit_bsm_klib.c Modified: head/sys/security/audit/audit_bsm_klib.c ============================================================================== --- head/sys/security/audit/audit_bsm_klib.c Fri Feb 21 01:39:51 2020 (r358189) +++ head/sys/security/audit/audit_bsm_klib.c Fri Feb 21 01:40:20 2020 (r358190) @@ -423,50 +423,34 @@ auditon_command_event(int cmd) void audit_canon_path(struct thread *td, int dirfd, char *path, char *cpath) { - struct vnode *cvnp, *rvnp; + struct vnode *vp; char *rbuf, *fbuf, *copy; struct filedesc *fdp; struct sbuf sbf; cap_rights_t rights; - int error, needslash; + int error; WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s: at %s:%d", __func__, __FILE__, __LINE__); copy = path; - rvnp = cvnp = NULL; fdp = td->td_proc->p_fd; FILEDESC_SLOCK(fdp); - /* - * Make sure that we handle the chroot(2) case. If there is an - * alternate root directory, prepend it to the audited pathname. - */ - if (fdp->fd_rdir != NULL && fdp->fd_rdir != rootvnode) { - rvnp = fdp->fd_rdir; - vrefact(rvnp); - } - /* - * If the supplied path is relative, make sure we capture the current - * working directory so we can prepend it to the supplied relative - * path. - */ - if (*path != '/') { + if (*path == '/') { + vp = fdp->fd_rdir; + vrefact(vp); + } else { if (dirfd == AT_FDCWD) { - cvnp = fdp->fd_cdir; - vrefact(cvnp); + vp = fdp->fd_cdir; + vrefact(vp); } else { - error = fgetvp(td, dirfd, cap_rights_init(&rights), &cvnp); - if (error) { + error = fgetvp(td, dirfd, cap_rights_init(&rights), &vp); + if (error != 0) { FILEDESC_SUNLOCK(fdp); cpath[0] = '\0'; - if (rvnp != NULL) - vrele(rvnp); return; } } - needslash = (fdp->fd_rdir != cvnp); - } else { - needslash = 1; } FILEDESC_SUNLOCK(fdp); /* @@ -476,6 +460,8 @@ audit_canon_path(struct thread *td, int dirfd, char *p (void) sbuf_new(&sbf, cpath, MAXPATHLEN, SBUF_FIXEDLEN); /* * Strip leading forward slashes. + * + * Note this does nothing to fully canonicalize the path. */ while (*copy == '/') copy++; @@ -487,35 +473,26 @@ audit_canon_path(struct thread *td, int dirfd, char *p * on Darwin. As a result, this may need some additional attention * in the future. */ - if (rvnp != NULL) { - error = vn_fullpath_global(td, rvnp, &rbuf, &fbuf); - vrele(rvnp); - if (error) { - cpath[0] = '\0'; - if (cvnp != NULL) - vrele(cvnp); - return; - } - (void) sbuf_cat(&sbf, rbuf); - free(fbuf, M_TEMP); + error = vn_fullpath_global(td, vp, &rbuf, &fbuf); + vrele(vp); + if (error) { + cpath[0] = '\0'; + return; } - if (cvnp != NULL) { - error = vn_fullpath(td, cvnp, &rbuf, &fbuf); - vrele(cvnp); - if (error) { - cpath[0] = '\0'; - return; - } - (void) sbuf_cat(&sbf, rbuf); - free(fbuf, M_TEMP); - } - if (needslash) + (void) sbuf_cat(&sbf, rbuf); + /* + * We are going to concatenate the resolved path with the passed path + * with all slashes removed and we want them glued with a single slash. + * However, if the directory is /, the slash is already there. + */ + if (rbuf[1] != '\0') (void) sbuf_putc(&sbf, '/'); + free(fbuf, M_TEMP); /* * Now that we have processed any alternate root and relative path * names, add the supplied pathname. */ - (void) sbuf_cat(&sbf, copy); + (void) sbuf_cat(&sbf, copy); /* * One or more of the previous sbuf operations could have resulted in * the supplied buffer being overflowed. Check to see if this is the