From patchwork Wed Oct 21 12:05:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 11848945 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C1021580 for ; Wed, 21 Oct 2020 12:05:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13EF322251 for ; Wed, 21 Oct 2020 12:05:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=sargun.me header.i=@sargun.me header.b="RK5bzLag" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2411210AbgJUMFm (ORCPT ); Wed, 21 Oct 2020 08:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411168AbgJUMFm (ORCPT ); Wed, 21 Oct 2020 08:05:42 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE519C0613CF for ; Wed, 21 Oct 2020 05:05:41 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id g16so1048904pjv.3 for ; Wed, 21 Oct 2020 05:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Or3OrGmTCVsC6irW7Os1G3558l38zqrysNf3h0cfK5c=; b=RK5bzLagY7MwYmbltNGhZ6w2+8kHeVI0CkHzGATgoSmrNsbptAxmzQhPWoAWkxNez9 poU/XlsHTD1dqq1tXO0UgmZlpvOw60EdWjvsv0kXFrGYX7kL1h/IjceIXYGgPNoIj/aT sXHp09uleltxEiEw2swEHxSawsX0KYjaqMvxA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Or3OrGmTCVsC6irW7Os1G3558l38zqrysNf3h0cfK5c=; b=YUS+ly5fhVZ7Fd2QlCGu08CeKUL13DgQnZE/1kUJU9rHcxl/Pzi9/uH+nnY0AyxneZ cmGDrynpO9gm6yQ3hoa8E6xZVks1I2HI85abE8XwokygxucNtwlwwOw7f7/h+Vt+OluG pybACsPR+nVml+ggUwRu6g+pMjr9lm7vUdykYP8r1aOCURcuiotT2XcmK/qfQkJfkcKH K3m4sdMU/gKs+RCKXXUhwJScK1ngyAIoXNsAzdzuS8KtK0XeYw9iYklAwYLWd3sQTFkI C6n6QF3yvFAspXe33cq4lxFF6n20Idou6VbOFHyVJgo/k3VqlPX+591eLnaZRllCg+s8 u7AQ== X-Gm-Message-State: AOAM533C6UcJej+LyQMkg6VCb0pCla/2UsCoHPyTTmheO4Oy3YpRpaqu /3pQb1Kt7eyWxBvYKkmBHWea3Q== X-Google-Smtp-Source: ABdhPJwmpjHy1WRp9iSKqElLpy3hosxwYtT3h2VWW5BLoQCLOAYhuwx01oWjtT6w49LWtwTz/Vl4yg== X-Received: by 2002:a17:902:ac82:b029:d5:b159:3335 with SMTP id h2-20020a170902ac82b02900d5b1593335mr3386721plr.44.1603281941101; Wed, 21 Oct 2020 05:05:41 -0700 (PDT) Received: from ubuntu.netflix.com (203.20.25.136.in-addr.arpa. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id b5sm2276392pfo.64.2020.10.21.05.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 05:05:40 -0700 (PDT) From: Sargun Dhillon To: "J . Bruce Fields" , Chuck Lever , Trond Myklebust , Anna Schumaker , David Howells , Scott Mayhew Cc: Sargun Dhillon , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, kylea@netflix.com Subject: [PATCH v3 1/3] NFS: NFSv2/NFSv3: Use cred from fs_context during mount Date: Wed, 21 Oct 2020 05:05:27 -0700 Message-Id: <20201021120529.7062-2-sargun@sargun.me> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201021120529.7062-1-sargun@sargun.me> References: <20201021120529.7062-1-sargun@sargun.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org There was refactoring done to use the fs_context for mounting done in: 62a55d088cd87: NFS: Additional refactoring for fs_context conversion This made it so that the net_ns is fetched from the fs_context (the netns that fsopen is called in). This change also makes it so that the credential fetched during fsopen is used as well as the net_ns. NFS has already had a number of changes to prepare it for user namespaces: 1a58e8a0e5c1: NFS: Store the credential of the mount process in the nfs_server 264d948ce7d0: NFS: Convert NFSv3 to use the container user namespace c207db2f5da5: NFS: Convert NFSv2 to use the container user namespace Previously, different credentials could be used for creation of the fs_context versus creation of the nfs_server, as FSCONFIG_CMD_CREATE did the actual credential check, and that's where current_creds() were fetched. This meant that the user namespace which fsopen was called in could be a non-init user namespace. This still requires that the user that calls FSCONFIG_CMD_CREATE has CAP_SYS_ADMIN in the init user ns. This roughly allows a privileged user to mount on behalf of an unprivileged usernamespace, by forking off and calling fsopen in the unprivileged user namespace. It can then pass back that fsfd to the privileged process which can configure the NFS mount, and then it can call FSCONFIG_CMD_CREATE before switching back into the mount namespace of the container, and finish up the mounting process and call fsmount and move_mount. Signed-off-by: Sargun Dhillon --- fs/nfs/client.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 4b8cc93913f7..c3afe448a512 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -571,7 +571,7 @@ static int nfs_start_lockd(struct nfs_server *server) 1 : 0, .net = clp->cl_net, .nlmclnt_ops = clp->cl_nfs_mod->rpc_ops->nlmclnt_ops, - .cred = current_cred(), + .cred = server->cred, }; if (nlm_init.nfs_version > 3) @@ -985,7 +985,13 @@ struct nfs_server *nfs_create_server(struct fs_context *fc) if (!server) return ERR_PTR(-ENOMEM); - server->cred = get_cred(current_cred()); + if (fc->cred->user_ns != &init_user_ns) + dprintk("%s: Using creds from non-init userns\n", __func__); + else if (fc->cred != current_cred()) + dprintk("%s: Using creds from fs_context which are different than current_creds\n", + __func__); + + server->cred = get_cred(fc->cred); error = -ENOMEM; fattr = nfs_alloc_fattr(); From patchwork Wed Oct 21 12:05:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 11848949 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A18FC14B7 for ; Wed, 21 Oct 2020 12:05:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73C6122251 for ; Wed, 21 Oct 2020 12:05:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=sargun.me header.i=@sargun.me header.b="P5zrFhEb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2411168AbgJUMFp (ORCPT ); Wed, 21 Oct 2020 08:05:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439910AbgJUMFo (ORCPT ); Wed, 21 Oct 2020 08:05:44 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC03C0613CE for ; Wed, 21 Oct 2020 05:05:43 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id kk5so1045597pjb.1 for ; Wed, 21 Oct 2020 05:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vJHUiIV/mXgyDV0BplJrCZ+f4uBKxL2uz453PEXSerk=; b=P5zrFhEbkRW8IMbTRa8/5yw4n/AYJtpsEebsoYbAF4LdoGYLXxm1bUWxoAHdfvm3o1 Jx6pTPuhnirmBFkEi+usNt2pMpb+6y3ROBP7la/rEpRRhSwEJqykDtMf9O3wIs7SBbD/ NkSoPzDB6eWKj/QbRCz+9kHBoMeFOFzh16oNw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vJHUiIV/mXgyDV0BplJrCZ+f4uBKxL2uz453PEXSerk=; b=fI2nEFA8nbqv0jwfsTkZYqdGSaxrIng0O4vxvw7G/8SGuJU11ReEOXJ3Lqg2SZHmW2 KrTeKORQjIlYE/MCF4hiSiXhv4wcnfkai2icW0KqqYQiXZc6rAEi5/ppbXQR40jxeigh 095Ek7K/yNf6Iid3duyC0257aOnISSjOdUSTne7LNy9E5MFUZe1yIy697lB+334UYeJC /IjGx6CYb7tvuGhn5FOSOwjZxHlESfb/mwK+zGlYBq6wGU6FLzwaHkIslANo+I2XXg7c AOJ7se0coL+cPu8s7yPpu/iOgw3r+6QxcRvLg+NLFfVdNJaYqHgtHHKEI+527MzymqrR yVWQ== X-Gm-Message-State: AOAM531CgGW8rUFaAp9Y+0YxZzkaWaiKctl/Xe8kXO6wB22AzexgfKvU y92WFWcQPgXXTHheFXr8XQRAgg== X-Google-Smtp-Source: ABdhPJysrrQyxAa4d/4x9NCuKLjTunYJ7BtV7RXKMPOazdzn9BUWo7vaDlNYMHGY12tDVZR35B2h2Q== X-Received: by 2002:a17:902:8e89:b029:d5:fefd:9637 with SMTP id bg9-20020a1709028e89b02900d5fefd9637mr3217602plb.39.1603281942696; Wed, 21 Oct 2020 05:05:42 -0700 (PDT) Received: from ubuntu.netflix.com (203.20.25.136.in-addr.arpa. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id b5sm2276392pfo.64.2020.10.21.05.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 05:05:42 -0700 (PDT) From: Sargun Dhillon To: "J . Bruce Fields" , Chuck Lever , Trond Myklebust , Anna Schumaker , David Howells , Scott Mayhew Cc: Sargun Dhillon , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, kylea@netflix.com Subject: [PATCH v3 2/3] NFSv4: Refactor: reference user namespace from nfs4idmap Date: Wed, 21 Oct 2020 05:05:28 -0700 Message-Id: <20201021120529.7062-3-sargun@sargun.me> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201021120529.7062-1-sargun@sargun.me> References: <20201021120529.7062-1-sargun@sargun.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The nfs4idmapper only needs access to the user namespace, and not the entire cred struct. This replaces the struct cred* member with struct user_namespace*. This is so we don't have to hold onto the cred object, which has extraneous references to things like user_struct. This also makes switching away from init_user_ns more straightforward in the future. Signed-off-by: Sargun Dhillon --- fs/nfs/nfs4idmap.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c index 62e6eea5c516..8d8aba305ecc 100644 --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "internal.h" #include "netns.h" @@ -69,13 +70,13 @@ struct idmap { struct rpc_pipe *idmap_pipe; struct idmap_legacy_upcalldata *idmap_upcall_data; struct mutex idmap_mutex; - const struct cred *cred; + struct user_namespace *user_ns; }; static struct user_namespace *idmap_userns(const struct idmap *idmap) { - if (idmap && idmap->cred) - return idmap->cred->user_ns; + if (idmap && idmap->user_ns) + return idmap->user_ns; return &init_user_ns; } @@ -286,7 +287,7 @@ static struct key *nfs_idmap_request_key(const char *name, size_t namelen, if (ret < 0) return ERR_PTR(ret); - if (!idmap->cred || idmap->cred->user_ns == &init_user_ns) + if (!idmap->user_ns || idmap->user_ns == &init_user_ns) rkey = request_key(&key_type_id_resolver, desc, ""); if (IS_ERR(rkey)) { mutex_lock(&idmap->idmap_mutex); @@ -462,7 +463,7 @@ nfs_idmap_new(struct nfs_client *clp) return -ENOMEM; mutex_init(&idmap->idmap_mutex); - idmap->cred = get_cred(clp->cl_rpcclient->cl_cred); + idmap->user_ns = get_user_ns(clp->cl_rpcclient->cl_cred->user_ns); rpc_init_pipe_dir_object(&idmap->idmap_pdo, &nfs_idmap_pipe_dir_object_ops, @@ -486,7 +487,7 @@ nfs_idmap_new(struct nfs_client *clp) err_destroy_pipe: rpc_destroy_pipe_data(idmap->idmap_pipe); err: - put_cred(idmap->cred); + get_user_ns(idmap->user_ns); kfree(idmap); return error; } @@ -503,7 +504,7 @@ nfs_idmap_delete(struct nfs_client *clp) &clp->cl_rpcclient->cl_pipedir_objects, &idmap->idmap_pdo); rpc_destroy_pipe_data(idmap->idmap_pipe); - put_cred(idmap->cred); + put_user_ns(idmap->user_ns); kfree(idmap); } From patchwork Wed Oct 21 12:05:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 11848953 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17D0817D5 for ; Wed, 21 Oct 2020 12:05:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3C462224B for ; Wed, 21 Oct 2020 12:05:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=sargun.me header.i=@sargun.me header.b="GxJ3G4RD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440003AbgJUMFs (ORCPT ); Wed, 21 Oct 2020 08:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439994AbgJUMFp (ORCPT ); Wed, 21 Oct 2020 08:05:45 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F01CFC0613CE for ; Wed, 21 Oct 2020 05:05:44 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id o9so1103562plx.10 for ; Wed, 21 Oct 2020 05:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jLn1x0a229/WkcL7/dHpbssMTZU0rXgDdf1xqdaPV3Q=; b=GxJ3G4RDlax+CMWklzAbiprEUD+1G2uWIJmvVWDLA/XN7EHQ8OSVGo06rSs0k7M0H8 nEkZhQpI6AXtct80ms0hra9wJOf4R4ldgfSAPS1p7dwhgayvynUrndILReguMrHxD+Gq rtYMTAN3Iql7l5vYUN/mIgJGGHp8sH39yxPm8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jLn1x0a229/WkcL7/dHpbssMTZU0rXgDdf1xqdaPV3Q=; b=qWxAe6spHZ1RW5SJFkoZCQWJEzAImEDwpN/QJezg9VXDSZP7FFTAoGhKIooEWvkILL 8R1ASzw5ftl7TxevauOK3aWPUB0ENlXHL26+Fc7flOn7huyZZnVpyqXaxFqBwg+YDcJW K52QvGvy5U08LWAYiSj6Ke8wwIH49AyjnozXxEAJJIHsIfuDVcPXKT3mFLhP4uTrfYCJ jnv3qUigBQv9/YsCVeGAt133PdrV5n/jlecYmWaMfLlaNI5Rrl1S5545QlqI2UaYdrJy vX4hapTdJhELFjPe08V5idsx/DvY5Fnkqbz9VtV9fEn1tSgPEibDUt87DMx+n2NbvqNk vI3g== X-Gm-Message-State: AOAM5316/bzM+mCavI4u/Lw8DtWCRAOp121n7DNkIHo+wiLkuuVPFxIw 2MiT69Vh56grT0m/cuRlFGPORg== X-Google-Smtp-Source: ABdhPJwbJOHDfZc9DluTXh1hC3PF30lFHtcQ8YvHY2EPqNGCPlk96//ypyM34ATIq9vWGH5taROkkQ== X-Received: by 2002:a17:902:7798:b029:d5:d3b6:2526 with SMTP id o24-20020a1709027798b02900d5d3b62526mr3424428pll.2.1603281944284; Wed, 21 Oct 2020 05:05:44 -0700 (PDT) Received: from ubuntu.netflix.com (203.20.25.136.in-addr.arpa. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id b5sm2276392pfo.64.2020.10.21.05.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 05:05:43 -0700 (PDT) From: Sargun Dhillon To: "J . Bruce Fields" , Chuck Lever , Trond Myklebust , Anna Schumaker , David Howells , Scott Mayhew Cc: Sargun Dhillon , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, kylea@netflix.com Subject: [PATCH v3 3/3] NFSv4: Refactor NFS to be use user namespaces Date: Wed, 21 Oct 2020 05:05:29 -0700 Message-Id: <20201021120529.7062-4-sargun@sargun.me> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201021120529.7062-1-sargun@sargun.me> References: <20201021120529.7062-1-sargun@sargun.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In several patches work has been done to enable NFSv4 to use user namespaces: 58002399da65: NFSv4: Convert the NFS client idmapper to use the container user namespace 3b7eb5e35d0f: NFS: When mounting, don't share filesystems between different user namespaces Unfortunately, the userspace APIs were only such that the userspace facing side of the filesystem (superblock s_user_ns) could be set to a non init user namespace. This furthers the fs_context related refactoring, and piggybacks on top of that logic, so the superblock user namespace, and the NFS user namespace are the same. This change only allows those users whom are not using ID mapping to use user namespaces because the upcall mechanism still needs to be made fully namespace aware. Currently, it is only network namespace aware (and this patch doesn't impede that behaviour). Also, there is currently a limitation that enabling / disabling ID mapping can only be done on a machine-wide basis. Eventually, we will need to at least: * Separate out the keyring cache by namespace * Come up with an upcall mechanism that can be triggered inside of the container, or safely triggered outside, with the requisite context to do the right mapping. * Handle whatever refactoring needs to be done in net/sunrpc. Signed-off-by: Sargun Dhillon --- fs/nfs/nfs4client.c | 27 ++++++++++++++++++++++++++- fs/nfs/nfs4idmap.c | 2 +- fs/nfs/nfs4idmap.h | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index daacc78a3d48..0811e9540bf5 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c @@ -1151,7 +1151,19 @@ struct nfs_server *nfs4_create_server(struct fs_context *fc) if (!server) return ERR_PTR(-ENOMEM); - server->cred = get_cred(current_cred()); + /* + * current_cred() must have CAP_SYS_ADMIN in init_user_ns. All non + * init user namespaces cannot mount NFS, but the fs_context + * can be created in any user namespace. + */ + if (fc->cred->user_ns != &init_user_ns) { + dprintk("%s: Using creds from non-init userns\n", __func__); + } else if (fc->cred != current_cred()) { + dprintk("%s: Using creds from fs_context which are different than current_creds\n", + __func__); + } + + server->cred = get_cred(fc->cred); auth_probe = ctx->auth_info.flavor_len < 1; @@ -1164,6 +1176,19 @@ struct nfs_server *nfs4_create_server(struct fs_context *fc) if (error < 0) goto error; + /* + * nfs4idmap is not fully isolated by user namespaces. It is currently + * only network namespace aware. If upcalls never happen, we do not + * need to worry as nfs_client instances aren't shared between + * user namespaces. + */ + if (idmap_userns(server->nfs_client->cl_idmap) != &init_user_ns && + !(server->caps & NFS_CAP_UIDGID_NOMAP)) { + error = -EINVAL; + errorf(fc, "Mount credentials are from non init user namespace and ID mapping is enabled. This is not allowed."); + goto error; + } + return server; error: diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c index 8d8aba305ecc..33dc9b76dc17 100644 --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c @@ -73,7 +73,7 @@ struct idmap { struct user_namespace *user_ns; }; -static struct user_namespace *idmap_userns(const struct idmap *idmap) +struct user_namespace *idmap_userns(const struct idmap *idmap) { if (idmap && idmap->user_ns) return idmap->user_ns; diff --git a/fs/nfs/nfs4idmap.h b/fs/nfs/nfs4idmap.h index de44d7330ab3..2f5296497887 100644 --- a/fs/nfs/nfs4idmap.h +++ b/fs/nfs/nfs4idmap.h @@ -38,7 +38,7 @@ #include #include - +#include /* Forward declaration to make this header independent of others */ struct nfs_client; @@ -50,6 +50,7 @@ int nfs_idmap_init(void); void nfs_idmap_quit(void); int nfs_idmap_new(struct nfs_client *); void nfs_idmap_delete(struct nfs_client *); +struct user_namespace *idmap_userns(const struct idmap *idmap); void nfs_fattr_init_names(struct nfs_fattr *fattr, struct nfs4_string *owner_name,