Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2962021rwl; Mon, 27 Mar 2023 07:33:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ZtIieTYVtEH6tT6RQ3MGXTE/NvaD6frAt2rzfvUtYRblyfK3a5G1ZNkV6dRlNiS6o8GUpX X-Received: by 2002:a17:907:c292:b0:93f:9b1c:a45 with SMTP id tk18-20020a170907c29200b0093f9b1c0a45mr7855704ejc.35.1679927629508; Mon, 27 Mar 2023 07:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679927629; cv=none; d=google.com; s=arc-20160816; b=qZXj47UT+DFoAJWNWj31cELEp3zRbC4TVx35cDMODGpotnpcw0oJjesOg9IiUAUYw6 4G10P6RAPKZNefdLGJ6jNU/kQ8Hmtq43vtkjRuDLw3KemSv++OwdvfamRTZsMAG1L11B z0vjr9zAC9OfmFcafKqGRC4kzRHAD4yDTeVaS5eavidPYK9JU7njRBUAr6H/S6qtq0uP xnLCuKXLbvDneh2x43t8M8+g/LapZtlLRrYDCS2JsvPPSDPXPCtAbCvFyjJotYiWYsjy 2ZmpYJUPOVj1LyNU/glfREEdzVie+NxvaVadQnf5E8s0NIxPk5vE2zOLp2Xvr7ODY4AR xc7w== 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=SvEi0JOPCrm4GmslSR25zor/CN/ztPjY/zV6ntSGxeI=; b=ayGZCRuXrVhYiMhgVbPxiNczxOm42P+7orxemEz3ol9PhmHEwHiAHKTIffKvLSqimv Nnqq9sgPB6t3WOxUOzBsiUROCVq+/5OkXSR9A+r/5xNfsUGkLj3PxtNdHkwZTfiYEB81 xtXMqeQybMRqVTICIcSf7LfgWx93yTjmd890HKATsrX/2lk0ZsAWbbn/zz3p4FmuS0t1 /YT+c3YtyUeayO4sQwvC4sPauRLvXyqL9mQNUJn1HXTrpHuz9+4PyWLEfaWhLRM8NOgM WMog56Zvo5Y6IUtcU7RmZdD76nt4+s93hXIIQNCK1J0B+0VTR//+782n3cSjfJWooYdn 7q+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SmflCMB6; 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 m6-20020a1709060d8600b00930b13f6ab1si28229014eji.642.2023.03.27.07.33.08; Mon, 27 Mar 2023 07:33:49 -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=SmflCMB6; 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 S232717AbjC0Ocq (ORCPT + 99 others); Mon, 27 Mar 2023 10:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjC0Ocm (ORCPT ); Mon, 27 Mar 2023 10:32:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33D72B5 for ; Mon, 27 Mar 2023 07:32:33 -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 BE4B061295 for ; Mon, 27 Mar 2023 14:32:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6994C433D2; Mon, 27 Mar 2023 14:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679927552; bh=8qASZ1qocBeaLqiqw5NqIi1qKMvQMwyjDALtpIveXiQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=SmflCMB6c78piklXhX0Nn1NR3qMUQ9+Yyq75kYG9aIdy7xd+i0H86+bAB2xNhFeCL cHwdLWiAOOpgbCArWLtUr20IKLk+Vy0ONuzs9MnbhrMTz5S2zgslhNCl4R+4C7UmDt yB+y3boj4bDv7tIADvLV3fjgiKLTfntAzqpldljRhYcC5ZIPxr80IplRZ1riq13cMh OgJ6sO6aS8eCew/r/n1VZkHUmKbnNRCKzMfeyaL2pWM/qPk7jVr8Urd+qAfpw8Bn1c 2TTYDpjhacZ8t8ZIaNM7M58S4vLqPT2EC07+9dWBZXZDLJSlSooviiGb8xa4qwsMl8 uQsk7ceNUwxfw== Message-ID: <97ed6d002603347a14b12796808b7aa9d729a13c.camel@kernel.org> 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: Mon, 27 Mar 2023 10:32:30 -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=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 >=20 Sure. It does look like the leaks stretch back at least that far. =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