From nobody Mon Dec 16 14:45:51 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 4YBjRg3bWJz5hWWl; Mon, 16 Dec 2024 14:45:51 +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 4YBjRg1ltcz4ddT; Mon, 16 Dec 2024 14:45:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360351; 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=aVLOWAfFThYoevWYMuXeDnT1DvvKrsrbPbH1ryhZfBo=; b=mlV3WnjJzLRykRIPTLxHO7DGZFOZdFWChel36+voww1GwIUvyuPL2JSQml/SrAtgOOZdH3 ULNVHqt2057EpirRtc+UbcPDLhKXCwCYRh6KGQjR7sK7BQqbOZpBEDsZAuwstBz9psQHTL nxACyxNDmbFOX8Z4syYWfp/pwlQU63nZenmP6I1EXU2a0XIjTm+epBg23yEEVFpa+x68JQ n3ftJX2srMThzVProydRpZiJtz+/ybB85qAdA4U4JqmngNZNAzb8y6cUOMzhRpK7ij+pSW TLQY2GuloZt5dyI9eGFP8rW23Dz6s1+oA0h7NAoO/gFitz/0K7/6XiujV7LtHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360351; 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=aVLOWAfFThYoevWYMuXeDnT1DvvKrsrbPbH1ryhZfBo=; b=jG2tNBWf/raWkcmh2HcJZcv9ot4uHg5ncukQx9v+c7KRru8eD5jtI7ee5sCfpmHyy1A8mr +J/0M3e+cE06JH/wp4JcmpxpyzkipXX8/oFeXEJTVizeA8TRjkR8KY9vOFc+EyhiWjD8F4 Uka8OoOgDFKTieCjR2dpDLj/j2DsirE51u9SAHxsYyySuzEuvLZwljJaGR7RjlWWmSt9Ip cfrVFA31DRSXjGr5VVMpLuAUZ/ON7o4g3oQie6m5Enwm9eJTYsiVlKe4h8XJ2dt/eO2kUf 2NhkaFuJ1Ooe+53eCaKXVezwTQdMQsduM4S3gcC+Ag6XdZEyHm4r9mvEFgVydQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734360351; a=rsa-sha256; cv=none; b=j29O6nVS3l/LonfZ9w3d5U9IW08v21b/SLeSnFXIa2GaAtTgbK9qxAZKNhfwYABgvCvyH2 2be9Fq1NnLiUTQ2BVBLMYxA4dGacsxdqIbNjGmjaLBfrMnli2gd6N4lMH4hh4JHoROMNiS 8xOLbK9ubbPmL4JtPzdn399eKCaQO8HJq6eWIwwuBQvHjUsU4jJZsa1beT2IDa/0OHoW8t X7/WZEGw8F1bJBY3KtISCg4QBGKuzjdMUkDA/Ku0tIQKHs0O9r7741YdtixyAFvfN4I/sB yeMXv+SffKJEPh60YJCW/gkm1my7v+0jMX4L0eI2PerCkThNyX/rDvaKKAATcQ== 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 4YBjRg1N5yzxWv; Mon, 16 Dec 2024 14:45:51 +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 4BGEjpQL053088; Mon, 16 Dec 2024 14:45:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BGEjpI2053085; Mon, 16 Dec 2024 14:45:51 GMT (envelope-from git) Date: Mon, 16 Dec 2024 14:45:51 GMT Message-Id: <202412161445.4BGEjpI2053085@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: beb5603c51e0 - main - MAC/do: Remove the 'prison0' special cases in the common paths 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: beb5603c51e0323e267ceff8f83b3c95151f0822 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=beb5603c51e0323e267ceff8f83b3c95151f0822 commit beb5603c51e0323e267ceff8f83b3c95151f0822 Author: Olivier Certner AuthorDate: 2024-07-03 13:23:26 +0000 Commit: Olivier Certner CommitDate: 2024-12-16 14:42:35 +0000 MAC/do: Remove the 'prison0' special cases in the common paths The rules on 'prison0' are initialized in init(), now using set_empty_rules(). Until the jail is destroyed, they can never be uninitialized by a call to osd_jail_del(), since the only chain to call it is mac_do_prison_set() -> remove_rules() -> osd_jail_del(), and mac_do_prison_set() (method PR_METHOD_SET) can never be called on 'prison0'. This guarantees that find_rules() always find a valid 'rules' pointer to return. There's no need to do anything special in destroy() for 'prison0', as osd_jail_deregister() now takes care of it. Reviewed by: bapt Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47603 --- sys/security/mac_do/mac_do.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index 787790cb2b34..8ce84d7ba099 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -58,8 +58,6 @@ struct rules { TAILQ_HEAD(rulehead, rule) head; }; -static struct rules *rules0; - static void toast_rules(struct rules *const rules) { @@ -204,19 +202,20 @@ out: static struct rules * find_rules(struct prison *const pr, struct prison **const aprp) { - struct prison *cpr; + struct prison *cpr, *ppr; struct rules *rules; - for (cpr = pr;; cpr = cpr->pr_parent) { + cpr = pr; + for (;;) { prison_lock(cpr); - if (cpr == &prison0) { - rules = rules0; - break; - } rules = osd_jail_get(cpr, mac_do_osd_jail_slot); if (rules != NULL) break; prison_unlock(cpr); + + ppr = cpr->pr_parent; + MPASS(ppr != NULL); /* prison0 always has rules. */ + cpr = ppr; } *aprp = cpr; @@ -265,13 +264,8 @@ set_rules(struct prison *const pr, struct rules *const rules) rsv = osd_reserve(mac_do_osd_jail_slot); prison_lock(pr); - if (pr == &prison0) { - old_rules = rules0; - rules0 = rules; - } else { - old_rules = osd_jail_get(pr, mac_do_osd_jail_slot); - osd_jail_set_reserved(pr, mac_do_osd_jail_slot, rsv, rules); - } + old_rules = osd_jail_get(pr, mac_do_osd_jail_slot); + osd_jail_set_reserved(pr, mac_do_osd_jail_slot, rsv, rules); prison_unlock(pr); if (old_rules != NULL) toast_rules(old_rules); @@ -339,7 +333,6 @@ static void destroy(struct mac_policy_conf *mpc) { osd_jail_deregister(mac_do_osd_jail_slot); - toast_rules(rules0); } static int @@ -452,7 +445,7 @@ init(struct mac_policy_conf *mpc) struct prison *pr; mac_do_osd_jail_slot = osd_jail_register(dealloc_osd, osd_methods); - rules0 = alloc_rules(); + set_empty_rules(&prison0); sx_slock(&allprison_lock); TAILQ_FOREACH(pr, &allprison, pr_list) set_empty_rules(pr);