diff mbox series

[SRU,Bionic,3/4] (upstream) NFS: Judge the file access cache's timestamp in rcu path

Message ID 20230121144713.39111-4-chengen.du@canonical.com
State New
Headers show
Series NFS: client permission error after adding user to permissible group | expand

Commit Message

Chengen Du Jan. 21, 2023, 2:47 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2003053

If the user's login time is newer than the cache's timestamp,
we expect the cache may be stale and need to clear.
The stale cache will remain in the list's tail if no other
users operate on that inode.
Once the user accesses the inode, the stale cache will be
returned in rcu path.

Signed-off-by: Chengen Du <chengen.du@canonical.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
(backported from commit 029085b8949f5d269ae2bbd14915407dd0c7f902)
[chengen - use current_cred() as the argument to get login time]
Signed-off-by: Chengen Du <chengen.du@canonical.com>
---
 fs/nfs/dir.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 3ff938164381..9a39bb94d5d8 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -2366,6 +2366,8 @@  static int nfs_access_get_cached_rcu(struct inode *inode, struct rpc_cred *cred,
 	 * but do it without locking.
 	 */
 	struct nfs_inode *nfsi = NFS_I(inode);
+	const struct cred *cur_cred = current_cred();
+	u64 login_time = nfs_access_login_time(current, cur_cred);
 	struct nfs_access_entry *cache;
 	int err = -ECHILD;
 	struct list_head *lh;
@@ -2380,6 +2382,8 @@  static int nfs_access_get_cached_rcu(struct inode *inode, struct rpc_cred *cred,
 		cache = NULL;
 	if (cache == NULL)
 		goto out;
+	if ((s64)(login_time - cache->timestamp) > 0)
+		goto out;
 	if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_ACCESS))
 		goto out;
 	res->cred = cache->cred;