Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1865317ybk; Mon, 11 May 2020 06:17:15 -0700 (PDT) X-Google-Smtp-Source: APiQypLV5MugsGTSN4LRXBqrCYVcV94Z5jEJpvC1wkG7oIVaBAzKvS2MXAnBsgEiQy9q+M2bxWfv X-Received: by 2002:a50:a883:: with SMTP id k3mr13197360edc.198.1589203035704; Mon, 11 May 2020 06:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589203035; cv=none; d=google.com; s=arc-20160816; b=mqkZar3yMZ+bzdLXUSUj/zEFEoI4VFVQ/0OHVPohRGbbq/mm2k2U0FuvA5Siust09P eGVfSwSRD5xH/5es96Rg5muxGRgmZJBUAEzIMB3ROCc3120wfat0tfG1qDQNZmM2FyRQ hr550Q98cq9bLe09zOZ7lf7xfmM/lYuwtXuT4yNni1SDkXo7Op5n67XJUG7h0gw6zLpQ bXDlK1QjIvUDLORxs9qiHG1AVj6V/Q/C1Vf5pUWxcRSBfoHn8CpSd3SyX6AhJAN1X4ad sdbvQ4DNTWYempbgDAuh6trC6wf5EzG4XymzgZTvDj+U+Y7QPl64n5qvQg4VzcjoDAYP 6TZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=iRx1i94zZEwFJaaHAki4g02GR9mH4L2DvymnX7bs+Xw=; b=Nqcld7UCM7vTe2jAYeZxuCBjS7kiG3nk5md9BqoYkCkGOy1VtLkjAs1GPeL1yJg7fc /x1I/NUGJOPN3Ucey5s/0dz/bCa1ML/hX7Sh0lvVaY47Ii1pVH4EZql9cwy2zJkLaJQA aUY9LmGGfCPxzVZOi5RTYNOW/srOtfIR3nBw7Vee7A2ndxV1TY1MPJKwM05y9FSvlwYn 9WcEnzvOvEvZcIlwHEMArgXBSsfX2RfIq/CZ/dDaW0Mh5tFTgzVx5LEfYHW5HjCGHB8u CTofVR/MccukuYAXZvCFVSN0E8yIJwwBZNvGGhyBxPUFfvCJrqr//q3hldTEVgkLfXOr gkHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si1862144ejg.502.2020.05.11.06.16.41; Mon, 11 May 2020 06:17:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbgEKNQi (ORCPT + 99 others); Mon, 11 May 2020 09:16:38 -0400 Received: from fieldses.org ([173.255.197.46]:54424 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726013AbgEKNQh (ORCPT ); Mon, 11 May 2020 09:16:37 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 695401CB4; Mon, 11 May 2020 09:16:37 -0400 (EDT) Date: Mon, 11 May 2020 09:16:37 -0400 From: "J. Bruce Fields" To: Masayoshi Mizuma Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: Re: [PATCH] nfs: fix NULL deference in nfs4_get_valid_delegation Message-ID: <20200511131637.GA8629@fieldses.org> References: <20200508221935.GA11225@fieldses.org> <20200511121054.l2j34vnwqxhvd2ao@gabell> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200511121054.l2j34vnwqxhvd2ao@gabell> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Thanks, applying.--b. On Mon, May 11, 2020 at 08:10:54AM -0400, Masayoshi Mizuma wrote: > On Fri, May 08, 2020 at 06:19:35PM -0400, J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > > > We add the new state to the nfsi->open_states list, making it > > potentially visible to other threads, before we've finished initializing > > it. > > > > That wasn't a problem when all the readers were also taking the i_lock > > (as we do here), but since we switched to RCU, there's now a possibility > > that a reader could see the partially initialized state. > > > > Symptoms observed were a crash when another thread called > > nfs4_get_valid_delegation() on a NULL inode. > > > > Fixes: 9ae075fdd190 "NFSv4: Convert open state lookup to use RCU" > > Signed-off-by: J. Bruce Fields > > --- > > fs/nfs/nfs4state.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c > > index ac93715c05a4..a8dc25ce48bb 100644 > > --- a/fs/nfs/nfs4state.c > > +++ b/fs/nfs/nfs4state.c > > @@ -734,9 +734,9 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) > > state = new; > > state->owner = owner; > > atomic_inc(&owner->so_count); > > - list_add_rcu(&state->inode_states, &nfsi->open_states); > > ihold(inode); > > state->inode = inode; > > + list_add_rcu(&state->inode_states, &nfsi->open_states); > > spin_unlock(&inode->i_lock); > > /* Note: The reclaim code dictates that we add stateless > > * and read-only stateids to the end of the list */ > > -- > > Thank you for posting the patch! It works for our box. > Please feel free to add: > > Reviewed-by: Seiichi Ikarashi > Tested-by: Daisuke Matsuda > Tested-by: Masayoshi Mizuma > > Without the patch, the system which is a NFSv4 client has been > crashed randomly. The panic log is such as: > > BUG: unable to handle page fault for address: ffffffffffffffb0 > ... > RIP: 0010:nfs4_get_valid_delegation+0x6/0x30 [nfsv4] > ... > Call Trace: > nfs4_open_prepare+0x80/0x1c0 [nfsv4] > __rpc_execute+0x75/0x390 [sunrpc] > ? finish_task_switch+0x75/0x260 > rpc_async_schedule+0x29/0x40 [sunrpc] > process_one_work+0x1ad/0x370 > worker_thread+0x30/0x390 > ? create_worker+0x1a0/0x1a0 > kthread+0x10c/0x130 > ? kthread_park+0x80/0x80 > ret_from_fork+0x22/0x30 > > After applied the patch, the panic is gone. > > Thanks! > Masa