Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp246685rwb; Fri, 30 Sep 2022 21:58:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5LsDgU0oorPUNOPL1IrCbIrucZLrb+c6DbTIAefA3QW/NXIh7YtGOkRPW277qlEncXHxoW X-Received: by 2002:a63:e513:0:b0:42b:d733:602d with SMTP id r19-20020a63e513000000b0042bd733602dmr9850323pgh.549.1664600319037; Fri, 30 Sep 2022 21:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664600319; cv=none; d=google.com; s=arc-20160816; b=cefVeVJ67GlvRl95s33FzUpe2FtFHy2g/ksIPYn8zNO4RJymck+YFw7QsaYlHiBNHR 1hP+hs6zS1fJnzDBpKiQHA9HIAqIqjXJmg3TD9lWYUWS00S+5DRYYPLITckinbX5pEVq YcY+enLoOasJywrxdHKR7UHCpQVicRRhard9xVcC2d7VFHIJRCMFluOvcSTfRO6tNmto EPEPCmscSeCaDz2zJ+YfI1xxl+yk8w+BAMSeG0aogzTKAT61k0+5VCChMpwo4foo/ob6 wvfd4wI89/PuHGcHYtV578RUN7OwT9FUUDqqVm6Bxaq7EDQoPge5KXvNSsHixqSfbWRC omQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=g3G+a07EAqu6SiU85l8fAD7nyUc3XRqVHf+iDEqvp3Q=; b=aEHD9njC20FywTRIjslGVpX63UGmLA221DcW5m7IESUM/sO3M3mK6vJvZAhtcU9+dg 7O+UBCeBPCkoJwls3D5w7oU2oDJRxlb+Q0rqK77Sa1ZgSYy8JXYIoajlLE/O7QU3PTwr skXMr4Pf/C//bxyz3ooYOMqV2+EH8RsolQ88WTRQT57V+ArV3HGvmlE5y97UBxK2VIl+ EzglSYEyHEUDcAfZoXghuFkcKaDshie+9TC25AM7wIwbETo07ZdFGFJ+EgEgGbi4med/ cJfrOyIKi1wyH9+fJmz+B2TZlX68OxKfFHSRTeVf9LHYVDd3U7qrJ7u+H0eMKWm4nIvz DvgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Jd5inrjU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f126-20020a625184000000b00540db8be1c0si4223246pfb.195.2022.09.30.21.58.06; Fri, 30 Sep 2022 21:58:39 -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; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Jd5inrjU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbiJAEpE (ORCPT + 99 others); Sat, 1 Oct 2022 00:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiJAEpC (ORCPT ); Sat, 1 Oct 2022 00:45:02 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8822B63A for ; Fri, 30 Sep 2022 21:44:58 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E2D631F892; Sat, 1 Oct 2022 04:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664599496; h=from:from:reply-to: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=g3G+a07EAqu6SiU85l8fAD7nyUc3XRqVHf+iDEqvp3Q=; b=Jd5inrjUijcRADO+L5Ct/ntcE1B4ZZTA4vtt+uxHyfcAfukvjsT7FyP+rdJDXlbYqziAa8 Bo8sDUQ3HWoEPInJMU9DHGE0yNIuMouFmVx8ms+jR94bRw7Cnn/3VEklI7o+0mYOd+GY4Y J7j3PnOKMf9Oywn1CsSmlWfsqWOc+xk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664599496; h=from:from:reply-to: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=g3G+a07EAqu6SiU85l8fAD7nyUc3XRqVHf+iDEqvp3Q=; b=/+VqhOGLdeEkI/V3VHWwgYrvrHrvIS02Me7oZGfLCn7CTYD2VTLe7PPSSVeczsQSvyIkoF LPMvhq2xQMiYfMBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BA717133E5; Sat, 1 Oct 2022 04:44:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id s4uBHMfFN2N4bgAAMHmgww (envelope-from ); Sat, 01 Oct 2022 04:44:55 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Jeff Layton" Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org Subject: Re: [PATCH 1/3] nfsd: nfsd_do_file_acquire should hold rcu_read_lock while getting refs In-reply-to: <20220930191550.172087-2-jlayton@kernel.org> References: <20220930191550.172087-1-jlayton@kernel.org>, <20220930191550.172087-2-jlayton@kernel.org> Date: Sat, 01 Oct 2022 14:44:50 +1000 Message-id: <166459949085.17572.9387753773056673569@noble.neil.brown.name> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 On Sat, 01 Oct 2022, Jeff Layton wrote: > nfsd_file is RCU-freed, so it's possible that one could be found that's > in the process of being freed and the memory recycled. Ensure we hold > the rcu_read_lock while attempting to get a reference on the object. >=20 > Signed-off-by: Jeff Layton > --- > fs/nfsd/filecache.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) >=20 > diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c > index d5c57360b418..6237715bd23e 100644 > --- a/fs/nfsd/filecache.c > +++ b/fs/nfsd/filecache.c > @@ -1077,10 +1077,12 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct= svc_fh *fhp, > =20 > retry: > /* Avoid allocation if the item is already in cache */ > + rcu_read_lock(); > nf =3D rhashtable_lookup_fast(&nfsd_file_rhash_tbl, &key, > nfsd_file_rhash_params); > if (nf) > nf =3D nfsd_file_get(nf); > + rcu_read_unlock(); Looks good. > if (nf) > goto wait_for_construction; > =20 > @@ -1090,16 +1092,21 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct= svc_fh *fhp, > goto out_status; > } > =20 > + rcu_read_lock(); > nf =3D rhashtable_lookup_get_insert_key(&nfsd_file_rhash_tbl, > &key, &new->nf_rhash, > nfsd_file_rhash_params); > if (!nf) { > + rcu_read_unlock(); > nf =3D new; > goto open_file; > } > - if (IS_ERR(nf)) > + if (IS_ERR(nf)) { > + rcu_read_unlock(); > goto insert_err; > + } > nf =3D nfsd_file_get(nf); > + rcu_read_unlock(); Ugh. Could we make this: rcu_read_lock() nf =3D r_l_g_i_k() if (!IS_ERR_OR_NULL(nf)) nf =3D nfsd_file_get(nf); rcu_read_unlock() ... ?? NeilBrown > if (nf =3D=3D NULL) { > nf =3D new; > goto open_file; > --=20 > 2.37.3 >=20 >=20