From nobody Mon Dec 16 14:45:43 2024 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 4YBjRW4Px3z5hWc4; Mon, 16 Dec 2024 14:45:43 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YBjRW1nF7z4dR8; Mon, 16 Dec 2024 14:45:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360343; 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=KporskfEq90bAnh+PgbsywbaHQxKE1JrSGQjUM+unzs=; b=hKxR1Aqi8qfxjod26TEcgvkddbOWEg5z3s909NyVCegSSgLIxlJnaktavX5gm5QgpELu/a Z3wcs3THUVh8TzWt004a8dstuwZFC0EDWNrQpVjCxeUzO3AFbB9RMzdZIG1gSHcyEk8nxN RrIVr4dfJ+i15hSFq042nrFHRZdtDfKqxIHGWoPFmPXCFNEChPSk007OtF7bYoEmsNw3lN gPMLpNK5V+k0uTKc+0xps7UL5Qi+6xjTUs+V8mCn7tUQo+6pB1mQH4eM5Y9fu77/+nPpy3 L/63aUWZONv2RTzIG4Xe07PutKLir0nNkMYA3NiY0ktYBakf68JYuY8msEtSUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360343; 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=KporskfEq90bAnh+PgbsywbaHQxKE1JrSGQjUM+unzs=; b=GUKCZ9RkLH5jK343hqhBY3mraCN5u3e31uTXtK3CPm/1Ijkj5lG+OGygmY2TVMwqUTZ3mX WHpAUKT28MUKcVzBHRiM9UC8kyNJpG5tPHbQkPDTqpk2Mdly3T7WhgSEBZmCrtuKfMIY0l q62mcpVeCRuBsmaG9dIOTlOcxKQ6Uc+Yqs3ZE5zSOrG1E3/AXbKZEYswFN7xubKTGy2TBu HTM71BQr6XlHbP1FI2LOdsr/tEC9mIT6cjXF3i4IBsL4X8wbVEwbCINkkfbCtshF/ZXsEa k1XJE4Qqi8ErmBv/eqYjc0xyTC4fAAbdPk2Q0txl7OR5NvLNqINE8LMELIHA1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734360343; a=rsa-sha256; cv=none; b=ANl80B6mQ69qM+rMFULIUupNwNfE7yL058PipGI4/Es/65QRordjlXSluTMfBZ4qhwXOxW J3PSCNeHTumlClWTunlwi20uAxchmest/Urb0Ak3qtd4nMZH/Dox2ESEjQY6yyBv04xYws PE/LHaI2Kju/6vYzkanXOv3Gwh6ISF4bDncL3NMYApMSzwyF/M7malXsfjB07zycjE5BT+ pGy4sqy9AqVGvH98TYLYj1xLWIWPOPf3dj/vzfHI8uaVrhMX1xEQF/SnrUW9JDo7HrlUny YTivIygV0kDKXzaLi4qJQmw/VccEuJDx3h+VYHQIP2QAv2Qfq2xV8qgCj3GfJg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YBjRW1P8Rzxkc; Mon, 16 Dec 2024 14:45:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BGEjhiY052719; Mon, 16 Dec 2024 14:45:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BGEjhiU052716; Mon, 16 Dec 2024 14:45:43 GMT (envelope-from git) Date: Mon, 16 Dec 2024 14:45:43 GMT Message-Id: <202412161445.4BGEjhiU052716@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: b2c661fe7e0b - main - MAC/do: find_rules(): Clarify the contract 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 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/main X-Git-Reftype: branch X-Git-Commit: b2c661fe7e0b0dff859767a6a8714198b38dc235 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=b2c661fe7e0b0dff859767a6a8714198b38dc235 commit b2c661fe7e0b0dff859767a6a8714198b38dc235 Author: Olivier Certner AuthorDate: 2024-07-03 13:11:12 +0000 Commit: Olivier Certner CommitDate: 2024-12-16 14:42:33 +0000 MAC/do: find_rules(): Clarify the contract While here, rename an internal variable. Reviewed by: bapt Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47596 --- sys/security/mac_do/mac_do.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index ce4ab7fa9e3a..dca5a1809966 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -153,24 +153,32 @@ out: return (error); } +/* + * Find rules applicable to the passed prison. + * + * Returns the applicable rules (and never NULL). 'pr' must be unlocked. + * 'aprp' is set to the (ancestor) prison holding these, and it must be unlocked + * once the caller is done accessing the rules. '*aprp' is equal to 'pr' if and + * only if the current jail has its own set of rules. + */ static struct rules * -find_rules(struct prison *spr, struct prison **prp) +find_rules(struct prison *const pr, struct prison **const aprp) { - struct prison *pr; + struct prison *cpr; struct rules *rules; - for (pr = spr;; pr = pr->pr_parent) { - prison_lock(pr); - if (pr == &prison0) { + for (cpr = pr;; cpr = cpr->pr_parent) { + prison_lock(cpr); + if (cpr == &prison0) { rules = &rules0; break; } - rules = osd_jail_get(pr, mac_do_osd_jail_slot); + rules = osd_jail_get(cpr, mac_do_osd_jail_slot); if (rules != NULL) break; - prison_unlock(pr); + prison_unlock(cpr); } - *prp = pr; + *aprp = cpr; return (rules); }