Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp956292rdg; Fri, 13 Oct 2023 06:21:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2liDaUYv5d0VeGpQ0RLY/xHkJ4tmlXpXDvsf1mxBul3yno0/fC6uBD97nz7kst/XXuU1C X-Received: by 2002:a17:902:f544:b0:1c5:c546:fece with SMTP id h4-20020a170902f54400b001c5c546fecemr92574plf.34.1697203311650; Fri, 13 Oct 2023 06:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697203311; cv=none; d=google.com; s=arc-20160816; b=TbAua1QHbIvhwtRhGOcfl3qgBWiAmWGcj3yT7I0oqvCpBTAs6XXE2h8NhzcU/AVL9m /iVA917btv975DEdk8roKTjEd+AaW5kHbGf+/KdTN5C67/ze/P1NTchc1Jg79N6F8sUl rtL4yoZCWtpOhUcQqAEA7J3p0yt/hvFg8X2bvyB4lLGqGqqOaO+cmMGrOfUBwBgYCCiW D6mEcyBKjw5BWUBqgO+Ip+zvwucTdqy3zaNp8ByFDYpU50fU3u/QltsnMl2fUDPTTnmD Fj1gbZPjlMzEOgaS4ZMV0NzPYj2NBr2AP18tlnH+G4Xq3zGi+fzJ+r8lYbZrTv9qt+12 Z9Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XUcC3/nJHcpydayDlbwMmc/zWgVW1Ax7C/pcg0A0/uA=; fh=y0duoSpLUMMyUllwAd7xXTp0S4yOcMDX982UKgSDPR8=; b=Sc1QQLcpPeLdhWxqSGBnTFguLRoa9xQai/OYriD0W4aP5MtIarPFehAWvDQicZ43Mg KmYAYC7WawQur9ip32k3wni16VyWg3rIGBQAwxLz9WiVycCWgeVRZDE6oODu0rkV1vi+ hR8TUV4umZr3URQ5QRkhTWHStDTOMXNt7l2fEadmcgvRoCMBWI4pTcLsYgGLflgLNimR 8saJRzpWMbuz+3cGkoo2mDeoflx6z6/QJKPGH6zB+Gtytfl9tuLpMJVfb0Va+NB4MtDQ DlgKv3JpsQj4vDZlTZDBQQkJ4sy3ITJFoFIucmYyLM6v60kIz9Vsu/nw5mV+ndyM9HKR 1icQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A8MhbfNf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q5-20020a17090311c500b001c9ad6278ddsi4840807plh.96.2023.10.13.06.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 06:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A8MhbfNf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E4A6F8022B14; Fri, 13 Oct 2023 06:21:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231967AbjJMNVb (ORCPT + 99 others); Fri, 13 Oct 2023 09:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjJMNVZ (ORCPT ); Fri, 13 Oct 2023 09:21:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28BBA91 for ; Fri, 13 Oct 2023 06:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697203239; h=from:from:reply-to:subject:subject: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=XUcC3/nJHcpydayDlbwMmc/zWgVW1Ax7C/pcg0A0/uA=; b=A8MhbfNf/HX4gQI8kxWfXKHbzM4/IydM9CV6fJ/q1HrLBsQnTDWEzyMl+5MP6DmaONykZN Hu/LrKzE88jvTWqMnPBqeMGcPpctz1pN6xQK/wgdfQlZByWmNY9uxzT9q5zeS+i9CtPZst 5JDqwe9y/8xXWjVXdK/SelDt82bzDkY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-l8iAXsM0N7-p_6Dd2KzaWA-1; Fri, 13 Oct 2023 09:20:30 -0400 X-MC-Unique: l8iAXsM0N7-p_6Dd2KzaWA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 692AF858F19; Fri, 13 Oct 2023 13:20:30 +0000 (UTC) Received: from [10.22.32.24] (unknown [10.22.32.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4553A492BFA; Fri, 13 Oct 2023 13:20:30 +0000 (UTC) From: Benjamin Coddington To: Chuck Lever Cc: linux-nfs@vger.kernel.org, Chuck Lever Subject: Re: [PATCH] NFSD: Remove a layering violation when encoding lock_denied Date: Fri, 13 Oct 2023 09:20:29 -0400 Message-ID: In-Reply-To: <169720169786.5129.10628552146876100129.stgit@oracle-102.nfsv4bat.org> References: <169720169786.5129.10628552146876100129.stgit@oracle-102.nfsv4bat.org> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 06:21:42 -0700 (PDT) On 13 Oct 2023, at 8:56, Chuck Lever wrote: > From: Chuck Lever > > An XDR encoder is responsible for marshaling results, not releasing > memory that was allocated by the upper layer. We have .op_release > for that purpose. > > Move the release of the ld_owner.data string to op_release functions > for LOCK and LOCKT. > > Signed-off-by: Chuck Lever > --- > fs/nfsd/nfs4proc.c | 2 ++ > fs/nfsd/nfs4state.c | 16 ++++++++++++++++ > fs/nfsd/nfs4xdr.c | 16 ++-------------- > fs/nfsd/xdr4.h | 17 +++++------------ > 4 files changed, 25 insertions(+), 26 deletions(-) > > Fix for kmemleak found during Bake-a-thon. > > I'm planning to insert this fix into nfsd-next just before the > patches that clean up the lock_denied encoder. > > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c > index 60262fd27b15..f288039545e3 100644 > --- a/fs/nfsd/nfs4proc.c > +++ b/fs/nfsd/nfs4proc.c > @@ -3210,6 +3210,7 @@ static const struct nfsd4_operation nfsd4_ops[] =3D= { > }, > [OP_LOCK] =3D { > .op_func =3D nfsd4_lock, > + .op_release =3D nfsd4_lock_release, > .op_flags =3D OP_MODIFIES_SOMETHING | > OP_NONTRIVIAL_ERROR_ENCODE, > .op_name =3D "OP_LOCK", > @@ -3218,6 +3219,7 @@ static const struct nfsd4_operation nfsd4_ops[] =3D= { > }, > [OP_LOCKT] =3D { > .op_func =3D nfsd4_lockt, > + .op_release =3D nfsd4_lockt_release, > .op_flags =3D OP_NONTRIVIAL_ERROR_ENCODE, > .op_name =3D "OP_LOCKT", > .op_rsize_bop =3D nfsd4_lock_rsize, > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index 07840ee721ef..305c353a416c 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -7773,6 +7773,14 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_= compound_state *cstate, > return status; > } > > +void nfsd4_lock_release(union nfsd4_op_u *u) > +{ > + struct nfsd4_lock *lock =3D &u->lock; > + struct nfsd4_lock_denied *deny =3D &lock->lk_denied; > + > + kfree(deny->ld_owner.data); > +} > + > /* > * The NFSv4 spec allows a client to do a LOCKT without holding an OPE= N, > * so we do a temporary open here just to get an open file to pass to > @@ -7878,6 +7886,14 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4= _compound_state *cstate, > return status; > } > > +void nfsd4_lockt_release(union nfsd4_op_u *u) > +{ > + struct nfsd4_lockt *lockt =3D &u->lockt; > + struct nfsd4_lock_denied *deny =3D &lockt->lt_denied; > + > + kfree(deny->ld_owner.data); > +} > + > __be32 > nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstat= e, > union nfsd4_op_u *u) > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c > index dafb3a91235e..26e7bb6d32ab 100644 > --- a/fs/nfsd/nfs4xdr.c > +++ b/fs/nfsd/nfs4xdr.c > @@ -3990,28 +3990,16 @@ nfsd4_encode_lock_denied(struct xdr_stream *xdr= , struct nfsd4_lock_denied *ld) > struct xdr_netobj *conf =3D &ld->ld_owner; > __be32 *p; > > -again: > p =3D xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); > - if (!p) { > - /* > - * Don't fail to return the result just because we can't > - * return the conflicting open: > - */ > - if (conf->len) { > - kfree(conf->data); > - conf->len =3D 0; > - conf->data =3D NULL; > - goto again; > - } > + if (!p) > return nfserr_resource; Should we worry about removing this corner-case fix? I'm not sure I understand it.. just wanted to bring it up. Here's what Bruce originally= said: commit 8c7424cff6bd33459945646cfcbf6dc6c899ab24 Author: J. Bruce Fields Date: Mon Mar 10 12:19:10 2014 -0400 nfsd4: don't try to encode conflicting owner if low on space I ran into this corner case in testing: in theory clients can provide= state owners up to 1024 bytes long. In the sessions case there might= be a risk of this pushing us over the DRC slot size. The conflicting owner isn't really that important, so let's humor a client that provides a small maxresponsize_cached by allowing ourselv= es to return without the conflicting owner instead of outright failing t= he operation. Signed-off-by: J. Bruce Fields Ben