diff --git a/package/refpolicy/Config.in b/package/refpolicy/Config.in index 242d7f34e0..f330c685ab 100644 --- a/package/refpolicy/Config.in +++ b/package/refpolicy/Config.in @@ -121,6 +121,19 @@ config BR2_REFPOLICY_EXTRA_MODULES endif +config BR2_REFPOLICY_SET_BOOLEANS + string "Set policy booleans" + help + Set default values for policy booleans before compiling the + policy (see policy/booleans.conf in the refpolicy + README). The value of this option is a space separated list + of either plain names (to set that boolean to true), or + "name=(true|false)" pairs (to set the given value). + + Boolean values can still be changed at runtime if the policy + permits, but such changes cannot be persisted with a + monolithic policy. + config BR2_REFPOLICY_ENABLEAUDIT bool "remove dontaudit rules from policy (debugging only)" help diff --git a/package/refpolicy/refpolicy.mk b/package/refpolicy/refpolicy.mk index 698f38f738..c5d8ce3b57 100644 --- a/package/refpolicy/refpolicy.mk +++ b/package/refpolicy/refpolicy.mk @@ -107,6 +107,15 @@ define REFPOLICY_CONFIGURE_ENABLEAUDIT endef endif +# Override defaults for policy booleans. name=(true|false) will result +# in the given value, just a name implies "true". +define REFPOLICY_CONFIGURE_BOOLEANS + $(foreach b,$(call qstrip,$(BR2_REFPOLICY_SET_BOOLEANS)), + read -r name value < <(echo "$(subst =, ,$(b))"); \ + $(SED) "/^$${name} =/c\\$${name} = $${value:-true}" $(@D)/policy/booleans.conf + ) +endef + define REFPOLICY_CONFIGURE_CMDS $(SED) "/OUTPUT_POLICY/c\OUTPUT_POLICY = $(REFPOLICY_POLICY_VERSION)" \ $(@D)/build.conf @@ -119,6 +128,7 @@ define REFPOLICY_CONFIGURE_CMDS $(REFPOLICY_MAKE) -C $(@D) bare conf $(REFPOLICY_CONFIGURE_ENABLEAUDIT) $(REFPOLICY_CONFIGURE_MODULES) + $(REFPOLICY_CONFIGURE_BOOLEANS) endef define REFPOLICY_BUILD_CMDS diff --git a/support/testing/tests/core/test_selinux.py b/support/testing/tests/core/test_selinux.py index 683a424d6f..e72431211d 100644 --- a/support/testing/tests/core/test_selinux.py +++ b/support/testing/tests/core/test_selinux.py @@ -51,6 +51,24 @@ class TestSELinuxExtraModulesDirs(TestSELinuxInfra): self.assertEqual(out[2].strip(), "buildroot_test_t") +class TestSELinuxSetBooleans(TestSELinuxInfra): + config = TestSELinuxInfra.config + \ + """ + BR2_REFPOLICY_SET_BOOLEANS="user_dmesg user_all_users_send_syslog=false" + """ + + def test_run(self): + TestSELinuxInfra.base_test_run(self) + + out, ret = self.emulator.run("seinfo -x -b", 15) + self.assertEqual(ret, 0) + # lines follow the pattern "name (true|false);", plus indentation + bools = dict(line.strip().rstrip(';').split()[1:] for line in out[2:]) + # both of these booleans have the opposite default in refpolicy + self.assertEqual(bools["user_dmesg"], "true") + self.assertEqual(bools["user_all_users_send_syslog"], "false") + + class TestSELinuxCustomGit(TestSELinuxInfra): config = TestSELinuxInfra.config + \ """