From patchwork Wed Oct 7 21:07:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11821853 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 31958175A for ; Wed, 7 Oct 2020 21:09:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1858720872 for ; Wed, 7 Oct 2020 21:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602104971; bh=GXaU3M6BLK3127ujfY/xK84VRhiOMR0hLgt6rnBkcoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=aji+/8nFC85G1Gpq2lse5ci7BrGjCCOhSvkmL2DVBvZN6Sb06u4lAjRXx4Pzg4oN6 XPEF9KWIgdylVrCVri1fwkeVPKvu4Pu6fL0PqXtwuS01IZtF54wMGzN69xWdqY1Sxu KoJpdkg74L872U9vb7ez45BJuEcRxf+Pwcr0fBAg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728524AbgJGVJa (ORCPT ); Wed, 7 Oct 2020 17:09:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:38552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728292AbgJGVJa (ORCPT ); Wed, 7 Oct 2020 17:09:30 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D6EC20872; Wed, 7 Oct 2020 21:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602104969; bh=GXaU3M6BLK3127ujfY/xK84VRhiOMR0hLgt6rnBkcoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=acAuySyuILVlJlw8uJ6KUuUcxASbovvgVOBQL6BQj9akMDV4EGIFw7mkxTzyHfjQy uyxLJCKn53ik1Fb+t/KKdpdmh7QBaudEDVPov8VA/wQERY8sTSkNb5bOd5v1yKSI/G L2CkS13jdZvVs6uEadOUfnvs3EE4714WdzB9cWtU= From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] NFSv4: Clean up initialisation of uniquified client id strings Date: Wed, 7 Oct 2020 17:07:19 -0400 Message-Id: <20201007210720.537880-2-trondmy@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201007210720.537880-1-trondmy@kernel.org> References: <20201007210720.537880-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust When the user sets a uniquifier, then ensure we copy the string so that calls to strlen() etc are atomic with calls to snprintf(). Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 73 +++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 6e95c85fe395..3a39887e0e6e 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -6006,9 +6006,20 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp, memcpy(bootverf->data, verf, sizeof(bootverf->data)); } +static size_t +nfs4_get_uniquifier(char *buf, size_t buflen) +{ + buf[0] = '\0'; + if (nfs4_client_id_uniquifier[0] != '\0') + return strlcpy(buf, nfs4_client_id_uniquifier, buflen); + return 0; +} + static int nfs4_init_nonuniform_client_string(struct nfs_client *clp) { + char buf[NFS4_CLIENT_ID_UNIQ_LEN]; + size_t buflen; size_t len; char *str; @@ -6022,8 +6033,11 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp) strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + 1; rcu_read_unlock(); - if (nfs4_client_id_uniquifier[0] != '\0') - len += strlen(nfs4_client_id_uniquifier) + 1; + + buflen = nfs4_get_uniquifier(buf, sizeof(buf)); + if (buflen) + len += buflen + 1; + if (len > NFS4_OPAQUE_LIMIT + 1) return -EINVAL; @@ -6037,10 +6051,9 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp) return -ENOMEM; rcu_read_lock(); - if (nfs4_client_id_uniquifier[0] != '\0') + if (buflen) scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", - clp->cl_rpcclient->cl_nodename, - nfs4_client_id_uniquifier, + clp->cl_rpcclient->cl_nodename, buf, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); else @@ -6054,51 +6067,24 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp) return 0; } -static int -nfs4_init_uniquifier_client_string(struct nfs_client *clp) -{ - size_t len; - char *str; - - len = 10 + 10 + 1 + 10 + 1 + - strlen(nfs4_client_id_uniquifier) + 1 + - strlen(clp->cl_rpcclient->cl_nodename) + 1; - - if (len > NFS4_OPAQUE_LIMIT + 1) - return -EINVAL; - - /* - * Since this string is allocated at mount time, and held until the - * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying - * about a memory-reclaim deadlock. - */ - str = kmalloc(len, GFP_KERNEL); - if (!str) - return -ENOMEM; - - scnprintf(str, len, "Linux NFSv%u.%u %s/%s", - clp->rpc_ops->version, clp->cl_minorversion, - nfs4_client_id_uniquifier, - clp->cl_rpcclient->cl_nodename); - clp->cl_owner_id = str; - return 0; -} - static int nfs4_init_uniform_client_string(struct nfs_client *clp) { + char buf[NFS4_CLIENT_ID_UNIQ_LEN]; + size_t buflen; size_t len; char *str; if (clp->cl_owner_id != NULL) return 0; - if (nfs4_client_id_uniquifier[0] != '\0') - return nfs4_init_uniquifier_client_string(clp); - len = 10 + 10 + 1 + 10 + 1 + strlen(clp->cl_rpcclient->cl_nodename) + 1; + buflen = nfs4_get_uniquifier(buf, sizeof(buf)); + if (buflen) + len += buflen + 1; + if (len > NFS4_OPAQUE_LIMIT + 1) return -EINVAL; @@ -6111,9 +6097,14 @@ nfs4_init_uniform_client_string(struct nfs_client *clp) if (!str) return -ENOMEM; - scnprintf(str, len, "Linux NFSv%u.%u %s", - clp->rpc_ops->version, clp->cl_minorversion, - clp->cl_rpcclient->cl_nodename); + if (buflen) + scnprintf(str, len, "Linux NFSv%u.%u %s/%s", + clp->rpc_ops->version, clp->cl_minorversion, + buf, clp->cl_rpcclient->cl_nodename); + else + scnprintf(str, len, "Linux NFSv%u.%u %s", + clp->rpc_ops->version, clp->cl_minorversion, + clp->cl_rpcclient->cl_nodename); clp->cl_owner_id = str; return 0; } From patchwork Wed Oct 7 21:07:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11821855 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 7BC81139F for ; Wed, 7 Oct 2020 21:09:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5775320872 for ; Wed, 7 Oct 2020 21:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602104971; bh=oKoHzfk4Pdw+BEotzgkjisWZt/IwoCU5xdDP7N1iyU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=w1lZ1nmKkwJJtILybSYVX6A+N9JzM0shLXZR7TKW6S9pPPM3K8FxVRgr6JC9DMuyR Gevxpj/35uvTpqqVZlZYJ4vbe59bAoRIGn6Vrc0x1RC7tUNvcU36PnWI+HyCq4KXwl ubWwPxVSOmTdr4WQa7Rg7Gey2nISI9gsuikDt/AM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728292AbgJGVJa (ORCPT ); Wed, 7 Oct 2020 17:09:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:38564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728428AbgJGVJa (ORCPT ); Wed, 7 Oct 2020 17:09:30 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E253E2087D; Wed, 7 Oct 2020 21:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602104970; bh=oKoHzfk4Pdw+BEotzgkjisWZt/IwoCU5xdDP7N1iyU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ys5VVr8zn9yp9WM3whPTC69udHoT3i5MnAyNmUWkLesbLFrVDHWI/UR3kzXg4WwmD EC+2/ggWFwLWM4aFSV71HGLkCy9Cft6losCKTzKe7SgqN3AdeaBiWiJC39QfLZMMce tq0QWKWMcT0vf35IC3YOZYkizLZcEl+FvebNXd1A= From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] NFSv4: Use the net namespace uniquifier if it is set Date: Wed, 7 Oct 2020 17:07:20 -0400 Message-Id: <20201007210720.537880-3-trondmy@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201007210720.537880-2-trondmy@kernel.org> References: <20201007210720.537880-1-trondmy@kernel.org> <20201007210720.537880-2-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If a container sets a net namespace specific uniquifier, then use that in the setclientid/exchangeid process. Signed-off-by: Trond Myklebust Reported-by: kernel test robot --- fs/nfs/nfs4proc.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 3a39887e0e6e..a1dd46e7440b 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -63,6 +63,7 @@ #include "callback.h" #include "pnfs.h" #include "netns.h" +#include "sysfs.h" #include "nfs4idmap.h" #include "nfs4session.h" #include "fscache.h" @@ -6007,9 +6008,25 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp, } static size_t -nfs4_get_uniquifier(char *buf, size_t buflen) +nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) { + struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); + struct nfs_netns_client *nn_clp = nn->nfs_client; + const char *id; + size_t len; + buf[0] = '\0'; + + if (nn_clp) { + rcu_read_lock(); + id = rcu_dereference(nn_clp->identifier); + if (id && *id != '\0') + len = strlcpy(buf, id, buflen); + rcu_read_unlock(); + if (len) + return len; + } + if (nfs4_client_id_uniquifier[0] != '\0') return strlcpy(buf, nfs4_client_id_uniquifier, buflen); return 0; @@ -6034,7 +6051,7 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp) 1; rcu_read_unlock(); - buflen = nfs4_get_uniquifier(buf, sizeof(buf)); + buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); if (buflen) len += buflen + 1; @@ -6081,7 +6098,7 @@ nfs4_init_uniform_client_string(struct nfs_client *clp) len = 10 + 10 + 1 + 10 + 1 + strlen(clp->cl_rpcclient->cl_nodename) + 1; - buflen = nfs4_get_uniquifier(buf, sizeof(buf)); + buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); if (buflen) len += buflen + 1;