Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp906816rdb; Wed, 1 Nov 2023 06:21:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkHg+JdcPVHW9Dy2fg8QbvqkHVeCSm3ytds+S99rU6EBgyf5YIsAk4+CUvJ4jvXYYeU9n4 X-Received: by 2002:a05:6a20:7485:b0:171:c88a:891e with SMTP id p5-20020a056a20748500b00171c88a891emr13847673pzd.55.1698844903732; Wed, 01 Nov 2023 06:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698844903; cv=none; d=google.com; s=arc-20160816; b=xrypR0XU0tFah0yMb6gXcZXxtjhv1rcAMPbQhJMGElxmsi9oPYn0igIHGb2v0p7skj Lk1NzxI4VxF6QZ+mRISijylfDm0pF/DVC7oXXD49bhul85WKT0bFVxy735ocYJH7jAJx 159dC1XlDy8eFlVUQ1fxQJqRi4NSHFGu1iuSuLgVw7wRn6c2T9bw7HkhV2g5B5/404/o 61Qj2g9nD25GU2bfFFruYJdns0Fgqz7hYLinCtJUNTCIibWnG2irbchwJ1mqfpbjOP0u cbKYPiOSN8Jqi6V3zeWmEA2MHCcvBsjR2QAdIr8eppzbdH6RidCfnWrDjTrzmVeXV0W4 iekg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xThp48OO5GzIlur7YkP4GgzDT8B7pPmZBQECo2sOWgY=; fh=NaCkPmw/Qjkr2j3gBJAeYZgQFTGQ8y2QBvy+xjfXDYE=; b=j9tan5xfSJ5uROAsk8NjObKb7EmxPRgphGEQAZCsBMHfwxeBRn25lc+OI8ZqrMsmgI aFtzAWpLrp7RHGaGnylJWrXfoewZDM7nTFy+kA4QVs3TDQxe7b2ej0XxDJ+LAcGNU8dO VH6Y3T2gZ3PAXwbCxKBbqrBBJxcAeSWFMJ+q4R6UUm3P8RAWbyhZqlCa9PXa/5K0Qz0n gBoZ5L5rRjiJWTWLRJLcbfYWYsxt4+mSp9Y60q64Cz0g0XUKTmqSJsaBptp75UWDA1Le aoRh1gOZzsLc77Znu+8boDT2wR8dnyKy8f2EZHvgQmIUqDRQ18oCtKV1HRte1LIn6tf/ QW9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rf4cA1cs; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id jx1-20020a17090b46c100b002774ecb2ecdsi830875pjb.19.2023.11.01.06.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 06:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rf4cA1cs; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3C160809024E; Wed, 1 Nov 2023 06:21:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343846AbjKANVj (ORCPT + 99 others); Wed, 1 Nov 2023 09:21:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343851AbjKANVi (ORCPT ); Wed, 1 Nov 2023 09:21:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CF1DFC for ; Wed, 1 Nov 2023 06:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698844850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xThp48OO5GzIlur7YkP4GgzDT8B7pPmZBQECo2sOWgY=; b=Rf4cA1cs/rg8BJyy7ha7d9zsM9oDf3ozZmcqBVpC/RSKkzHee00rXHAFHKBOOpYs8ytuXG fs9K3I3PtrRSEHPtdZoKa5G5HQ60qzly395hVSNr170KmDXucDpXQprEHeOX0QR54cLJR7 +1YNQxBu/ykCMI/tpBIM4h1CUy5w1Yc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-zNXRGIp_P0Oe5Uw6LTZQ7Q-1; Wed, 01 Nov 2023 09:20:47 -0400 X-MC-Unique: zNXRGIp_P0Oe5Uw6LTZQ7Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A88F185A780; Wed, 1 Nov 2023 13:20:47 +0000 (UTC) Received: from [192.168.37.1] (unknown [10.22.50.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 563781121308; Wed, 1 Nov 2023 13:20:46 +0000 (UTC) From: Benjamin Coddington To: trondmy@kernel.org Cc: Anna Schumaker , linux-nfs@vger.kernel.org, Scott Mayhew Subject: Re: [PATCH] pNFS: Fix a hang in nfs4_evict_inode() Date: Wed, 01 Nov 2023 09:20:45 -0400 Message-ID: <92B7CF2E-26C4-412A-AAED-B06F6B9B4383@redhat.com> In-Reply-To: <20231008182019.12842-1-trondmy@kernel.org> References: <20231008182019.12842-1-trondmy@kernel.org> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 01 Nov 2023 06:21:39 -0700 (PDT) Hi Trond, On 8 Oct 2023, at 14:20, trondmy@kernel.org wrote: > From: Trond Myklebust > > We are not allowed to call pnfs_mark_matching_lsegs_return() without > also holding a reference to the layout header, since doing so could lea= d > to the reference count going to zero when we call > pnfs_layout_remove_lseg(). This again can lead to a hang when we get to= > nfs4_evict_inode() and are unable to clear the layout pointer. > > pnfs_layout_return_unused_byserver() is guilty of this behaviour, and > has been seen to trigger the refcount warning prior to a hang. > > Fixes: b6d49ecd1081 ("NFSv4: Fix a pNFS layout related use-after-free r= ace when freeing the inode") > Cc: stable@vger.kernel.org > Signed-off-by: Trond Myklebust > --- > fs/nfs/pnfs.c | 33 +++++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 10 deletions(-) > > diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c > index 63904a372b2f..21a365357629 100644 > --- a/fs/nfs/pnfs.c > +++ b/fs/nfs/pnfs.c > @@ -2638,31 +2638,44 @@ pnfs_should_return_unused_layout(struct pnfs_la= yout_hdr *lo, > return mode =3D=3D 0; > } > > -static int > -pnfs_layout_return_unused_byserver(struct nfs_server *server, void *da= ta) > +static int pnfs_layout_return_unused_byserver(struct nfs_server *serve= r, > + void *data) > { > const struct pnfs_layout_range *range =3D data; > + const struct cred *cred; > struct pnfs_layout_hdr *lo; > struct inode *inode; > + nfs4_stateid stateid; > + enum pnfs_iomode iomode; > + > restart: > rcu_read_lock(); > list_for_each_entry_rcu(lo, &server->layouts, plh_layouts) { > - if (!pnfs_layout_can_be_returned(lo) || > + inode =3D lo->plh_inode; > + if (!inode || !pnfs_layout_can_be_returned(lo) || > test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) > continue; > - inode =3D lo->plh_inode; > spin_lock(&inode->i_lock); > - if (!pnfs_should_return_unused_layout(lo, range)) { > + if (!lo->plh_inode || > + !pnfs_should_return_unused_layout(lo, range)) { > spin_unlock(&inode->i_lock); > continue; > } > + pnfs_get_layout_hdr(lo); We're getting a crash with the nfs_inode.layout =3D=3D NULL in writeback.= We haven't bisected to this yet, but I think this change is exposing the case where the pnfs_layout_hdr refcount goes to zero, but we can still fi= nd it here on server->layouts, and bump the refcount incorrectly. Plausible? We can send a fix or test one.. Ben