From nobody Wed May 17 22:15:17 2023 X-Original-To: dev-commits-src-all@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 4QM6qW5GB2z4BfYm; Wed, 17 May 2023 22:15:19 +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 4QM6qW3CNTz3Jvt; Wed, 17 May 2023 22:15:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684361719; 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=86ciIEOLxugLtQ335v8gIJVz/vrc1TJVCk4W5phxhH0=; b=jHP1cjFNbXKJqmDV11o/sh2zGHkrPgY3SnzcDm9ypD9YsAZ8Y/ggkdX2/0rnzEhehaewGS UzfBo04U6XquXOf9WF7UMcT/a58LmqUdCQVtHoi+cq34M5tJfBmh4KJA20rrr2GBMJRDD7 4OJNBn6b8sahJZic37pZE+nfoZlPFbQlrdnNKdo732oioDscW1jbzrdcc1gMsPISsEZdlA KK345lHRCE5PphHQ7loJQIVHu+awZB5k4FwsTCFBBVH6IHFGG9NeQ709C0HuEA+3FfSE7e 1eKMOIq7obU3grTvqeSAB9+KwhamKBDUjFSAStOdyVCHSCLiLoxIDjW6RB65cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684361719; 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=86ciIEOLxugLtQ335v8gIJVz/vrc1TJVCk4W5phxhH0=; b=rdqvae/P70L+vPVclx8p4JICoaBvt+Ql46C7ZaNRxL/F7Cyv4yUhYpoje/qWPKmZOuzYgE 8r9hxAbLlP2DCU/OzMlM3YFzVaudsBgioJ/seOIbehOYLg3gV2zRwB3iJvYwCDGeSadCtB KNPDShEAc9Gtk2oYcAMywYUGWbZ4i83auegLVDH7PI8O4sq42yX82lTXtENnt7opZTmAIK 8PpeLT/QcW6MgYbYZ1QNPfDfNbvJCsUmFSb2H8Ff0kmEF95tvYiM9zn9HRIs2/lMQ0nIHC 1zBJc60vUwXKBx+VX1wG+MJsVd14zS0mmCAu3G/v9zG85U/Kh4+sSoUB/ogXvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684361719; a=rsa-sha256; cv=none; b=NJJVc9pO7ETfF4QOIILqlI8481n3JL1vm6lWjZi4G4UxeWRjbPsd4X1ZtnwUqNxN336y03 2zH0nCPYQ1Y5QKwMlljcWvSR5+E0aAndIXBFawu9uvnjrL5FmqEeiYAcTAmuJhquMXCy85 6lpmOO0kayAK+xWCM04xSj08m9iT/EuTUGK2JL95rNIEO4L3lJCOrS6W219AYqQQSSRyI7 eXjFFzF7pL7pv+RO+Sy0RsBb7glEenZzLWmohuCGqbWQA8G6VxZx8BWnv2Jt0eSwdwsn7i Gg0QKYC/ea1E0/sAi4jgYv1lLWCxO3Dh5Lnq67bD/IL2qWOELfB6Jz2M2iaSyQ== 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 4QM6qT4jS4zLmD; Wed, 17 May 2023 22:15:17 +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 34HMFHi9058224; Wed, 17 May 2023 22:15:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34HMFHu2058223; Wed, 17 May 2023 22:15:17 GMT (envelope-from git) Date: Wed, 17 May 2023 22:15:17 GMT Message-Id: <202305172215.34HMFHu2058223@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: fddac96ca559 - stable/13 - krpc: Allow mountd/nfsd to optionally run in a jail List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: fddac96ca55968f42156e6286547de513f980a52 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=fddac96ca55968f42156e6286547de513f980a52 commit fddac96ca55968f42156e6286547de513f980a52 Author: Rick Macklem AuthorDate: 2022-12-18 20:40:48 +0000 Commit: Rick Macklem CommitDate: 2023-05-17 22:14:07 +0000 krpc: Allow mountd/nfsd to optionally run in a jail This patch modifies the kernel RPC so that it will allow mountd/nfsd to run inside of a vnet jail. Running mountd/nfsd inside a vnet jail will be enabled via a new kernel build option called VNET_NFSD, which will be implemented in future commits. Although I suspect cr_prison can be set from the credentials of the current thread unconditionally, I #ifdef'd the code VNET_NFSD and only did this for the jailed case mainly to document that it is only needed for use in a jail. The TLS support code has not yet been modified to work in a jail. That is planned as future development after the basic VNET_NFSD support is in the kernel. This patch should not result in any semantics change until VNET_NFSD is implemented and used in a kernel configuration. (cherry picked from commit 6a76d35cac8e1549f74bd4cdceccc2ee52c8e556) --- sys/rpc/svc.c | 3 ++- sys/rpc/svc_auth.c | 15 +++++++++++++-- sys/rpc/svc_dg.c | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sys/rpc/svc.c b/sys/rpc/svc.c index be0f08ebca9d..065da0cc23a4 100644 --- a/sys/rpc/svc.c +++ b/sys/rpc/svc.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); */ #include +#include #include #include #include @@ -126,7 +127,7 @@ svcpool_create(const char *name, struct sysctl_oid_list *sysctl_base) pool->sp_space_low = (pool->sp_space_high / 3) * 2; sysctl_ctx_init(&pool->sp_sysctl); - if (sysctl_base) { + if (!jailed(curthread->td_ucred) && sysctl_base) { SYSCTL_ADD_PROC(&pool->sp_sysctl, sysctl_base, OID_AUTO, "minthreads", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, pool, 0, svcpool_minthread_sysctl, "I", diff --git a/sys/rpc/svc_auth.c b/sys/rpc/svc_auth.c index 21149139b5a5..a5c9753c4fde 100644 --- a/sys/rpc/svc_auth.c +++ b/sys/rpc/svc_auth.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -197,7 +198,12 @@ svc_getcred(struct svc_req *rqst, struct ucred **crp, int *flavorp) cr->cr_uid = cr->cr_ruid = cr->cr_svuid = xprt->xp_uid; crsetgroups(cr, xprt->xp_ngrps, xprt->xp_gidp); cr->cr_rgid = cr->cr_svgid = xprt->xp_gidp[0]; - cr->cr_prison = &prison0; +#ifdef VNET_NFSD + if (jailed(curthread->td_ucred)) + cr->cr_prison = curthread->td_ucred->cr_prison; + else +#endif + cr->cr_prison = &prison0; prison_hold(cr->cr_prison); *crp = cr; return (TRUE); @@ -210,7 +216,12 @@ svc_getcred(struct svc_req *rqst, struct ucred **crp, int *flavorp) cr->cr_uid = cr->cr_ruid = cr->cr_svuid = xcr->cr_uid; crsetgroups(cr, xcr->cr_ngroups, xcr->cr_groups); cr->cr_rgid = cr->cr_svgid = cr->cr_groups[0]; - cr->cr_prison = &prison0; +#ifdef VNET_NFSD + if (jailed(curthread->td_ucred)) + cr->cr_prison = curthread->td_ucred->cr_prison; + else +#endif + cr->cr_prison = &prison0; prison_hold(cr->cr_prison); *crp = cr; return (TRUE); diff --git a/sys/rpc/svc_dg.c b/sys/rpc/svc_dg.c index 36724ed07b98..e4cf0d8c45e3 100644 --- a/sys/rpc/svc_dg.c +++ b/sys/rpc/svc_dg.c @@ -45,11 +45,13 @@ __FBSDID("$FreeBSD$"); */ #include +#include #include #include #include #include #include +#include #include #include #include @@ -104,6 +106,8 @@ svc_dg_create(SVCPOOL *pool, struct socket *so, size_t sendsize, struct sockaddr* sa; int error; + if (jailed(curthread->td_ucred)) + return (NULL); if (!__rpc_socket2sockinfo(so, &si)) { printf(svc_dg_str, svc_dg_err1); return (NULL);