From nobody Mon Jun 29 19:25:45 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 4gpx8B0ht2z6jjZ9 for ; Mon, 29 Jun 2026 19:25:46 +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 4gpx895f3Pz40W0 for ; Mon, 29 Jun 2026 19:25:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782761145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wWGoEJA9K1DgU7TbyLq4ho8xmLXZYMYHXi/RoKFCqX0=; b=sz6YA0IGke+zUpa6AGI72cmJM32Dde6+FyG9hXnUzhm017cO73PCfCICyvZ0548t4VXI8R VGQF/XF3Xou0lKa98TyNVO6ySp5r+B55yl7X3rLZaJtTxjUhsY5oZUk0N7ysDPgeaxfMd5 uatd8ClT0QEoEW9O4l7bakgKHPMczwaYDY3Fy6Oen4lYueZec2DOiABROs3q8EYliGjvUt nfRqOxKGmtAdyd2aasRcb/LrtOvKe5LurPPP9dHxDSw+LNHwcaZB8B+dB6sjDvDYAjHNL4 slG5qBhq2RYbsw9hk7rEoZednTIbQu1DloaeVKbbOKhWu5vvQo42cI12x7ClSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782761145; a=rsa-sha256; cv=none; b=mQkzs87MHXeiOzy1r41XVhMQOLlYbSfa92l5Wl9BfsLfqBk+sex1KT64s4dapxanQDfztJ jTBKW/ZeM2A96AwF/4CackZVpR1+ruZLiQyKVhLchwDCLH+bJI6sdaUGPOdctsKBC2hwHs Zh6Kt0uvHWiDVOWXEbaKXDqIAmg0K9u0cJIPtSOnQLqohiyKFkmr0ZjVQyXoaLUVOrjvzh 8wVBkGTTk134tUXxvcSdDnxJpYRs1qchSRrNVHForKqAFhjChc75GhmSU4x4B1RMbbtO5t vC0uxn86e3OgjzhRrBm+HSlyXTnvdE5ntiyui0WEa0PjTcEkxCB37FV2FdYuFA== 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=1782761145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wWGoEJA9K1DgU7TbyLq4ho8xmLXZYMYHXi/RoKFCqX0=; b=f3j4Ul7QHqccT/uVTw9wzPas9W/al9WOg8C37N+B85gKo+KiLvAOb1tYLTBq7GIWocOCpb FNmk91sXldh0KZnHmUeGJXIikBWCPZ32M20LrrYci6YeZFSAp2vYN+dVPss/EM4WalJ9y2 fr3zDDImRebkg+7FSLf8gw0tYSiyscTEbZbQihzA/Rdq+5MJ/kCCK95ckf7yK3yuYDh+0d 36filbI1k7KTZvRgY9aDib+HPVBVZUtLPHbssNb1snn5yrnPXnRpvHa7hhtMwq7ia1zd8y jI+Kktwu5p0QfQqmBMcf11d1XwrQsqcYG4/czuzLONbtT+bZRG9VJ8UTLjroQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gpx894HQFz19bT for ; Mon, 29 Jun 2026 19:25:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21d0d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 29 Jun 2026 19:25:45 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: e4ab9584a765 - stable/15 - MAC/do: Fix releasing a nonexistent reference on configuration parsing error 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: e4ab9584a765bb022f898cd703497b74f5e69ab0 Auto-Submitted: auto-generated Date: Mon, 29 Jun 2026 19:25:45 +0000 Message-Id: <6a42c6b9.21d0d.2447768c@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=e4ab9584a765bb022f898cd703497b74f5e69ab0 commit e4ab9584a765bb022f898cd703497b74f5e69ab0 Author: Olivier Certner AuthorDate: 2026-04-28 08:42:01 +0000 Commit: Olivier Certner CommitDate: 2026-06-29 19:23:44 +0000 MAC/do: Fix releasing a nonexistent reference on configuration parsing error On parsing error, parse_and_set_conf(), introduced with the recent "executable paths" feature, has been calling drop_conf() on the being-built configuration. However, that configuration structure is allocated through alloc_conf(), which does not grab a reference. Calling drop_conf() on it, which releases a reference, is thus erroneous, and causes the underlying counter to saturate, translating into a memory leak. To fix this bug, make alloc_conf() grab a reference on the newly-created 'struct conf', and rename it to new_conf() to be more in line with what it does. Keep set_conf() as is, i.e., grabbing an additional reference on behalf of the jail that is going to hold the configuration. Consequently, make sure that callers of alloc_conf() unconditionally drop the reference acquired by the latter before returning (i.e., even if set_conf() has been called). While here, since hold_conf() is always used to obtain additional references on a configuration (new_conf() does not use it, instead directly setting the use count), add an assertion that it is never used on a configuration that has no references at all (which indicates that the configuration has been destroyed). These changes generally simplify the lifecycle of configurations, reducing the probability of re-introducing reference mismatches (at the expense of slightly more reference counting operations, but performance does not matter here). Reviewed by: bapt Fixes: 9818224174c4 ("MAC/do: Executable paths feature (GSoC 2025's final state)") MFC after: 1 month Sponsored by: The FreeBSD Foundation Pull Request: https://ron-dev.freebsd.org/FreeBSD/src/pulls/38 (cherry picked from commit a7a9e6cc64aa90a899aad9ea1395bfc77bb26f48) --- sys/security/mac_do/mac_do.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index 19ea3768153d..8276ac3f9bc5 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -368,14 +368,14 @@ init_exec_paths(struct exec_paths *const exec_paths) } static struct conf * -alloc_conf(void) +new_conf(void) { struct conf *const conf = malloc(sizeof(*conf), M_MAC_DO, M_WAITOK | M_ZERO); init_rules(&conf->rules); init_exec_paths(&conf->exec_paths); - conf->use_count = 0; + refcount_init(&conf->use_count, 1); return (conf); } @@ -1165,7 +1165,10 @@ error: static void hold_conf(struct conf *const conf) { - refcount_acquire(&conf->use_count); + int old_count __diagused = refcount_acquire(&conf->use_count); + + KASSERT(old_count != 0, + ("MAC/do: Trying to resurrect a destroyed configuration.")); } static void @@ -1331,7 +1334,7 @@ set_conf(struct prison *const pr, struct conf *const conf) static void set_default_conf(struct prison *const pr) { - struct conf *const conf = alloc_conf(); + struct conf *const conf = new_conf(); strlcpy(conf->exec_paths.exec_paths_str, "/usr/bin/mdo", MAX_EXEC_PATHS_SIZE); @@ -1339,6 +1342,7 @@ set_default_conf(struct prison *const pr) conf->exec_paths.exec_path_count = 1; set_conf(pr, conf); + drop_conf(conf); } /* @@ -1408,7 +1412,7 @@ parse_and_set_conf(struct prison *pr, const char *rules_string, if (need_applicable_conf) applicable_conf = find_conf(pr, NULL); - conf = alloc_conf(); + conf = new_conf(); if (rules_string != NULL && rules_string[0] != '\0') { error = parse_rules(rules_string, &conf->rules, parse_error); @@ -1431,12 +1435,12 @@ parse_and_set_conf(struct prison *pr, const char *rules_string, MPASS(error == 0 && *parse_error == NULL); out: + drop_conf(conf); if (applicable_conf != NULL) drop_conf(applicable_conf); return (error); error: MPASS(error != 0 && *parse_error != NULL); - drop_conf(conf); goto out; }