Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 25673268690 for ; Mon, 20 Oct 2025 15:27:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760974035; cv=none; b=PFArQVN0FEX2C8KBUpDh8VKWCvkr0vzPxySpmyjbXYw0K30BzooyGg9ZULDAakcBPhJBuQn3DhjnES9tnik1n2bjzP69OFNB+TtuJKkf27JaVmISl/tXTcsO8WGs3NuijAMgvf/yVCsRTtknyNojb9Bodani396AB9E5aOTFmyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760974035; c=relaxed/simple; bh=MspDlk8sc6Obom0F2N13ms+mu3jmFv5sPDl/leuyjEM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ce4KHmv3H4mCCspofoC2PKzr5wDXx39M9O2TBXHWPu9bW/jmbmyaQLKIDhNvNc+2kKKlHhNbGjGaTijhYvjFRN0etin5k11wbZ2HeZY5ExE5fQ2xK42luBH6re+Lw5SlwEmfEgydiGXXJ+lk00tY5cZLJ/eEe8O314TTh1++GlE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FlIVB3ZI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FlIVB3ZI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D9B7C4CEF9; Mon, 20 Oct 2025 15:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760974034; bh=MspDlk8sc6Obom0F2N13ms+mu3jmFv5sPDl/leuyjEM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=FlIVB3ZIsWJbZjVsj9cHTUQom6kppGWwIpON2zxuGhr/HPDIWwgaSzAijaChTXOUa 39ZeqEsalz0zDb4DLTPADDOFQPLS7jRHnan0Hq9l+1OEou+Vr2mJT+uAGBcRDwkIZH leHTWb1ly3NlSaPBQEVLmwUc63182Xmz2/K6EF3g= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-40007: netfs: fix reference leak Date: Mon, 20 Oct 2025 17:27:03 +0200 Message-ID: <2025102002-CVE-2025-40007-3315@gregkh> X-Mailer: git-send-email 2.51.1.dirty Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=4915; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=g42YLt6P9NAsWiXWLMa0Qr3+7LohW6rFAV2htxI0Rtc=; b=kA0DAAIRMUfUDdst+ykByyZiAGj2VMagtIsXuOczR+E9SRVcvQJlBPvx6gWIdVjV10Pr/3Irf YhdBAARAgAdFiEE9LYMxb94wiFKMT3LMUfUDdst+ykFAmj2VMYACgkQMUfUDdst+ykNUQCgoTKR Cv1lrdPKUdv1MyNROMWaOvoAoMJLNMQGCGXB6llAA+gaEZiPuMAi X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: netfs: fix reference leak Commit 20d72b00ca81 ("netfs: Fix the request's work item to not require a ref") modified netfs_alloc_request() to initialize the reference counter to 2 instead of 1. The rationale was that the requet's "work" would release the second reference after completion (via netfs_{read,write}_collection_worker()). That works most of the time if all goes well. However, it leaks this additional reference if the request is released before the I/O operation has been submitted: the error code path only decrements the reference counter once and the work item will never be queued because there will never be a completion. This has caused outages of our whole server cluster today because tasks were blocked in netfs_wait_for_outstanding_io(), leading to deadlocks in Ceph (another bug that I will address soon in another patch). This was caused by a netfs_pgpriv2_begin_copy_to_cache() call which failed in fscache_begin_write_operation(). The leaked netfs_io_request was never completed, leaving `netfs_inode.io_count` with a positive value forever. All of this is super-fragile code. Finding out which code paths will lead to an eventual completion and which do not is hard to see: - Some functions like netfs_create_write_req() allocate a request, but will never submit any I/O. - netfs_unbuffered_read_iter_locked() calls netfs_unbuffered_read() and then netfs_put_request(); however, netfs_unbuffered_read() can also fail early before submitting the I/O request, therefore another netfs_put_request() call must be added there. A rule of thumb is that functions that return a `netfs_io_request` do not submit I/O, and all of their callers must be checked. For my taste, the whole netfs code needs an overhaul to make reference counting easier to understand and less fragile & obscure. But to fix this bug here and now and produce a patch that is adequate for a stable backport, I tried a minimal approach that quickly frees the request object upon early failure. I decided against adding a second netfs_put_request() each time because that would cause code duplication which obscures the code further. Instead, I added the function netfs_put_failed_request() which frees such a failed request synchronously under the assumption that the reference count is exactly 2 (as initially set by netfs_alloc_request() and never touched), verified by a WARN_ON_ONCE(). It then deinitializes the request object (without going through the "cleanup_work" indirection) and frees the allocation (with RCU protection to protect against concurrent access by netfs_requests_seq_start()). All code paths that fail early have been changed to call netfs_put_failed_request() instead of netfs_put_request(). Additionally, I have added a netfs_put_request() call to netfs_unbuffered_read() as explained above because the netfs_put_failed_request() approach does not work there. The Linux kernel CVE team has assigned CVE-2025-40007 to this issue. Affected and fixed versions =========================== Issue introduced in 6.16 with commit 20d72b00ca814d748f5663484e5c53bb2bf37a3a and fixed in 6.16.10 with commit 8df142e93098b4531fadb5dfcf93087649f570b3 Issue introduced in 6.16 with commit 20d72b00ca814d748f5663484e5c53bb2bf37a3a and fixed in 6.17 with commit 4d428dca252c858bfac691c31fa95d26cd008706 Issue introduced in 6.15.3 with commit 1a8360c2eed3b292ed654c2ac61b09de4a80e298 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2025-40007 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/netfs/buffered_read.c fs/netfs/direct_read.c fs/netfs/direct_write.c fs/netfs/internal.h fs/netfs/objects.c fs/netfs/read_pgpriv2.c fs/netfs/read_single.c fs/netfs/write_issue.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/8df142e93098b4531fadb5dfcf93087649f570b3 https://git.kernel.org/stable/c/4d428dca252c858bfac691c31fa95d26cd008706