Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3885824imw; Thu, 7 Jul 2022 09:04:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sxJsoBOgMVOZikGlRy0YFSJXn59bp4v8OhwtAmTn01ggLQD8em78GGzWhgwKW1LPTbbptw X-Received: by 2002:a17:906:7049:b0:70c:a5fe:d4f8 with SMTP id r9-20020a170906704900b0070ca5fed4f8mr43193863ejj.493.1657209865306; Thu, 07 Jul 2022 09:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657209865; cv=none; d=google.com; s=arc-20160816; b=cXUnpyRp9DEwNWsLuh3xU/+xBis36nA8gUjbcUtpsg0sKAKJLpp2ft2YyFnkrjtN6v Uoqj2MynlY3RymXVIth6aG4lQUmxv+FNVXD/w2WQ3T225/nXWRE96FcyH+QhPsospa+U eIlIejjl6dGI03O2CroiqLySc8s3w9MffllFhMvzeRHNTLRgPb7emGaDdN2Ha2OYpPxs qqzMp3qLDls1Xt/5MrOXNAbCVXkMu69EHmn/Ye8wUTOc9SMz4GA31rdy0S4MTxv4IToC rc4UXFnkOqhgRyQE0OfF/cGrgkTwPEFkSkwSRNZ+ELZhQhfvMETeYg0/o9xWH3i1ETm6 z7AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject; bh=3Gh0VIl+5+3SDZY0BgHtkWwp6wOycV9iXnXsRER1urM=; b=h9kuvJnhECItr6LqjrN6k1q+Ims6dZzDvpjZijfH1HLtdhUUoDwIM8VDHh8RKzAIiz dhykorm3Gjy5DguzqHIVfSq1Fq/ovuVrS5XzG+Fq/EAOiPzCok+CYfPnrMQyr5NVn8BA wQd5bG1P8uWgG8Zzw6N8b11vsqfiaHvTgV7x9cJr+H4/lRx5MKYVYW4KDPPqV7CV8x/E ngnIeoPUihr4hS8NFHz8JXKFNgy4l3DUlyEMgPbaHomvzN+B3TZGUjljSg/xNphbFh0h 9ZPcTIOk5iYVN29064d/cIJwR4+mDGHOKRLo9r9FogIeYDmA/m1i1Q6GfK9lPhglerd/ uX6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a056402274700b0043a91cbc43fsi1838307edd.349.2022.07.07.09.03.32; Thu, 07 Jul 2022 09:04:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbiGGP6h (ORCPT + 99 others); Thu, 7 Jul 2022 11:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbiGGP6f (ORCPT ); Thu, 7 Jul 2022 11:58:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A02651261E for ; Thu, 7 Jul 2022 08:58:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 55361B8228C for ; Thu, 7 Jul 2022 15:58:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C95DDC3411E; Thu, 7 Jul 2022 15:58:31 +0000 (UTC) Subject: [PATCH RFC] NFSD: Bump the ref count on nf_inode From: Chuck Lever To: jlayton@redhat.com Cc: linux-nfs@vger.kernel.org Date: Thu, 07 Jul 2022 11:58:30 -0400 Message-ID: <165720933938.1180.14325183467695610136.stgit@klimt.1015granger.net> User-Agent: StGit/1.5.dev3+g9561319 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The documenting comment for struct nf_file states: /* * A representation of a file that has been opened by knfsd. These are hashed * in the hashtable by inode pointer value. Note that this object doesn't * hold a reference to the inode by itself, so the nf_inode pointer should * never be dereferenced, only used for comparison. */ However, nfsd_file_mark_find_or_create() does dereference the pointer stored in this field. Signed-off-by: Chuck Lever --- fs/nfsd/filecache.c | 3 +++ fs/nfsd/filecache.h | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) Hi Jeff- I'm still testing this one, but I'm wondering what you think of it. I did hit a KASAN splat that might be related, but it's not 100% reproducible. diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 9cb2d590c036..7b43bb427a53 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -180,6 +180,7 @@ nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval, nf->nf_cred = get_current_cred(); nf->nf_net = net; nf->nf_flags = 0; + ihold(inode); nf->nf_inode = inode; nf->nf_hashval = hashval; refcount_set(&nf->nf_ref, 1); @@ -210,6 +211,7 @@ nfsd_file_free(struct nfsd_file *nf) fput(nf->nf_file); flush = true; } + iput(nf->nf_inode); call_rcu(&nf->nf_rcu, nfsd_file_slab_free); return flush; } @@ -940,6 +942,7 @@ nfsd_do_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, if (nf == NULL) goto open_file; spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock); + iput(new->nf_inode); nfsd_file_slab_free(&new->nf_rcu); wait_for_construction: diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index 1da0c79a5580..01fbf6e88cce 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -24,9 +24,7 @@ struct nfsd_file_mark { /* * A representation of a file that has been opened by knfsd. These are hashed - * in the hashtable by inode pointer value. Note that this object doesn't - * hold a reference to the inode by itself, so the nf_inode pointer should - * never be dereferenced, only used for comparison. + * in the hashtable by inode pointer value. */ struct nfsd_file { struct hlist_node nf_node;