From nobody Tue Aug 11 18:24:29 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hKKlf638Zz6p6pF for ; Tue, 11 Aug 2026 18:24:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hKKlf2jJSz3fLr for ; Tue, 11 Aug 2026 18:24:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786472670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4uA0TC/zGydx57tmhWhR4ipefaXc7JiwzGsx8VRtt4w=; b=YAfA2Bl0QTxQBwiRTPa+LGPIwZlKxsolrCxEHwWcnj9OFnGnbWAlQsY17VD3Iy0GQak/Dj ZNDFb5bbyJTdGDaORYv/6ZVKt8Quk/janDlrGsHF/WPSyi0mgA9IgmXfn+VsCuakIv858h BJ57x5GODSj2irvIfhWtXIInnoUm4b/pHHKpjAxGfyvimuvUu4+YjO2YIxl8v2G/X8Up2i QuuAkxDODq05QTYsvzhwOrckvvT6GFM35n7pBKhuann0rjqMM4rg/vIKLQ9fWIUai5FDjt INnI8lEYO1s3upovHZCQj51IypwlcE/qEDNteiLHPgvpjZ6BlJHiq/4fpbRauw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786472670; a=rsa-sha256; cv=none; b=QIf6Wd9ikuvDmG+kNVZ0ICkaYXUW+uszYoNt+T02S1xSgpLEw8+vbVby4fyHZvK1LyeJgA zVckWCuSgCA4c6kbeKYh8zLT/beUW64m25DrEvy4N1W2KwZlK97k1NL1m2wsQlexbbCCk/ p/865FkWS0wh0mZNlqMRjSqMfINWrE+5P7P2IcVM2aLLb4Us2eRGkjcr/yB8uRsBIv7F1G E9OOhOOj6chlDBrsvYYXvZY6z/ux0tQQWCxbBR4RfEQElWByYugaomVmdejN5lDpDPM9Qb E4Tbz0asPXmPnpq0xJST6qPyXyD6CUdkcRnCvzjNeQxORow3Zk1LWZ+bV1AgUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786472670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4uA0TC/zGydx57tmhWhR4ipefaXc7JiwzGsx8VRtt4w=; b=ZY8XybOrpagEEiZBOOjWDwwgwYdOosuioWTi3y2XGkwpbxLJDdig2ZH8aIuhQhutbslyYE owE5VhV/S12JMZpiwOOaDOk/EJTxXzkYPAnMnnlkfkqZzEQfuILHyhvCrstUlPd2Ve3xHm VD1Qp52x+XkKnUGG6hK1xTTJdDIL+KyTT7UGpXwwrf2bATOCsGTG2sCjlceWuPkW9cz8KG J1mHBkgWMb71XsUNgeQSZX51y7PY3ri30WnRnOW0L9sJFd4+uREIWV0NeTvZLHG6dHatzy 0pkUo8CH/3txD9lmXBWL+81dZg4pc1Xf9IYKois0gW9T2cXLqEwnp5UpK0IHmw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hKKld5QVsz15wg for ; Tue, 11 Aug 2026 18:24:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1dcd6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 11 Aug 2026 18:24:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: giacomo From: Christos Margiolis Subject: git: a46b8546b1c8 - stable/15 - cuse: Fix server reference leak in cuse_client_open() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: a46b8546b1c8cafc529024aa87ce82ceb7bf84cb Auto-Submitted: auto-generated Date: Tue, 11 Aug 2026 18:24:29 +0000 Message-Id: <6a7b68dd.1dcd6.1cd0a338@gitrepo.freebsd.org> The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=a46b8546b1c8cafc529024aa87ce82ceb7bf84cb commit a46b8546b1c8cafc529024aa87ce82ceb7bf84cb Author: giacomo AuthorDate: 2026-07-15 12:10:54 +0000 Commit: Christos Margiolis CommitDate: 2026-08-11 18:24:04 +0000 cuse: Fix server reference leak in cuse_client_open() If the server is closing (or the device node is going away), or if devfs_set_cdevpriv() fails, cuse_client_open() returns with the server reference taken at the top of the function still held and the newly allocated client still linked on pcs->hcli. Since cuse_client_free() has not been registered as the cdevpriv destructor at that point, nothing ever undoes this work: every open() that races the is_closing window permanently leaks one server reference and one cuse_client. A leaked reference is fatal on server exit: cuse_server_free() busy-waits in an uninterruptible pause("W", hz) loop until pcs->refs drops to 1, which now never happens, so the exiting server process (e.g. virtual_oss(8)) is left wedged in state "D", immune to SIGKILL, cuse.ko is pinned (kldunload hangs too), and only a reboot recovers. Before 634e578ac7b0 the is_closing error path dropped the reference by calling devfs_clear_cdevpriv(), which ran the cuse_client_free() destructor. That commit moved devfs_set_cdevpriv() after the is_closing check to fix the panic paths, but left both error returns without any cleanup. Fix by calling cuse_client_free() directly on both error paths. The client is fully constructed and linked on pcs->hcli at these points, which is exactly the state cuse_client_free() expects. PR: 296291 Fixes: 634e578ac7b0 ("cuse: Fix cdevpriv bugs in cuse_client_open()") Assisted-By: Claude Opus 4.8 (claude-opus-4-8) Signed-off-by: giacomo MFC after: 2 weeks Reviewed by: christos Pull-Request: https://github.com/freebsd/freebsd-src/pull/2324 (cherry picked from commit d83e42234f76504a1ff7f4309ad629b6644bfb16) --- sys/fs/cuse/cuse.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/fs/cuse/cuse.c b/sys/fs/cuse/cuse.c index 8f67c4b5572b..ef786d125c15 100644 --- a/sys/fs/cuse/cuse.c +++ b/sys/fs/cuse/cuse.c @@ -1546,11 +1546,19 @@ cuse_client_open(struct cdev *dev, int fflags, int devtype, struct thread *td) } cuse_server_unlock(pcs); - if (error != 0) + /* + * On error, free the client and unref the server, so that the + * exiting server process does not become unkillable. + */ + if (error != 0) { + cuse_client_free(pcc); return (error); + } - if ((error = devfs_set_cdevpriv(pcc, &cuse_client_free)) != 0) + if ((error = devfs_set_cdevpriv(pcc, &cuse_client_free)) != 0) { + cuse_client_free(pcc); return (error); + } pccmd = &pcc->cmds[CUSE_CMD_OPEN];