From patchwork Sat Jan 21 14:47:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1729948 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=nBPUHPz9; 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 4NzfNL1D5sz23hK for ; Sun, 22 Jan 2023 01:47:30 +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 1pJF9P-0000BQ-FS; Sat, 21 Jan 2023 14:47:23 +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 1pJF9N-00009j-19 for kernel-team@lists.ubuntu.com; Sat, 21 Jan 2023 14:47:21 +0000 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 C6ED0418E4 for ; Sat, 21 Jan 2023 14:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674312440; bh=KHeud4x8DYkt0LmbEtXun38Wko1mqDc6/VNe67/XaD8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nBPUHPz9wTxrQMMccRgGiLIM2kOReto8jymHakyKaSXHgg2lfz2P4KmvxhJS4KkWG sV7k+UJnnmWAK9GObrOsT7iz0+h9F+ny3+lavmFq1ESoBTdciuK6GiaqHI1AZRfu0W D5GeWY8NzgMEESScJ9vvzlQWa3LTEkAp9OmJuf1WhbRfuyki74k6uRtKFBwKuu2i7f hYN2+JFTRRhDpBLGBo0UZ1ZjCCXRkH5UipIRlZkxSeXMS1mKk2CnbPN/tdrf0ow3qt Wya/GUPaIkSgIAUip4gsz5rPfrjFtwdyveKhEhhOxPt+vzX4QYLkcD2WUYGomWp21z dCHJg63ufh9qg== Received: by mail-pj1-f72.google.com with SMTP id h1-20020a17090a470100b0022646263abfso3594813pjg.6 for ; Sat, 21 Jan 2023 06:47:20 -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=KHeud4x8DYkt0LmbEtXun38Wko1mqDc6/VNe67/XaD8=; b=hHbchdQDu0zAG1s48pe67QAzg6TT7N10+xZUAGvm8tEP5GPzutVhpwLZYiCD3paM5/ bjySAH+eozK6tJ996AtnCFTl23bh44U9L1OfQQnl0dRwtAaE8R2ymJK8RU/nn1nYZgsX Al64oowT/1bZm4clx/UuC2Qak6Y6O8GmRFR2ZvhzomO+zMUfZCVsXVc9RRuCK5Ue2y7g p1UVv7ZeTEypyY4TKct/bnmGEUVE+jZmIvI4Ss8m+dAIlM6xJprYfaA5wNkg5cpcD2Cj OkJdFGtdm9m573Gyf4N9YT+qcSRApDiGXURl9e2nUaOTJ8d7PsjkPICb8XeqFUqCfPmg Kv7A== X-Gm-Message-State: AFqh2kp/+Vwdh8JC/cHWt001HLigZuTG1WN8CF6XXb7RMMG6mvG62WtP PwWpvno1Bve0BtDyAjIhJ3vlneYz8LVp4uOYYKAMxYlCgAlnIYbUv328Z4n+KNw96syRKAXw/14 dzPr5E2UdaqGbagMlmxi+FG/ohX2wGXLWzcfwnnQ8NA== X-Received: by 2002:a17:902:c948:b0:194:6414:12e1 with SMTP id i8-20020a170902c94800b00194641412e1mr26934087pla.25.1674312438633; Sat, 21 Jan 2023 06:47:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXuJnSd/yycsm4idWV++9Dhyb41QrVXj85yZUDZlWqwWOAXKOlzEsqj/EPOiysul3T0tJ6BW2w== X-Received: by 2002:a17:902:c948:b0:194:6414:12e1 with SMTP id i8-20020a170902c94800b00194641412e1mr26934076pla.25.1674312438353; Sat, 21 Jan 2023 06:47:18 -0800 (PST) Received: from chengendu.. (111-248-116-144.dynamic-ip.hinet.net. [111.248.116.144]) by smtp.gmail.com with ESMTPSA id p5-20020a170902bd0500b001932a9e4f2csm25656235pls.255.2023.01.21.06.47.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 06:47:18 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 2/4] (upstream) NFS: Clear the file access cache upon login Date: Sat, 21 Jan 2023 22:47:11 +0800 Message-Id: <20230121144713.39111-3-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230121144713.39111-1-chengen.du@canonical.com> References: <20230121144713.39111-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) [chengen - adjust context and use current_cred() as the argument to get login time] Signed-off-by: Chengen Du --- fs/nfs/dir.c | 24 ++++++++++++++++++++++++ include/linux/nfs_fs.h | 1 + 2 files changed, 25 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 7d9cf9f92b56..3ff938164381 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2294,9 +2294,29 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, st 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, struct rpc_cred *cred, struct nfs_access_entry *res, bool may_block) { 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; bool retry = true; int err; @@ -2324,6 +2344,9 @@ static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, str 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); @@ -2387,6 +2410,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 78ca796cd50e..21eeee96fa5a 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; struct rpc_cred * cred; + u64 timestamp; __u32 mask; struct rcu_head rcu_head; };