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 92C91390608; Fri, 7 Aug 2026 15:28:13 +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=1786116494; cv=none; b=MlimV5zWQd/0RBtTNBovEUKve6ENKBoBeAQpATC4da4UYozxqbJk+5DBebrsWopJIKYX4mPOX1ZmlS8Mz6CRW2cvs9KKz4WiHqNE8k9qoB8mgzrfKUhlyn+nRuKofcsia7ccdXaUbEu0DZC7o3JKqHyDxKo+b6eoYarBLvon3ek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786116494; c=relaxed/simple; bh=mG3eWKpu9GfvGt5SxLDHoZUZppRmkI2cAe0Ot2zpdR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TVFTlZA6OGHaKPhHczfMGnpve/2Xnzxvj9dpUh690sa5CtVadtfrtc8C5ZX/ogRXXtz/bp2n5+p8NXp4WV9yqZ3A/0uJkX+OxgpYM4AkzlzWznq2m/H/pyL2DG2UKfZKZsM/P/nNxhI9vHH6eMvLBjQL4MYp4YWYkGC4RTMkmoI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qbdB55IW; 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="qbdB55IW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF6111F00A3A; Fri, 7 Aug 2026 15:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786116493; bh=fX7iqBxQDIqP+AaQbAdULnkK/Kk6Q5fdTio3cSW5mk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qbdB55IWJUH5MArUOAyC/2ZZEd79VJP3MG0VSGIUfWvh711beSLqbA2vlnsxOSf0c fmS5m+Z4hB1QHtCFqlm2NkB0Of1x8J2FlvHBO6EwWZbA9KObqD4IhTk+XlYNUVe0j7 73/x9hbsZZqwWbDGOWNGsIqb4aZcG8F4dD87jms8= 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 , Sasha Levin Subject: [PATCH 6.6 248/261] ceph: fix refcount leak in ceph_readdir() Date: Fri, 7 Aug 2026 16:40:05 +0200 Message-ID: <20260807143420.769546457@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143415.358597922@linuxfoundation.org> References: <20260807143415.358597922@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: WenTao Liang [ Upstream commit c3e64079d8b9663e3998d0caac9aba915b6b93ae ] 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: Sasha Levin 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,