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 DFEDB37BE9C; Thu, 30 Jul 2026 15:45:54 +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=1785426356; cv=none; b=ZZRB5pPIAWMGDgFZrNoem4yjWg7mQMOZLFTl0Om4kILnBmdanHaUE2AfHUsUhwmJrYLwRBT2I1l3IxnH0EGK0RI8omVhjQkVexpqMAIljdIpBlWp1mw5RR0mzh6zfe39H+lrF04saBxTpTbtAa7QgMTx8YzPYTiIG7rgw9hhnuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785426356; c=relaxed/simple; bh=BKgeUsRTfktQ6UQ9lJmWsuMHoGYEvM2Q8NHNNFfUjBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qggws5gNJi7/5KsptJSCl4b6uDpDMzBCEczUFhLxsMwKdmt2VOUBNIKlkWviAO/VQN5ki6SbBYBWhaeptgKxJSE1qXKMjMgWVAf/HOFTrCPDENm0P3xkB4NJg32p/QjWHg2zoxoj5buV3Zn3+2bsdIZ7Kikcj/PAYSI0e2YjQOM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=G2+sVSu4; 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="G2+sVSu4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47E981F000E9; Thu, 30 Jul 2026 15:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785426354; bh=/eMw3L/hEMHv4UN1AG1G7FVrCDpS6C49pFis/wI1WWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=G2+sVSu4nu00CC/2dhdvPeRRXLVsv+aYU3Q4uIoRGPnUS2/IHxCN5TBP4+jDnPaBA Zd98Abig32Qs1P7co9znc63DSmhgH7FJnNfdjSCOICABWSnC284tokeJ35tbLhQPyD qmmQMnfvXNe6y8XibQHdtkUrR9jRs+d1XK4GqBDA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, WenTao Liang , Viacheslav Dubeyko , Alex Markuze , Ilya Dryomov Subject: [PATCH 6.12 391/602] ceph: fix refcount leak in ceph_readdir() Date: Thu, 30 Jul 2026 16:13:03 +0200 Message-ID: <20260730141444.175924538@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141435.976815864@linuxfoundation.org> References: <20260730141435.976815864@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: WenTao Liang commit c3e64079d8b9663e3998d0caac9aba915b6b93ae upstream. The ceph_readdir() function allocates a ceph_mds_request via ceph_mdsc_create_request() and stores it in dfi->last_readdir. In the directory entry processing loop, if the entry's offset is less than ctx->pos or if the inode pointer is unexpectedly NULL, the function returns -EIO without releasing the reference held by dfi->last_readdir, causing a refcount leak. Fix this by adding ceph_mdsc_put_request(dfi->last_readdir) before returning on these error paths. Also set dfi->last_readdir to NULL for safety, matching the cleanup done at the normal exit. Cc: stable@vger.kernel.org Fixes: af9ffa6df7e3 ("ceph: add support to readdir for encrypted names") Signed-off-by: WenTao Liang Reviewed-by: Viacheslav Dubeyko Reviewed-by: Alex Markuze Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/dir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -546,11 +546,16 @@ more: pr_warn_client(cl, "%p %llx.%llx rde->offset 0x%llx ctx->pos 0x%llx\n", inode, ceph_vinop(inode), rde->offset, ctx->pos); + ceph_mdsc_put_request(dfi->last_readdir); + dfi->last_readdir = NULL; return -EIO; } - if (WARN_ON_ONCE(!rde->inode.in)) + if (WARN_ON_ONCE(!rde->inode.in)) { + ceph_mdsc_put_request(dfi->last_readdir); + dfi->last_readdir = NULL; return -EIO; + } ctx->pos = rde->offset; doutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%.*s' %p\n", inode,