Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1400039rwl; Thu, 5 Jan 2023 13:02:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXsG6n2CDOn8OKmQlZUKZ8O6jji1p0YmRP2DflMYiZ1HVfrmMovC67/aYmDCxf419Yq9xMYg X-Received: by 2002:a05:6402:3909:b0:492:846d:e86d with SMTP id fe9-20020a056402390900b00492846de86dmr3258084edb.23.1672952568726; Thu, 05 Jan 2023 13:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672952568; cv=none; d=google.com; s=arc-20160816; b=RzZ4xpZOqZ5UovCb2BbzY15EC+oOe1mPA6PxNTguoSwp6TBoZmYFTLu27KKffbE+Gt x21h7125lj/TjjMaiX/QI8enOgaWHAS0K+PT9/91idcFR9fN8zc+hiNQaulq1xyjMPvv u5GgkZb2LmJwxf6Gs86sGdzApH9NNDj8MG0MPFswxCrFjy+rGfhNTyM15KobXnRbZjrC Lcg76SPrpVilxqmYTTNNprWMgJl45qy/AF3/3AuVaEMrn8SFkJtVFfEclkeBySoocKCf E471EUlvepiZKCfg8CuM3ugIqc1XmxskUIiDfZKIoJmjO8ERjrkgyUa7CUuZLDKZI39E YYAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=NeryYea0e+NOKBwyv5SVl2QgBnV6giNV+jS8PkYwttw=; b=jAlRic83MrmgrjlDgtKFtTkq1uJGjOh/NCRaigh2elUbPanGxb1ZovJ0U+V3DLWlLX hy7cgGO3HGZnFvDLf4XYmacO+hkH026P7PlMKHiMjP/JIFkYzb1g/wXneyE5Vb8RAzS2 O/Gv1G2UQk1LuQTA5EU+BT3XnhkntpSc5X/wCFUypf4ulojFztd2dB7RyUf7b3+l9QIg ua5aW3hNqw8fN0gbL/RmDK9dqpADJ6X9b29Hf5ZiZ4GJtESndh5FmHXs0KFillL/8JtA ONdIUK4w03myUZVYZ13azFPiy3IHb2GumvwF8sGlbgd3AxgX/bSVGGbRgo1dEwnbcBrJ tXDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QgcrsNvQ; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ez16-20020a056402451000b0048fd69cf2absi4110564edb.63.2023.01.05.13.02.11; Thu, 05 Jan 2023 13:02:48 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=QgcrsNvQ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234755AbjAEUoE (ORCPT + 99 others); Thu, 5 Jan 2023 15:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232255AbjAEUoD (ORCPT ); Thu, 5 Jan 2023 15:44:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7475515FD7 for ; Thu, 5 Jan 2023 12:44:02 -0800 (PST) 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 31113B81BEE for ; Thu, 5 Jan 2023 20:44:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4D3BC433EF; Thu, 5 Jan 2023 20:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672951440; bh=XMYcM9VPImEnwOKbdQY90gO5LhgEDZBkPFGffz6YFIQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QgcrsNvQZtOSDFkrsp5UF2atD//9OH5f1QeB/pp4Nf7V/mNVy701+CCUBSZNX/eN7 ooKA8Pbhm7bzoeHNRAqVGCEVGZHpsbQ2F/j1s0CMpArzbr+y/unkzVntA8f1W/0ezH gUuFI5H6Dt26bCe2VdRWQhTjM0pRM3vpZ6XwmP0pDahxcmCF9m9q4zpUcgE1AZ2vXY bDFBowh+mQka7X3ROjuL+WdhnNVwjbf4s41dQyz1Hx4duhcxT7gUSNRYlE9rFjfVLZ 8nJ59WPwZL271kZfR2eNBFIBm+8ks9oJW/ast8ZNia3q+EqvDAnEl39ACc/jpQaAEh RJpTD+v1gYxWw== Message-ID: <6ef7caa1b21f7fc2edf2722e504c1b18ff3a6023.camel@kernel.org> Subject: Re: [PATCH] nfsd: fix potential race in nfs4_find_file From: Jeff Layton To: Chuck Lever III Cc: Linux NFS Mailing List Date: Thu, 05 Jan 2023 15:43:58 -0500 In-Reply-To: <4255172A-EFB5-48B4-B2EF-700C10862427@oracle.com> References: <20230105121823.21935-1-jlayton@kernel.org> <4255172A-EFB5-48B4-B2EF-700C10862427@oracle.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.2 (3.46.2-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Thu, 2023-01-05 at 14:46 +0000, Chuck Lever III wrote: >=20 > > On Jan 5, 2023, at 7:18 AM, Jeff Layton wrote: > >=20 > > Even though there is a WARN_ON_ONCE check, it seems possible for > > nfs4_find_file to race with the destruction of an fi_deleg_file while > > trying to take a reference to it. > >=20 > > put_deleg_file is done while holding the fi_lock. Take and hold it > > when dealing with the fi_deleg_file in nfs4_find_file. > >=20 > > Signed-off-by: Jeff Layton > > --- > > fs/nfsd/nfs4state.c | 16 ++++++++++------ > > 1 file changed, 10 insertions(+), 6 deletions(-) > >=20 > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > > index b68238024e49..3df3ae84bd07 100644 > > --- a/fs/nfsd/nfs4state.c > > +++ b/fs/nfsd/nfs4state.c > > @@ -6417,23 +6417,27 @@ nfsd4_lookup_stateid(struct nfsd4_compound_stat= e *cstate, > > static struct nfsd_file * > > nfs4_find_file(struct nfs4_stid *s, int flags) > > { > > + struct nfsd_file *ret =3D NULL; > > + > > if (!s) > > return NULL; > >=20 > > switch (s->sc_type) { > > case NFS4_DELEG_STID: > > - if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file)) > > - return NULL; > > - return nfsd_file_get(s->sc_file->fi_deleg_file); > > + spin_lock(&s->sc_file->fi_lock); > > + if (!WARN_ON_ONCE(!s->sc_file->fi_deleg_file)) >=20 > You'd think this would be a really really hard race to hit. >=20 > What I'm wondering, though, is whether the WARN_ON_ONCE should > be dropped by this patch. I've never seen it fire. >=20 >=20 I have: https://bugzilla.redhat.com/show_bug.cgi?id=3D1997177 It's possible though that those WARNs are fallout from other bugs in the delegation handling, but it's hard to know for sure. I think we ought to keep it there for now. > > + ret =3D nfsd_file_get(s->sc_file->fi_deleg_file); > > + spin_unlock(&s->sc_file->fi_lock); > > + break; > > case NFS4_OPEN_STID: > > case NFS4_LOCK_STID: > > if (flags & RD_STATE) > > - return find_readable_file(s->sc_file); > > + ret =3D find_readable_file(s->sc_file); > > else > > - return find_writeable_file(s->sc_file); > > + ret =3D find_writeable_file(s->sc_file); > > } > >=20 > > - return NULL; > > + return ret; > > } > >=20 > > static __be32 > > --=20 > > 2.39.0 > >=20 >=20 > -- > Chuck Lever >=20 >=20 >=20 --=20 Jeff Layton