From nobody Fri May 19 21:37:42 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QNKvB68Fhz4CPlw; Fri, 19 May 2023 21:37:42 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QNKvB5g2pz3kC6; Fri, 19 May 2023 21:37:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684532262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WBsX3La9VvTm7KT4fBEQJLoM1IX+Nj51ERvJEpnFTLE=; b=fgWTAMwx2Nem7yvCypfsWOHVobI1QnnITs001F26lSueY7rNc/wno/rAx+c5HEKZLYqZAv DGb+JQgYjXIWwaEyvpNHRCcSIaBw8rQX/aoLDNV5aHKWVO8J9moDGaUA/zYoxbU2En5eXx e+F7K0iK1cbdzFDtCzPzmqqEAe8QjTcMqiFWzmRspV/kfzOuAuSi2EsvH+o0VXyA+ruwpR mNcbB/0bMUGMq6eCu9j8ra8r/8vdYXyWS8fQyc4gd6oR/aAtLoAZEPzeKQB/Xshu4v46Yt KFmCyTbDtnH+u91XYeGyfXFStfJozrcxZPUXCcoT6y/pcVUsbTsG3R4hcuYHew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684532262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WBsX3La9VvTm7KT4fBEQJLoM1IX+Nj51ERvJEpnFTLE=; b=ouvNSxF/z797ZtOKSIOe2ecJofTlQYgixQHwEtlqFtOIGs4pNNt3Z3PfocD+0FiNeewoF4 msC69/i3B39BJ3RrVNIDFjozvlHlGaFGxRfpXiyqs/2Tt21OyoffITzPbKW6iZ6mWr8Af4 FFZzqKha1m5ZGiasF26UDDPsKPu3Hp7QJXdqDOHc4dz8mSUPpEbdNcjMQ/S+lLFuSLz1eA n8twffa2PcnldBq4upyNkDFugb+FIrjqRGSK3nL8+mva1AWnz8mGRve3g3djN71MgEkbWj Eanm2xnVE4uDbi5R6bEkW1bFmVa/OABuX8d/8SiTfXHCb2THEbDSNoOlpQe1FA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684532262; a=rsa-sha256; cv=none; b=wWU3Pbhms1LYDCmgLUBr+MA0uKPRp4nqJ36QgVtyb5MqeMhuPcEkCnzHfo23gqpPZZ3DZg xuWt41eLOX/KPZqugsBCr+R3kh219llQEPTYp6cFlP/jUETwrCM/z9gjEmF9vvcMiyfRMY B1AijUBJr3SiAjtVrHRXHaM/6iruAS1T1PrIyJu+lKT7qEtPbLztFMIVF/TnSsWFTgBzTJ QMBOqEmeNKj/lY1fCfO2SQMXmcePcDmofU78w66PMEIxiwvo/evo38vbDI93r8NN6270NF w59mfeNWkDFj7ZUK4izvCOeXYK/H5zyeGGI2GJ52YTFLfE8WH8UyXzS/T51Fbg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QNKvB4hjczkNb; Fri, 19 May 2023 21:37:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34JLbggi034163; Fri, 19 May 2023 21:37:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34JLbgr9034162; Fri, 19 May 2023 21:37:42 GMT (envelope-from git) Date: Fri, 19 May 2023 21:37:42 GMT Message-Id: <202305192137.34JLbgr9034162@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 3866502e1817 - stable/13 - Revert "vfs_mount.c: Allow mountd(8) to do exports in a vnet prison" List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3866502e1817aa28446d5e103277583bde65670d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=3866502e1817aa28446d5e103277583bde65670d commit 3866502e1817aa28446d5e103277583bde65670d Author: Rick Macklem AuthorDate: 2023-05-19 21:36:52 +0000 Commit: Rick Macklem CommitDate: 2023-05-19 21:36:52 +0000 Revert "vfs_mount.c: Allow mountd(8) to do exports in a vnet prison" Revert this commit until I can figure out build issue. This reverts commit 527e6b02d65db8d6294b1e66f7bd063899a4de02. --- sys/kern/vfs_mount.c | 107 +++++++-------------------------------------------- 1 file changed, 14 insertions(+), 93 deletions(-) diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index e3a7ca50e792..4c941c2616ff 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -76,8 +76,7 @@ __FBSDID("$FreeBSD$"); #define VFS_MOUNTARG_SIZE_MAX (1024 * 64) static int vfs_domount(struct thread *td, const char *fstype, char *fspath, - uint64_t fsflags, bool jail_export, - struct vfsoptlist **optlist); + uint64_t fsflags, struct vfsoptlist **optlist); static void free_mntarg(struct mntarg *ma); static int usermount = 0; @@ -664,7 +663,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) struct vfsopt *opt, *tmp_opt; char *fstype, *fspath, *errmsg; int error, fstypelen, fspathlen, errmsg_len, errmsg_pos; - bool autoro, has_nonexport, jail_export; + bool autoro; errmsg = fspath = NULL; errmsg_len = fspathlen = 0; @@ -700,37 +699,15 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) goto bail; } - /* - * Check to see that "export" is only used with the "update", "fstype", - * "fspath", "from" and "errmsg" options when in a vnet jail. - * These are the ones used to set/update exports by mountd(8). - * If only the above options are set in a jail that can run mountd(8), - * then the jail_export argument of vfs_domount() will be true. - * When jail_export is true, the vfs_suser() check does not cause - * failure, but limits the update to exports only. - * This allows mountd(8) running within the vnet jail - * to export file systems visible within the jail, but - * mounted outside of the jail. - */ /* * We need to see if we have the "update" option * before we call vfs_domount(), since vfs_domount() has special * logic based on MNT_UPDATE. This is very important * when we want to update the root filesystem. */ - has_nonexport = false; - jail_export = false; TAILQ_FOREACH_SAFE(opt, optlist, link, tmp_opt) { int do_freeopt = 0; - if (jailed(td->td_ucred) && - strcmp(opt->name, "export") != 0 && - strcmp(opt->name, "update") != 0 && - strcmp(opt->name, "fstype") != 0 && - strcmp(opt->name, "fspath") != 0 && - strcmp(opt->name, "from") != 0 && - strcmp(opt->name, "errmsg") != 0) - has_nonexport = true; if (strcmp(opt->name, "update") == 0) { fsflags |= MNT_UPDATE; do_freeopt = 1; @@ -813,10 +790,9 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) fsflags |= MNT_SYNCHRONOUS; else if (strcmp(opt->name, "union") == 0) fsflags |= MNT_UNION; - else if (strcmp(opt->name, "export") == 0) { + else if (strcmp(opt->name, "export") == 0) fsflags |= MNT_EXPORTED; - jail_export = true; - } else if (strcmp(opt->name, "automounted") == 0) { + else if (strcmp(opt->name, "automounted") == 0) { fsflags |= MNT_AUTOMOUNTED; do_freeopt = 1; } else if (strcmp(opt->name, "nocover") == 0) { @@ -846,15 +822,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) goto bail; } - /* - * If has_nonexport is true or the caller is not running within a - * vnet prison that can run mountd(8), set jail_export false. - */ - if (has_nonexport || !jailed(td->td_ucred) || - !prison_check_nfsd(td->td_ucred)) - jail_export = false; - - error = vfs_domount(td, fstype, fspath, fsflags, jail_export, &optlist); + error = vfs_domount(td, fstype, fspath, fsflags, &optlist); if (error == ENOENT) { error = EINVAL; if (errmsg != NULL) @@ -872,8 +840,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) printf("%s: R/W mount failed, possibly R/O media," " trying R/O mount\n", __func__); fsflags |= MNT_RDONLY; - error = vfs_domount(td, fstype, fspath, fsflags, jail_export, - &optlist); + error = vfs_domount(td, fstype, fspath, fsflags, &optlist); } bail: /* copyout the errmsg */ @@ -1147,7 +1114,6 @@ vfs_domount_update( struct thread *td, /* Calling thread. */ struct vnode *vp, /* Mount point vnode. */ uint64_t fsflags, /* Flags common to all filesystems. */ - bool jail_export, /* Got export option in vnet prison. */ struct vfsoptlist **optlist /* Options local to the filesystem. */ ) { @@ -1159,7 +1125,6 @@ vfs_domount_update( int error, export_error, i, len; uint64_t flag; gid_t *grps; - bool vfs_suser_failed; ASSERT_VOP_ELOCKED(vp, __func__); KASSERT((fsflags & MNT_UPDATE) != 0, ("MNT_UPDATE should be here")); @@ -1188,20 +1153,7 @@ vfs_domount_update( * Only privileged root, or (if MNT_USER is set) the user that * did the original mount is permitted to update it. */ - /* - * For the case of mountd(8) doing exports in a jail, the vfs_suser() - * call does not cause failure. vfs_domount() has already checked - * that "root" is doing this and vfs_suser() will fail when - * the file system has been mounted outside the jail. - * jail_export set true indicates that "export" is not mixed - * with other options that change mount behaviour. - */ - vfs_suser_failed = false; error = vfs_suser(mp, td); - if (jail_export && error != 0) { - error = 0; - vfs_suser_failed = true; - } if (error != 0) { vput(vp); return (error); @@ -1231,26 +1183,11 @@ vfs_domount_update( error = EBUSY; goto end; } - if (vfs_suser_failed) { - KASSERT((fsflags & (MNT_EXPORTED | MNT_UPDATE)) == - (MNT_EXPORTED | MNT_UPDATE), - ("%s: jailed export did not set expected fsflags", - __func__)); - /* - * For this case, only MNT_UPDATE and - * MNT_EXPORTED have been set in fsflags - * by the options. Only set MNT_UPDATE, - * since that is the one that would be set - * when set in fsflags, below. - */ - mp->mnt_flag |= MNT_UPDATE; - } else { - mp->mnt_flag &= ~MNT_UPDATEMASK; - mp->mnt_flag |= fsflags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE | - MNT_SNAPSHOT | MNT_ROOTFS | MNT_UPDATEMASK | MNT_RDONLY); - if ((mp->mnt_flag & MNT_ASYNC) == 0) - mp->mnt_kern_flag &= ~MNTK_ASYNC; - } + mp->mnt_flag &= ~MNT_UPDATEMASK; + mp->mnt_flag |= fsflags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE | + MNT_SNAPSHOT | MNT_ROOTFS | MNT_UPDATEMASK | MNT_RDONLY); + if ((mp->mnt_flag & MNT_ASYNC) == 0) + mp->mnt_kern_flag &= ~MNTK_ASYNC; rootvp = vfs_cache_root_clear(mp); MNT_IUNLOCK(mp); mp->mnt_optnew = *optlist; @@ -1261,17 +1198,7 @@ vfs_domount_update( * XXX The final recipients of VFS_MOUNT just overwrite the ndp they * get. No freeing of cn_pnbuf. */ - /* - * For the case of mountd(8) doing exports from within a vnet jail, - * "from" is typically not set correctly such that VFS_MOUNT() will - * return ENOENT. It is not obvious that VFS_MOUNT() ever needs to be - * called when mountd is doing exports, but this check only applies to - * the specific case where it is running inside a vnet jail, to - * avoid any POLA violation. - */ - error = 0; - if (!jail_export) - error = VFS_MOUNT(mp); + error = VFS_MOUNT(mp); export_error = 0; /* Process the export option. */ @@ -1409,7 +1336,6 @@ vfs_domount( const char *fstype, /* Filesystem type. */ char *fspath, /* Mount path. */ uint64_t fsflags, /* Flags common to all filesystems. */ - bool jail_export, /* Got export option in vnet prison. */ struct vfsoptlist **optlist /* Options local to the filesystem. */ ) { @@ -1427,11 +1353,7 @@ vfs_domount( if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN) return (ENAMETOOLONG); - if (jail_export) { - error = priv_check(td, PRIV_NFS_DAEMON); - if (error) - return (error); - } else if (jailed(td->td_ucred) || usermount == 0) { + if (jailed(td->td_ucred) || usermount == 0) { if ((error = priv_check(td, PRIV_VFS_MOUNT)) != 0) return (error); } @@ -1512,8 +1434,7 @@ vfs_domount( } free(pathbuf, M_TEMP); } else - error = vfs_domount_update(td, vp, fsflags, jail_export, - optlist); + error = vfs_domount_update(td, vp, fsflags, optlist); out: NDFREE(&nd, NDF_ONLY_PNBUF);