Commit Graph

7 Commits

Author SHA1 Message Date
Christian Göttsche e7bbd67be6 checkpolicy/fuzz: fix setjmp condition
setjmp(3) returns 0 on the first fake invocation, adjust the condition
accordingly.

Reported by the OSS Fuzz Introspector[1].

[1]: https://storage.googleapis.com/oss-fuzz-introspector/selinux/inspector-report/20241016/fuzz_report.html

Fixes: f07fc2a75 ("checkpolicy/fuzz: override YY_FATAL_ERROR")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-10-30 08:04:38 -04:00
Christian Göttsche 82d99136cf checkpolicy: drop global policyvers variable
Drop the global variable policyvers.  The variable is only used within
checkpolicy.c and checkmodule.c, but never in any shared code.

Since the variable declaration is the only content of checkpolicy.h drop
it.

Also set the policy version before calls to read_source_policy(), so the
parser can access the requested version for checks this way.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-05-01 16:48:25 -04:00
Christian Göttsche f07fc2a752 checkpolicy/fuzz: override YY_FATAL_ERROR
The default action of the lexer macro YY_FATAL_ERROR(msg) is to print
the message and call exit().  This might happen on an overlong token
(8192 bytes) that does not fit into the token buffer.
Fuzz targets must not call exit() though, since an exit is treated as an
abnormal behavior, see https://llvm.org/docs/LibFuzzer.html#fuzz-target.

Since YY_FATAL_ERROR is used in functions with different return value
types and is expected to not return, jump to a location in the fuzzer
right before yyparse() instead.

Reported-by: oss-fuzz (issue 67728)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-04-04 11:17:44 -04:00
Christian Göttsche f3b67a84fa checkpolicy/fuzz: scan Xen policies
In addition to standard SELinux platform policies also check Xen ones.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-03-20 14:16:22 -04:00
Christian Göttsche b106fad29f checkpolicy/fuzz: drop redundant notdefined check
The level_datum_t member notdefined is checked to be 1 during validation
and the fuzzer calls policydb_validate().
Drop the redundant check (as announced in the TODO).

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-03-20 14:16:15 -04:00
James Carter 8c9d2d656b checkpolicy/fuzz: Update check_level() to use notdefined field
Commit fe16f586 (Fix potential double free of mls_level_t) renamed
the "defined" field to "notdefined", but did not update this use of
it.

Use the new field "notdefined" for the check.

Signed-off-by: James Carter <jwcart2@gmail.com>
2024-03-07 09:12:00 -05:00
Christian Göttsche 595c4163f0 checkpolicy: add libfuzz based fuzzer
Introduce a libfuzz[1] based fuzzer testing the parsing and policy
generation code used within checkpolicy(8) and checkmodule(8), similar
to the fuzzer for secilc(8).
The fuzzer will work on generated source policy input and try to parse,
link, expand, optimize, sort and output it.
This fuzzer will also ensure policy validation is not too strict by
checking compilable source policies are valid.

Build the fuzzer in the oss-fuzz script.

[1]: https://llvm.org/docs/LibFuzzer.html

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-03-04 09:54:47 -05:00