From patchwork Wed Jan 18 14:57:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1728292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hQU7Jxcq; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NxplD535nz23fT for ; Thu, 19 Jan 2023 01:57:28 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pI9sP-0007RK-RV; Wed, 18 Jan 2023 14:57:21 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pI9sI-0007G3-26 for kernel-team@lists.ubuntu.com; Wed, 18 Jan 2023 14:57:14 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id AE9484191E for ; Wed, 18 Jan 2023 14:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674053833; bh=ckDMo1PL2WJ8cdJ+yxq0+EBr9r44YQjRUKmnR3d73dI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hQU7Jxcq74Au7v/Szquor0SeY7FMW2HJHTYpme2qyCHBvLTYlfnA7InFC+kLsxy9y EY2DLWtmDgFRzUL4+HG+gW8pGT6rYxCWNp+74UMOiLDHNwxB11KZfbekUjyyHZ1C4D TsJT1g1Wi84nkXp07S5vIM/3L8Lx+aErahVNvcYIuFLWfnP5Sx1gEr1z+TeONIuYqB kyihDlsKpUBeVfaHY5m/TkwRRCl76gN0/gKe80selmH23jepca4CKebO/ISk2Ww/bb 7GWYmPjOfO0PnxRcLAVIOMwH66SKvokOyHtCobT38yuA7gQmkqowVu8znaLT89cSIM 8E7Q0eWAKLoZQ== Received: by mail-pj1-f69.google.com with SMTP id g20-20020a17090adb1400b0022941a246aaso4793598pjv.0 for ; Wed, 18 Jan 2023 06:57:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ckDMo1PL2WJ8cdJ+yxq0+EBr9r44YQjRUKmnR3d73dI=; b=bBTH2vOCqKMpiVDzOQstg/m6cvstlwj6xlXpZWcr7jIWTse3UNVcoUE85VaKGvtK7Y 1LH1zxpbN45DTlsNaTgff1VwerwLznZr5taRHjMwSgiFqioGekU0qjbIbjkjjlOgg4F9 bU3NkLYTf5h5WLoPuvG5bbu703pie7UxTxhMxxlB37onZ5N1nuyDsXOvGrMLvcm/zYuJ HLKwtPsAoq+4Cv7SYn7Cnu1NKtQh2TeZxc5gKKtz7IFLk6DJyea1LfPCOwIBnteR/qnu QINvGppyDKcNmo5bFEgZ09kRn4w82kOig3bbzQCXG2KTksficluRR7jIxJMcLw2yFOJp ysyw== X-Gm-Message-State: AFqh2kqTmtl1W8N1K+WsFZWRti6Cy1+8STgaQVnWbWZEvgEq0od/NyAv AzhhWcfBM5xd/KJ0qu/jq2xVRMjaX50vuyqJDaGEM1PDtKPG0+4mK6IiLUrl9JPFUuC5rZvVbHl 21PgURJsiZWaFnZ1Cm5BNDSlqPF4gFLMCuQfaQvwhbQ== X-Received: by 2002:a17:902:ab50:b0:192:a10a:3270 with SMTP id ij16-20020a170902ab5000b00192a10a3270mr5938627plb.51.1674053832220; Wed, 18 Jan 2023 06:57:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXv7rvNf09oO5qgXdV12TqofOvp7AT38/1yW3aI/3/3jtWtrggCrpkdAHN4EXJdEwKTw3fsl3A== X-Received: by 2002:a17:902:ab50:b0:192:a10a:3270 with SMTP id ij16-20020a170902ab5000b00192a10a3270mr5938614plb.51.1674053831951; Wed, 18 Jan 2023 06:57:11 -0800 (PST) Received: from chengendu.. (111-248-160-17.dynamic-ip.hinet.net. [111.248.160.17]) by smtp.gmail.com with ESMTPSA id a1-20020a63d201000000b004ae6e97ed10sm17437865pgg.17.2023.01.18.06.57.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:57:11 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 1/3] (upstream) NFS: Clear the file access cache upon login Date: Wed, 18 Jan 2023 22:57:06 +0800 Message-Id: <20230118145708.35996-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230118145708.35996-1-chengen.du@canonical.com> References: <20230118145708.35996-1-chengen.du@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Trond Myklebust BugLink: https://bugs.launchpad.net/bugs/2003053 POSIX typically only refreshes the user's supplementary group information upon login. Since NFS servers may often refresh their concept of the user supplementary group membership at their own cadence, it is possible for the NFS client's access cache to become stale due to the user's group membership changing on the server after the user has already logged in on the client. While it is reasonable to expect that such group membership changes are rare, and that we do not want to optimise the cache to accommodate them, it is also not unreasonable for the user to expect that if they log out and log back in again, that the staleness would clear up. Reviewed-by: Benjamin Coddington Tested-by: Benjamin Coddington Signed-off-by: Trond Myklebust (backported from commit 0eb43812c0270ee3d005ff32f91f7d0a6c4943af) Signed-off-by: Chengen Du --- fs/nfs/dir.c | 23 +++++++++++++++++++++++ include/linux/nfs_fs.h | 1 + 2 files changed, 24 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 28ceee102d0b..f35b705d2351 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2350,9 +2350,28 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, co return NULL; } +static u64 nfs_access_login_time(const struct task_struct *task, + const struct cred *cred) +{ + const struct task_struct *parent; + u64 ret; + + rcu_read_lock(); + for (;;) { + parent = rcu_dereference(task->real_parent); + if (parent == task || cred_fscmp(parent->cred, cred) != 0) + break; + task = parent; + } + ret = task->start_time; + rcu_read_unlock(); + return ret; +} + static int nfs_access_get_cached(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res, bool may_block) { struct nfs_inode *nfsi = NFS_I(inode); + u64 login_time = nfs_access_login_time(current, cred); struct nfs_access_entry *cache; bool retry = true; int err; @@ -2380,6 +2399,9 @@ static int nfs_access_get_cached(struct inode *inode, const struct cred *cred, s spin_lock(&inode->i_lock); retry = false; } + err = -ENOENT; + if ((s64)(login_time - cache->timestamp) > 0) + goto out; res->cred = cache->cred; res->mask = cache->mask; list_move_tail(&cache->lru, &nfsi->access_cache_entry_lru); @@ -2445,6 +2467,7 @@ static void nfs_access_add_rbtree(struct inode *inode, struct nfs_access_entry * else goto found; } + set->timestamp = ktime_get_ns(); rb_link_node(&set->rb_node, parent, p); rb_insert_color(&set->rb_node, root_node); list_add_tail(&set->lru, &nfsi->access_cache_entry_lru); diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 7c59af824e4e..9a2d56d4b6dd 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -52,6 +52,7 @@ struct nfs_access_entry { struct rb_node rb_node; struct list_head lru; const struct cred * cred; + u64 timestamp; __u32 mask; struct rcu_head rcu_head; };