From owner-svn-src-all@freebsd.org Tue Aug 11 01:34:41 2020 Return-Path: Delivered-To: svn-src-all@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 D838C3B3D92; Tue, 11 Aug 2020 01:34:41 +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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4BQb3j5Nk8z3Xxf; Tue, 11 Aug 2020 01:34:41 +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 9C21C1378E; Tue, 11 Aug 2020 01:34:41 +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 07B1YfZl052766; Tue, 11 Aug 2020 01:34:41 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07B1YfLQ052764; Tue, 11 Aug 2020 01:34:41 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202008110134.07B1YfLQ052764@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 11 Aug 2020 01:34:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364095 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 364095 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Aug 2020 01:34:41 -0000 Author: mjg Date: Tue Aug 11 01:34:40 2020 New Revision: 364095 URL: https://svnweb.freebsd.org/changeset/base/364095 Log: vfs: stricter validation for flags passed to namei in cn_flags namei de facto expects that the naimeidata object is properly initialized, but at the same time it mixes consumer-passable and internal flags, while tolerating this part by explicitly clearing some of them. Tighten the interface instead. While here renumber the flags and denote the gap between the 2 variants. Try to piggy back th renumber on the just bumped __FreeBSD_version. Modified: head/sys/kern/vfs_lookup.c head/sys/sys/namei.h Modified: head/sys/kern/vfs_lookup.c ============================================================================== --- head/sys/kern/vfs_lookup.c Tue Aug 11 01:09:06 2020 (r364094) +++ head/sys/kern/vfs_lookup.c Tue Aug 11 01:34:40 2020 (r364095) @@ -61,6 +61,9 @@ __FBSDID("$FreeBSD$"); #ifdef KTRACE #include #endif +#ifdef INVARIANTS +#include +#endif #include #include @@ -484,14 +487,14 @@ namei(struct nameidata *ndp) ("namei: nameiop contaminated with flags")); KASSERT((cnp->cn_flags & OPMASK) == 0, ("namei: flags contaminated with nameiops")); + KASSERT((cnp->cn_flags & NAMEI_INTERNAL_FLAGS) == 0, + ("namei: unexpected flags: %" PRIx64 "\n", + cnp->cn_flags & NAMEI_INTERNAL_FLAGS)); if (cnp->cn_flags & NOCACHE) KASSERT(cnp->cn_nameiop != LOOKUP, ("%s: NOCACHE passed with LOOKUP", __func__)); MPASS(ndp->ni_startdir == NULL || ndp->ni_startdir->v_type == VDIR || ndp->ni_startdir->v_type == VBAD); - - /* We will set this ourselves if we need it. */ - cnp->cn_flags &= ~TRAILINGSLASH; ndp->ni_lcf = 0; ndp->ni_vp = NULL; Modified: head/sys/sys/namei.h ============================================================================== --- head/sys/sys/namei.h Tue Aug 11 01:09:06 2020 (r364094) +++ head/sys/sys/namei.h Tue Aug 11 01:34:40 2020 (r364095) @@ -152,22 +152,31 @@ int cache_fplookup(struct nameidata *ndp, enum cache_f #define HASBUF 0x00000400 /* has allocated pathname buffer */ #define SAVENAME 0x00000800 /* save pathname buffer */ #define SAVESTART 0x00001000 /* save starting directory */ -#define ISDOTDOT 0x00002000 /* current component name is .. */ -#define MAKEENTRY 0x00004000 /* entry is to be added to name cache */ -#define ISLASTCN 0x00008000 /* this is last component of pathname */ -#define ISSYMLINK 0x00010000 /* symlink needs interpretation */ -#define ISWHITEOUT 0x00020000 /* found whiteout */ -#define DOWHITEOUT 0x00040000 /* do whiteouts */ -#define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */ -#define ISOPEN 0x00200000 /* caller is opening; return a real vnode. */ -#define NOCROSSMOUNT 0x00400000 /* do not cross mount points */ -#define NOMACCHECK 0x00800000 /* do not perform MAC checks */ -#define AUDITVNODE1 0x04000000 /* audit the looked up vnode information */ -#define AUDITVNODE2 0x08000000 /* audit the looked up vnode information */ -#define TRAILINGSLASH 0x10000000 /* path ended in a slash */ -#define NOCAPCHECK 0x20000000 /* do not perform capability checks */ -#define NOEXECCHECK 0x40000000 /* do not perform exec check on dir */ +#define ISWHITEOUT 0x00002000 /* found whiteout */ +#define DOWHITEOUT 0x00004000 /* do whiteouts */ +#define WILLBEDIR 0x00008000 /* new files will be dirs; allow trailing / */ +#define ISOPEN 0x00010000 /* caller is opening; return a real vnode. */ +#define NOCROSSMOUNT 0x00020000 /* do not cross mount points */ +#define NOMACCHECK 0x00040000 /* do not perform MAC checks */ +#define AUDITVNODE1 0x00080000 /* audit the looked up vnode information */ +#define AUDITVNODE2 0x00100000 /* audit the looked up vnode information */ +#define NOCAPCHECK 0x00200000 /* do not perform capability checks */ +/* UNUSED 0x00400000 */ +/* UNUSED 0x00800000 */ +/* UNUSED 0x01000000 */ +#define NOEXECCHECK 0x02000000 /* do not perform exec check on dir */ +#define MAKEENTRY 0x04000000 /* entry is to be added to name cache */ +#define ISSYMLINK 0x08000000 /* symlink needs interpretation */ +#define ISLASTCN 0x10000000 /* this is last component of pathname */ +#define ISDOTDOT 0x20000000 /* current component name is .. */ +#define TRAILINGSLASH 0x40000000 /* path ended in a slash */ #define PARAMASK 0x7ffffe00 /* mask of parameter descriptors */ + +/* + * Flags which must not be passed in by callers. + */ +#define NAMEI_INTERNAL_FLAGS \ + (NOEXECCHECK | MAKEENTRY | ISSYMLINK | ISLASTCN | ISDOTDOT | TRAILINGSLASH) /* * Namei results flags