From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0561717BB21; Thu, 9 Jul 2026 21:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783631921; cv=none; b=ZlHnzxrJBUhTnG6bM4LsWOQ17vH7Foph6Y1lmFDGgPlG4Za+CWgimH/qp3jPTqDpgPFckLHXKysoSt6iXwQ5wpNDceyWt2/KlWcjrb3Jpq6tHqLF+OoprHrLkkJQ7PsY1Khlirw3lTOWzAau/5SvxkK6uPQ3o9f2ZKh8UxS2ISQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783631921; c=relaxed/simple; bh=u6jWFHlNBcjeRFuYBNI7HyfGpbDDNuaOJIJNVzYwrps=; h=MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type; b=jhE1huks+uCsr1Spv4LDxVN10CuuAu7tRP9eTHIzmtAg8HQY1QRtgVm1/y0gnRoT57DD5DJVovLFH8PyfubLj98/ttsULb5kuHuU8tnTsvcekRMslA2D2QvUWLF8nSoXJjjdiW8ZjC1G8VlewC+KwdEDzSO8lV0TRCSsM7YoI5s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hVohIjt9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hVohIjt9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3694A1F00A3D; Thu, 9 Jul 2026 21:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783631919; bh=6tA/AkueJVVCryxoPengSYVhMo/gv7kgTKjpTgzF1ss=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=hVohIjt9FWIuLri3hxxh58w7KCzsFIM7H1JDtcPltJDhvYAV29TWuR8yj4iO5QmLS nMoaDVKDkWx9ukSwS9OXKQbpnG63Qy1r6NNDxFmh8zG7DWS4nAX5gUal34Hbv3/cU+ 7fpKFenaVNIfcUa4Tse2ZSp/ohSuB4Vk/Ts3Z+KahVXk2rUoFeLQoBmyCKaa+nvL1u PUcUmKVLywF7/IaF7e931BljnyVTDKfCZqEPEfqbg/79y2P3+3phib2wRkNtFT0KOy GG8425CKMJaRuxR7voYBtDcbknJPa/pd/SjJjhr0QpvLUSM8ckjVdqw8+dpUAAjC/M bwsnBiYODTr6w== Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id 44268F40072; Thu, 9 Jul 2026 17:18:38 -0400 (EDT) Received: from phl-imap-15 ([10.202.2.104]) by phl-compute-10.internal (MEProxy); Thu, 09 Jul 2026 17:18:38 -0400 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTF0PmM/JyJzX9zNRDx4cykCeE6rnr2HmfnKw0rnF31LQiS+DNkCtoTjL3h7W1bveU IUM9Bk52F6oxKY5qy2qhWGxFmmMVP5L6VxTBWLIR1jr+sdBJ/gvxUlgZpXWErlf81hs8TL SEb9n/ubhGGkCUDQmBI180tv0viTXdYNdouhuBqywUNtUUvMXIU8DAqpsrGnhpMkYQPE1l A1qZlwWPw+CfaF4XWEdvOZ5odS6kDr+TesxDuF7KK/dQukwQ6FVfmFF/za/YoGmbroL5Ku w2Y1NtQ5SV4seCnAGlyoY02Ybohcvon99jx7MgOJloYElmkUZZoaaMK6j6eV/AQXuKp+ae cpqSc6OdMZRKvbqgkcBmhirzolMqBicCNSlzsFwpOIG+i3yLwrR2QFpbl/pv9gj1AsuGSL ahcyaKcUCXBS7ssjav00PU/8bR2cV/A58G2KvPteQEVHwEnuJA6+5+dbStvkCBGTmVuo67 3jX4ShJ2D3PpmVXb+auki9I0NT2je9/724E15fWaVSWKzptWSz58ELKWFFQ6j8S6gdqVZQ bIMkFKf8EnCDKrkpt4Qa6b5vi8HLytdKv2SlauF/5PVd7gDoT12Pn/8vmBtm6vFxZp56IX qAVv+lD5W/V89SwcoWFW/STKN2vxTJNchrrQNLOGH4sYif1CXaly9vbiKZdw X-ME-Proxy: Feedback-ID: ifa6e4810:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 1D457780AB5; Thu, 9 Jul 2026 17:18:38 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ThreadId: A7uBYZMR0p1N Date: Thu, 09 Jul 2026 17:18:17 -0400 From: "Chuck Lever" To: "Jeff Layton" , NeilBrown , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Andy Adamson" Cc: "Chris Mason" , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: In-Reply-To: <20260709-nfsd-testing-v2-3-0a1ba233bf87@kernel.org> References: <20260709-nfsd-testing-v2-0-0a1ba233bf87@kernel.org> <20260709-nfsd-testing-v2-3-0a1ba233bf87@kernel.org> Subject: Re: [PATCH v2 03/10] nfsd: fix stale s2s_cp_stateids IDR entry for async COPY Content-Type: text/plain Content-Transfer-Encoding: 7bit On Thu, Jul 9, 2026, at 2:47 PM, Jeff Layton wrote: > For an async COPY, nfsd4_copy() called nfs4_init_copy_state() before > dup_copy_fields(), so the s2s_cp_stateids IDR was pointed at > &u->copy->cp_stateid -- memory in the per-rqstp COMPOUND buffer that is > reused by the next request. dup_copy_fields() copies only the value into > async_copy, so the IDR slot dangled at the transient buffer for the whole > background copy. Any IDR walker then dereferences reused request memory: > the laundromat reads cs_type from it and, if the bytes look like an > expired NFS4_COPYNOTIFY_STID, follows into > refcount_dec()/idr_remove()/kfree() on garbage; manage_cpntf_state() has > the same exposure via idr_find(). > > Duplicate the fields first, then register the stateid on the stable > async_copy. result->cb_stateid is unchanged. > > Fixes: e0639dc5805a ("NFSD introduce async copy feature") > Assisted-by: Claude:claude-opus-4-8 > Signed-off-by: Jeff Layton > --- > fs/nfsd/nfs4proc.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c > index fad01d67bf3f..1c674479d4ca 100644 > --- a/fs/nfsd/nfs4proc.c > +++ b/fs/nfsd/nfs4proc.c > @@ -2272,11 +2272,21 @@ nfsd4_copy(struct svc_rqst *rqstp, struct > nfsd4_compound_state *cstate, > async_copy->cp_src = kmalloc_obj(*async_copy->cp_src); > if (!async_copy->cp_src) > goto out_dec_async_copy_err; > - if (!nfs4_init_copy_state(nn, copy)) > + dup_copy_fields(copy, async_copy); > + /* > + * Register the copy stateid on the long-lived async_copy > + * rather than on the transient COMPOUND argument buffer > + * (&u->copy). nfs4_init_copy_state() installs a pointer to > + * the copy_stateid_t in nn->s2s_cp_stateids, and that pointer > + * outlives this call (it is removed only when the background > + * copy finishes). Pointing it at &u->copy would leave a stale > + * pointer into reused request memory that the laundromat and > + * OFFLOAD_CANCEL later dereference. > + */ > + if (!nfs4_init_copy_state(nn, async_copy)) > goto out_dec_async_copy_err; > - memcpy(&result->cb_stateid, ©->cp_stateid.cs_stid, > + memcpy(&result->cb_stateid, &async_copy->cp_stateid.cs_stid, > sizeof(result->cb_stateid)); > - dup_copy_fields(copy, async_copy); > if ((READ_ONCE(copy->nf_dst->nf_file->f_mode) & > FMODE_NOCMTIME) != 0) > async_copy->attr_update = true; > > -- > 2.55.0 Sashiko spotted some severe issues: - [Critical] Async copy cancellation paths remove the copy from `clp->async_copies` and free the `async_copy` object, but fail to call `nfs4_free_copy_state()`. This leaks the IDR entry in `nn->s2s_cp_stateids` and leaves it pointing to freed memory, causing a remote Use-After-Free (UAF) DoS. - [High] Reordering `dup_copy_fields()` before `nfs4_init_copy_state()` leaves `async_copy->cp_res.cb_stateid` uninitialized, causing the server to send an invalid (all-zero) stateid in the `CB_OFFLOAD` callback. The second one was also spotted by gpt-5.6-sol. The new code comment here is a design breadcrumb. Probably not useful to carry it as part of the code, but YMMV. -- Chuck Lever