From patchwork Sat Jan 21 14:25:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1729944 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=Ckrx6v6A; 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 4Nzdvq49hpz23hK for ; Sun, 22 Jan 2023 01:26:14 +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 1pJEog-0006Nd-4g; Sat, 21 Jan 2023 14:25:58 +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 1pJEod-0006Ms-BN for kernel-team@lists.ubuntu.com; Sat, 21 Jan 2023 14:25:55 +0000 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 2BE60418E4 for ; Sat, 21 Jan 2023 14:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674311155; bh=Ap5al4INAGF+Ot1JAOnPrC9J4ZdpB9VNG42OFJDl5sk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ckrx6v6AgNwxysgKJF83I6ujgUUla8TYlNmdW5x6bg+oteE7m87ZCCXi2pjaM1nTd dugXCo19GI/TExGdSb3kG5MHi5oksTkpB58SOLMl1Qz3Y2HCUWLC6ZgQ0IckSohl8t /oGxcjcU80q+G3w//AOHoufLInWYdIGQ5JnqBGeh85wO4XP8dGllRzQELD8zApR+nq 2Pa9jJEv+AVmIE5YA9Cd6nIPo33LlcpfZvttKvSQmrigPqyDD2fyXjylThtftkt0JX JQWtctp3r1UggurBbHA+fa6dvZWaymKj8dfrdlUyZ0wagCcfoGKzS6HvJNhPvBcbGg KU5guCXH3XwMw== Received: by mail-pj1-f71.google.com with SMTP id fy20-20020a17090b021400b00226f0026263so3507622pjb.2 for ; Sat, 21 Jan 2023 06:25:55 -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=Ap5al4INAGF+Ot1JAOnPrC9J4ZdpB9VNG42OFJDl5sk=; b=vrR1IZ+o5v8W/hYTlWUpmPgtd5W5lZBkKIHiAMEAvgtkc2t9y8SMdVXkv2rXwGKKpP JdYWVqILYi4evEw5qSZQaJMBxvkjnxfCrCGnQgJ+5zD33ReI3M6iTlcy/72qse4l7Z/4 FJ0OKFG9LEWqk/e6mIY11wnSl9KktrHjKEK5JIbfN1lA8H47XhySg1ZD6mmpyvQK536n E1evX4udFT+/f9Li4wmOka6VTstgWMglih8S2NoJxiRmodcrHUKokCVZkNSgG5NWFTBG 4dfJsMDYNkGgUNCQ0Af00zXC4V+Fpoq16p890szNmtDpZJpTufXLHgPvbmeyRJ/0GhJ6 zOeA== X-Gm-Message-State: AFqh2kqd1G94inXfHZDJP+OCPjEHO9EYUpq2hgdl0U1RaMLY7ZnrJmIy u4ji49awEyGe9IOgbphqA0vy1DExlY3HDrgbcFYLtxbIrr5z9KwlDQnbvpMb1+WuxcDj/jyCyuE zMvxW5nlH2UAqW/jlJVakY2YkXcSp59UoZ5rIhHPSoA== X-Received: by 2002:aa7:87ca:0:b0:56b:dae1:e946 with SMTP id i10-20020aa787ca000000b0056bdae1e946mr17266626pfo.28.1674311153157; Sat, 21 Jan 2023 06:25:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXv6ow5pqbF7G6L6dd7EVcS3XOAmWaCnPDSJCqZDp9nFKlyljG+pPlNAa72nmf9dvIkSSZ2oxQ== X-Received: by 2002:aa7:87ca:0:b0:56b:dae1:e946 with SMTP id i10-20020aa787ca000000b0056bdae1e946mr17266612pfo.28.1674311152821; Sat, 21 Jan 2023 06:25:52 -0800 (PST) Received: from chengendu.. (111-248-116-144.dynamic-ip.hinet.net. [111.248.116.144]) by smtp.gmail.com with ESMTPSA id h124-20020a628382000000b0058bb2f12080sm15569586pfe.48.2023.01.21.06.25.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 06:25:52 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Kinetic][Lunar][PATCH 1/3] NFS: Clear the file access cache upon login Date: Sat, 21 Jan 2023 22:25:47 +0800 Message-Id: <20230121142549.37283-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230121142549.37283-1-chengen.du@canonical.com> References: <20230121142549.37283-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 (cherry picked 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 861d23eeac6e..fe95e4573df6 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2906,9 +2906,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_locked(struct inode *inode, const struct cred *cred, u32 *mask, 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; @@ -2936,6 +2955,9 @@ static int nfs_access_get_cached_locked(struct inode *inode, const struct cred * spin_lock(&inode->i_lock); retry = false; } + err = -ENOENT; + if ((s64)(login_time - cache->timestamp) > 0) + goto out; *mask = cache->mask; list_move_tail(&cache->lru, &nfsi->access_cache_entry_lru); err = 0; @@ -3015,6 +3037,7 @@ static void nfs_access_add_rbtree(struct inode *inode, 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 e74a66c29a4b..341334f5ae42 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -59,6 +59,7 @@ struct nfs_access_entry { kuid_t fsuid; kgid_t fsgid; struct group_info *group_info; + u64 timestamp; __u32 mask; struct rcu_head rcu_head; };