Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4639383pxb; Tue, 2 Nov 2021 13:12:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRsN4Lx35f5DIUFaqFwOWfZI32QIHnDgjuAt5lr7KKiKXV7/YCHit7bnJvLBp31VlPIVSx X-Received: by 2002:a05:6602:2ccf:: with SMTP id j15mr13893625iow.77.1635883942552; Tue, 02 Nov 2021 13:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635883942; cv=none; d=google.com; s=arc-20160816; b=CpPSAla3FfdLvCYlTpO/0+x4YPe86INS5331lW3pht9L/DTH+5gAQwGEoX4bb2Ias3 pshxEk0ZG2OOlMoFdZBWJM98fpgvmDxC/Qqwnv/cuH1WCqtTdQrs32P2UA/dDX9KzGbJ pCc4luJfbFbXAyhBYVTAHgaDLlWKjcKBRso9d5ZGH4jOx6wKxvuO+OcY5qtyIrNnEvoj J4uHrmmpMJNjk0lAByK7O+BDCMKzWioLiq5p+LzvT8ElX6NEQcNaR9+jQqcHndeSF0S1 B4yxA11cxZ6/54BDhHJdINcnYepF0rpMlnZ/6DzybvQb6LSwyQIU3o+wD8gSIr3PPQfJ cnsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YMAM7WDordbN+0T5nufZPCivA9NoTZWTAZlUQRCBfEM=; b=ftX/HspDfy4zw3VfDRb8kH0iTxVnlVKGQtqitKScbtZqlWuBiOX3a3IJz2NDMDyrML loFymTh2fpiXe2HsG8PYkdC4Gs+Ns6W+CmPQvqfw7sFT3TTtVbfTZ0Zka8BXB2A6Kc4Y zMG1xJ/xr6s8js8LxWYpZaOS4oqLirKRVs4Xf/eS7AzhZELGNWclzlf1IzlLLZ3mT+4R +I6Uodgrp0dar+/13s8yhdPbYErW7sPxk2MOd+9zFQRXZ+4VTQy6/2Q1vXEwQi2ApFhe WnMsROh/9DZl6Td2/k6SicdwZYRxtRGVgs4DtS3XXniadunXjI203K+J/NCxQ010scp+ tjZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="FbH/zFQK"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w8si6362713ill.177.2021.11.02.13.12.02; Tue, 02 Nov 2021 13:12:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="FbH/zFQK"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbhKBUOG (ORCPT + 99 others); Tue, 2 Nov 2021 16:14:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36007 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbhKBUOB (ORCPT ); Tue, 2 Nov 2021 16:14:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635883885; 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=YMAM7WDordbN+0T5nufZPCivA9NoTZWTAZlUQRCBfEM=; b=FbH/zFQKMVboyXZTQM9tNazcMxyEWhpSRmdnzH0hr1Adyb+x37wbdt/lG6q4TPV2ZlcUNr tl9Ys6kPol+u+7Kjv+0gkUaPuuQeprX3CF+594LsJgweEQsDCpV+oqGziMzpIkwtGvIwgp GYLLrnQ55dOezLM3q/qdvu88i5MNOco= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-301-d_DgYXMFOomVTgeiTQUsRA-1; Tue, 02 Nov 2021 16:11:22 -0400 X-MC-Unique: d_DgYXMFOomVTgeiTQUsRA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D9AC100CCC1; Tue, 2 Nov 2021 20:11:21 +0000 (UTC) Received: from aion.usersys.redhat.com (unknown [10.22.9.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BA8A5C232; Tue, 2 Nov 2021 20:11:21 +0000 (UTC) Received: by aion.usersys.redhat.com (Postfix, from userid 1000) id 9E3B11A0024; Tue, 2 Nov 2021 16:11:20 -0400 (EDT) Date: Tue, 2 Nov 2021 16:11:20 -0400 From: Scott Mayhew To: Trond Myklebust Cc: "anna.schumaker@netapp.com" , "linux-nfs@vger.kernel.org" Subject: Re: [PATCH 1/1] nfs4: take a reference on the nfs_client when running FREE_STATEID Message-ID: References: <20211101200623.2635785-1-smayhew@redhat.com> <20211101200623.2635785-2-smayhew@redhat.com> <9c677842d46b95e1ac7011afd44e29229d9efaa9.camel@hammerspace.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <9c677842d46b95e1ac7011afd44e29229d9efaa9.camel@hammerspace.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, 02 Nov 2021, Trond Myklebust wrote: > Hi Scott, >=20 > Thanks. This mostly looks good, but I do have 1 comment below. >=20 > On Mon, 2021-11-01 at 16:06 -0400, Scott Mayhew wrote: > > During umount, the session slot tables are freed.=A0 If there are > > outstanding FREE_STATEID tasks, a use-after-free and slab corruption > > can > > occur when rpc_exit_task calls rpc_call_done -> nfs41_sequence_done - > > > > > nfs4_sequence_process/nfs41_sequence_free_slot. > >=20 > > Prevent that from happening by taking a reference on the nfs_client > > in > > nfs41_free_stateid and putting it in nfs41_free_stateid_release. > >=20 > > Signed-off-by: Scott Mayhew > > --- > > =A0fs/nfs/nfs4proc.c | 12 +++++++++++- > > =A01 file changed, 11 insertions(+), 1 deletion(-) > >=20 > > diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c > > index e1214bb6b7ee..76e6786b797e 100644 > > --- a/fs/nfs/nfs4proc.c > > +++ b/fs/nfs/nfs4proc.c > > @@ -10145,18 +10145,24 @@ static void > > nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) > > =A0static void nfs41_free_stateid_done(struct rpc_task *task, void > > *calldata) > > =A0{ > > =A0=A0=A0=A0=A0=A0=A0=A0struct nfs_free_stateid_data *data =3D calldata; > > +=A0=A0=A0=A0=A0=A0=A0struct nfs_client *clp =3D data->server->nfs_clie= nt; > > =A0 > > =A0=A0=A0=A0=A0=A0=A0=A0nfs41_sequence_done(task, &data->res.seq_res); > > =A0 > > =A0=A0=A0=A0=A0=A0=A0=A0switch (task->tk_status) { > > =A0=A0=A0=A0=A0=A0=A0=A0case -NFS4ERR_DELAY: > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0if (nfs4_async_handle_e= rror(task, data->server, NULL, > > NULL) =3D=3D -EAGAIN) > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0r= pc_restart_call_prepare(task); > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0i= f (refcount_read(&clp->cl_count) > 1) > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0rpc_restart_call_prepare(task); >=20 > Do we really need to make the rpc restart call conditional here? Most > servers prefer that you finish freeing state before calling > DESTROY_CLIENTID. Good point. No, it's not necessary. Do you want me to send a v2, or can you apply the patch without this hunk? -Scott >=20 > > =A0=A0=A0=A0=A0=A0=A0=A0} > > =A0} > > =A0 > > =A0static void nfs41_free_stateid_release(void *calldata) > > =A0{ > > +=A0=A0=A0=A0=A0=A0=A0struct nfs_free_stateid_data *data =3D calldata; > > +=A0=A0=A0=A0=A0=A0=A0struct nfs_client *clp =3D data->server->nfs_clie= nt; > > + > > +=A0=A0=A0=A0=A0=A0=A0nfs_put_client(clp); > > =A0=A0=A0=A0=A0=A0=A0=A0kfree(calldata); > > =A0} > > =A0 > > @@ -10193,6 +10199,10 @@ static int nfs41_free_stateid(struct > > nfs_server *server, > > =A0=A0=A0=A0=A0=A0=A0=A0}; > > =A0=A0=A0=A0=A0=A0=A0=A0struct nfs_free_stateid_data *data; > > =A0=A0=A0=A0=A0=A0=A0=A0struct rpc_task *task; > > +=A0=A0=A0=A0=A0=A0=A0struct nfs_client *clp =3D server->nfs_client; > > + > > +=A0=A0=A0=A0=A0=A0=A0if (!refcount_inc_not_zero(&clp->cl_count)) > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return -EIO; > > =A0 > > =A0=A0=A0=A0=A0=A0=A0=A0nfs4_state_protect(server->nfs_client, > > NFS_SP4_MACH_CRED_STATEID, > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0&task_setup.rpc_client,= &msg); >=20 > --=20 > Trond Myklebust > Linux NFS client maintainer, Hammerspace > trond.myklebust@hammerspace.com >=20 >=20