Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7027rwl; Thu, 30 Mar 2023 11:17:49 -0700 (PDT) X-Google-Smtp-Source: AKy350Z993BCvUKS/GwIFQzxTemJaoL+6jO6vTNdQMfZOl8WqpgPRvggR2uutOm8Tm7y6uBujg+/ X-Received: by 2002:a05:6a20:1606:b0:d9:27f7:8c52 with SMTP id l6-20020a056a20160600b000d927f78c52mr7397479pzj.16.1680200269002; Thu, 30 Mar 2023 11:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680200268; cv=none; d=google.com; s=arc-20160816; b=YHvJTG4xC4xZpeeZlqIemElVnY9IDdF6wOcbMnAhhRHTNpbuLkFmj/5FvMdiMGucqf 105biD1osNVKsUnF7FkfwqISM/MY9hQ6kwL3QtGANnL1m2SZLXXsOhsqYzMZDyeGSlfO xQHKHDpcNyxA7skcBOjasGz1jCENHUw5Alabl0pTUUDEwtnAPk7d5JV+S6F44ezts3m/ jLEgrFpFMv/7pwY8DiYGQocArhvh1WyL8CkNmrVcn62hD3eBw4tE7qGjBPNXPies2Fql chVlpDfeL7Q+p+bXE6SdDhB+qp2KPftR1hTbyQ48nnlPGMtNfE0HIu5BepP1+D31TINw bW1g== 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=VnT23jr3ctvg4Mc91AYk5tCe6OPMR7bpTLW4HvLlFjU=; b=LcLRfAxpiAIKQ7nQwC+aDT+eiSWN8Uhy/5pUfXUFwElYCcVUUpKBodUzah1cEVBsAs k5IBD3G+FnXmBkJFMcLR/aflb3jnakLElWJtWYznEARHiVgTyg3akod5TmKNJLtkf3wr lKxGgR5r+hPUVRVrl1YiIbnSIdQFB9Jx+bp3AQ+Uircq6NvuAew61HAoEOMI2ciWmG7k OfAAsepW6De0pbESJHBe3werRrAPOg7PONBpqyttmNfKSIcU8+gigvr0wAlLz5WumWEU etnbG0p7113N3Ax7AiIhPYCmxBytFWPdZqTQ86TX2lWmWLzXYQq7IWDH032FjbduzaJL Cs0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ARQ1Wr6E; 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 bm18-20020a656e92000000b004fbbb35999dsi181906pgb.832.2023.03.30.11.17.26; Thu, 30 Mar 2023 11:17:48 -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=@kernel.org header.s=k20201202 header.b=ARQ1Wr6E; 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 S229685AbjC3SPi (ORCPT + 99 others); Thu, 30 Mar 2023 14:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjC3SPe (ORCPT ); Thu, 30 Mar 2023 14:15:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD5AD516 for ; Thu, 30 Mar 2023 11:15:04 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 273B16215E for ; Thu, 30 Mar 2023 18:15:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D7E8C4339B; Thu, 30 Mar 2023 18:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680200103; bh=0OrWXcbPKMAF4lmWnYLRuGIeSBQFRJkWcF3YWkHn15c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ARQ1Wr6EhD3AjlWCwCyjihqxgEpeS9UAMFkD8fKfkKk2uqfPg4lPmuXegqFTpsv7s Ezx8VUlCuyIZ1jq+u9kcgoWFwHUNHw61IxYB00I5VG0l8B+ER+v1hM3dgye4eax2A6 AQ9CLc0gt5uRV8W9TcsErKe5zGgStq/cZSlc3dsbBSCnco99U5FHp2sn3ReLI5xBAm QkyjN0DUr0ntFodkR3CwPK+aTJLF2XTw3UX7Ft8U4WGN9TpzD+4Io8wOTO2PW4nDf7 Jy7BNA7Mc49y/c8z3pQYPS3kLLbXqsG3aYuzMQd+vSaDN5YOZqRSRW01tWxHM4cGKm I7NfxRBfv5B5w== Message-ID: Subject: Re: [PATCH] nfsd: call op_release, even when op_func returns an error From: Jeff Layton To: Chuck Lever III Cc: Linux NFS Mailing List , Zhi Li Date: Thu, 30 Mar 2023 14:15:01 -0400 In-Reply-To: References: <20230327102137.15412-1-jlayton@kernel.org> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 Mon, 2023-03-27 at 13:14 +0000, Chuck Lever III wrote: >=20 > > On Mar 27, 2023, at 6:21 AM, Jeff Layton wrote: > >=20 > > For ops with "trivial" replies, nfsd4_encode_operation will shortcut > > most of the encoding work and skip to just marshalling up the status. > > One of the things it skips is calling op_release. This could cause a > > memory leak in the layoutget codepath if there is an error at an > > inopportune time. > >=20 > > Have the compound processing engine always call op_release, even when > > op_func sets an error in op->status. With this change, we also need > > nfsd4_block_get_device_info_scsi to set the gd_device pointer to NULL > > on error to avoid a double free. > >=20 > > Reported-by: Zhi Li > > Link: https://bugzilla.redhat.com/show_bug.cgi?id=3D2181403 > > Signed-off-by: Jeff Layton >=20 > Thanks, Jeff. >=20 > May I add: Fixes: 34b1744c91cc ("nfsd4: define ->op_release for > compound ops") ? >=20 I've seen some problems with this patch in testing and I have a fix forthcoming (once I finish testing it): The root cause is the OPDESC() function which can walk off the end of the nfsd4_ops array when passed a large value (like OP_ILLEGAL). I think we'll want to fix that to do something more sane before merging this patch. >=20 > > --- > > fs/nfsd/blocklayout.c | 1 + > > fs/nfsd/nfs4xdr.c | 13 +++++++------ > > 2 files changed, 8 insertions(+), 6 deletions(-) > >=20 > > diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c > > index 04697f8dc37d..01d7fd108cf3 100644 > > --- a/fs/nfsd/blocklayout.c > > +++ b/fs/nfsd/blocklayout.c > > @@ -297,6 +297,7 @@ nfsd4_block_get_device_info_scsi(struct super_block= *sb, > >=20 > > out_free_dev: > > kfree(dev); > > + gdp->gd_device =3D NULL; > > return ret; > > } > >=20 > > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c > > index e12e5a4ad502..6b675fbdabd0 100644 > > --- a/fs/nfsd/nfs4xdr.c > > +++ b/fs/nfsd/nfs4xdr.c > > @@ -5402,7 +5402,7 @@ nfsd4_encode_operation(struct nfsd4_compoundres *= resp, struct nfsd4_op *op) > > p =3D xdr_reserve_space(xdr, 8); > > if (!p) { > > WARN_ON_ONCE(1); > > - return; > > + goto release; > > } > > *p++ =3D cpu_to_be32(op->opnum); > > post_err_offset =3D xdr->buf->len; > > @@ -5418,8 +5418,6 @@ nfsd4_encode_operation(struct nfsd4_compoundres *= resp, struct nfsd4_op *op) > > op->status =3D encoder(resp, op->status, &op->u); > > if (op->status) > > trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); > > - if (opdesc && opdesc->op_release) > > - opdesc->op_release(&op->u); > > xdr_commit_encode(xdr); > >=20 > > /* nfsd4_check_resp_size guarantees enough room for error status */ > > @@ -5460,11 +5458,14 @@ nfsd4_encode_operation(struct nfsd4_compoundres= *resp, struct nfsd4_op *op) > > } > > status: > > *p =3D op->status; > > +release: > > + if (opdesc && opdesc->op_release) > > + opdesc->op_release(&op->u); > > } > >=20 > > -/*=20 > > - * Encode the reply stored in the stateowner reply cache=20 > > - *=20 > > +/* > > + * Encode the reply stored in the stateowner reply cache > > + * > > * XDR note: do not encode rp->rp_buflen: the buffer contains the > > * previously sent already encoded operation. > > */ > > --=20 > > 2.39.2 > >=20 >=20 > -- > Chuck Lever >=20 >=20 --=20 Jeff Layton