Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3474754pxx; Mon, 2 Nov 2020 09:48:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPxxWUrwt1D9Jr8nko3Xd/X7mu2ycxdBWWgzcdKg2gM6SUP87BfNxC1DVoiTHDjb2aGVsW X-Received: by 2002:a17:906:ca54:: with SMTP id jx20mr17242167ejb.541.1604339335473; Mon, 02 Nov 2020 09:48:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604339335; cv=none; d=google.com; s=arc-20160816; b=cJ/9eAeasHMDBkT6TCZKnNr1pXYoYPow6PxZf/pGhhcIW/kBWEAko+QYaTaD6/L88T qZs7QJs51Pw65TDI4KkfaUfmhtDlzgY8QWNq1hJB582VXkjYjOMvjMjymz4MCq8xIFCu IJZ/Rpdk9JgAW7EhTlYucyyKIonoreLkIOLUPqP6hEGTn5w6ZwTZT6Z6GZXiavNpLWAH SrsfQpxnfxwPOvm2WZpsQSnuuRbJY4Dl8uZmftaRmtrAD4TzLBd/ZAJYFdj50s7V0507 eKCub78+IrVcl9rHYhsPKUGazTFyTgllnv7j5Q9nCxNJ3ipnSJXH1k0kqjYhUd9IxGQL +tKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Or3OrGmTCVsC6irW7Os1G3558l38zqrysNf3h0cfK5c=; b=Qf6oOtpLGCCelXQuG180GenY1jw5xNvkF9rlIG5rQUuq/KXCjPSCPZ5CpzY/dXcMKR qa+D4lr75nBZk6wUJaQkAmySNqBT0P7hqBHknwGjXc18LOFOKUADfsYJ1IMPNSulOhpr TCAI1QSiNDy5pms3giY8T8hBmujptetxqtBq2owOsgU7z39amE9xOGaIGm/mQWY65/JH Y0CF7EEffb9hoS330pzFRyKiNwhJ4I9vPzKZIXb4Ne4OihQsehODNfILPQboDjh+hrWU bOorhaMUIJ4sxxU6BXPAAtqiagVLRew6/F44z2W2N52/JIx4/gjM/ISC0qoI3n34Gs/i edLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=dg1q155m; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si1660188ejd.402.2020.11.02.09.48.32; Mon, 02 Nov 2020 09:48:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=dg1q155m; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726058AbgKBRrs (ORCPT + 99 others); Mon, 2 Nov 2020 12:47:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbgKBRrr (ORCPT ); Mon, 2 Nov 2020 12:47:47 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C997C061A48 for ; Mon, 2 Nov 2020 09:47:47 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id j5so7184058plk.7 for ; Mon, 02 Nov 2020 09:47:47 -0800 (PST) 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=dg1q155mU4N5HJ5VxaD/IhrXeEbL95QkuqJG/mMnQ9E9Pqj28zeAGjVO3Fcass6f6Y /sMvitvIVUaIpuwHSbAFnfyM1ISHwOZ3FN8TLQNpeB12VDQYqsbnNmQQq2jkk3weG/+O Q2vLr4P5PTi3SCPWQGZh5DsRg0OR5wvHHpw7s= 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=UNvR1KEvM4KaZTEY3SrHaUyHP2uv4IlKVkZIx13Mt9yDoYB4b1q4Hu/2anvD9g/nOV 0wdE3NLKBcTd7bMyWc/jF++KEELKmeGr87MinGN8obAUkBZtQDMAB7tEcWfsm99LGszY hSMmK7a+Ypovv1iqLPdLlfQKJZUyb8UNdZd7v6lIqQn9BygAvBhoFu26Pa7Al7cbixH9 kM/Yo3KGXJmXUwVUh8xvoLSr6p8cjJOhO3yDu3Yp4t5KHmKe5xDBxIumhMtEhaVhCKWk IwmyxmB+mC3Z5SvJC8H+Nw6GDQXHHuHEQfMNEhyHZuSlTS2IXnEO822rUursLiY91oQ+ p+6Q== X-Gm-Message-State: AOAM533BcHIFEEG0coy0EqTfle6GPxW1Y8Si82ViqWoIMOZTIihLuOS3 14ub7I/UusQx9BluUnONRkSV5ftWcjcEm8AB4XI= X-Received: by 2002:a17:902:788a:b029:d6:b9f:820a with SMTP id q10-20020a170902788ab02900d60b9f820amr21461584pll.76.1604339266776; Mon, 02 Nov 2020 09:47:46 -0800 (PST) Received: from ubuntu.netflix.com (203.20.25.136.in-addr.arpa. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id f4sm115989pjs.8.2020.11.02.09.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 09:47:46 -0800 (PST) From: Sargun Dhillon To: "J . Bruce Fields" , Chuck Lever , Trond Myklebust , Anna Schumaker , Anna Schumaker , David Howells , Scott Mayhew Cc: Sargun Dhillon , linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] NFS: NFSv2/NFSv3: Use cred from fs_context during mount Date: Mon, 2 Nov 2020 09:47:36 -0800 Message-Id: <20201102174737.2740-2-sargun@sargun.me> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201102174737.2740-1-sargun@sargun.me> References: <20201102174737.2740-1-sargun@sargun.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(); -- 2.25.1