From patchwork Wed Jan 18 14:56:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1728285 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=CUmAH63K; 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 4Nxpl025wdz23h2 for ; Thu, 19 Jan 2023 01:57:15 +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 1pI9s5-0006xs-Qh; Wed, 18 Jan 2023 14:57:01 +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 1pI9s3-0006wf-Fn for kernel-team@lists.ubuntu.com; Wed, 18 Jan 2023 14:56:59 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 3B07F4191E for ; Wed, 18 Jan 2023 14:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674053819; bh=1ztq/T5A7IJ8ZJQH6sMmUmwYtWPumVS2CgQ/e5H3sac=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CUmAH63KTfY2/T0aQjW1M4Vi/8HoYy0vcjO6+hmSpv1itBs29KCfh0oY5Jm++340h PTipV60GGvsjuon6r7SqOtD7BgzuS3S8ojTYbqSMxNOuUwrUMbLdKk65mjvFIDdKvx MbsqC3ARaubKHVSDAjZ2H1LtogmblURdjEk+e3nM7e4JLV0YBttUF81R2H/ZUd0sAu /QTDr1GU3k6pVRqFKZMKXGu+ZoFqZ9hCXiPpBItjR9tJxV/4wIrgOEv5vhf+OBnR0b +Mo1kbwJJAEFPZP2glmZH6k1g92RuMn8Jee+KmAzrfLoscLQhJ+QvRvP/jRSYThSIM Z96GkjBJHMaRA== Received: by mail-pl1-f197.google.com with SMTP id d7-20020a170903230700b00194821e606dso7540047plh.7 for ; Wed, 18 Jan 2023 06:56:59 -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=1ztq/T5A7IJ8ZJQH6sMmUmwYtWPumVS2CgQ/e5H3sac=; b=5XfESWfz2dHZQ88xVc0hhWHCNh1ApypYW2pLlbCmTC57xvQ4hSriU9P2cK9XVIQuo6 2tFaXsXRzQmeUdJyD6MRsbmuRhoKmlcaCSqZoHAcGHIT5ELpA/P9/7OLEAlX8baGPxgu VwLuFWWyNFwu0JB/7DBPEbLgr5zqpd+iUNxCJ4avyWy2FhemffxSYyXBTWtZOUQRIJVP ZSnMVgY4DzpWhDKT6ddpyrbVBb88PS0LYEU89BRJ9AHLeim/bvuZAPEPKnyFgnX5roPt YR6vxIJ0RHbkARmFM9/ymFOJsy9S1Argy4JByEq7HM42zrfWeDFuTUztU5iJb5Pzc1CQ qjeA== X-Gm-Message-State: AFqh2kpTTP8T6YQ4kKwFK/9K7YG93uFLxpnknyTlJm/fNYacWF2CJWRI jurE890yh3dC9OwqQwWtvVRwKUlUdtF1k02wkS36BaFMl6wD9O9gPxYmLnhckdDDn85IzhYFPVn Ys6SYn0mHEMb50T5KZgShx+mJ6uFdDXUVHfU5B1mEPQ== X-Received: by 2002:aa7:8619:0:b0:581:12c5:1356 with SMTP id p25-20020aa78619000000b0058112c51356mr7786404pfn.30.1674053817315; Wed, 18 Jan 2023 06:56:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXvYMXH5/Q+1Zxq8Ufq3vYpEU/toIfHFSsvwwa5agr/ORAiDf2QDDqJtvBbRKlgsK/ElXUvUrw== X-Received: by 2002:aa7:8619:0:b0:581:12c5:1356 with SMTP id p25-20020aa78619000000b0058112c51356mr7786389pfn.30.1674053817009; Wed, 18 Jan 2023 06:56:57 -0800 (PST) Received: from chengendu.. (111-248-160-17.dynamic-ip.hinet.net. [111.248.160.17]) by smtp.gmail.com with ESMTPSA id p2-20020aa79e82000000b005825b8e0540sm6964736pfq.204.2023.01.18.06.56.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:56:56 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 1/4] (upstream) cred: add cred_fscmp() for comparing creds. Date: Wed, 18 Jan 2023 22:56:49 +0800 Message-Id: <20230118145652.35953-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230118145652.35953-1-chengen.du@canonical.com> References: <20230118145652.35953-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: NeilBrown BugLink: https://bugs.launchpad.net/bugs/2003053 NFS needs to compare to credentials, to see if they can be treated the same w.r.t. filesystem access. Sometimes an ordering is needed when credentials are used as a key to an rbtree. NFS currently has its own private credential management from before 'struct cred' existed. To move it over to more consistent use of 'struct cred' we need a comparison function. This patch adds that function. Signed-off-by: NeilBrown Signed-off-by: Anna Schumaker (cherry picked from commit d89b22d46a40da3a1630ecea111beaf3ef10bc21) Signed-off-by: Chengen Du --- include/linux/cred.h | 1 + kernel/cred.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/linux/cred.h b/include/linux/cred.h index 044c6b72d1e9..dbef5294121e 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -169,6 +169,7 @@ extern int change_create_files_as(struct cred *, struct inode *); extern int set_security_override(struct cred *, u32); extern int set_security_override_from_ctx(struct cred *, const char *); extern int set_create_files_as(struct cred *, struct inode *); +extern int cred_fscmp(const struct cred *, const struct cred *); extern void __init cred_init(void); /* diff --git a/kernel/cred.c b/kernel/cred.c index eed2bc6aa7d8..ca3ccdbccd7e 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -19,6 +19,7 @@ #include #include #include +#include #if 0 #define kdebug(FMT, ...) \ @@ -589,6 +590,60 @@ void revert_creds(const struct cred *old) } EXPORT_SYMBOL(revert_creds); +/** + * cred_fscmp - Compare two credentials with respect to filesystem access. + * @a: The first credential + * @b: The second credential + * + * cred_cmp() will return zero if both credentials have the same + * fsuid, fsgid, and supplementary groups. That is, if they will both + * provide the same access to files based on mode/uid/gid. + * If the credentials are different, then either -1 or 1 will + * be returned depending on whether @a comes before or after @b + * respectively in an arbitrary, but stable, ordering of credentials. + * + * Return: -1, 0, or 1 depending on comparison + */ +int cred_fscmp(const struct cred *a, const struct cred *b) +{ + struct group_info *ga, *gb; + int g; + + if (a == b) + return 0; + if (uid_lt(a->fsuid, b->fsuid)) + return -1; + if (uid_gt(a->fsuid, b->fsuid)) + return 1; + + if (gid_lt(a->fsgid, b->fsgid)) + return -1; + if (gid_gt(a->fsgid, b->fsgid)) + return 1; + + ga = a->group_info; + gb = b->group_info; + if (ga == gb) + return 0; + if (ga == NULL) + return -1; + if (gb == NULL) + return 1; + if (ga->ngroups < gb->ngroups) + return -1; + if (ga->ngroups > gb->ngroups) + return 1; + + for (g = 0; g < ga->ngroups; g++) { + if (gid_lt(ga->gid[g], gb->gid[g])) + return -1; + if (gid_gt(ga->gid[g], gb->gid[g])) + return 1; + } + return 0; +} +EXPORT_SYMBOL(cred_fscmp); + /* * initialise the credentials stuff */ From patchwork Wed Jan 18 14:56:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1728288 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=RTmQHsXa; 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 4Nxpl021V2z23fT for ; Thu, 19 Jan 2023 01:57:15 +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 1pI9s7-0006yu-2X; Wed, 18 Jan 2023 14:57:03 +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 1pI9s4-0006wn-Fh for kernel-team@lists.ubuntu.com; Wed, 18 Jan 2023 14:57:00 +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 E23FF4191E for ; Wed, 18 Jan 2023 14:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674053819; bh=ksHbwBdjdDTd45jasHEfen4wi7tu3TkBT+QcOuqOZMk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RTmQHsXacZnDP1BcQiAcTIqqptAcuexwS//b7T/XrP5d6JGYSL60KTd+E9R1pLVIX 4YZJ1H7aSAR0JGM96d67BaWPbvUsBv8xzjZsgKoEZJZg0x47oFFQpGJRZMhtX+7stX gDr8rYHy6REb40pjbbpLHl4icbPqzo9m2MAwJjZryZxH23VCsdTDhAu0xdTOocTfkI iEs201LZvcCe94i4ob5LCNyPFChmim37u72H4f59GxB23UZSlNWXhGRjmZU3fEYVRy WQrReLwAmlJltIcUukTszXfPvdKyNfZxoTfRYiEpPAE9eUj3wcSLZZU5avgoOwT0Yh SIWYLZ8JbW9AA== Received: by mail-pj1-f69.google.com with SMTP id oa8-20020a17090b1bc800b002292ab4cc4cso1605413pjb.0 for ; Wed, 18 Jan 2023 06:56:59 -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=ksHbwBdjdDTd45jasHEfen4wi7tu3TkBT+QcOuqOZMk=; b=3AEvzLCE69z1NhutYDIiLakFveaD8ySE+QicH7f7MsF7z7r07/X4Z9N4S+eOUxX7l2 vUEBe2B8hF8EF/E8edQqtqgz3KZs0dhxslfwIZzfosi3oTnl+COlmolHGi5w+wDTpp4I Uotyrdvyja8/bvsroBs8qoOABaocqFDvYpYJD4J0P/nmgpPSzUWDKAAGplXMyg9gvXsJ vywCAHcBEoQNjfO9vsr5uEFrnW7TKXwSlud5t6wdN/k7KjEIjUAPVv1shLytQ1o7kiMs p44mHWvEED1pF2O1iOojSEn6mmAOxiaKNlWI0LAjbWHUBVYjHcKluDABiarJ+UVjFLSV lbDA== X-Gm-Message-State: AFqh2kpLZGJSqY9AAhxT+tQ4FVD2pqGEpBmSNFL6eWOuroPKqZBXsMpq au7vti35A2XEbVJMJ8DXlsBHaCkcX3EMdzbroR4awP1/76W5stuW9Qva+xvwRB79HDe+hgEFxuu MltN0HQqRn0VdHhBkfmULeJP0FHl4p72nRF165K8wSA== X-Received: by 2002:a62:19cb:0:b0:58d:b2eb:86ef with SMTP id 194-20020a6219cb000000b0058db2eb86efmr7019088pfz.9.1674053818346; Wed, 18 Jan 2023 06:56:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvVPdqUyS3tsz2YA2PUo6icrpHNH+mH/Sd2DOpPMmw5oq6H/seyvmXJJ+wO7zXCfxXgl8lQlg== X-Received: by 2002:a62:19cb:0:b0:58d:b2eb:86ef with SMTP id 194-20020a6219cb000000b0058db2eb86efmr7019070pfz.9.1674053817994; Wed, 18 Jan 2023 06:56:57 -0800 (PST) Received: from chengendu.. (111-248-160-17.dynamic-ip.hinet.net. [111.248.160.17]) by smtp.gmail.com with ESMTPSA id p2-20020aa79e82000000b005825b8e0540sm6964736pfq.204.2023.01.18.06.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:56:57 -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: Wed, 18 Jan 2023 22:56:50 +0800 Message-Id: <20230118145652.35953-3-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230118145652.35953-1-chengen.du@canonical.com> References: <20230118145652.35953-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 | 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; }; From patchwork Wed Jan 18 14:56:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1728284 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=NHUJ560V; 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 4Nxpl02yp0z23h6 for ; Thu, 19 Jan 2023 01:57:15 +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 1pI9sB-00076P-7i; Wed, 18 Jan 2023 14:57:07 +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 1pI9s7-0006yt-2q for kernel-team@lists.ubuntu.com; Wed, 18 Jan 2023 14:57:03 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 E735C41922 for ; Wed, 18 Jan 2023 14:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674053820; bh=vMMrcLZRzMZCGf7OJeN61EGyTG2pSd9m1Oic6COAJsc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NHUJ560VQt5vn1wLFsDm9Oi+NhKOeK1ysB0VaSuBSpM+4GsLDJ+88DTS1T/OwOT6n sf9EVntBeyYzwEPmMd4pAIWggZoaeWI1UsXedhZN7zX+FfHkwPF7DxB+vcxdCPEojT xxtqAPxVEBNwiTXUEYnbe0a2jfCBQ34CnSrWxQ74uPYZahNTfz8Sbnv7EAXUp0+CW7 b+Cnei3gFUkdqysqv7cIWurq5aJ9d0wPlefHhiW6G3QJv/HhzB7VXj/2uLJOuwbMJz EOh4eWt31TIFLTL7rTuc6dtnYPOloOGABQZQUMz3v/whvHorsqzEoEoExsrDueMfPF i/83c7FWka14w== Received: by mail-pj1-f70.google.com with SMTP id h6-20020a17090aa88600b00223fccff2efso1573772pjq.6 for ; Wed, 18 Jan 2023 06:57:00 -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=vMMrcLZRzMZCGf7OJeN61EGyTG2pSd9m1Oic6COAJsc=; b=P6aKYUAoSx/s4oBjuwEctqmRWPGVUF1lNuOzHQA0IdD446SUkC1UUPQE539/k9iTb9 H6rxrnkO2B0O/5ANCzRwW2cY/uI8uPyvStf2ME2wDHNn2r/llMv/Ns6AhNSDS+BRtGaJ KQLtJe6ZkbAoHZiTmI5TiA06p9DfdIUExKpB+iVLFbFu4tjOpiaPqJFXm4SPqybfJN0d qOb0q+LUuxxzTqwtxpyT878MGnYll98e/NuryKSwoSk3Wq75ISIS+yfBk19oV1S9koVO RYaz9aXJmV+CTbyfjuXej8Qmh6Ix3CM05Ancdy1Hk/1kWv63ZCw+C4d6qstHqK7Zr9I8 izeg== X-Gm-Message-State: AFqh2koNhAA1N3BeyIHDIgmsNOVP4geAfrkuHCp/UhXaV8HpMv7Or93O Qgjbn5Pq1203f9xXL6rtozNtOURK7OsyoEedR4sNCflJvT4OHAUw94XYTTDYGn0bKF2Qqbmmttf c4PfZyyLjcr2sWbcxNInIWYN7yKcnPwzcjIMHm+4dhw== X-Received: by 2002:a05:6a20:e610:b0:9d:efbf:787d with SMTP id my16-20020a056a20e61000b0009defbf787dmr7174406pzb.50.1674053819327; Wed, 18 Jan 2023 06:56:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXvqgftFe21nCPfHAyt9MmDqb7vpLn6bopUrpRe/SQBX8NmuW7HOS+ofTng2eMpwu1hb84HTew== X-Received: by 2002:a05:6a20:e610:b0:9d:efbf:787d with SMTP id my16-20020a056a20e61000b0009defbf787dmr7174394pzb.50.1674053819053; Wed, 18 Jan 2023 06:56:59 -0800 (PST) Received: from chengendu.. (111-248-160-17.dynamic-ip.hinet.net. [111.248.160.17]) by smtp.gmail.com with ESMTPSA id p2-20020aa79e82000000b005825b8e0540sm6964736pfq.204.2023.01.18.06.56.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:56:58 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 3/4] (upstream) NFS: Judge the file access cache's timestamp in rcu path Date: Wed, 18 Jan 2023 22:56:51 +0800 Message-Id: <20230118145652.35953-4-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230118145652.35953-1-chengen.du@canonical.com> References: <20230118145652.35953-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" 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 Signed-off-by: Trond Myklebust (backported from commit 029085b8949f5d269ae2bbd14915407dd0c7f902) Signed-off-by: Chengen Du --- fs/nfs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) 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; From patchwork Wed Jan 18 14:56:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1728286 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=n5n3EBDB; 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 4Nxpl027v7z23h4 for ; Thu, 19 Jan 2023 01:57:15 +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 1pI9sC-00077f-JT; Wed, 18 Jan 2023 14:57:08 +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 1pI9s9-00071s-1q for kernel-team@lists.ubuntu.com; Wed, 18 Jan 2023 14:57:05 +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 3FCE44191E for ; Wed, 18 Jan 2023 14:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674053823; bh=0bl0UGbtEp0YresrzuBy4C9WetOQWvdy91vfOBslV1c=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n5n3EBDBna7M/znj7TeTH+DU/uLMuX/NleWDfxXaJdmqpM9nEvLri97vaoWEaCigt p8toKgtfuDkJaN3ehD7b73MTUyopWKBVQIu15ysqje2eLaFFUqus1KDcYzQ0XDxxR9 flz5RhaRNHg4mTxbw+ZTPtivZjmW9KKByjQRCSJI7XTabbRflrOmeDHxHoXMJUkun6 wLxE68uFRDmtxxCfe5PuBe5CebsgDtw5SKVmy7bvpq465W8cAC0Qf4/8N0rGRx3D5S CPrAvcQSk8B8La1EPjm7NoHbyEN0N6JCHaGW8+rLfYL/Vy9jZskgGIlf2pYWhyDHFW T/ukxN8xl9kUw== Received: by mail-pj1-f69.google.com with SMTP id pa16-20020a17090b265000b0020a71040b4cso14837430pjb.6 for ; Wed, 18 Jan 2023 06:57:03 -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=0bl0UGbtEp0YresrzuBy4C9WetOQWvdy91vfOBslV1c=; b=JIszHfMnhGBz0BqOLZqsHIrKuPmVnKwk9R7UUlJniMNusZpyDXjrqGAriwzP7HsZwS Dmen3r60rUTxHoVinQRasAcp5thy4heX802YuwRqgwwlT9I1KwnO2uAnoblxBETdUvo9 aqlXW4VDnKqZZaEi0ZbOsS94z37G3lhIX7JEOYZhpIE5F24DPOpMSdmeVB8YAahviTh6 71rfmbgTADdc/qaDdmGROpG4/9PuawKX+2/dxQ05BW+X40KbA0eUnBsV4rouIiwKCCUy HvC4GghDq50P/ZpljQJA3mEb9ZCEgueUOYSzd4XMfmszyESZL/P9hUhF0v+4tJ/rd5dI MQwQ== X-Gm-Message-State: AFqh2krsGX9A5mq82pgN3M4joheG8NXlBzGg4BG2ojlltpH4VMcWpzR2 0K1duEPCub4o1tsJ95Blk2EnXEmU6h3NhUGyjrtr9+N58kGpsgQ02oCbEDpl4avI9/q5Uclod6P WMoRnxV01cGWrr3APv4svzivRwbR15oH6yTId2sFsTA== X-Received: by 2002:a62:1713:0:b0:582:a492:f302 with SMTP id 19-20020a621713000000b00582a492f302mr7459274pfx.16.1674053820478; Wed, 18 Jan 2023 06:57:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXs5NGDSyn3rUCs5Tlgy27JzCErjCxITZZ+Ogxj86dPZKXsbmBgp+aGMrGbaB5guX1o7AaTzcw== X-Received: by 2002:a62:1713:0:b0:582:a492:f302 with SMTP id 19-20020a621713000000b00582a492f302mr7459265pfx.16.1674053820197; Wed, 18 Jan 2023 06:57:00 -0800 (PST) Received: from chengendu.. (111-248-160-17.dynamic-ip.hinet.net. [111.248.160.17]) by smtp.gmail.com with ESMTPSA id p2-20020aa79e82000000b005825b8e0540sm6964736pfq.204.2023.01.18.06.56.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:56:59 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 4/4] (upstream) NFS: Fix up a sparse warning Date: Wed, 18 Jan 2023 22:56:52 +0800 Message-Id: <20230118145652.35953-5-chengen.du@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230118145652.35953-1-chengen.du@canonical.com> References: <20230118145652.35953-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 sparse is warning about an incorrect RCU dereference. fs/nfs/dir.c:2965:56: warning: incorrect type in argument 1 (different address spaces) fs/nfs/dir.c:2965:56: expected struct cred const * fs/nfs/dir.c:2965:56: got struct cred const [noderef] __rcu *const cred Signed-off-by: Trond Myklebust (cherry picked from commit 5e9a7b9c2ea18551759833146a181b14835bfe39) Signed-off-by: Chengen Du --- fs/nfs/dir.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 9a39bb94d5d8..b98b19ca367c 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2298,12 +2298,14 @@ static u64 nfs_access_login_time(const struct task_struct *task, const struct cred *cred) { const struct task_struct *parent; + const struct cred *pcred; u64 ret; rcu_read_lock(); for (;;) { parent = rcu_dereference(task->real_parent); - if (parent == task || cred_fscmp(parent->cred, cred) != 0) + pcred = rcu_dereference(parent->cred); + if (parent == task || cred_fscmp(pcred, cred) != 0) break; task = parent; }