From nobody Sun Dec 18 20:41:51 2022 X-Original-To: dev-commits-src-main@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 4NZvrw1dC3zt7gq; Sun, 18 Dec 2022 20:41:52 +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 4NZvrw1BtVz3k6w; Sun, 18 Dec 2022 20:41:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671396112; 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=SKIxmX30WhzTVyal1apbp9Ib2NVmjePpWsvERT3w7lY=; b=WixcRF5MPHj0ubhsyNfN5txTm+B4WsJ0snwyez7ywbFtw7lgBaQohish1pLOFILRUhxfMV zXAg9sg4jQxOfqSb62LgfdtE2Vfn1BdKFCuwnHM6fQ0AjxePIfTgPkxcYLZuWoADnpOTgT Rvuu97SlTunRy3t23v9HFs4RGl6h5UAwmwZ/I6j5w/Esf/jdwO4qoGh+Vz5yJAfrTul8cS E97ODILtbtrvr4r3Pomh+OiiCF1B5nyEda2nLEeBClBebj/hwobYsQ/a+0dCIhUpP2muNR qmekiZfbfvJ+h5eTXrR1bwOKFioqdTXBX/15MCeiKJkR0gY5+uK3+bVTgJXH5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671396112; 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=SKIxmX30WhzTVyal1apbp9Ib2NVmjePpWsvERT3w7lY=; b=E3n60XZTxsk9MeUPjYchZaSoWhxuvKZe5WOvK0M8jJiJKldj3ZEplgVT6lZL9K4idUySzH uZfqx3sDplQkZ30Z14C2K85xr1t6pH/+D5/CNYTt4N5gi9NGr9Vc6UD0KqEHV6RwIzU4Qh PSLfEjL/AYvmOAWkPUI08sonYBR9jtJCFUHbrEG4awhPrk5FcdhMSP3e38x2QKpQdHrezg wb8cxNj8+jvwVkYaVT6mOGPiWpxkJ9yCvPBgidPq8IxiR5paxKeYezl4gy7ZeSiZ7Zr4Yv 9KvGIeetaUO4oQZVP8AJb/ZY5/AxCGr8kDqGFnb+kCL4iUqIVjVVVNVYhhroEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671396112; a=rsa-sha256; cv=none; b=w8J4tcz+dPFsDZjcPu15uSY3pjHSjA3iLR/F6L7OTZXE3bcgLOoupnDNx56bFA4xkvj2rd TP5jcdotAtO/S2JGEO3AUWup+W7vJdBDkA2UuAQtdqJGmBGd024Hlxq1AjIV4IIhF2tkz/ n4v3JPTpqZhIwCW7GdqQA6hsjB0Gd6vgoSD1YkaKWxAOw+0ohDRCKAEBpnLciUdpx8FTtw nkV95z38edMmY2c1elS1t9+PBPSB1S2p+RgMw1emI7Qik4ejGRgb647yKlCIFYBPyaTxXB 0CGbpszHRQ3acQ/8D4ODgQWiJJoKoj11/iWkgEMkNpP3WQBZHIPF9586hmAHCA== 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 4NZvrw0G4jzVHW; Sun, 18 Dec 2022 20:41:52 +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 2BIKfpYi064252; Sun, 18 Dec 2022 20:41:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BIKfpAg064251; Sun, 18 Dec 2022 20:41:51 GMT (envelope-from git) Date: Sun, 18 Dec 2022 20:41:51 GMT Message-Id: <202212182041.2BIKfpAg064251@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 6a76d35cac8e - main - krpc: Allow mountd/nfsd to optionally run in a jail List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 6a76d35cac8e1549f74bd4cdceccc2ee52c8e556 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=6a76d35cac8e1549f74bd4cdceccc2ee52c8e556 commit 6a76d35cac8e1549f74bd4cdceccc2ee52c8e556 Author: Rick Macklem AuthorDate: 2022-12-18 20:40:48 +0000 Commit: Rick Macklem CommitDate: 2022-12-18 20:40:48 +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. MFC after: 4 months --- sys/rpc/rpcsec_gss/svc_rpcsec_gss.c | 7 ++++++- sys/rpc/svc.c | 3 ++- sys/rpc/svc_auth.c | 15 +++++++++++++-- sys/rpc/svc_dg.c | 4 ++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c index d87a57ad514b..f375a184d1cc 100644 --- a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c +++ b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c @@ -478,7 +478,12 @@ rpc_gss_svc_getcred(struct svc_req *req, struct ucred **crp, int *flavorp) cr->cr_uid = cr->cr_ruid = cr->cr_svuid = uc->uid; cr->cr_rgid = cr->cr_svgid = uc->gid; crsetgroups(cr, uc->gidlen, uc->gidlist); - 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 = crhold(cr); 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 4ab86bb5904a..bf3cbd2a6137 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);