FUZZING.md,{checkpolicy,libselinux}/fuzz: document selinux fuzzing
Stephen Smalley
maintainerPATCH v2 1/1 FUZZING.md,{checkpolicy,libselinux}/fuzz: document selinux fuzzing
Document the use of OSS-Fuzz and CIFuzz by the selinux userspace project and provide some instructions and scaffolding for debugging fuzzing failures.
Signed-off-by Stephen Smalley <[email protected]>
---
v2 renames FUZZ.md to FUZZING.md, folds the helpers for debugging into the existing fuzzers, and updates the Makefiles to enable building them more easily. NB Building the fuzzers this way does not build with sanitizers enabled or link in the fuzzing framework; it is for building them as standalone programs that can be run under a debugger or valgrind easily.
FUZZING.md | 79 +++++++++++++++++++ checkpolicy/.gitignore | 1 + checkpolicy/Makefile | 9 ++- checkpolicy/fuzz/checkpolicy-fuzzer.c | 53 +++++++++++++ libselinux/Makefile | 6 ++ .../fuzz/selabel_file_compiled-fuzzer.c | 41 ++++++++++ libselinux/fuzz/selabel_file_text-fuzzer.c | 75 ++++++++++++++++++ libselinux/src/.gitignore | 2 + libselinux/src/Makefile | 16 +++- 9 files changed, 280 insertions(+), 2 deletions(-) create mode 100644 FUZZING.md
FUZZING.md new file +79 -0
@@ -0,0 +1,79 @@ +Fuzzing of the SELinux userspace +================================ + +OSS-Fuzz +-------- + +Portions of the SELinux userspace are regularly fuzzed by OSS-Fuzz based +on the configuration at: +https://github.com/google/oss-fuzz/blob/master/projects/selinux/project.yaml + +The fuzzers can be found under the fuzz subdirectories of various +directories within the selinux repository, and can be built using the +./scripts/oss-fuzz.sh script. OSS-Fuzz itself uses this script to +build the fuzzers. + +See +https://issues.oss-fuzz.com/issues?q=project:selinux +for public OSS-Fuzz selinux issues. OSS-Fuzz automatically makes +issues public once they are verified to be fixed or after a 90 day +disclosure window. Issues are initially created private and +sent via email to those listed in the configuration above. + +Not all issues will be fixed by the upstream SELinux project, e.g. +small memory leaks on error paths for checkpolicy are not viewed as +worth fixing since checkpolicy will exit shortly thereafter, and OSS +Fuzz will create issues if it encounters a timeout during fuzzing even +though the fuzzer would have completed if given more time. + +Items categorized as a vulnerability by OSS-Fuzz will not always be +treated as security issues by the upstream SELinux project; in +particular, issues that depend on attacker-controlled policy are not +considered to be security issues and will just be handled as regular +bugs. See +[SECURITY.md](https://github.com/SELinuxProject/selinux/blob/main/SECURITY.md) +for more information on the SELinux userspace security vulnerability +handling process. + +CIFuzz +------ + +The selinux GitHub CI Actions include a CIFuzz workflow based on the +configuration at: +https://github.com/SELinuxProject/selinux/blob/main/.github/workflows/cifuzz.yml + +This action is invoked for pushes and pull requests targeting the main +branch of the SELinuxProject/selinux repository to help detect +regressions on new commits. + +The status of CIFuzz workflow runs can be viewed at: +https://github.com/SELinuxProject/selinux/actions/workflows/cifuzz.yml +as well as in the check status for each push or pull request and +displayed in the banner at the top of the +[README.md](https://github.com/SELinuxProject/selinux/blob/main/README.md) +file. + +Debugging Fuzzing Failures +-------------------------- + +OSS-Fuzz provides a detailed report and, when possible, a reproducer +testcase. If the cause cannot be determined from the report, the +reproducer testcase can be downloaded locally, the fuzzer can be built +using ./scripts/oss-fuzz.sh, and the fuzzer can be manually run on the +reproducer testcase input. + +The fuzzers are built without debugging information and with verbose +logging disabled when built using oss-fuzz.sh. You can recompile them +with debugging, logging, and trivial main() function as follows: + make -C checkpolicy checkpolicy-fuzzer + make -C libselinux selabel_file_text-fuzzer selabel_file_compiled-fuzzer + +In some cases, it may be helpful to run one of the selinux userspace +programs on the fuzzer input directly, potentially under gdb or +valgrind, to better understand the issue and whether it is applicable +to any production tool. This can be done when the fuzzer input is +accepted directly as input to one of the selinux userspace programs, +such as a CIL policy file to secilc or a binary policy file to +checkpolicy -b. In other cases you may need to split the fuzzer input +into its parts and only feed one portion to a program like checkpolicy +or selabel_lookup.
checkpolicy/.gitignore +1 -0
@@ -1,5 +1,6 @@ checkmodule checkpolicy +checkpolicy-fuzzer lex.yy.c y.tab.c y.tab.h
checkpolicy/Makefile +8 -1
@@ -58,6 +58,13 @@ test: checkpolicy checkmodule # helper target for fuzzing checkobjects: $(CHECKOBJS) +checkpolicy-fuzzer.o: fuzz/checkpolicy-fuzzer.c + $(CC) $(CPPFLAGS) $(CFLAGS) -g -I. -c -o $@ $^ + +checkpolicy-fuzzer: CFLAGS = -g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DDEBUG -D_GNU_SOURCE +checkpolicy-fuzzer: checkpolicy-fuzzer.o $(CHECKOBJS) $(LIBSEPOLA) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA) + install: all -mkdir -p $(DESTDIR)$(BINDIR) -mkdir -p $(DESTDIR)$(MANDIR)/man8
@@ -76,5 +83,5 @@ relabel: install /sbin/restorecon $(DESTDIR)$(BINDIR)/checkmodule clean: - -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin + -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) checkpolicy-fuzzer checkpolicy-fuzzer.o y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin $(MAKE) -C test clean
checkpolicy/fuzz/checkpolicy-fuzzer.c +53 -0
87 lines not on this page · raw message
libselinux/Makefile +6 -0
@@ -55,6 +55,12 @@ all install relabel clean distclean: (cd $$subdir && $(MAKE) $@) || exit 1; \ done +selabel_file_text-fuzzer: + $(MAKE) -C src $@ + +selabel_file_compiled-fuzzer: + $(MAKE) -C src $@ + swigify: all $(MAKE) -C src $@
libselinux/fuzz/selabel_file_compiled-fuzzer.c +41 -0
58 lines not on this page · raw message
libselinux/fuzz/selabel_file_text-fuzzer.c +75 -0
98 lines not on this page · raw message
libselinux/src/.gitignore +2 -0
@@ -3,3 +3,5 @@ selinuxswig_python_wrap.c selinuxswig_ruby_wrap.c selinux.egg-info/ dist/ +selabel_file_text-fuzzer +selabel_file_compiled-fuzzer
libselinux/src/Makefile +15 -1
@@ -181,6 +181,20 @@ selinuxswig_python_exception.i: exception.sh ../include/selinux/selinux.h %.lo: %.c policy.h $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -DSHARED -c -o $@ $< +selabel_file_text-fuzzer.o: ../fuzz/selabel_file_text-fuzzer.c + $(CC) $(CPPFLAGS) $(CFLAGS) -g -I. -c -o $@ $^ + +selabel_file_text-fuzzer: CFLAGS = -g -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND $(PCRE_CFLAGS) -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DDEBUG +selabel_file_text-fuzzer: selabel_file_text-fuzzer.o $(LIBA) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(PCRE_LDLIBS) + +selabel_file_compiled-fuzzer.o: ../fuzz/selabel_file_compiled-fuzzer.c + $(CC) $(CPPFLAGS) $(CFLAGS) -g -I. -c -o $@ $^ + +selabel_file_compiled-fuzzer: CFLAGS = -g -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND $(PCRE_CFLAGS) -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DDEBUG +selabel_file_compiled-fuzzer: selabel_file_text-fuzzer.o $(LIBA) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(PCRE_LDLIBS) + $(SWIGRUBYCOUT): $(SWIGRUBYIF) $(SWIGRUBY) $<
@@ -215,7 +229,7 @@ clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) selabel_file_text-fuzzer selabel_file_compiled-fuzzer *.o *.lo *~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)
Signature · 1 line
2.55.0