diff --git a/backport-fixfiles-Unmount-temporary-bind-mounts-on-SIGINT.patch b/backport-fixfiles-Unmount-temporary-bind-mounts-on-SIGINT.patch new file mode 100644 index 0000000000000000000000000000000000000000..9aee05bdd8a02c247595db99aab185d62f0d7ea4 --- /dev/null +++ b/backport-fixfiles-Unmount-temporary-bind-mounts-on-SIGINT.patch @@ -0,0 +1,86 @@ +From 25d7941aee870c16264e7c3dfe7f48b9efbf524f Mon Sep 17 00:00:00 2001 +From: Petr Lautrbach +Date: Mon, 7 Nov 2022 10:25:05 +0100 +Subject: [PATCH] fixfiles: Unmount temporary bind mounts on SIGINT +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +`fixfiles -M relabel` temporary bind mounts file systems before +relabeling, but it left the / directory mounted in /tmp/tmp.XXXX when a +user hit CTRL-C. It means that if the user run `fixfiles -M relabel` +again and answered Y to clean out /tmp directory, it would remove all +data from mounted fs. + +This patch changes the location where `fixfiles` mounts fs to /run, uses +private mount namespace via unshare and adds a handler for exit signals +which tries to umount fs mounted by `fixfiles`. + +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2125355 + +Signed-off-by: Petr Lautrbach +Tested-by: Christian Göttsche +Acked-by: James Carter + +Conflict adapt context, delete THREADS +--- + policycoreutils/scripts/fixfiles | 36 +++++++++++++++++++++++++------- + 1 file changed, 28 insertions(+), 8 deletions(-) + +diff --git a/policycoreutils/scripts/fixfiles b/policycoreutils/scripts/fixfiles +index c72ca0eb..166af6f3 100755 +--- a/policycoreutils/scripts/fixfiles ++++ b/policycoreutils/scripts/fixfiles +@@ -207,6 +207,25 @@ rpm -q --qf '[%{FILESTATES} %{FILENAMES}\n]' "$1" | grep '^0 ' | cut -f2- -d ' ' + [ ${PIPESTATUS[0]} != 0 ] && echo "$1 not found" >/dev/stderr + } + ++# unmount tmp bind mount before exit ++umount_TMP_MOUNT() { ++ if [ -n "$TMP_MOUNT" ]; then ++ umount "${TMP_MOUNT}${m}" || exit 130 ++ rm -rf "${TMP_MOUNT}" || echo "Error cleaning up." ++ fi ++ exit 130 ++} ++ ++fix_labels_on_mountpoint() { ++ test -z ${TMP_MOUNT+x} && echo "Unable to find temporary directory!" && exit 1 ++ mkdir -p "${TMP_MOUNT}${m}" || exit 1 ++ mount --bind "${m}" "${TMP_MOUNT}${m}" || exit 1 ++ ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -q ${FC} -r "${TMP_MOUNT}" "${TMP_MOUNT}${m}" ++ umount "${TMP_MOUNT}${m}" || exit 1 ++ rm -rf "${TMP_MOUNT}" || echo "Error cleaning up." ++} ++export -f fix_labels_on_mountpoint ++ + # + # restore + # if called with -n will only check file context +@@ -252,14 +271,15 @@ case "$RESTORE_MODE" in + # we bind mount so we can fix the labels of files that have already been + # mounted over + for m in `echo $FILESYSTEMSRW`; do +- TMP_MOUNT="$(mktemp -d)" +- test -z ${TMP_MOUNT+x} && echo "Unable to find temporary directory!" && exit 1 +- +- mkdir -p "${TMP_MOUNT}${m}" || exit 1 +- mount --bind "${m}" "${TMP_MOUNT}${m}" || exit 1 +- ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -q ${FC} -r "${TMP_MOUNT}" "${TMP_MOUNT}${m}" +- umount "${TMP_MOUNT}${m}" || exit 1 +- rm -rf "${TMP_MOUNT}" || echo "Error cleaning up." ++ TMP_MOUNT="$(mktemp -p /run -d fixfiles.XXXXXXXXXX)" ++ export SETFILES VERBOSE EXCLUDEDIRS FORCEFLAG THREADS FC TMP_MOUNT m ++ if type unshare &> /dev/null; then ++ unshare -m bash -c "fix_labels_on_mountpoint $*" || exit $? ++ else ++ trap umount_TMP_MOUNT EXIT ++ fix_labels_on_mountpoint $* ++ trap EXIT ++ fi + done; + fi + else +-- +2.27.0 + diff --git a/backport-newrole-check-for-crypt-3-failure.patch b/backport-newrole-check-for-crypt-3-failure.patch new file mode 100644 index 0000000000000000000000000000000000000000..1d061d26d36e6dbfc9b5882f358842dd7fd39e18 --- /dev/null +++ b/backport-newrole-check-for-crypt-3-failure.patch @@ -0,0 +1,35 @@ +From 1af808982460ec74a23820dcc4d582bb39e2b223 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Tue, 22 Feb 2022 14:51:42 +0100 +Subject: [PATCH] newrole: check for crypt(3) failure +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Depending on the implementation crypt(3) can fail either by returning +NULL, or returning a pointer to an invalid hash and setting errno. + +Signed-off-by: Christian Göttsche +--- + policycoreutils/newrole/newrole.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/policycoreutils/newrole/newrole.c b/policycoreutils/newrole/newrole.c +index c99898635..781f99b63 100644 +--- a/policycoreutils/newrole/newrole.c ++++ b/policycoreutils/newrole/newrole.c +@@ -368,9 +368,14 @@ static int authenticate_via_shadow_passwd(const char *uname) + } + + /* Use crypt() to encrypt user's input password. */ ++ errno = 0; + encrypted_password_s = crypt(unencrypted_password_s, + p_shadow_line->sp_pwdp); + memset(unencrypted_password_s, 0, strlen(unencrypted_password_s)); ++ if (errno || !encrypted_password_s) { ++ fprintf(stderr, _("Cannot encrypt password.\n")); ++ return 0; ++ } + return (!strcmp(encrypted_password_s, p_shadow_line->sp_pwdp)); + } + #endif /* if/else USE_PAM */ diff --git a/backport-newrole-ensure-password-memory-erasure.patch b/backport-newrole-ensure-password-memory-erasure.patch new file mode 100644 index 0000000000000000000000000000000000000000..2536e6bd30f979eebf95de027723965d23744b8f --- /dev/null +++ b/backport-newrole-ensure-password-memory-erasure.patch @@ -0,0 +1,63 @@ +From c71d14e824e965e42493f5275d90272ab0c6825c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Tue, 22 Feb 2022 14:51:43 +0100 +Subject: [PATCH] newrole: ensure password memory erasure +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Compiler can optimize calls to memset(3), due to the as-if rule, away if +the object is not accessed later on. Use a wrapper using volatile +pointers to ensure the memory is guaranteed to be erased. Also erase +the encrypted password. + +Signed-off-by: Christian Göttsche +--- + policycoreutils/newrole/newrole.c | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/policycoreutils/newrole/newrole.c b/policycoreutils/newrole/newrole.c +index 781f99b63..ae37d7253 100644 +--- a/policycoreutils/newrole/newrole.c ++++ b/policycoreutils/newrole/newrole.c +@@ -333,6 +333,14 @@ static int read_pam_config(void) + + #define PASSWORD_PROMPT _("Password:") /* prompt for getpass() */ + ++static void memzero(void *ptr, size_t size) ++{ ++ volatile unsigned char * volatile p = ptr; ++ while (size--) { ++ *p++ = '\0'; ++ } ++} ++ + /* authenticate_via_shadow_passwd() + * + * in: uname - the calling user's user name +@@ -351,6 +359,7 @@ static int authenticate_via_shadow_passwd(const char *uname) + struct spwd *p_shadow_line; + char *unencrypted_password_s; + char *encrypted_password_s; ++ int ret; + + setspent(); + p_shadow_line = getspnam(uname); +@@ -371,12 +380,15 @@ static int authenticate_via_shadow_passwd(const char *uname) + errno = 0; + encrypted_password_s = crypt(unencrypted_password_s, + p_shadow_line->sp_pwdp); +- memset(unencrypted_password_s, 0, strlen(unencrypted_password_s)); ++ memzero(unencrypted_password_s, strlen(unencrypted_password_s)); + if (errno || !encrypted_password_s) { + fprintf(stderr, _("Cannot encrypt password.\n")); + return 0; + } +- return (!strcmp(encrypted_password_s, p_shadow_line->sp_pwdp)); ++ ++ ret = !strcmp(encrypted_password_s, p_shadow_line->sp_pwdp); ++ memzero(encrypted_password_s, strlen(encrypted_password_s)); ++ return ret; + } + #endif /* if/else USE_PAM */ + diff --git a/backport-policycoreutils-fix-potential-NULL-reference-in-load_checks.patch b/backport-policycoreutils-fix-potential-NULL-reference-in-load_checks.patch new file mode 100644 index 0000000000000000000000000000000000000000..8c33426df3c13df544fdfdcaa7a17e1b0a6d776c --- /dev/null +++ b/backport-policycoreutils-fix-potential-NULL-reference-in-load_checks.patch @@ -0,0 +1,38 @@ +From 1fe82e5cf581158cdfa184c64218b0bade82b01a Mon Sep 17 00:00:00 2001 +From: Jie Lu +Date: Mon, 5 Dec 2022 17:36:44 +0800 +Subject: [PATCH] policycoreutils: fix potential NULL reference in load_checks + +In load_checks(), add return check for malloc() to avoid NULL reference. + +Signed-off-by: Jie Lu +Acked-by: James Carter +--- + policycoreutils/sestatus/sestatus.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c +index 7dcc9944..6c95828e 100644 +--- a/policycoreutils/sestatus/sestatus.c ++++ b/policycoreutils/sestatus/sestatus.c +@@ -140,6 +140,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc) + pc[*npc] = + (char *)malloc((buf_len) * + sizeof(char)); ++ if (!pc[*npc]) ++ break; + memcpy(pc[*npc], bufp, buf_len); + (*npc)++; + bufp = NULL; +@@ -150,6 +152,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc) + fc[*nfc] = + (char *)malloc((buf_len) * + sizeof(char)); ++ if (!fc[*nfc]) ++ break; + memcpy(fc[*nfc], bufp, buf_len); + (*nfc)++; + bufp = NULL; +-- +2.27.0 + diff --git a/backport-policycoreutils-handle-argument-counter-of-zero.patch b/backport-policycoreutils-handle-argument-counter-of-zero.patch new file mode 100644 index 0000000000000000000000000000000000000000..e8be222c96d7d1721a5b2f2aa2436e8b57d2dfdd --- /dev/null +++ b/backport-policycoreutils-handle-argument-counter-of-zero.patch @@ -0,0 +1,73 @@ +From 9229f8b3b7348e4990c8493365d68ff241cfbeb7 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Wed, 26 Jan 2022 15:56:45 +0100 +Subject: [PATCH] policycoreutils: handle argument counter of zero +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The number of arguments passed to main(), argc, can be zero if the +pathname passed to execve(2) is NULL, e.g. via: + + execve("/path/to/exe", {NULL}, {NULL}); + +Also avoid NULL pointer dereferences on the argument value. + +Signed-off-by: Christian Göttsche +--- + policycoreutils/run_init/open_init_pty.c | 2 +- + policycoreutils/secon/secon.c | 3 +++ + policycoreutils/setfiles/setfiles.c | 6 +++++- + 3 files changed, 9 insertions(+), 2 deletions(-) + +diff --git a/policycoreutils/run_init/open_init_pty.c b/policycoreutils/run_init/open_init_pty.c +index 150cb45ee..19101c506 100644 +--- a/policycoreutils/run_init/open_init_pty.c ++++ b/policycoreutils/run_init/open_init_pty.c +@@ -244,7 +244,7 @@ int main(int argc, char *argv[]) + rb_init(&inbuf, inbuf_mem, sizeof(inbuf_mem)); + rb_init(&outbuf, outbuf_mem, sizeof(outbuf_mem)); + +- if (argc == 1) { ++ if (argc < 2) { + printf("usage: %s PROGRAM [ARGS]...\n", argv[0]); + exit(1); + } +diff --git a/policycoreutils/secon/secon.c b/policycoreutils/secon/secon.c +index a0957d091..d624fa136 100644 +--- a/policycoreutils/secon/secon.c ++++ b/policycoreutils/secon/secon.c +@@ -333,6 +333,9 @@ static void cmd_line(int argc, char *argv[]) + opts->from_type = OPTS_FROM_CUR; + + if (opts->from_type == OPTS_FROM_ARG) { ++ if (!argv[0]) ++ errx(EXIT_FAILURE, "No argument given"); ++ + opts->f.arg = argv[0]; + + if (xstreq(argv[0], "-")) +diff --git a/policycoreutils/setfiles/setfiles.c b/policycoreutils/setfiles/setfiles.c +index 44cab46d0..ab7016aca 100644 +--- a/policycoreutils/setfiles/setfiles.c ++++ b/policycoreutils/setfiles/setfiles.c +@@ -163,6 +163,10 @@ int main(int argc, char **argv) + policyfile = NULL; + + r_opts.abort_on_error = 0; ++ if (!argv[0]) { ++ fprintf(stderr, "Called without required program name!\n"); ++ exit(-1); ++ } + r_opts.progname = strdup(argv[0]); + if (!r_opts.progname) { + fprintf(stderr, "%s: Out of memory!\n", argv[0]); +@@ -423,7 +427,7 @@ int main(int argc, char **argv) + + altpath = argv[optind]; + optind++; +- } else if (argc == 1) ++ } else if (argc < 2) + usage(argv[0]); + + /* Set selabel_open options. */ diff --git a/backport-python-Do-not-query-the-local-database-if-the-fcontext-is-non-local.patch b/backport-python-Do-not-query-the-local-database-if-the-fcontext-is-non-local.patch new file mode 100644 index 0000000000000000000000000000000000000000..6bc860c03e309cf8a0e3939671ef960f2526999b --- /dev/null +++ b/backport-python-Do-not-query-the-local-database-if-the-fcontext-is-non-local.patch @@ -0,0 +1,65 @@ +From 7238ad32a3171d82bba9b99660e55399161236fc Mon Sep 17 00:00:00 2001 +From: James Carter +Date: Wed, 19 Oct 2022 14:20:11 -0400 +Subject: [PATCH] python: Do not query the local database if the fcontext is + non-local + +Vit Mojzis reports that an error message is produced when modifying +a non-local fcontext. + +He gives the following example: + # semanage fcontext -f f -m -t passwd_file_t /etc/security/opasswd + libsemanage.dbase_llist_query: could not query record value (No such file or directory). + +When modifying an fcontext, the non-local database is checked for the +key and then, if it is not found there, the local database is checked. +If the key doesn't exist, then an error is raised. If the key exists +then the local database is queried first and, if that fails, the non- +local database is queried. + +The error is from querying the local database when the fcontext is in +the non-local database. + +Instead, if the fcontext is in the non-local database, just query +the non-local database. Only query the local database if the +fcontext was found in it. + +Reported-by: Vit Mojzis +Signed-off-by: James Carter +--- + python/semanage/seobject.py | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py +index 0782c082..d82da494 100644 +--- a/python/semanage/seobject.py ++++ b/python/semanage/seobject.py +@@ -2504,16 +2504,19 @@ class fcontextRecords(semanageRecords): + (rc, exists) = semanage_fcontext_exists(self.sh, k) + if rc < 0: + raise ValueError(_("Could not check if file context for %s is defined") % target) +- if not exists: ++ if exists: ++ try: ++ (rc, fcontext) = semanage_fcontext_query(self.sh, k) ++ except OSError: ++ raise ValueError(_("Could not query file context for %s") % target) ++ else: + (rc, exists) = semanage_fcontext_exists_local(self.sh, k) ++ if rc < 0: ++ raise ValueError(_("Could not check if file context for %s is defined") % target) + if not exists: + raise ValueError(_("File context for %s is not defined") % target) +- +- try: +- (rc, fcontext) = semanage_fcontext_query_local(self.sh, k) +- except OSError: + try: +- (rc, fcontext) = semanage_fcontext_query(self.sh, k) ++ (rc, fcontext) = semanage_fcontext_query_local(self.sh, k) + except OSError: + raise ValueError(_("Could not query file context for %s") % target) + +-- +2.27.0 + diff --git a/backport-python-Split-semanage-import-into-two-transactions.patch b/backport-python-Split-semanage-import-into-two-transactions.patch new file mode 100644 index 0000000000000000000000000000000000000000..8f1a1acd598e70b8d3a10324c8453abee1006ad2 --- /dev/null +++ b/backport-python-Split-semanage-import-into-two-transactions.patch @@ -0,0 +1,63 @@ +From abaf812c3877f6b595eb8643582eacef2dd4df3f Mon Sep 17 00:00:00 2001 +From: Vit Mojzis +Date: Mon, 30 May 2022 14:20:21 +0200 +Subject: [PATCH] python: Split "semanage import" into two transactions + +First transaction applies all deletion operations, so that there are no +collisions when applying the rest of the changes. + +Fixes: + # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024 + # semanage export | semanage import + ValueError: Port tcp/3024 already defined + +Signed-off-by: Vit Mojzis +--- + python/semanage/semanage | 21 +++++++++++++++++++-- + 1 file changed, 19 insertions(+), 2 deletions(-) + +diff --git a/python/semanage/semanage b/python/semanage/semanage +index 8f4e44a7..1d828128 100644 +--- a/python/semanage/semanage ++++ b/python/semanage/semanage +@@ -852,10 +852,29 @@ def handleImport(args): + trans = seobject.semanageRecords(args) + trans.start() + ++ deleteCommands = [] ++ commands = [] ++ # separate commands for deletion from the rest so they can be ++ # applied in a separate transaction + for l in sys.stdin.readlines(): + if len(l.strip()) == 0: + continue ++ if "-d" in l or "-D" in l: ++ deleteCommands.append(l) ++ else: ++ commands.append(l) ++ ++ if deleteCommands: ++ importHelper(deleteCommands) ++ trans.finish() ++ trans.start() ++ ++ importHelper(commands) ++ trans.finish() + ++ ++def importHelper(commands): ++ for l in commands: + try: + commandParser = createCommandParser() + args = commandParser.parse_args(mkargv(l)) +@@ -869,8 +888,6 @@ def handleImport(args): + except KeyboardInterrupt: + sys.exit(0) + +- trans.finish() +- + + def setupImportParser(subparsers): + importParser = subparsers.add_parser('import', help=_('Import local customizations')) +-- +2.23.0 diff --git a/backport-python-audit2allow-close-file-stream-on-error.patch b/backport-python-audit2allow-close-file-stream-on-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..fc85cf4d5c00b1ebbc57a684dda5234b143e05a1 --- /dev/null +++ b/backport-python-audit2allow-close-file-stream-on-error.patch @@ -0,0 +1,48 @@ +From c14a86af9a2304175e54897634f808b42345325b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Fri, 20 May 2022 14:51:07 +0200 +Subject: [PATCH] python/audit2allow: close file stream on error +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + + sepolgen-ifgen-attr-helper.c: In function ‘load_policy’: + sepolgen-ifgen-attr-helper.c:196:17: warning: leak of FILE ‘fp’ [CWE-775] [-Wanalyzer-file-leak] + 196 | fprintf(stderr, "Out of memory!\n"); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Signed-off-by: Christian Göttsche +Acked-by: James Carter +--- + python/audit2allow/sepolgen-ifgen-attr-helper.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/python/audit2allow/sepolgen-ifgen-attr-helper.c b/python/audit2allow/sepolgen-ifgen-attr-helper.c +index 6f3ba962..5e6cffc1 100644 +--- a/python/audit2allow/sepolgen-ifgen-attr-helper.c ++++ b/python/audit2allow/sepolgen-ifgen-attr-helper.c +@@ -194,12 +194,14 @@ static policydb_t *load_policy(const char *filename) + policydb = malloc(sizeof(policydb_t)); + if (policydb == NULL) { + fprintf(stderr, "Out of memory!\n"); ++ fclose(fp); + return NULL; + } + + if (policydb_init(policydb)) { + fprintf(stderr, "Out of memory!\n"); + free(policydb); ++ fclose(fp); + return NULL; + } + +@@ -208,6 +210,7 @@ static policydb_t *load_policy(const char *filename) + fprintf(stderr, + "error(s) encountered while parsing configuration\n"); + free(policydb); ++ fclose(fp); + return NULL; + } + +-- +2.23.0 diff --git a/backport-python-sepolicy-Cache-conditional-rule-queries.patch b/backport-python-sepolicy-Cache-conditional-rule-queries.patch new file mode 100644 index 0000000000000000000000000000000000000000..e786ffa9a14386012bb861eaa332ddb45af932d6 --- /dev/null +++ b/backport-python-sepolicy-Cache-conditional-rule-queries.patch @@ -0,0 +1,74 @@ +From d8eb8b309f7a3e11bdcf86505ed24c1d50007213 Mon Sep 17 00:00:00 2001 +From: Vit Mojzis +Date: Mon, 30 Jan 2023 18:58:28 +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 +Acked-by: James Carter +--- + 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 e2d5c11a..c177cdfc 100644 +--- a/python/sepolicy/sepolicy/__init__.py ++++ b/python/sepolicy/sepolicy/__init__.py +@@ -125,6 +125,7 @@ all_attributes = None + booleans = None + booleans_dict = None + all_allow_rules = None ++all_bool_rules = None + all_transitions = None + + +@@ -1136,6 +1137,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 = 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: +@@ -1146,7 +1155,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.27.0 + diff --git a/backport-python-sepolicy-add-missing-booleans-to-man-pages.patch b/backport-python-sepolicy-add-missing-booleans-to-man-pages.patch new file mode 100644 index 0000000000000000000000000000000000000000..6eed8700a79564cc1745ed526b6d329ebca7d2fc --- /dev/null +++ b/backport-python-sepolicy-add-missing-booleans-to-man-pages.patch @@ -0,0 +1,112 @@ +From 7506771e4b630fe0ab853f96574e039055cb72eb 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 be89dd2f..e2d5c11a 100644 +--- a/python/sepolicy/sepolicy/__init__.py ++++ b/python/sepolicy/sepolicy/__init__.py +@@ -335,7 +335,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 + +@@ -440,12 +445,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 = {} +@@ -459,10 +464,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): +@@ -716,9 +721,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: +@@ -1141,7 +1146,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.27.0 + diff --git a/backport-semodule_package-Close-leaking-fd.patch b/backport-semodule_package-Close-leaking-fd.patch new file mode 100644 index 0000000000000000000000000000000000000000..586ac6b662930a0c727f7b32efbbfe59eca42ce3 --- /dev/null +++ b/backport-semodule_package-Close-leaking-fd.patch @@ -0,0 +1,24 @@ +From ac16531b5ab6c40bdf5eae91c8cf7ae25355d61a Mon Sep 17 00:00:00 2001 +From: Petr Lautrbach +Date: Fri, 1 Apr 2022 15:35:48 +0200 +Subject: [PATCH] semodule_package: Close leaking fd + +Signed-off-by: Petr Lautrbach +--- + semodule-utils/semodule_package/semodule_package.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/semodule-utils/semodule_package/semodule_package.c b/semodule-utils/semodule_package/semodule_package.c +index 3515234e..bc8584b5 100644 +--- a/semodule-utils/semodule_package/semodule_package.c ++++ b/semodule-utils/semodule_package/semodule_package.c +@@ -73,6 +73,7 @@ static int file_to_data(const char *path, char **data, size_t * len) + goto err; + } + if (!sb.st_size) { ++ close(fd); + *len = 0; + return 0; + } +-- +2.23.0 diff --git a/backport-sepolicy-Call-os.makedirs-with-exist_ok-True.patch b/backport-sepolicy-Call-os.makedirs-with-exist_ok-True.patch new file mode 100644 index 0000000000000000000000000000000000000000..297d81259cd10b004fe2dcf5c90b50db1ff8e52e --- /dev/null +++ b/backport-sepolicy-Call-os.makedirs-with-exist_ok-True.patch @@ -0,0 +1,39 @@ +From 7ff1d7f1c2a141a24a2af5db01fff07754ba18bc Mon Sep 17 00:00:00 2001 +From: Petr Lautrbach +Date: Mon, 12 Dec 2022 18:43:49 +0100 +Subject: [PATCH] sepolicy: Call os.makedirs() with exist_ok=True + +Since commit 7494bb1298b3 ("sepolicy: generate man pages in parallel") +man pages are generated in parallel and there's a race between +os.path.exists() and os.makedirs(). + +The check os.path.exists() is not necessary when os.makedirs() is called +with exist_ok=True. + +Fixes: +/usr/bin/sepolicy manpage -a -p /__w/usr/share/man/man8/ -w -r /__w/ +FileExistsError: [Errno 17] File exists: '/__w/usr/share/man/man8/' + +Signed-off-by: Petr Lautrbach +Acked-by: James Carter +--- + python/sepolicy/sepolicy/manpage.py | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py +index edeb3b77..1bff8f9a 100755 +--- a/python/sepolicy/sepolicy/manpage.py ++++ b/python/sepolicy/sepolicy/manpage.py +@@ -376,8 +376,7 @@ class ManPage: + + self.fcdict = sepolicy.get_fcdict(self.fcpath) + +- if not os.path.exists(path): +- os.makedirs(path) ++ os.makedirs(path, exist_ok=True) + + self.path = path + +-- +2.27.0 + diff --git a/policycoreutils.spec b/policycoreutils.spec index 5eb74d293d185aa7be98e4fb448c000e315f20c1..e52e5138abc17bf72939b4bed5459374b0b94cc6 100644 --- a/policycoreutils.spec +++ b/policycoreutils.spec @@ -3,7 +3,7 @@ Name: policycoreutils Version: 3.3 -Release: 3 +Release: 6 Summary: Policy core utilities of selinux License: GPLv2 URL: https://github.com/SELinuxProject @@ -17,9 +17,22 @@ Source11: selinux-autorelabel-generator.sh Patch0: fix-fixfiles-N-date-function.patch Patch1: fix-fixfiles-N-date-function-two.patch +Patch6000: backport-policycoreutils-handle-argument-counter-of-zero.patch +Patch6001: backport-newrole-check-for-crypt-3-failure.patch +Patch6002: backport-newrole-ensure-password-memory-erasure.patch +Patch6003: backport-semodule_package-Close-leaking-fd.patch +Patch6004: backport-python-Split-semanage-import-into-two-transactions.patch +Patch6005: backport-python-audit2allow-close-file-stream-on-error.patch +Patch6006: backport-python-Do-not-query-the-local-database-if-the-fcontext-is-non-local.patch +Patch6007: backport-fixfiles-Unmount-temporary-bind-mounts-on-SIGINT.patch +Patch6008: backport-sepolicy-Call-os.makedirs-with-exist_ok-True.patch +Patch6009: backport-policycoreutils-fix-potential-NULL-reference-in-load_checks.patch +Patch6010: backport-python-sepolicy-add-missing-booleans-to-man-pages.patch +Patch6011: backport-python-sepolicy-Cache-conditional-rule-queries.patch + BuildRequires: gcc BuildRequires: pam-devel libsepol-static >= 3.3 libsemanage-static >= 3.3 libselinux-devel >= 3.3 libcap-devel audit-libs-devel gettext -BuildRequires: desktop-file-utils dbus-devel dbus-glib-devel python3-devel libcap-ng-devel +BuildRequires: desktop-file-utils dbus-devel glib2-devel python3-devel libcap-ng-devel BuildRequires: systemd systemd-units Requires: libsepol >= 3.3 libselinux-utils util-linux grep gawk diffutils rpm sed coreutils @@ -256,6 +269,15 @@ find %{buildroot}%{python3_sitelib} %{buildroot}%{python3_sitearch} \ %{_mandir}/* %changelog +* Wed Mar 22 2023 zhangguangzhi - 3.3-6 +- backport patches from upstream + +* Sat Feb 4 2023 zhangguangzhi - 3.3-5 +- modify buildrequires to glib2-devel + +* Sat Dec 17 2022 ExtinctFire - 3.3-4 +- backport patches from upstream + * Tue Oct 18 2022 shenxiangwei - 3.3-3 - update to 3.3-3