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 2222C391E51; Sat, 17 Oct 2026 17:58:29 +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=1792259910; cv=none; b=iLxClnVb8LvMEHvC7U2ITDiZbeH/iMS/JlWZV5ITZn/t3br/nFSOCyaz3zrl/bd5OXsXuhNCYlrm7gl8ne+ja0QtOdLZGzPk0VvScdKZzWVz8sE+IXLm3Zyzi18uX5sVIRT177xx+gdb7K36sgKZP3DI+r8viEBnmzjz3M5qZUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792259910; c=relaxed/simple; bh=OPKz8KgnNXKDiUdEw2XSrPv1fwvVY7oEXwpT7MLdmps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gD1VWG6+7r2YHKXhjnbOW6Y02bXtwusbHtglCWX3prrkRHQQ5HylMckeuXfK6Rb++DU+YNm7A82GYSw26ChDS36gG8UNKnREcG6qNEQmEY9oTTeBLmOeB0WknljwUDBE4oBHEVo5qKCT2uj2dlVXblS9pIt1jEgf5cK+vP9aV94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OhXmnTP3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OhXmnTP3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 707681F000C4; Sat, 17 Oct 2026 17:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792259909; bh=M1ZhnMGsgroiVoywIl4rZ9spTnhbiPHTe7ATROZrPLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OhXmnTP3czt/68wAKZZPPnkiIbquUHEvG+Cib+bNW75luYSoBROXcByElFj1fvb6M kzEic1Pcezz/FKutI2PQOY3tu2zttD7062w3yqv+fQXKIICE3ZRtLV4dQeY3crsybi G83GaWUa4EFqcBilRYwT41D3QWr7+7UIdKvHDtLQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jeff Layton , Chuck Lever , Sasha Levin Subject: [PATCH 6.6 1319/1674] nfsd: fix stale s2s_cp_stateids IDR entry for async COPY Date: Sat, 17 Oct 2026 17:59:51 +0200 Message-ID: <20261017160505.001427704@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeff Layton [ Upstream commit d0beaee498e11880e72826026db0e9c9890fc114 ] 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") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Layton Link: https://patch.msgid.link/20260710-nfsd-testing-v3-3-a0ff7db6aa3e@kernel.org Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- fs/nfsd/nfs4proc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 79791ebfc1a30..de32446f58b37 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1853,11 +1853,14 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL); if (!async_copy->cp_src) goto out_err; - if (!nfs4_init_copy_state(nn, copy)) + dup_copy_fields(copy, async_copy); + + if (!nfs4_init_copy_state(nn, async_copy)) goto out_err; - memcpy(&result->cb_stateid, ©->cp_stateid.cs_stid, + memcpy(&result->cb_stateid, &async_copy->cp_stateid.cs_stid, + sizeof(result->cb_stateid)); + memcpy(&async_copy->cp_res.cb_stateid, &result->cb_stateid, sizeof(result->cb_stateid)); - dup_copy_fields(copy, async_copy); async_copy->copy_task = kthread_create(nfsd4_do_async_copy, async_copy, "%s", "copy thread"); if (IS_ERR(async_copy->copy_task)) -- 2.53.0