From bb7a3dc25120d54b29f47972c8ff46d663a9c1ca Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 22 Nov 2019 23:27:47 -0500 Subject: [PATCH] Add a program to test images provided by UBSAN fuzzing reports This program calls a few ext2fs library functions used by the current generation of libext2fs fuzzers, and is helpful in reproducing UBSAN failures reported externally. Signed-off-by: Theodore Ts'o --- misc/Makefile.in | 22 ++++++++++++++++++- misc/check_fuzzer.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 misc/check_fuzzer.c diff --git a/misc/Makefile.in b/misc/Makefile.in index f255444..9f2a893 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -102,7 +102,8 @@ SRCS= $(srcdir)/tune2fs.c $(srcdir)/mklost+found.c $(srcdir)/mke2fs.c $(srcdir)/ $(srcdir)/filefrag.c $(srcdir)/base_device.c \ $(srcdir)/ismounted.c $(srcdir)/e2undo.c \ $(srcdir)/e2freefrag.c $(srcdir)/create_inode.c \ - $(srcdir)/fuse2fs.c \ + $(srcdir)/fuse2fs.c $(srcdir)/e2fuzz.c \ + $(srcdir)/check_fuzzer.c \ $(srcdir)/../debugfs/journal.c $(srcdir)/../e2fsck/revoke.c \ $(srcdir)/../e2fsck/recovery.c @@ -388,6 +389,10 @@ e2fuzz: $(E2FUZZ_OBJS) $(DEPLIBS) $(DEPLIBBLKID) $(DEPLIBUUID) \ $(Q) $(CC) $(ALL_LDFLAGS) -o e2fuzz $(E2FUZZ_OBJS) $(LIBS) \ $(LIBBLKID) $(LIBUUID) $(LIBEXT2FS) $(SYSLIBS) +check_fuzzer: check_fuzzer.o $(DEPLIBS) + $(E) " LD $@" + $(Q) $(CC) $(ALL_LDFLAGS) -o check_fuzzer check_fuzzer.o $(LIBS) + filefrag: $(FILEFRAG_OBJS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o filefrag $(FILEFRAG_OBJS) $(SYSLIBS) @@ -840,6 +845,19 @@ fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/version.h +e2fuzz.o: $(srcdir)/e2fuzz.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ + $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ + $(top_srcdir)/lib/ext2fs/bitops.h +check_fuzzer.o: $(srcdir)/check_fuzzer.c $(top_srcdir)/lib/ext2fs/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ + $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ + $(top_srcdir)/lib/ext2fs/bitops.h journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \ $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \ @@ -855,6 +873,7 @@ journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \ $(top_srcdir)/lib/ext2fs/kernel-list.h revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \ + $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \ $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ @@ -867,6 +886,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \ $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \ $(top_srcdir)/lib/ext2fs/kernel-list.h recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \ + $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \ $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ diff --git a/misc/check_fuzzer.c b/misc/check_fuzzer.c new file mode 100644 index 0000000..cee21bf --- /dev/null +++ b/misc/check_fuzzer.c @@ -0,0 +1,61 @@ +/* + * Play with a file system image quickly to find UBSAN problems + * + * Run a file system through some of the libext2fs functions used by + * some fuzzer reports. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +int main (int argc, char *argv[]) +{ + errcode_t retval = 0; + ext2_filsys fs; + int exit_status = 1; + + initialize_ext2_error_table(); + + if (argc != 2) { + fprintf(stderr, "%s: Usage \n", argv[0]); + exit(1); + } + + retval = ext2fs_open(argv[1], 0, 0, 0, + unix_io_manager, &fs); + if (retval) { + com_err(argv[0], retval, "while trying to open '%s'", + argv[1]); + exit(1); + } + + retval = ext2fs_read_inode_bitmap(fs); + if (retval) { + com_err(argv[0], retval, "while trying to read inode bitmaps"); + goto errout; + } + + retval = ext2fs_read_block_bitmap(fs); + if (retval) { + com_err(argv[0], retval, "while trying to read inode bitmaps"); + goto errout; + } + + retval = ext2fs_check_directory(fs, EXT2_ROOT_INO); + if (retval) { + com_err(argv[0], retval, "while trying to read inode bitmaps"); + goto errout; + } + exit_status = 0; +errout: + ext2fs_close(fs); + return exit_status; +} -- 1.8.3.1