From nobody Tue Jul 14 15:19:04 2026 X-Original-To: dev-commits-src-main@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 4h02yk1CJgz6kscm for ; Tue, 14 Jul 2026 15:19:10 +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 4h02yj4PZjz3VLy for ; Tue, 14 Jul 2026 15:19:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784042349; 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=MiG1wZ3qizRnpeD/zl7ZtoNqxP9Fom7MMHtQ1yE1ClA=; b=KiKSgnEl2R3WSyOQa/u7VATXgLS2lMgiyMCtCnXALMNLEjZz6Ns7HdqFDn7hklJyA6P1Jr IVadYeQ6sIHwd/wRCJioJ0tWR10VSokWqpx9GvP6HjVSNSS/tM6cC0Wt9ypGCHBjZfrQ+8 /+j0mUIbcA1KmEA283nZD0oLac18mCGK3U/KXCQGmd3zYqVvp8DpSWe0Rx/+Q9+OKE/+tK 15igY7lkSPmuRXhz5fCHbzazNGG/zJpBs/EZQ2x9OwoC4G/y5BkVib+z6kxlS9gVS4au6O KKlETYZA1d8c2MXT5KJ2uHZyZEZARSROJalLvPEheBGOb8VbepoRNDnbMaegaw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784042349; a=rsa-sha256; cv=none; b=Il1tghgJ2UVKGmgujaI+zahyiq25gem0pDzgICd4E5hGcPxO6kLwJjtPu1oYloO2EzrKgz 6q42udC1S2LE1SWgRSxRUeMiW+Pfdx1KBcQpuwRzdpls+aW4EtVfAM5xZknZiksIS+t0gI 7EFcjoqufo+ZvcZPy5BeX7s1xzrSytmstafUK81QqvAmsj24tA8Xcyc9OZ9O6mdeF1IK6T 3tTf/v99F02CKgV2sblypybkdvLMCFBF+GHy7syRYXsY1dKmXZCNGyHh+7HrdJZdoXVGc4 zzsxaUABasAwf0xldXK9WenGAdTONig6VdENyBGCNL088nGD6eayFsWqlPAYKQ== 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=1784042349; 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=MiG1wZ3qizRnpeD/zl7ZtoNqxP9Fom7MMHtQ1yE1ClA=; b=jPaGB8OThfyaV/Up6X43K+pCXbsIbegyV13PHWpqJf7UHZ2B4keo/yBBt3WIh9Ju1Cy8dU 3RPYt1HbgzJ8qI51MzLt9Ev4enNWMdKILova49RNSWGxUaw9FL/z5AIm1DGAmZBVzub2NA 4ru4CiKegvNPAzVWF1EmDI+UVKd3x9mD7YE05C3DqXOta8NvXZyWiAhGtRjT40cyujqg8g xMUBxAJcvwGLixpWMHBl+pSoRvV70CPVtcYGPeYIGOnzRfQR8Wlwgs5c9fwae1T0qsRr7r +WXj4UFbQ/Em0+9iFIHi2rxCbOHMVNfEqE3jYMfu2WemTY3dgMlzP7Q6STsMXQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h02yj2vwvzqST for ; Tue, 14 Jul 2026 15:19:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 401f1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 14 Jul 2026 15:19:04 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Slawa Olhovchenkov From: Bojan Novk=?utf-8?Q?ovi=C4=87?= Subject: git: 0228338fc9c6 - main - bhyve: Fix some leaks in usr.sbin/bhyve/block_if.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: bnovkov X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0228338fc9c6d2243fe4fd3259286d2fbc6df786 Auto-Submitted: auto-generated Date: Tue, 14 Jul 2026 15:19:04 +0000 Message-Id: <6a565368.401f1.3af4522d@gitrepo.freebsd.org> The branch main has been updated by bnovkov: URL: https://cgit.FreeBSD.org/src/commit/?id=0228338fc9c6d2243fe4fd3259286d2fbc6df786 commit 0228338fc9c6d2243fe4fd3259286d2fbc6df786 Author: Slawa Olhovchenkov AuthorDate: 2026-07-13 16:02:43 +0000 Commit: Bojan Novković CommitDate: 2026-07-14 15:17:51 +0000 bhyve: Fix some leaks in usr.sbin/bhyve/block_if.c Modify `blockif_open` to properly release a partially initialized `blockif_ctxt` structure on error. Differential Revision: https://reviews.freebsd.org/D57887 Reviewed by: novel, bnovkov, glebius Tested by: bnovkov MFC after: 2 weeks --- usr.sbin/bhyve/block_if.c | 48 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c index 32543f9f3a18..0a4f76ae197d 100644 --- a/usr.sbin/bhyve/block_if.c +++ b/usr.sbin/bhyve/block_if.c @@ -495,6 +495,7 @@ blockif_open(nvlist_t *nvl, const char *ident) pthread_once(&blockif_once, blockif_init); + bc = NULL; fd = -1; extra = 0; ssopt = 0; @@ -650,10 +651,13 @@ blockif_open(nvlist_t *nvl, const char *ident) bc->bc_sectsz = sectsz; bc->bc_psectsz = psectsz; bc->bc_psectoff = psectoff; - pthread_mutex_init(&bc->bc_mtx, NULL); - pthread_cond_init(&bc->bc_cond, NULL); + if (pthread_mutex_init(&bc->bc_mtx, NULL) != 0) + goto err; + if (pthread_cond_init(&bc->bc_cond, NULL) != 0) + goto err; bc->bc_paused = 0; - pthread_cond_init(&bc->bc_work_done_cond, NULL); + if (pthread_cond_init(&bc->bc_work_done_cond, NULL) != 0) + goto err; TAILQ_INIT(&bc->bc_freeq); TAILQ_INIT(&bc->bc_pendq); TAILQ_INIT(&bc->bc_busyq); @@ -664,13 +668,34 @@ blockif_open(nvlist_t *nvl, const char *ident) } for (i = 0; i < BLOCKIF_NUMTHR; i++) { - pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc); + if (pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc) != 0) { + bc->bc_btid[i] = NULL; + goto err; + } snprintf(tname, sizeof(tname), "blk-%s-%d", ident, i); pthread_set_name_np(bc->bc_btid[i], tname); } return (bc); err: + if (bc != NULL) { + void *jval; + if (bc->bc_cond != NULL) { + pthread_mutex_lock(&bc->bc_mtx); + bc->bc_closing = 1; + pthread_mutex_unlock(&bc->bc_mtx); + pthread_cond_broadcast(&bc->bc_cond); + for (i = 0; i < BLOCKIF_NUMTHR; i++) + if (bc->bc_btid[i] != NULL) + pthread_join(bc->bc_btid[i], &jval); + pthread_cond_destroy(&bc->bc_cond); + } + if (bc->bc_mtx != NULL) + pthread_mutex_destroy(&bc->bc_mtx); + if (bc->bc_work_done_cond != NULL) + pthread_cond_destroy(&bc->bc_work_done_cond); + free(bc); + } if (fd >= 0) close(fd); return (NULL); @@ -806,6 +831,7 @@ blockif_delete(struct blockif_ctxt *bc, struct blockif_req *breq) int blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq) { + struct blockif_sig_elem bse; struct blockif_elem *be; assert(bc->bc_magic == BLOCKIF_SIG); @@ -849,11 +875,10 @@ blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq) * Interrupt the processing thread to force it return * prematurely via it's normal callback path. */ + pthread_mutex_init(&bse.bse_mtx, NULL); + pthread_cond_init(&bse.bse_cond, NULL); while (be->be_status == BST_BUSY) { - struct blockif_sig_elem bse, *old_head; - - pthread_mutex_init(&bse.bse_mtx, NULL); - pthread_cond_init(&bse.bse_cond, NULL); + struct blockif_sig_elem *old_head; bse.bse_pending = 1; @@ -872,6 +897,8 @@ blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq) pthread_mutex_unlock(&bse.bse_mtx); } + pthread_mutex_destroy(&bse.bse_mtx); + pthread_cond_destroy(&bse.bse_cond); pthread_mutex_unlock(&bc->bc_mtx); /* @@ -895,7 +922,7 @@ blockif_close(struct blockif_ctxt *bc) pthread_mutex_lock(&bc->bc_mtx); bc->bc_closing = 1; if (bc->bc_resize_event != NULL) - mevent_disable(bc->bc_resize_event); + mevent_delete(bc->bc_resize_event); pthread_mutex_unlock(&bc->bc_mtx); pthread_cond_broadcast(&bc->bc_cond); for (i = 0; i < BLOCKIF_NUMTHR; i++) @@ -908,6 +935,9 @@ blockif_close(struct blockif_ctxt *bc) */ bc->bc_magic = 0; close(bc->bc_fd); + pthread_mutex_destroy(&bc->bc_mtx); + pthread_cond_destroy(&bc->bc_cond); + pthread_cond_destroy(&bc->bc_work_done_cond); free(bc); return (0);