From nobody Fri Jul 24 11:20:41 2026 X-Original-To: dev-commits-src-all@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 4h65By1VxYz6lhwj for ; Fri, 24 Jul 2026 11:20:42 +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 4h65By0Pr1z4PBx for ; Fri, 24 Jul 2026 11:20:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784892042; 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=A4NTRJp7gtiPI7HxLjx4pI2+/+8/LXGzKqEQDJyTZdQ=; b=gN+GpgCcmnY7Cz2XFydSf+6Nk5n0/gKKzq1ms/wfDr/ALUx//3HCRDYECa3ZrdcvGeMkGw isbOcaC/pLP1tXOjZft5jEXIqbaKAhRP5hYRpG8dIv1CUt0//0e22cOMcaPvg3kBGOsAD+ XKPbGm6DCIRSe3qCYxXBVkq+bTXIOQQKAG9i3un8WD6pA8xe0KrQh8UaeaQFPc0fJcf0G1 q8IRAZR7KK/tCsG/NGgZV5XSiEvIqv8EJacNdlGFVPhn6aG78MTJOLoS9XyipeV9Mlg6h6 J8BrJ0eeRcVBwLT2V7m+y1MqB6yZcEIC3/cVqMFV0ZijAXy3NDbWyB+gx0edgQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784892042; a=rsa-sha256; cv=none; b=LKs0JtVCM0846oQleWGEiYqH3EXqxVrFw+a2LmxifS2mkfkZ4II1S3djsfXaO7AgW2HI/h Xm9wqjLSRH3ejW7dm/uPad+q1aP2kRQgFE7EKszU9wqnwNOGZMFMox7esprqe46DHbp+T3 2wKAHp9XosZmC/w3HkxBj4Y0jdceBUPWiL+36kSClfW6vxnoAWbWJWFPjnZ+ix56gMttKl JF2cC8d+3RY/7T02lpHgcBRw+V6PTDwVJZB1+ejDsi6b3rMlegI5Viq5Hqsion57zwF9LV TCwhaWPHngSzDjgEMQeF6qk6xGrcn4JRJSkEkqOEoN/pV+Fj5I7wEszdxpCY+w== 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=1784892042; 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=A4NTRJp7gtiPI7HxLjx4pI2+/+8/LXGzKqEQDJyTZdQ=; b=uGP0PUNkXI0+1siUo68OGkFSbO1C49hF71/wrTQzAv9ksbp1xi6rHVwqaQUBpew8PQ7QsP berfoRR6XGM2cn+DS8ZyMuvwenB4sIxBdmnVHZfd45I8T6cXWbk7tOqrvaskRTKz9e77Bz kR4NkDjem30qEC8XSZj1cCz1FhbzQjXEJoAuCPm/0AltN0A2793PJ0HYqguykkma3piqc+ gIwksGnqzWJqtF0tzq2zHiN4iQYX5YusBTGDGnnN/o93ZrS728Q1vvqUjpgeYLpeZRYCAb VMh/tq1K2dZKab2zRc9EO6ZnfAt9Fm2x2ubPlby5/X7/eeIs9VHq01lTJZt0UQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h65Bx65XXzpn3 for ; Fri, 24 Jul 2026 11:20:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 45cd4 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 24 Jul 2026 11:20:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: giacomo From: Christos Margiolis Subject: git: d83e42234f76 - main - cuse: Fix server reference leak in cuse_client_open() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: d83e42234f76504a1ff7f4309ad629b6644bfb16 Auto-Submitted: auto-generated Date: Fri, 24 Jul 2026 11:20:41 +0000 Message-Id: <6a634a89.45cd4.76dcfac@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=d83e42234f76504a1ff7f4309ad629b6644bfb16 commit d83e42234f76504a1ff7f4309ad629b6644bfb16 Author: giacomo AuthorDate: 2026-07-15 12:10:54 +0000 Commit: Christos Margiolis CommitDate: 2026-07-24 11:20:09 +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 --- 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];