aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2019-11-22 23:27:47 -0500
committerTheodore Ts'o <tytso@mit.edu>2019-11-22 23:27:47 -0500
commitbb7a3dc25120d54b29f47972c8ff46d663a9c1ca (patch)
treec0ae62f7e323e329cfa4dc35f9eb49b593795d8a
parent612296d63ec81de5498e8a6d72b0a87f9ace616e (diff)
downloade2fsprogs-bb7a3dc25120d54b29f47972c8ff46d663a9c1ca.tar.gz
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 <tytso@mit.edu>
-rw-r--r--misc/Makefile.in22
-rw-r--r--misc/check_fuzzer.c61
2 files changed, 82 insertions, 1 deletions
diff --git a/misc/Makefile.in b/misc/Makefile.in
index f2554446b..9f2a8939d 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 000000000..cee21bfe6
--- /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 <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <ext2fs/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
+
+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 <device|filesystem>\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;
+}