Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp106980ybk; Fri, 8 May 2020 15:20:01 -0700 (PDT) X-Google-Smtp-Source: APiQypL4bseyf/deMbiIeJycKLV6g2NIKQvaUM/J5A+stuvAEBbnOYdz/SilnJT/Nk27XUKyDEKA X-Received: by 2002:aa7:c38a:: with SMTP id k10mr4213270edq.74.1588976401281; Fri, 08 May 2020 15:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588976401; cv=none; d=google.com; s=arc-20160816; b=iJT5LbHvFhHDkrfZqNqfHKjiTfsePwNL6JHAh0wNTd/9qEHzIP+P3rP+Goc4XNa1e6 Vq+48uPAIV67kq1PVbCaTOlP0zkij3MLTEmkNEsEhlfuAoa95ospJ/1aJYapoYHOxn00 j4xcEZWF0btInojDACa8YL/61DLfjhrdOwI1bActqLFsrUChOnWtbqippMut+eq9vJPq 4hO83k29NyvqUDIpuJ/pZrU1iNT/DFtxccMUO8CwlNPA6T5Xr4WIHzoEnKYA1+iq7XG0 rqJCfZm+adBbnQFhcb1Zi4QUemQq7tTrIE7kGB6wXqMkDOaHlSDo3z+/szRlI0bnbY+G tAjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:from:user-agent:content-disposition :mime-version:message-id:subject:cc:to:date; bh=f1ZQ82uKkvaSyIbXNtHG7IZ67WZklSRTPvB41QP2UE4=; b=NoIJ9UrsQ1dtuuqpDn6iIM7q794RJIpNi5BB39kgGPjdy0lJmlSWLe1OzI2h9Jv4Ph UN7ipkewN7LSsOQLOzF4BHFw7+5j6xoQo/dnudUw69XHxbXUN+YOLBWlW6kGrxQW++C+ zrjEaxDYt24HV6Z5Ron9y/GPKbfbMDiQBe3ikUndqInk1Rr3TQnt9hQNadc3zRKDjCas EU8SrApAOS0AEDR+sAsHFPqUj/XpCVSuVebeoBG+sY1bjKIzWNBM6TDQsOlcdaNIZhrn 8FRrqGfkQv1f5IAyDo1mrGl6t1UhEwQ0BtUL40HFKU2esy/k3OlXyOtHLqtq+rg8Nxkm Yisw== 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 de5si264672edb.511.2020.05.08.15.19.38; Fri, 08 May 2020 15:20:01 -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 S1727778AbgEHWTf (ORCPT + 99 others); Fri, 8 May 2020 18:19:35 -0400 Received: from fieldses.org ([173.255.197.46]:51030 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbgEHWTf (ORCPT ); Fri, 8 May 2020 18:19:35 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 0772E20C8; Fri, 8 May 2020 18:19:35 -0400 (EDT) Date: Fri, 8 May 2020 18:19:35 -0400 To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH] nfs: fix NULL deference in nfs4_get_valid_delegation Message-ID: <20200508221935.GA11225@fieldses.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) From: bfields@fieldses.org (J. Bruce Fields) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 */ -- 2.26.2