From 10e4bd25577743767c3faf18e3890b04d5c695db Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Feb 18 2023 00:29:12 +0000 Subject: import policycoreutils-2.9-23.el8 --- diff --git a/SOURCES/0051-python-sepolicy-add-missing-booleans-to-man-pages.patch b/SOURCES/0051-python-sepolicy-add-missing-booleans-to-man-pages.patch new file mode 100644 index 0000000..ccfe7da --- /dev/null +++ b/SOURCES/0051-python-sepolicy-add-missing-booleans-to-man-pages.patch @@ -0,0 +1,112 @@ +From f3ddbd8220d9646072c9a4c9ed37f2dff998a53c Mon Sep 17 00:00:00 2001 +From: Vit Mojzis +Date: Tue, 10 Jan 2023 11:37:26 +0100 +Subject: [PATCH] python/sepolicy: add missing booleans to man pages + +get_bools should return a list of booleans that can affect given type, +but it did not handle non trivial conditional statements properly +(returning the whole conditional statement instead of a list of booleans +in the statement). + +e.g. for +allow httpd_t spamc_t:process transition; [ httpd_can_check_spam && httpd_can_sendmail ]:True +get_bools used to return [("httpd_can_check_spam && httpd_can_sendmail", False)] instead of +[("httpd_can_check_spam", False), ("httpd_can_sendmail", False)] + +- rename "boolean" in sepolicy rule dictionary to "booleans" to suggest + it can contain multiple values and make sure it is populated correctly +- add "conditional" key to the rule dictionary to accommodate + get_conditionals, which requires the whole conditional statement +- extend get_bools search to dontaudit rules so that it covers booleans + like httpd_dontaudit_search_dirs + +Note: get_bools uses security_get_boolean_active to get the boolean + value, but the value is later used to represent the default. + Not ideal, but I'm not aware of a way to get the actual defaults. + +Fixes: + "sepolicy manpage" generates man pages that are missing booleans + which are included in non trivial conditional expressions + e.g. httpd_selinux(8) does not include httpd_can_check_spam, + httpd_tmp_exec, httpd_unified, or httpd_use_gpg + + This fix, however, also adds some not strictly related booleans + to some man pages. e.g. use_nfs_home_dirs and + use_samba_home_dirs are added to httpd_selinux(8) + +Signed-off-by: Vit Mojzis +Acked-by: Jason Zaman +--- + python/sepolicy/sepolicy/__init__.py | 21 +++++++++++++-------- + 1 file changed, 13 insertions(+), 8 deletions(-) + +diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py +index b6ca57c3..0f51174d 100644 +--- a/python/sepolicy/sepolicy/__init__.py ++++ b/python/sepolicy/sepolicy/__init__.py +@@ -324,7 +324,12 @@ def _setools_rule_to_dict(rule): + pass + + try: +- d['boolean'] = [(str(rule.conditional), enabled)] ++ d['booleans'] = [(str(b), b.state) for b in rule.conditional.booleans] ++ except AttributeError: ++ pass ++ ++ try: ++ d['conditional'] = str(rule.conditional) + except AttributeError: + pass + +@@ -426,12 +431,12 @@ def get_conditionals(src, dest, tclass, perm): + x['source'] in src_list and + x['target'] in dest_list and + set(perm).issubset(x[PERMS]) and +- 'boolean' in x, ++ 'conditional' in x, + get_all_allow_rules())) + + try: + for i in allows: +- tdict.update({'source': i['source'], 'boolean': i['boolean']}) ++ tdict.update({'source': i['source'], 'conditional': (i['conditional'], i['enabled'])}) + if tdict not in tlist: + tlist.append(tdict) + tdict = {} +@@ -445,10 +450,10 @@ def get_conditionals_format_text(cond): + + enabled = False + for x in cond: +- if x['boolean'][0][1]: ++ if x['conditional'][1]: + enabled = True + break +- return _("-- Allowed %s [ %s ]") % (enabled, " || ".join(set(map(lambda x: "%s=%d" % (x['boolean'][0][0], x['boolean'][0][1]), cond)))) ++ return _("-- Allowed %s [ %s ]") % (enabled, " || ".join(set(map(lambda x: "%s=%d" % (x['conditional'][0], x['conditional'][1]), cond)))) + + + def get_types_from_attribute(attribute): +@@ -703,9 +708,9 @@ def get_boolean_rules(setype, boolean): + boollist = [] + permlist = search([ALLOW], {'source': setype}) + for p in permlist: +- if "boolean" in p: ++ if "booleans" in p: + try: +- for b in p["boolean"]: ++ for b in p["booleans"]: + if boolean in b: + boollist.append(p) + except: +@@ -1124,7 +1129,7 @@ def get_bools(setype): + bools = [] + domainbools = [] + domainname, short_name = gen_short_name(setype) +- for i in map(lambda x: x['boolean'], filter(lambda x: 'boolean' in x and x['source'] == setype, get_all_allow_rules())): ++ for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, search([ALLOW, DONTAUDIT]))): + for b in i: + if not isinstance(b, tuple): + continue +-- +2.37.3 + diff --git a/SOURCES/0052-python-sepolicy-Cache-conditional-rule-queries.patch b/SOURCES/0052-python-sepolicy-Cache-conditional-rule-queries.patch new file mode 100644 index 0000000..0dac123 --- /dev/null +++ b/SOURCES/0052-python-sepolicy-Cache-conditional-rule-queries.patch @@ -0,0 +1,73 @@ +From 25373db5cac520b85350db91b8a7ed0737d3316c Mon Sep 17 00:00:00 2001 +From: Vit Mojzis +Date: Tue, 24 Jan 2023 21:05:05 +0100 +Subject: [PATCH] python/sepolicy: Cache conditional rule queries + +Commit 7506771e4b630fe0ab853f96574e039055cb72eb +"add missing booleans to man pages" dramatically slowed down +"sepolicy manpage -a" by removing caching of setools rule query. +Re-add said caching and update the query to only return conditional +rules. + +Before commit 7506771e: + #time sepolicy manpage -a + real 1m43.153s + # time sepolicy manpage -d httpd_t + real 0m4.493s + +After commit 7506771e: + #time sepolicy manpage -a + real 1h56m43.153s + # time sepolicy manpage -d httpd_t + real 0m8.352s + +After this commit: + #time sepolicy manpage -a + real 1m41.074s + # time sepolicy manpage -d httpd_t + real 0m7.358s + +Signed-off-by: Vit Mojzis +--- + python/sepolicy/sepolicy/__init__.py | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py +index 0f51174d..f48231e9 100644 +--- a/python/sepolicy/sepolicy/__init__.py ++++ b/python/sepolicy/sepolicy/__init__.py +@@ -114,6 +114,7 @@ all_attributes = None + booleans = None + booleans_dict = None + all_allow_rules = None ++all_bool_rules = None + all_transitions = None + + +@@ -1119,6 +1120,14 @@ def get_all_allow_rules(): + all_allow_rules = search([ALLOW]) + return all_allow_rules + ++def get_all_bool_rules(): ++ global all_bool_rules ++ if not all_bool_rules: ++ q = setools.TERuleQuery(_pol, boolean=".*", boolean_regex=True, ++ ruletype=[ALLOW, DONTAUDIT]) ++ all_bool_rules = [_setools_rule_to_dict(x) for x in q.results()] ++ return all_bool_rules ++ + def get_all_transitions(): + global all_transitions + if not all_transitions: +@@ -1129,7 +1138,7 @@ def get_bools(setype): + bools = [] + domainbools = [] + domainname, short_name = gen_short_name(setype) +- for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, search([ALLOW, DONTAUDIT]))): ++ for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, get_all_bool_rules())): + for b in i: + if not isinstance(b, tuple): + continue +-- +2.37.3 + diff --git a/SPECS/policycoreutils.spec b/SPECS/policycoreutils.spec index 54f2f69..a239a86 100644 --- a/SPECS/policycoreutils.spec +++ b/SPECS/policycoreutils.spec @@ -12,7 +12,7 @@ Summary: SELinux policy core utilities Name: policycoreutils Version: 2.9 -Release: 21.1%{?dist} +Release: 23%{?dist} License: GPLv2 # https://github.com/SELinuxProject/selinux/wiki/Releases Source0: https://github.com/SELinuxProject/selinux/releases/download/20190315/policycoreutils-2.9.tar.gz @@ -88,6 +88,8 @@ Patch0047: 0047-python-Split-semanage-import-into-two-transactions.patch Patch0048: 0048-semodule-rename-rebuild-if-modules-changed-to-refres.patch Patch0049: 0049-python-Harden-tools-against-rogue-modules.patch Patch0050: 0050-python-Do-not-query-the-local-database-if-the-fconte.patch +Patch0051: 0051-python-sepolicy-add-missing-booleans-to-man-pages.patch +Patch0052: 0052-python-sepolicy-Cache-conditional-rule-queries.patch Obsoletes: policycoreutils < 2.0.61-2 Conflicts: filesystem < 3, selinux-policy-base < 3.13.1-138 @@ -527,6 +529,12 @@ The policycoreutils-restorecond package contains the restorecond service. %systemd_postun_with_restart restorecond.service %changelog +* Wed Feb 08 2023 Vit Mojzis - 2.9-23 +- python/sepolicy: Cache conditional rule queries (#2155540) + +* Mon Jan 09 2023 Vit Mojzis - 2.9-22 +- python/sepolicy: add missing booleans to man pages (#2155540) + * Mon Dec 19 2022 Vit Mojzis - 2.9-21.1 - python: Harden tools against "rogue" modules (#2128976) - Update "pathfix" arguments to match ^^^ (#2128976)