Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4101016pxu; Mon, 21 Dec 2020 04:26:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJylo1zQ+anjraTJcdBe/NFu/pyrDpp5EotThfkzgQ33Bt+abtGop8kkzaak3Csf0bgTBJ5d X-Received: by 2002:a17:906:1b46:: with SMTP id p6mr15529724ejg.68.1608553570849; Mon, 21 Dec 2020 04:26:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608553570; cv=none; d=google.com; s=arc-20160816; b=MoC4YBMxmSTyklBITi6wnkZKvcIIWpQbO+RlfD6WyuP+g+arOaOZeQqVcIUdqJgcud gPiIGJHwugIQUGLJUelh75KGd3zoWuK95ht32rxpt58QVScI6sYnPVG39UHKiMfeI9nM CLjVYfxcJUefVpsrUyiZTcpO2DzBpbHq67Lp9xHFccBcS274pRveOE3IC33NfUKT3Cnh ULglaSvZ0pvFkVeJgOvr66R47lGZc+aL/ZQz3bh53Stkwo3+U8POsPynBO+ZsJKZyBkh L2HEed9IHNkOSqsW0/xYtNh3cn7Cc4dmqIlzl7t33LJ3EEY32KIz4ml1Bp46Bapwpd9R P0GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+tiNXR3CP7vw1MrP3qmDEONZL4kqJ+lwkHg6eMk12iM=; b=tS9Lizpi8fdd46MsgTaSlsKgxOECDC/gpGlvyll6rqZw7MXYZtXybjLL9mjsQUXaYP C8MIoZcA1ULjw1B3STdhEtJoqK5YZ2MKjH72fRcSjfFkplTJQ0jpi3MkvGaICMuVD210 O8m8YzA5tgnh0RqqvtL8JZ+zrYNIEO7429hnFjt+EoxHmCqQYJ/iKAVbhXjB2ba44UH4 VupsU4hwjOM6dfQaWDluPLmRGrQwnPJaOEWoQ2G3wZRHFaM/D/PZRqxpBi7R9DUghe43 Xg3vTbH9czg9EH3GJhyPT3TlfuoGyFGsT3NHvCr3QGycGWVOJlTXynDizY+gnsjS8vOW P1+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@btinternet.com header.s=btmx201904 header.b=OD3euKpg; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=btinternet.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si9192324ejj.45.2020.12.21.04.26.03; Mon, 21 Dec 2020 04:26:10 -0800 (PST) Received-SPF: pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@btinternet.com header.s=btmx201904 header.b=OD3euKpg; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=btinternet.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbgLUMXF (ORCPT + 18 others); Mon, 21 Dec 2020 07:23:05 -0500 Received: from mailomta10-sa.btinternet.com ([213.120.69.16]:15161 "EHLO sa-prd-fep-042.btinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725973AbgLUMXF (ORCPT ); Mon, 21 Dec 2020 07:23:05 -0500 Received: from sa-prd-rgout-003.btmx-prd.synchronoss.net ([10.2.38.6]) by sa-prd-fep-042.btinternet.com with ESMTP id <20201221122221.LUFY15135.sa-prd-fep-042.btinternet.com@sa-prd-rgout-003.btmx-prd.synchronoss.net>; Mon, 21 Dec 2020 12:22:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com; s=btmx201904; t=1608553341; bh=+tiNXR3CP7vw1MrP3qmDEONZL4kqJ+lwkHg6eMk12iM=; h=From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version; b=OD3euKpgdemJhG61Zxase7HhSWxC1JJPr5sYJwBvPZu7qvldyB/S30E/MQNfMKEn6G1ZgUamREUpSAEcDJCVxBd21Hk0KeoyvWCQTBEYE9ENDENjzohFllIhmzcMYdkfbtVohIF6TSj7QZ9DTSIm0HnXNUGss1M1yJGuxE4Awqk9LGkZbm3RjP7CEogfD17+vCCLYE6CXcQonUvrGyEZ5cJbIYz5vryTNiwMZ1cgkz7Fo5X1rh3V3CFgfbG+jOV8BjneWZO2UUfmkAM4o/clJfVmhUMF2UtHDGPDCCH1W8nYHLflMDdIiaN38rB7tbPt0kMlS1fZnCf0om4ZjtfWlA== Authentication-Results: btinternet.com; auth=pass (PLAIN) smtp.auth=richard_c_haines@btinternet.com X-SNCR-Rigid: 5ED9AFBE1FA314E0 X-Originating-IP: [86.177.31.108] X-OWM-Source-IP: 86.177.31.108 (GB) X-OWM-Env-Sender: richard_c_haines@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedujedrvddtvddggedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeftihgthhgrrhguucfjrghinhgvshcuoehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpeelteffgeevveejheevhfetgfeuveduteetuddtffdvjeekieetgeehveefjedtfeenucfkphepkeeirddujeejrdefuddruddtkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopehlohgtrghlhhhoshhtrdhlohgtrghlughomhgrihhnpdhinhgvthepkeeirddujeejrdefuddruddtkedpmhgrihhlfhhrohhmpeeorhhitghhrghruggptggphhgrihhnvghssegsthhinhhtvghrnhgvthdrtghomheqpdhrtghpthhtohepoehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmqecuqfftvefrvfeprhhftgekvddvnehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmpdhrtghpthhtohepoehsvghlihhnuhigqdhrvghfphholhhitgihsehvghgvrhdrkhgvrhhnvghlrdhorhhgqe X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean X-SNCR-hdrdom: btinternet.com Received: from localhost.localdomain (86.177.31.108) by sa-prd-rgout-003.btmx-prd.synchronoss.net (5.8.340) (authenticated as richard_c_haines@btinternet.com) id 5ED9AFBE1FA314E0; Mon, 21 Dec 2020 12:22:21 +0000 From: Richard Haines To: selinux-refpolicy@vger.kernel.org Cc: Richard Haines Subject: [PATCH V3] Ensure correct monolithic binary policy is loaded Date: Mon, 21 Dec 2020 12:22:13 +0000 Message-Id: <20201221122213.11643-1-richard_c_haines@btinternet.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org When building a monolithic policy with 'make load', the selinux_config(5) file 'SELINUXTYPE' entry determines what policy is loaded as load_policy(8) does not take a path value (it always loads the active system policy as defined by /etc/selinux/config). Currently it is possible to load the wrong binary policy, for example if the Reference Policy source is located at: /etc/selinux/refpolicy and the /etc/selinux/config file has the following entry: SELINUXTYPE=targeted Then the /etc/selinux/targeted/policy/policy. is loaded when 'make load' is executed. Resolve this by using selinux_binary_policy_path(3) to determine the current configured policy name and its location. Another example is that if the Reference Policy source is located at: /tmp/custom-rootfs/etc/selinux/refpolicy and the /etc/selinux/config file has the following entry: SELINUXTYPE=refpolicy Then the /etc/selinux/refpolicy/policy/policy. is loaded when 'make DESTDIR=/tmp/custom-rootfs load' is executed (not the /tmp/custom-rootfs/etc/selinux/refpolicy/policy/policy. that the developer thought would be loaded). Resolve this by checking if DESTDIR has been set. Remove the '@touch $(tmpdir)/load' line as the file is never referenced. Signed-off-by: Richard Haines --- V2 Changes: Use $(error .. instead of NO_LOAD logic. Use python script to find selinux path not sestatus. Reword error messages. V3 Change: Use the selinux_binary_policy_path() python script and reword error messages. Makefile | 1 + Rules.monolithic | 15 ++++++++++++++- support/selinux_binary_policy_path.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 support/selinux_binary_policy_path.py diff --git a/Makefile b/Makefile index 6ba215f1..1b0a4826 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ genxml := $(PYTHON) $(support)/segenxml.py gendoc := $(PYTHON) $(support)/sedoctool.py genperm := $(PYTHON) $(support)/genclassperms.py policyvers := $(PYTHON) $(support)/policyvers.py +binary_policy_path := $(PYTHON) $(support)/selinux_binary_policy_path.py fcsort := $(PYTHON) $(support)/fc_sort.py setbools := $(AWK) -f $(support)/set_bools_tuns.awk get_type_attr_decl := $(SED) -r -f $(support)/get_type_attr_decl.sed diff --git a/Rules.monolithic b/Rules.monolithic index a8ae98d1..7dbc2e1c 100644 --- a/Rules.monolithic +++ b/Rules.monolithic @@ -13,6 +13,12 @@ ifeq "$(kv)" "" kv := $(pv) endif +# load_policy(8) loads policy from /etc/selinux//policy/policy.$(pv) +# It does this by reading the /etc/selinux/config file SELINUXTYPE entry to +# form the full path. $(polbinpath) will contain this evaluated path for use as +# a validation check. +polbinpath := $(shell $(binary_policy_path)) + policy_conf = $(builddir)policy.conf fc = $(builddir)file_contexts polver = $(builddir)policy.$(pv) @@ -91,9 +97,16 @@ endif # Load the binary policy # reload $(tmpdir)/load: $(loadpath) $(fcpath) $(appfiles) +ifneq ($(DESTDIR),) + $(error Cannot load policy as '$$DESTDIR' is set to $(DESTDIR), \ + creating an invalid policy load path) +endif +ifneq ($(polbinpath).$(pv),$(loadpath)) + $(error Cannot load policy as invalid policy path: $(polbinpath).$(pv) - \ + Check $(topdir)/config file entry is: "SELINUXTYPE=$(NAME)") +endif @echo "Loading $(NAME) $(loadpath)" $(verbose) $(LOADPOLICY) -q $(loadpath) - @touch $(tmpdir)/load ######################################## # diff --git a/support/selinux_binary_policy_path.py b/support/selinux_binary_policy_path.py new file mode 100644 index 00000000..a30eb9b6 --- /dev/null +++ b/support/selinux_binary_policy_path.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +try: + import warnings + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=PendingDeprecationWarning) + import selinux + + if selinux.is_selinux_enabled(): + print(selinux.selinux_binary_policy_path()) +except ImportError: + exit(0) -- 2.29.2