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 4C75327732; Thu, 16 Jul 2026 14:22:04 +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=1784211725; cv=none; b=Pkcdr/leV3eTLDT/fjtVGOOg3zaKSDrNTx1RMESmJddhZbwDUxEcDSlvF5DTPvHDqjgGnYM5vM0L40Qky4h3cK2q5NeUsQSWfmUexqOmpSGuWX15c5kfd4QxRAS4QSksDq1I6K6pSDvEHVFcC/9oQ1khhpZJlIibKNHSEwO4UMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211725; c=relaxed/simple; bh=41LjK1vHii88HlyzxHaVmct/9uGyjd/+xfXfrpR6INg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mla6iPjjsOCi8Ra1FzXVpA3tOqoK0a2mDfVA1/PSu927VMKy4Uaa7914zQNSWCWc0TuegClfSmiXlbVCTSqU2xgbcTb3EKNlotglZCYx05ocrb/ICdx3yxGsdzA7vZQIjVZA2mrfbVkh2ExDB0qrDvFIGPBp7Pq3nqQj6nRmkw8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BaaOvaaS; 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="BaaOvaaS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B13851F000E9; Thu, 16 Jul 2026 14:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784211724; bh=ceCNqE5P+kliQXWQV3O/t5wASv5MoeEojRS9ickg75M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BaaOvaaScgEKct8cVXEao+ds2xO0X6dc5V/OHbqq3u+p5e6Uxv7n0bvsIyCJB21mn vgEJjbuKvWuViZs7WKtAzUxO4CdR8wmC4NXWAJQGfQTnCht0rhksfQaALsgohTBEUf MowLiOlkzXhDs+XXg5V1EcEnicXz8QnucO3Sz8ws= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Jeff Layton , Chuck Lever , Chuck Lever , Sasha Levin Subject: [PATCH 6.12 003/349] nfsd: release layout stid on setlease failure Date: Thu, 16 Jul 2026 15:28:57 +0200 Message-ID: <20260716133033.364558823@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133033.287196923@linuxfoundation.org> References: <20260716133033.287196923@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason commit 30d55c8aabb261bc3f427d6b9aae7ef6206063f9 upstream. nfs4_alloc_stid() publishes the new stid into cl->cl_stateids via idr_alloc_cyclic() under cl_lock before returning to nfsd4_alloc_layout_stateid(). When nfsd4_layout_setlease() then fails, the error path frees the layout stateid directly with kmem_cache_free() without ever calling idr_remove(), leaving the IDR slot pointing at freed slab memory. Any subsequent IDR walker (states_show, client teardown) dereferences the dangling pointer. The correct teardown for an IDR-published stid is nfs4_put_stid(), which removes the IDR slot under cl_lock, dispatches sc_free (nfsd4_free_layout_stateid) to release ls->ls_file via nfsd4_close_layout(), and drops the nfs4_file reference in its tail. Replace the manual nfsd_file_put + put_nfs4_file + kmem_cache_free cleanup with a single nfs4_put_stid(stp). Fixes: c5c707f96fc9 ("nfsd: implement pNFS layout recalls") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Chuck Lever [ cel: no ls_fence_work in 6.12.y; dropped INIT_DELAYED_WORK hunk ] Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- fs/nfsd/nfs4layouts.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c index fc5e82eddaa1af..c08bc2d0d37796 100644 --- a/fs/nfsd/nfs4layouts.c +++ b/fs/nfsd/nfs4layouts.c @@ -256,9 +256,7 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate, BUG_ON(!ls->ls_file); if (nfsd4_layout_setlease(ls)) { - nfsd_file_put(ls->ls_file); - put_nfs4_file(fp); - kmem_cache_free(nfs4_layout_stateid_cache, ls); + nfs4_put_stid(stp); return NULL; } -- 2.53.0