Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package checkpolicy for openSUSE:Factory checked in at 2026-12-05 19:08:57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/checkpolicy (Old) and /work/SRC/openSUSE:Factory/.checkpolicy.new.1340718 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "checkpolicy" Sat Dec 5 19:08:57 2026 rev:45 rq:1402962 version:3.12 Changes: -------- --- /work/SRC/openSUSE:Factory/checkpolicy/checkpolicy.changes 2026-07-13 14:25:19.781801747 +0200 +++ /work/SRC/openSUSE:Factory/.checkpolicy.new.1340718/checkpolicy.changes 2026-12-05 19:08:59.102582764 +0100 @@ -1,0 +2,30 @@ +Thu Dec 3 09:00:36 UTC 2026 - Cathy Hu <[email protected]> + +- Update to version 3.12 + https://github.com/SELinuxProject/selinux/releases/tag/v3.12 + - User-visible changes: + - Added a --multiple-decls option to checkpolicy and libsepol to allow a + type or type attribute to be declared more than once, with the + declarations merged, mirroring the secilc option of the same name. + - Security/hardening changes: + - Significantly strengthened validation of binary and source policies in + libsepol and checkpolicy, including checks on policy versions, symbol + and scope tables, permissions, MLS components and levels, type aliases, + and path, port and other labeling fields; invalid or malformed policy + data is rejected instead of being processed unsafely. checkpolicy now + also validates the policy database before writing it. + - Added overflow, bounds and allocation checks across libsepol, + libsemanage, libselinux, checkpolicy and secilc. + - Notable bug fixes: + - checkpolicy: fix double free of fstype in define_genfs_context_helper + - checkpolicy: fix operator precedence in flavor check + - checkpolicy: reject self as a type alias name + - checkpolicy: preserve policy type when reading a binary module +- Source URLs: upstream tags are prefixed with "v" now + +------------------------------------------------------------------- +Wed Dec 2 13:07:50 UTC 2026 - Cathy Hu <[email protected]> + +- keyring: update bachradsusi.gpg for next release + +------------------------------------------------------------------- Old: ---- checkpolicy-3.11.tar.gz checkpolicy-3.11.tar.gz.asc New: ---- checkpolicy-3.12.tar.gz checkpolicy-3.12.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ checkpolicy.spec ++++++ --- /var/tmp/diff_new_pack.UOkNZz/_old 2026-12-05 19:09:00.721650991 +0100 +++ /var/tmp/diff_new_pack.UOkNZz/_new 2026-12-05 19:09:00.726651201 +0100 @@ -16,16 +16,16 @@ # -%define libsepol_ver 3.11 +%define libsepol_ver 3.12 Name: checkpolicy -Version: 3.11 +Version: 3.12 Release: 0 Summary: SELinux policy compiler License: GPL-2.0-or-later Group: Productivity/Security URL: https://github.com/SELinuxProject/selinux -Source0: https://github.com/SELinuxProject/selinux/releases/download/%{version}/%{name}-%{version}.tar.gz -Source1: https://github.com/SELinuxProject/selinux/releases/download/%{version}/%{name}-%{version}.tar.gz.asc +Source0: https://github.com/SELinuxProject/selinux/releases/download/v%{version}/%{name}-%{version}.tar.gz +Source1: https://github.com/SELinuxProject/selinux/releases/download/v%{version}/%{name}-%{version}.tar.gz.asc Source2: checkpolicy.keyring Source3: checkpolicy-tests.tar.gz BuildRequires: bison ++++++ checkpolicy-3.11.tar.gz -> checkpolicy-3.12.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/.gitignore new/checkpolicy-3.12/.gitignore --- old/checkpolicy-3.11/.gitignore 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/.gitignore 2026-12-02 18:39:01.000000000 +0100 @@ -5,3 +5,4 @@ y.tab.h tests/testpol.bin tests/testpol.conf +tests/test-type-enabled diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/Makefile new/checkpolicy-3.12/Makefile --- old/checkpolicy-3.11/Makefile 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/Makefile 2026-12-02 18:39:01.000000000 +0100 @@ -51,12 +51,23 @@ $(LEX) policy_scan.l .PHONY: test -test: checkpolicy +test: checkpolicy checkmodule tests/test-type-enabled ./tests/test_roundtrip.sh + ./tests/test_checkmodule_negative.sh + sh ./tests/test_conditional_count.sh + ./tests/test-type-enabled + sh ./tests/test_multiple_decls.sh + +tests/test-type-enabled: tests/test_type_enabled.c $(LIBSEPOLA) + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA) # helper target for fuzzing checkobjects: $(CHECKOBJS) +.PHONY: fuzz +fuzz: + $(MAKE) -C fuzz + install: all -mkdir -p $(DESTDIR)$(BINDIR) -mkdir -p $(DESTDIR)$(MANDIR)/man8 @@ -75,5 +86,7 @@ /sbin/restorecon $(DESTDIR)$(BINDIR)/checkmodule clean: + -rm -f tests/test-type-enabled -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin $(MAKE) -C test clean + $(MAKE) -C fuzz clean diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/VERSION new/checkpolicy-3.12/VERSION --- old/checkpolicy-3.11/VERSION 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/VERSION 2026-12-02 18:39:01.000000000 +0100 @@ -1 +1 @@ -3.11 +3.12 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/checkmodule.c new/checkpolicy-3.12/checkmodule.c --- old/checkpolicy-3.11/checkmodule.c 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/checkmodule.c 2026-12-02 18:39:01.000000000 +0100 @@ -109,12 +109,10 @@ } static int write_binary_policy(policydb_t *p, FILE *outfp, - unsigned int policy_type, unsigned int policyvers) { struct policy_file pf; - p->policy_type = policy_type; p->policyvers = policyvers; p->handle_unknown = handle_unknown; @@ -264,13 +262,6 @@ exit(1); } - if (binary && (policy_type != POLICY_BASE)) { - fprintf(stderr, - "%s: -b and -m are incompatible with each other.\n", - argv[0]); - exit(1); - } - if (line_marker_for_allow && !cil) { fprintf(stderr, "%s: -L must be used along with -C.\n", argv[0]); @@ -293,6 +284,11 @@ if (read_binary_policy(&modpolicydb, file, argv[0]) == -1) { exit(1); } + /* + * Preserve the input's policy type instead of the getopt + * default; -m is redundant with -b but harmless. + */ + policy_type = modpolicydb.policy_type; } else { if (policydb_init(&modpolicydb)) { fprintf(stderr, "%s: out of memory!\n", argv[0]); @@ -313,7 +309,7 @@ } } - if (policy_type != POLICY_BASE && outfile) { + if (policy_type != POLICY_BASE && outfile && !binary) { char *out_name; char *separator; char *mod_name = modpolicydb.name; @@ -372,7 +368,7 @@ if (!cil) { if (write_binary_policy(&modpolicydb, outfp, - policy_type, policyvers) != 0) { + policyvers) != 0) { fprintf(stderr, "%s: error writing %s\n", argv[0], outfile); exit(1); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/checkpolicy.8 new/checkpolicy-3.12/checkpolicy.8 --- old/checkpolicy-3.11/checkpolicy.8 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/checkpolicy.8 2026-12-02 18:39:01.000000000 +0100 @@ -46,6 +46,9 @@ of the output CIL policy file, but the additional line markers helps debugging, especially neverallow failure reports. Can only be used when writing a CIL policy file. .TP +.B \-m,\-\-multiple\-decls +Allow types and attributes to be re-declared. +.TP .B \-c policyvers Specify the policy version, defaults to the latest. .TP @@ -73,15 +76,18 @@ Show usage information. .SH EXAMPLE +The read paths may be under /usr/lib on stateless systems. .nf Generate policy.conf based on the system policy # checkpolicy -b -M -F /etc/selinux/targeted/policy/policy.33 -o policy.conf +# checkpolicy -b -M -F /usr/lib/selinux/targeted/policy/policy.33 -o policy.conf Recompile system policy so that unknown permissions are denied (uses policy.conf from ^^). Note that binary policy extension represents its version, which is subject to change # checkpolicy -M -U deny -o /etc/selinux/targeted/policy/policy.33 policy.conf # load_policy Generate CIL representation of current system policy # checkpolicy -b -M -C /etc/selinux/targeted/policy/policy.33 -o policy.out +# checkpolicy -b -M -C /usr/lib/selinux/targeted/policy/policy.33 -o policy.out .SH "SEE ALSO" SELinux Reference Policy documentation at https://github.com/SELinuxProject/refpolicy/wiki diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/checkpolicy.c new/checkpolicy-3.12/checkpolicy.c --- old/checkpolicy-3.11/checkpolicy.c 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/checkpolicy.c 2026-12-02 18:39:01.000000000 +0100 @@ -60,6 +60,7 @@ #include <ctype.h> #include <getopt.h> +#include <limits.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> @@ -106,7 +107,7 @@ { printf("usage: %s [-b[F]] [-C] [-d] [-U handle_unknown (allow,deny,reject)] [-M] " "[-N] [-c policyvers (%d-%d)] [-o output_file|-] [-S] [-O] " - "[-t target_platform (selinux,xen)] [-E] [-V] [-L] [input_file]\n", + "[-t target_platform (selinux,xen)] [-E] [-V] [-L] [-m] [input_file]\n", progname, POLICYDB_VERSION_MIN, POLICYDB_VERSION_MAX); exit(1); } @@ -373,6 +374,8 @@ return 0; } +extern int policydb_validate(sepol_handle_t *handle, const policydb_t *p); + int main(int argc, char **argv) { policydb_t parse_policy; @@ -390,9 +393,12 @@ unsigned int binary = 0, debug = 0, sort = 0, cil = 0, conf = 0, optimize = 0, disable_neverallow = 0; unsigned int line_marker_for_allow = 0; + unsigned int multiple_decls = 0; struct val_to_name v; int ret, ch, fd, target = SEPOL_TARGET_SELINUX; unsigned int policyvers = 0; + unsigned int policyvers_min = POLICYDB_VERSION_MIN; + unsigned int policyvers_max = POLICYDB_VERSION_MAX; unsigned int nel, uret; struct stat sb; void *map; @@ -419,11 +425,12 @@ { "optimize", no_argument, NULL, 'O' }, { "werror", no_argument, NULL, 'E' }, { "line-marker-for-allow", no_argument, NULL, 'L' }, + { "multiple-decls", no_argument, NULL, 'm' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; - while ((ch = getopt_long(argc, argv, "o:t:dbU:MNCFSVc:OELh", + while ((ch = getopt_long(argc, argv, "o:t:dbU:MNCFSVc:OELmh", long_options, NULL)) != -1) { switch (ch) { case 'o': @@ -488,22 +495,13 @@ long int n; errno = 0; n = strtol(optarg, NULL, 10); - if (errno) { + if (errno || n < 1 || n > INT_MAX) { fprintf(stderr, "Invalid policyvers specified: %s\n", optarg); usage(argv[0]); exit(1); } - if (n < POLICYDB_VERSION_MIN || - n > POLICYDB_VERSION_MAX) { - fprintf(stderr, - "policyvers value %ld not in range %d-%d\n", - n, POLICYDB_VERSION_MIN, - POLICYDB_VERSION_MAX); - usage(argv[0]); - exit(1); - } policyvers = n; break; } @@ -513,16 +511,31 @@ case 'L': line_marker_for_allow = 1; break; + case 'm': + multiple_decls = 1; + break; case 'h': default: usage(argv[0]); } } + if (target == SEPOL_TARGET_XEN) { + policyvers_min = POLICYDB_XEN_VERSION_MIN; + policyvers_max = POLICYDB_XEN_VERSION_MAX; + } + + if (!policyvers) + policyvers = policyvers_max; + else if (policyvers < policyvers_min || policyvers > policyvers_max) { + fprintf(stderr, "policyvers value %u not in range %u-%u\n", + policyvers, policyvers_min, policyvers_max); + usage(argv[0]); + } + if (show_version) { - printf("%d (compatibility range %d-%d)\n", - policyvers ? policyvers : POLICYDB_VERSION_MAX, - POLICYDB_VERSION_MAX, POLICYDB_VERSION_MIN); + printf("%u (compatibility range %u-%u)\n", policyvers, + policyvers_max, policyvers_min); exit(0); } @@ -549,6 +562,12 @@ exit(1); } + if (multiple_decls && binary) { + fprintf(stderr, + "Multiple declarations are only meaningful when compiling source policy\n"); + exit(1); + } + if (binary) { fd = open(file, O_RDONLY); if (fd < 0) { @@ -605,18 +624,7 @@ } } - if (policydbp->policyvers <= POLICYDB_VERSION_PERMISSIVE) { - if (policyvers > policydbp->policyvers) { - fprintf(stderr, - "Binary policies with version <= %u cannot be upgraded\n", - POLICYDB_VERSION_PERMISSIVE); - } else if (policyvers) { - policydbp->policyvers = policyvers; - } - } else { - policydbp->policyvers = - policyvers ? policyvers : POLICYDB_VERSION_MAX; - } + policydbp->policyvers = policyvers; } else { if (conf) { fprintf(stderr, @@ -632,8 +640,8 @@ /* Let sepol know if we are dealing with MLS support */ parse_policy.mls = mlspol; parse_policy.handle_unknown = handle_unknown; - parse_policy.policyvers = policyvers ? policyvers : - POLICYDB_VERSION_MAX; + parse_policy.policyvers = policyvers; + parse_policy.multiple_decls = multiple_decls; policydbp = &parse_policy; @@ -661,8 +669,7 @@ "Error while expanding policy\n"); exit(1); } - policydb.policyvers = policyvers ? policyvers : - POLICYDB_VERSION_MAX; + policydb.policyvers = policyvers; policydb_destroy(policydbp); policydbp = &policydb; } @@ -678,6 +685,23 @@ argv[0]); exit(1); } + } + + /* + * Validate the kernel policydb before writing it so we fail here + * rather than producing a policy file that policydb_read() will + * reject. The POLICY_BASE parse_policy on the source->CIL path is + * not validated: policydb_validate() assumes read-side invariants + * that the parser does not establish, and the parser is authoritative + * on source input. + */ + if (policydbp->policy_type == POLICY_KERN) { + ret = policydb_validate(NULL, policydbp); + if (ret) { + fprintf(stderr, "%s: validation of policydb failed\n", + argv[0]); + exit(1); + } } if (outfile) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/fuzz/.gitignore new/checkpolicy-3.12/fuzz/.gitignore --- old/checkpolicy-3.11/fuzz/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/fuzz/.gitignore 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1 @@ +checkpolicy-fuzzer diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/fuzz/Makefile new/checkpolicy-3.12/fuzz/Makefile --- old/checkpolicy-3.11/fuzz/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/fuzz/Makefile 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,38 @@ +# Build the checkpolicy fuzzer as a standalone debug binary. +# oss-fuzz.sh handles the sanitizer/libFuzzer build; this Makefile +# only produces a plain binary suitable for gdb/valgrind on a single +# reproducer input. + +CHECKPOLICY := .. +LIBSEPOLA ?= ../../libsepol/src/libsepol.a +CFLAGS ?= -g -O0 -Wall +override CFLAGS += -I$(CHECKPOLICY) -I../../libsepol/include -D_GNU_SOURCE \ + -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DDEFINEMAIN -DVERBOSE=1 + +# Parser objects - same set as $(CHECKOBJS) in ../Makefile, built +# locally with the fuzzing defines so module_compiler_reset() and the +# lexer's non-exit error paths are compiled in. +CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \ + policy_define.o + +vpath %.c $(CHECKPOLICY) + +all: checkpolicy-fuzzer + +checkpolicy-fuzzer: checkpolicy-fuzzer.o $(CHECKOBJS) $(LIBSEPOLA) + $(CC) $(LDFLAGS) -o $@ $^ + +# Ensure the generated parser/lexer sources exist in the parent dir. +$(CHECKPOLICY)/y.tab.c $(CHECKPOLICY)/y.tab.h $(CHECKPOLICY)/lex.yy.c: + $(MAKE) -C $(CHECKPOLICY) $(@F) + +y.tab.o: $(CHECKPOLICY)/y.tab.c $(CHECKPOLICY)/y.tab.h + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +lex.yy.o: $(CHECKPOLICY)/lex.yy.c $(CHECKPOLICY)/y.tab.h + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +clean: + rm -f checkpolicy-fuzzer *.o + +.PHONY: all clean diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/fuzz/checkpolicy-fuzzer.c new/checkpolicy-3.12/fuzz/checkpolicy-fuzzer.c --- old/checkpolicy-3.11/fuzz/checkpolicy-fuzzer.c 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/fuzz/checkpolicy-fuzzer.c 2026-12-02 18:39:01.000000000 +0100 @@ -33,7 +33,9 @@ jmp_buf fuzzing_pre_parse_stack_state; // Set to 1 for verbose libsepol logging +#ifndef VERBOSE #define VERBOSE 0 +#endif static ssize_t full_write(int fd, const void *buf, size_t count) { @@ -106,8 +108,6 @@ } rc = yyparse(); - // TODO: drop global variable policydb_errors if proven to be redundant - assert(rc || !policydb_errors); if (rc || policydb_errors) { queue_destroy(id_queue); fclose(yyin); @@ -120,7 +120,6 @@ yyrestart(yyin); rc = yyparse(); - assert(rc || !policydb_errors); if (rc || policydb_errors) { queue_destroy(id_queue); fclose(yyin); @@ -159,16 +158,22 @@ /* * Take the first byte whether to generate a SELinux or Xen policy, * the second byte whether to parse as MLS policy, - * and the second byte as policy version. + * and the third byte as policy version. */ if (size < 3) return 0; switch (data[0]) { case 'S': platform = SEPOL_TARGET_SELINUX; +#if VERBOSE + printf("target: SELinux\n"); +#endif break; case 'X': platform = SEPOL_TARGET_XEN; +#if VERBOSE + printf("target: Xen\n"); +#endif break; default: return 0; @@ -176,9 +181,15 @@ switch (data[1]) { case '0': mls = 0; +#if VERBOSE + printf("MLS-disabled\n"); +#endif break; case '1': mls = 1; +#if VERBOSE + printf("MLS-enabled\n"); +#endif break; default: return 0; @@ -186,9 +197,17 @@ static_assert(0x7F - 'A' >= POLICYDB_VERSION_MAX, "Max policy version should be representable"); policyvers = data[2] - 'A'; - if (policyvers < POLICYDB_VERSION_MIN || - policyvers > POLICYDB_VERSION_MAX) + if (platform == SEPOL_TARGET_SELINUX && + (policyvers < POLICYDB_VERSION_MIN || + policyvers > POLICYDB_VERSION_MAX)) return 0; + if (platform == SEPOL_TARGET_XEN && + (policyvers < POLICYDB_XEN_VERSION_MIN || + policyvers > POLICYDB_XEN_VERSION_MAX)) + return 0; +#if VERBOSE + printf("policyvers=%d\n", policyvers); +#endif data += 3; size -= 3; @@ -285,3 +304,39 @@ /* Non-zero return values are reserved for future use. */ return 0; } + +#ifdef DEFINEMAIN +#include <sys/stat.h> + +int main(int argc, char **argv) +{ + if (argc < 2) { + fprintf(stderr, "usage: %s fuzzer-input-file\n", argv[0]); + exit(1); + } + + FILE *fp = fopen(argv[1], "rb"); + if (!fp) { + perror(argv[1]); + exit(1); + } + + struct stat sb; + int rc; + + rc = fstat(fileno(fp), &sb); + if (rc < 0) { + perror("fstat"); + exit(1); + } + + void *address = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fileno(fp), 0); + if (address == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + return LLVMFuzzerTestOneInput(address, sb.st_size); +} +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/module_compiler.c new/checkpolicy-3.12/module_compiler.c --- old/checkpolicy-3.11/module_compiler.c 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/module_compiler.c 2026-12-02 18:39:01.000000000 +0100 @@ -636,7 +636,8 @@ } else { free(id); - if (dest_typdatum->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE) { + if (dest_typdatum->flavor != + (isattr ? TYPE_ATTRIB : TYPE_TYPE)) { return NULL; } } @@ -685,7 +686,8 @@ } } else { free(id); - if (dest_roledatum->flavor != isattr ? ROLE_ATTRIB : ROLE_ROLE) + if (dest_roledatum->flavor != + (isattr ? ROLE_ATTRIB : ROLE_ROLE)) return NULL; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/policy_define.c new/checkpolicy-3.12/policy_define.c --- old/checkpolicy-3.11/policy_define.c 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/policy_define.c 2026-12-02 18:39:01.000000000 +0100 @@ -54,6 +54,7 @@ #include <sepol/policydb/conditional.h> #include <sepol/policydb/hierarchy.h> #include <sepol/policydb/polcaps.h> +#include <sepol/policydb/dtpath.h> #include "queue.h" #include "module_compiler.h" #include "policy_define.h" @@ -1318,6 +1319,11 @@ free(id); return -1; } + if (strcmp(id, "self") == 0) { + yyerror("\"self\" is a reserved type name."); + free(id); + return -1; + } aliasdatum = calloc(1, sizeof(type_datum_t)); if (!aliasdatum) { free(id); @@ -3787,6 +3793,11 @@ free(id); goto bad; } + /* a class listed twice gets a single constraint */ + if (ebitmap_get_bit(&classmap, cladatum->s.value - 1)) { + free(id); + continue; + } if (ebitmap_set_bit(&classmap, cladatum->s.value - 1, TRUE)) { yyerror("out of memory"); free(id); @@ -3947,6 +3958,11 @@ free(id); goto bad; } + /* a class listed twice gets a single validatetrans rule */ + if (ebitmap_get_bit(&classmap, cladatum->s.value - 1)) { + free(id); + continue; + } if (ebitmap_set_bit(&classmap, (cladatum->s.value - 1), TRUE)) { yyerror("out of memory"); free(id); @@ -4055,6 +4071,12 @@ e1->next = expr; return arg1; case CEXPR_ATTR: + if (!mlspol && (arg1 >= CEXPR_L1L2)) { + yyerror("MLS constraint expression " + "in non-MLS configuration"); + constraint_expr_destroy(expr); + return 0; + } expr->attr = arg1; expr->op = arg2; return (uintptr_t)expr; @@ -4916,6 +4938,11 @@ return 0; } + if (pirq > 0xffff) { + yyerror2("pirq %u out of range", pirq); + return -1; + } + newc = calloc(1, sizeof(ocontext_t)); if (!newc) { yyerror("out of memory"); @@ -5130,6 +5157,7 @@ int define_devicetree_context(void) { ocontext_t *newc, *c, *l, *head; + char *path; if (policydbp->target_platform != SEPOL_TARGET_XEN) { yyerror("devicetreecon not supported for target"); @@ -5142,17 +5170,26 @@ return 0; } + path = (char *)queue_remove(id_queue); + if (!path) { + yyerror("Missing devicetreepath"); + return -1; + } + + if (!is_valid_dt_path(path)) { + yyerror2("invalid devicetreecon path \"%s\"", path); + free(path); + return -1; + } + newc = calloc(1, sizeof(ocontext_t)); if (!newc) { yyerror("out of memory"); + free(path); return -1; } - newc->u.name = (char *)queue_remove(id_queue); - if (!newc->u.name) { - free(newc); - return -1; - } + newc->u.name = path; if (parse_security_context(&newc->context[0])) { free(newc->u.name); @@ -5224,15 +5261,15 @@ goto bad; } + if (low == 0 || low > high || high > 0xffff) { + yyerror2("Invalid port range %u-%u", low, high); + goto bad; + } + newc->u.port.protocol = protocol; newc->u.port.low_port = low; newc->u.port.high_port = high; - if (low > high) { - yyerror2("low port %d exceeds high port %d", low, high); - goto bad; - } - if (parse_security_context(&newc->context[0])) { goto bad; } @@ -5541,7 +5578,8 @@ return -1; } - if (newc->u.node.mask > c->u.node.mask) + /* The addresses and masks are stored in network byte order. */ + if (be32toh(newc->u.node.mask) > be32toh(c->u.node.mask)) break; } @@ -6054,6 +6092,8 @@ return -1; } newgenfs->fstype = fstype; + /* ownership transferred into the genfs list; do not free on error */ + fstype = NULL; newgenfs->next = genfs; if (genfs_p) genfs_p->next = newgenfs; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/bad_module_line.te new/checkpolicy-3.12/tests/negative/bad_module_line.te --- old/checkpolicy-3.11/tests/negative/bad_module_line.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/bad_module_line.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,5 @@ +module bad module name 1.0 garbage; + +require { + type foo_t; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/bad_require.te new/checkpolicy-3.12/tests/negative/bad_require.te --- old/checkpolicy-3.11/tests/negative/bad_require.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/bad_require.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,5 @@ +module bad_require 1.0; + +require { + garbage_token foo_t; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/bad_role.te new/checkpolicy-3.12/tests/negative/bad_role.te --- old/checkpolicy-3.11/tests/negative/bad_role.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/bad_role.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,13 @@ +module bad_role 1.0; + +require { + type foo_t; + class file { read }; +} + +# Empty type list after "types" (fails at ';'). +role bad_role_r types ; + +type foo_t; + +allow foo_t foo_t:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/bad_syntax.te new/checkpolicy-3.12/tests/negative/bad_syntax.te --- old/checkpolicy-3.11/tests/negative/bad_syntax.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/bad_syntax.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,8 @@ +module bad_syntax 1.0; + +require { + type foo_t; + class file { read }; +} + +allow foo_t foo_t:file { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/bad_user.te new/checkpolicy-3.12/tests/negative/bad_user.te --- old/checkpolicy-3.11/tests/negative/bad_user.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/bad_user.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,15 @@ +module bad_user 1.0; + +# Modular .te needs require before decls like user/role; without it +# checkmodule fails at "user" instead of the garbage_token below. +require { + type foo_t; + class file { read }; +} + +# Junk where "roles { ... }" should be. +user bad_user_u garbage_token; + +type foo_t; + +allow foo_t foo_t:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/dup_attribute.te new/checkpolicy-3.12/tests/negative/dup_attribute.te --- old/checkpolicy-3.11/tests/negative/dup_attribute.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/dup_attribute.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,13 @@ +module dup_attribute 1.0; + +require { + type foo_t; + class file { read }; +} + +attribute bar_attr; +attribute bar_attr; + +type foo_t; + +allow foo_t foo_t:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/dup_module.te new/checkpolicy-3.12/tests/negative/dup_module.te --- old/checkpolicy-3.11/tests/negative/dup_module.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/dup_module.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,6 @@ +module dup_module 1.0; +module dup_module 1.0; + +require { + type foo_t; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/dup_type.te new/checkpolicy-3.12/tests/negative/dup_type.te --- old/checkpolicy-3.11/tests/negative/dup_type.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/dup_type.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,11 @@ +module dup_type 1.0; + +require { + type foo_t; + class file { read }; +} + +type foo_t; +type foo_t; + +allow foo_t foo_t:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/good_module.te new/checkpolicy-3.12/tests/negative/good_module.te --- old/checkpolicy-3.11/tests/negative/good_module.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/good_module.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,8 @@ +module good_module 1.0; + +require { + type foo_t, bar_t; + class file { read write }; +} + +allow foo_t bar_t:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/invalid_module_version.te new/checkpolicy-3.12/tests/negative/invalid_module_version.te --- old/checkpolicy-3.11/tests/negative/invalid_module_version.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/invalid_module_version.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,5 @@ +module invalid_module_version; + +require { + type foo_t; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/invalid_type_name.te new/checkpolicy-3.12/tests/negative/invalid_type_name.te --- old/checkpolicy-3.11/tests/negative/invalid_type_name.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/invalid_type_name.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,9 @@ +module invalid_type_name 1.0; + +require { + class file { read }; +} + +type 1bad; + +allow 1bad 1bad:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/self_type_alias.te new/checkpolicy-3.12/tests/negative/self_type_alias.te --- old/checkpolicy-3.11/tests/negative/self_type_alias.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/self_type_alias.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,9 @@ +module self_type_alias 1.0; + +require { + class file { read }; +} + +type foo_t alias self; + +allow foo_t self:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/self_typealias.te new/checkpolicy-3.12/tests/negative/self_typealias.te --- old/checkpolicy-3.11/tests/negative/self_typealias.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/self_typealias.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,10 @@ +module self_typealias 1.0; + +require { + class file { read }; +} + +type foo_t; +typealias foo_t alias self; + +allow foo_t self:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/type_attr_conflict.te new/checkpolicy-3.12/tests/negative/type_attr_conflict.te --- old/checkpolicy-3.11/tests/negative/type_attr_conflict.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/type_attr_conflict.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,10 @@ +module type_attr_conflict 1.0; + +require { + class file { read }; +} + +type shared_id; +attribute shared_id; + +allow shared_id shared_id:file read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/unknown_class.te new/checkpolicy-3.12/tests/negative/unknown_class.te --- old/checkpolicy-3.11/tests/negative/unknown_class.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/unknown_class.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,7 @@ +module unknown_class 1.0; + +require { + type foo_t; +} + +allow foo_t self:not_a_class read; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/unknown_perm.te new/checkpolicy-3.12/tests/negative/unknown_perm.te --- old/checkpolicy-3.11/tests/negative/unknown_perm.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/unknown_perm.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,8 @@ +module unknown_perm 1.0; + +require { + type foo_t, bar_t; + class file { read }; +} + +allow foo_t bar_t:file circular_ref; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/negative/unknown_type.te new/checkpolicy-3.12/tests/negative/unknown_type.te --- old/checkpolicy-3.11/tests/negative/unknown_type.te 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/negative/unknown_type.te 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,8 @@ +module unknown_type 1.0; + +require { + type foo_t; + class file { read }; +} + +allow foo_t undeclared_t:file read; Binary files old/checkpolicy-3.11/tests/policy_allonce_xen.30.bin and new/checkpolicy-3.12/tests/policy_allonce_xen.30.bin differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/policy_dupclass.conf new/checkpolicy-3.12/tests/policy_dupclass.conf --- old/checkpolicy-3.11/tests/policy_dupclass.conf 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/policy_dupclass.conf 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,14 @@ +# handle_unknown deny +class CLASS1 +class CLASS2 +sid kernel +class CLASS1 { PERM1 } +class CLASS2 { PERM1 } +type TYPE1; +allow TYPE1 self:CLASS1 { PERM1 }; +role ROLE1; +role ROLE1 types { TYPE1 }; +user USER1 roles ROLE1; +constrain { CLASS1 CLASS2 CLASS1 } { PERM1 } u1 == u2; +validatetrans { CLASS2 CLASS1 CLASS2 } r1 == r2; +sid kernel USER1:ROLE1:TYPE1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/policy_dupclass.expected.conf new/checkpolicy-3.12/tests/policy_dupclass.expected.conf --- old/checkpolicy-3.11/tests/policy_dupclass.expected.conf 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/policy_dupclass.expected.conf 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,16 @@ +# handle_unknown deny +class CLASS1 +class CLASS2 +sid kernel +class CLASS1 { PERM1 } +class CLASS2 { PERM1 } +type TYPE1; +allow TYPE1 self:CLASS1 { PERM1 }; +role ROLE1; +role ROLE1 types { TYPE1 }; +user USER1 roles ROLE1; +constrain CLASS1 { PERM1 } u1 == u2; +constrain CLASS2 { PERM1 } u1 == u2; +validatetrans CLASS1 r1 == r2; +validatetrans CLASS2 r1 == r2; +sid kernel USER1:ROLE1:TYPE1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/test_checkmodule_negative.sh new/checkpolicy-3.12/tests/test_checkmodule_negative.sh --- old/checkpolicy-3.11/tests/test_checkmodule_negative.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/test_checkmodule_negative.sh 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,365 @@ +#!/bin/sh +# +# Negative / bad-data tests for checkmodule on module (.te) inputs. +# Matches the modular policy compile path: checkmodule -M -m <input> -o <module>.mod +# +# Size / resource robustness: generated fixtures; scale via LARGE_TE_ALLOWS, +# LARGE_CONF_ALLOWS, HUGE_ATTR_TYPES, or BAD_DATA_STRESS=1 for heavier runs. +# + +set -eu + +# Prefer an absolute script dir, but keep a relative dirname when cd fails. +# Non-root CI inherits the repo as CWD; absolute cd under /home/runner/work +# can fail for bad-data-test even when relative paths work. +BASEDIR=$(dirname -- "$0") +ABS_BASEDIR=$(CDPATH= cd -- "${BASEDIR}" 2>/dev/null && pwd) || ABS_BASEDIR= +if [ -n "${ABS_BASEDIR}" ]; then + BASEDIR="${ABS_BASEDIR}" +fi +NEGDIR="${BASEDIR}/negative" +if [ ! -d "${NEGDIR}" ]; then + echo "FAIL: cannot resolve negative fixtures (\$0=$0 BASEDIR=${BASEDIR})" >&2 + exit 1 +fi +CHECKMODULE="${BASEDIR}/../checkmodule" +CHECKPOLICY="${BASEDIR}/../checkpolicy" +OUTDIR=$(mktemp -d "${TMPDIR:-/tmp}/checkmodule-negative.XXXXXX") +PASS=0 +FAIL=0 + +LARGE_TE_ALLOWS="${LARGE_TE_ALLOWS:-5000}" +LARGE_CONF_ALLOWS="${LARGE_CONF_ALLOWS:-5000}" +HUGE_ATTR_TYPES="${HUGE_ATTR_TYPES:-2000}" + +if [ "${BAD_DATA_STRESS:-0}" = "1" ]; then + LARGE_TE_ALLOWS=10000 + LARGE_CONF_ALLOWS=10000 + HUGE_ATTR_TYPES=5000 +fi + +cleanup() { + rm -rf "${OUTDIR}" +} +trap cleanup EXIT + +mod_name_from_fixture() { + basename "$1" .te +} + +expect_pass() { + desc="$1" + fixture="$2" + modname=$(mod_name_from_fixture "${fixture}") + outmod="${OUTDIR}/${modname}.mod" + stderr="${OUTDIR}/${modname}.err" + + echo "==== POSITIVE (expect checkmodule success): ${desc}" + rm -f "${outmod}" + + set +e + "${CHECKMODULE}" -M -m -o "${outmod}" "${NEGDIR}/${fixture}" 2>"${stderr}" + rc=$? + set -e + + if [ "${rc}" -ne 0 ]; then + echo "FAIL: expected success (rc=0), got rc=${rc}" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if [ ! -s "${outmod}" ]; then + echo "FAIL: expected non-empty ${outmod}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + + echo "==== ${desc} success" + PASS=$((PASS + 1)) + echo "" +} + +expect_fail() { + desc="$1" + pattern="$2" + outname="${3:-fail}" + shift 3 + + outmod="${OUTDIR}/${outname}.mod" + stderr="${OUTDIR}/${outname}.err" + + echo "==== NEGATIVE (expect checkmodule error): ${desc}" + rm -f "${outmod}" + + set +e + "${CHECKMODULE}" -M -m "$@" -o "${outmod}" 2>"${stderr}" + rc=$? + set -e + + if [ "${rc}" -eq 0 ]; then + echo "FAIL: expected non-zero exit, got rc=0" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if [ -f "${outmod}" ]; then + echo "FAIL: did not expect output module ${outmod}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if ! grep -Eq "${pattern}" "${stderr}"; then + echo "FAIL: stderr did not match /${pattern}/" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + + echo "==== ${desc}: rejected as expected" + PASS=$((PASS + 1)) + echo "" +} + +expect_fail_unreadable() { + desc="unreadable .te file" + fixture="${OUTDIR}/unreadable.te" + outmod="${OUTDIR}/unreadable.mod" + stderr="${OUTDIR}/unreadable.err" + + echo "==== NEGATIVE (expect checkmodule error): ${desc}" + if [ "$(id -u)" -eq 0 ]; then + echo "SKIP: root can read mode 000 files; unreadable check is non-root only" + PASS=$((PASS + 1)) + echo "" + return 0 + fi + + rm -f "${outmod}" + + set +e + "${CHECKMODULE}" -M -m -o "${outmod}" "${fixture}" 2>"${stderr}" + rc=$? + set -e + + if [ "${rc}" -eq 0 ]; then + echo "FAIL: expected non-zero exit, got rc=0" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if [ -f "${outmod}" ]; then + echo "FAIL: did not expect output module ${outmod}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if ! grep -Eq 'unable to open|Permission denied' "${stderr}"; then + echo "FAIL: stderr did not mention unable to open or Permission denied" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + + echo "==== ${desc}: rejected as expected" + PASS=$((PASS + 1)) + echo "" +} + +robust_exit_is_crash() { + rc="$1" + + # Fatal signals (128+N): ILL(132), ABRT(134), BUS(135), FPE(136), + # KILL(137, includes OOM-kill), SEGV(139). + case "${rc}" in + 132|134|135|136|137|139) + return 0 + ;; + esac + return 1 +} + +expect_robust() { + desc="$1" + timeout_sec="$2" + outartifact="$3" + shift 3 + + tag=$(echo "${desc}" | tr ' /.' '___') + stderr="${OUTDIR}/${tag}.err" + + echo "==== ROBUST (expect no crash/hang): ${desc}" + rm -f "${outartifact}" + + if ! command -v timeout >/dev/null 2>&1; then + echo "FAIL: timeout(1) required for robustness tests" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + + set +e + timeout "${timeout_sec}" "$@" 2>"${stderr}" + rc=$? + set -e + + if [ "${rc}" -eq 124 ]; then + echo "FAIL: timed out after ${timeout_sec}s" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if robust_exit_is_crash "${rc}"; then + echo "FAIL: crashed with rc=${rc}" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + if [ "${rc}" -eq 0 ]; then + if [ ! -s "${outartifact}" ]; then + echo "FAIL: expected non-empty ${outartifact} on success" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + echo "==== ${desc}: finished (rc=0, output produced)" + else + if [ -f "${outartifact}" ]; then + echo "FAIL: did not expect output ${outartifact} on rc=${rc}" >&2 + cat "${stderr}" >&2 + FAIL=$((FAIL + 1)) + return 0 + fi + echo "==== ${desc}: finished safely (rc=${rc}, no output)" + fi + PASS=$((PASS + 1)) + echo "" +} + +generate_large_module_te() { + outte="$1" + count="$2" + + { + echo 'module large_module 1.0;' + echo 'require {' + echo ' type a_t, b_t;' + echo ' class file { read };' + echo '}' + i=0 + while [ "${i}" -lt "${count}" ]; do + echo 'allow a_t b_t:file read;' + i=$((i + 1)) + done + } > "${outte}" +} + +generate_large_conf() { + outconf="$1" + count="$2" + + { + echo '# handle_unknown deny' + echo 'class CLASS1' + echo 'sid kernel' + echo 'class CLASS1 { PERM1 }' + echo 'type TYPE1;' + echo 'type TYPE2;' + i=0 + while [ "${i}" -lt "${count}" ]; do + echo 'allow TYPE1 TYPE2:CLASS1 { PERM1 };' + i=$((i + 1)) + done + echo 'role ROLE1;' + echo 'role ROLE1 types { TYPE1 };' + echo 'user USER1 roles { ROLE1 };' + echo 'sid kernel USER1:ROLE1:TYPE1' + } > "${outconf}" +} + +generate_huge_attr_te() { + outte="$1" + count="$2" + + { + echo 'module huge_attr 1.0;' + echo 'require {' + echo ' class file { read };' + i=0 + while [ "${i}" -lt "${count}" ]; do + echo " type a${i}_t;" + i=$((i + 1)) + done + echo '}' + echo 'attribute big_attr;' + i=0 + while [ "${i}" -lt "${count}" ]; do + echo "typeattribute a${i}_t big_attr;" + i=$((i + 1)) + done + echo 'allow a0_t a1_t:file read;' + } > "${outte}" +} + +# Ephemeral fixtures for path-based cases. +ln -sf /nonexistent/path "${OUTDIR}/broken_symlink.te" +cat > "${OUTDIR}/unreadable.te" <<'EOF' +module unreadable 1.0; + +require { + type foo_t; +} +EOF +chmod 000 "${OUTDIR}/unreadable.te" + +# Control fixture: valid module compiles and produces .mod output. +expect_pass "good_module.te" "good_module.te" + +# Corrupted .te content. +expect_fail "bad_syntax.te" "syntax error" "bad_syntax" "${NEGDIR}/bad_syntax.te" +expect_fail "unknown_perm.te" "permission circular_ref is not defined" "unknown_perm" "${NEGDIR}/unknown_perm.te" +expect_fail "unknown_type.te" "unknown type undeclared_t" "unknown_type" "${NEGDIR}/unknown_type.te" +expect_fail "unknown_class.te" "unknown class not_a_class" "unknown_class" "${NEGDIR}/unknown_class.te" +expect_fail "bad_module_line.te" "syntax error" "bad_module_line" "${NEGDIR}/bad_module_line.te" +expect_fail "bad_require.te" "syntax error" "bad_require" "${NEGDIR}/bad_require.te" +expect_fail "invalid_module_version.te" "syntax error" "invalid_module_version" "${NEGDIR}/invalid_module_version.te" +expect_fail "dup_module.te" "syntax error" "dup_module" "${NEGDIR}/dup_module.te" +expect_fail "dup_type.te" "Duplicate declaration of type" "dup_type" "${NEGDIR}/dup_type.te" +expect_fail "dup_attribute.te" "Duplicate declaration of type" "dup_attribute" \ + "${NEGDIR}/dup_attribute.te" +expect_fail "type_attr_conflict.te" "Duplicate declaration of type" "type_attr_conflict" \ + "${NEGDIR}/type_attr_conflict.te" +expect_fail "invalid_type_name.te" "syntax error" "invalid_type_name" \ + "${NEGDIR}/invalid_type_name.te" +expect_fail "self_typealias.te" "\"self\" is a reserved type name" "self_typealias" \ + "${NEGDIR}/self_typealias.te" +expect_fail "self_type_alias.te" "\"self\" is a reserved type name" "self_type_alias" \ + "${NEGDIR}/self_type_alias.te" +expect_fail "bad_role.te" "syntax error" "bad_role" "${NEGDIR}/bad_role.te" +expect_fail "bad_user.te" "garbage_token" "bad_user" "${NEGDIR}/bad_user.te" + +# Missing / bad-path .te inputs. +expect_fail "missing .te path" "unable to open" "missing_path" "${OUTDIR}/does_not_exist.te" +expect_fail "directory instead of .te file" "input in flex scanner failed" "directory_input" "${NEGDIR}" +expect_fail "broken symlink to .te" "unable to open" "broken_symlink" "${OUTDIR}/broken_symlink.te" +expect_fail_unreadable +expect_fail "empty .te path argument" "unable to open" "empty_path" "" + +# CLI edge cases. +expect_fail "checkmodule with no input file" "unable to open policy.conf" "no_input" +expect_fail "checkmodule -o name mismatch" "Module name good_module is different" "name_mismatch" \ + -o "${OUTDIR}/wrong_name.mod" "${NEGDIR}/good_module.te" + +# Size / resource robustness (generated fixtures). +generate_large_module_te "${OUTDIR}/large_module.te" "${LARGE_TE_ALLOWS}" +expect_robust "very large .te module (${LARGE_TE_ALLOWS} allow rules)" 120 \ + "${OUTDIR}/large_module.mod" \ + "${CHECKMODULE}" -M -m -o "${OUTDIR}/large_module.mod" "${OUTDIR}/large_module.te" + +generate_large_conf "${OUTDIR}/large.conf" "${LARGE_CONF_ALLOWS}" +expect_robust "very large .conf policy (${LARGE_CONF_ALLOWS} allow rules)" 120 \ + "${OUTDIR}/large.bin" \ + "${CHECKPOLICY}" -E -o "${OUTDIR}/large.bin" "${OUTDIR}/large.conf" + +generate_huge_attr_te "${OUTDIR}/huge_attr.te" "${HUGE_ATTR_TYPES}" +expect_robust "huge attribute set (${HUGE_ATTR_TYPES} types)" 120 \ + "${OUTDIR}/huge_attr.mod" \ + "${CHECKMODULE}" -M -m -o "${OUTDIR}/huge_attr.mod" "${OUTDIR}/huge_attr.te" + +echo "checkmodule negative tests: ${PASS} passed, ${FAIL} failed" +if [ "${FAIL}" -ne 0 ]; then + exit 1 +fi diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/test_conditional_count.sh new/checkpolicy-3.12/tests/test_conditional_count.sh --- old/checkpolicy-3.11/tests/test_conditional_count.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/test_conditional_count.sh 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu + +BASEDIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +CHECKPOLICY=${CHECKPOLICY:-"${BASEDIR}/../checkpolicy"} +OUTDIR=$(mktemp -d "${TMPDIR:-/tmp}/conditional-count.XXXXXX") +trap 'rm -rf "$OUTDIR"' EXIT HUP INT TERM + +for count in 1 4 5 6 8; do + { + printf '%s\n' 'class file' 'sid kernel' 'class file { read write }' + i=1 + expr=b1 + while [ "$i" -le "$count" ]; do + printf 'bool b%s false;\n' "$i" + if [ "$i" -gt 1 ]; then + expr="($expr || b$i)" + fi + i=$((i + 1)) + done + printf '%s\n' 'type test_t;' 'allow test_t self:file read;' + printf 'if (%s) { allow test_t self:file write; }\n' "$expr" + printf '%s\n' 'role test_r;' 'role test_r types test_t;' \ + 'user system_u roles test_r;' 'sid kernel system_u:test_r:test_t' + } > "$OUTDIR/policy.conf" + for optimize in '' '-O'; do + # The optional flag is deliberately unquoted when empty. + "$CHECKPOLICY" $optimize -o "$OUTDIR/policy.bin" "$OUTDIR/policy.conf" + "$CHECKPOLICY" -b -F -o "$OUTDIR/roundtrip.conf" "$OUTDIR/policy.bin" + "$CHECKPOLICY" $optimize -o "$OUTDIR/roundtrip.bin" "$OUTDIR/roundtrip.conf" + cmp "$OUTDIR/policy.bin" "$OUTDIR/roundtrip.bin" + done +done +printf '%s\n' 'conditional count: 10 compiler round trips passed' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/test_multiple_decls.sh new/checkpolicy-3.12/tests/test_multiple_decls.sh --- old/checkpolicy-3.11/tests/test_multiple_decls.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/test_multiple_decls.sh 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,83 @@ +#!/bin/sh +set -eu + +CHECKPOLICY=${CHECKPOLICY:-./checkpolicy} +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT HUP INT TERM + +cat > "$tmp/prefix" <<'EOF' +class file +sid kernel +class file { read write } +attribute excluded; +attribute domain; +type source_t, domain; +type excluded_t, excluded, domain; +type ordinary_t, domain; +typealias source_t alias source_alias_t; +EOF +cat > "$tmp/suffix" <<'EOF' +user user_u roles role_r; +sid kernel user_u:role_r:source_t +EOF + +count=0 +for side in source target positive; do + case $side in + source) rule='allow { domain -excluded } ordinary_t:file write;' ;; + target) rule='allow source_t { domain -excluded }:file write;' ;; + positive) rule='allow excluded self:file write;' ;; + esac + for variant in control enabled disabled last_enabled last_disabled repeated_type require_only optional_only; do + cat "$tmp/prefix" > "$tmp/input.conf" + printf '%s\n' "$rule" \ + 'allow source_alias_t self:file read;' \ + 'role role_r;' 'role role_r types domain;' >> "$tmp/input.conf" + enabled='optional { require { class file { read }; } attribute excluded; }' + disabled='optional { require { type missing_t; } attribute excluded; }' + case $variant in + control) ;; + enabled) printf '%s\n' "$enabled" >> "$tmp/input.conf" ;; + disabled) printf '%s\n' "$disabled" >> "$tmp/input.conf" ;; + last_enabled) printf '%s\n' "$disabled" "$enabled" >> "$tmp/input.conf" ;; + last_disabled) printf '%s\n' "$enabled" "$disabled" >> "$tmp/input.conf" ;; + repeated_type) + printf '%s\n' 'optional { require { type missing_t; } type excluded_t; }' >> "$tmp/input.conf" ;; + require_only) + printf '%s\n' 'optional { require { attribute excluded; } allow source_t self:file read; }' >> "$tmp/input.conf" ;; + optional_only) + printf '%s\n' \ + 'optional { require { type missing_t; } type absent_t; }' \ + 'optional { require { type absent_t; } allow ordinary_t self:file write; }' >> "$tmp/input.conf" ;; + esac + cat "$tmp/suffix" >> "$tmp/input.conf" + "$CHECKPOLICY" -m -o "$tmp/policy.bin" "$tmp/input.conf" + "$CHECKPOLICY" -b -F -o "$tmp/output.conf" "$tmp/policy.bin" + # Full binary round-trip equality covers types, aliases, role membership, + # and rules, including exclusions on either side of an allow rule. + if [ "$variant" = control ]; then + # System cp may link libselinux without the sanitizer runtime. + LD_LIBRARY_PATH= cp "$tmp/output.conf" "$tmp/expected.conf" + else + diff -u "$tmp/expected.conf" "$tmp/output.conf" + fi + count=$((count + 1)) + done +done + +for decl in \ + 'type excluded_t;' \ + 'typealias source_t alias source_alias_t;' \ + 'attribute source_t;' \ + 'type excluded;'; do + cat "$tmp/prefix" > "$tmp/input.conf" + printf '%s\n' "$decl" 'allow source_t self:file read;' \ + 'role role_r;' 'role role_r types domain;' >> "$tmp/input.conf" + cat "$tmp/suffix" >> "$tmp/input.conf" + if "$CHECKPOLICY" -o "$tmp/policy.bin" "$tmp/input.conf" 2> "$tmp/error"; then + echo 'unexpected duplicate declaration acceptance' >&2 + exit 1 + fi + count=$((count + 1)) +done +printf 'PASS %s multiple-declaration compiler cases\n' "$count" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/test_roundtrip.sh new/checkpolicy-3.12/tests/test_roundtrip.sh --- old/checkpolicy-3.11/tests/test_roundtrip.sh 2026-07-01 18:51:05.000000000 +0200 +++ new/checkpolicy-3.12/tests/test_roundtrip.sh 2026-12-02 18:39:01.000000000 +0100 @@ -31,6 +31,8 @@ check_policy policy_minimal_mls.conf policy_minimal_mls.conf '-M -E' check_policy policy_minimal_mls.conf policy_minimal_mls.conf '-M -E -S -O' +check_policy policy_dupclass.conf policy_dupclass.expected.conf '' + check_policy policy_allonce.conf policy_allonce.expected.conf '' check_policy policy_allonce.conf policy_allonce.expected_opt.conf '-S -O' @@ -39,3 +41,28 @@ check_policy policy_allonce_xen.conf policy_allonce_xen.expected.conf '--target xen -c 30 -E' check_policy policy_allonce_xen.conf policy_allonce_xen.expected_opt.conf '--target xen -c 30 -E -S -O' + +# Compare against a binary policy written by an earlier release, to catch +# changes to the binary format of an existing policy version, which a +# roundtrip through the same implementation cannot detect. +# policy_allonce_xen.30.bin was written by checkpolicy 3.11 via: +# checkpolicy --target xen -c 30 -E policy_allonce_xen.conf +check_reference() { + POLICY=$1 + REFERENCE=$2 + EXPECTED=$3 + OPTS=$4 + + echo "==== Testing ${2}" + + ${CHECKPOLICY} ${OPTS} -b -F "${BASEDIR}/${REFERENCE}" -o "${BASEDIR}/testpol.conf" + diff -u "${BASEDIR}/${EXPECTED}" "${BASEDIR}/testpol.conf" + + ${CHECKPOLICY} ${OPTS} "${BASEDIR}/${POLICY}" -o "${BASEDIR}/testpol.bin" + cmp "${BASEDIR}/${REFERENCE}" "${BASEDIR}/testpol.bin" + + echo "==== ${2} success" + echo "" +} + +check_reference policy_allonce_xen.conf policy_allonce_xen.30.bin policy_allonce_xen.expected.conf '--target xen -c 30 -E' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/checkpolicy-3.11/tests/test_type_enabled.c new/checkpolicy-3.12/tests/test_type_enabled.c --- old/checkpolicy-3.11/tests/test_type_enabled.c 1970-01-01 01:00:00.000000000 +0100 +++ new/checkpolicy-3.12/tests/test_type_enabled.c 2026-12-02 18:39:01.000000000 +0100 @@ -0,0 +1,72 @@ +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <sepol/policydb/avrule_block.h> +#include <sepol/policydb/policydb.h> + +int main(void) +{ + policydb_t p = { 0 }; + avrule_decl_t decls[3] = { 0 }; + avrule_decl_t *index[] = { &decls[0], &decls[1], &decls[2] }; + uint32_t ids[3]; + scope_datum_t scope = { .scope = SCOPE_DECL, + .decl_ids = ids, + .decl_ids_len = 3 }; + type_datum_t type = { .s.value = 1, .primary = 1 }; + char name[] = "test_type"; + const uint32_t orders[][3] = { { 1, 2, 3 }, { 1, 3, 2 }, { 2, 1, 3 }, + { 2, 3, 1 }, { 3, 1, 2 }, { 3, 2, 1 } }; + unsigned int cases = 0; + + assert(symtab_init(&p.scope[SYM_TYPES], 16) == 0); + assert(symtab_init(&p.p_types, 16) == 0); + assert(hashtab_insert(p.scope[SYM_TYPES].table, name, &scope) == 0); + assert(hashtab_insert(p.p_types.table, name, &type) == 0); + p.decl_val_to_struct = index; + /* Types, attributes, and aliases use the declared bitmap, not merely + * the presence of an enabled block in the mixed scope list. */ + for (unsigned int flavor = TYPE_TYPE; flavor <= TYPE_ALIAS; flavor++) { + type.flavor = flavor; + for (unsigned int enabled = 0; enabled < 8; enabled++) + for (unsigned int declared = 0; declared < 8; + declared++) { + for (unsigned int i = 0; i < 3; i++) { + decls[i].enabled = + !!(enabled & (1U << i)); + assert(ebitmap_set_bit( + &decls[i].declared + .scope[SYM_TYPES], + 0, + !!(declared & + (1U << i))) == 0); + } + for (unsigned int order = 0; order < 6; + order++) { + for (unsigned int i = 0; i < 3; i++) + ids[i] = orders[order][i]; + scope.scope = SCOPE_DECL; + assert(is_id_enabled(name, &p, + SYM_TYPES) == + !!(enabled & declared)); + scope.scope = SCOPE_REQ; + assert(is_id_enabled(name, &p, + SYM_TYPES) == 0); + cases += 2; + } + } + } + scope.scope = SCOPE_DECL; + for (unsigned int i = 0; i < 3; i++) + index[i] = NULL; + assert(is_id_enabled(name, &p, SYM_TYPES) == 0); + scope.decl_ids_len = 0; + assert(is_id_enabled(name, &p, SYM_TYPES) == 0); + assert(is_id_enabled("missing", &p, SYM_TYPES) == 0); + for (unsigned int i = 0; i < 3; i++) + ebitmap_destroy(&decls[i].declared.scope[SYM_TYPES]); + hashtab_destroy(p.scope[SYM_TYPES].table); + hashtab_destroy(p.p_types.table); + printf("PASS %u type enablement checks\n", cases + 3); + return 0; +} ++++++ checkpolicy.keyring ++++++ ++++ 626 lines (skipped) ++++ between checkpolicy.keyring ++++ and /work/SRC/openSUSE:Factory/.checkpolicy.new.1340718/checkpolicy.keyring
