]> www.infradead.org Git - mtd-utils.git/commitdiff
ubifs-utils: Support Address-Sanitizier debug
authorZhihao Cheng <chengzhihao1@huawei.com>
Mon, 11 Nov 2024 09:08:30 +0000 (17:08 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 11 Nov 2024 09:32:46 +0000 (10:32 +0100)
Add new option '--asan' for configuration to support dynamic
Address-Sanitizier debugging, which could detect kinds of invalid
memory accessing problems(eg. UAF, r/w OOB, etc.). Currently, only
ubifs-utils(mkfs.ubifs/fsck.ubifs) is supported.
Enable Address-Sanitizier debugging with configuration:
  ./configure --enable-asan

Notice: The Address-Sanitizier will stop the program and print
problems if memory problems are detected. Sometimes the memory
problems come from third libs(not mtd-utils), which could stuck
the testcases.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
configure.ac
ubifs-utils/Makemodule.am

index 7b5d6096ecfadd73f4275d6eb02d6dfd46a7c4a8..b160c03715491adbdb3a7ba1ab5b140d37bab3a9 100644 (file)
@@ -105,6 +105,10 @@ AC_ARG_WITH([crypto],
        [AS_HELP_STRING([--with-crypto], [Support for UBIFS crypto features])],
        [], [with_crypto="check"])
 
+AC_ARG_ENABLE([asan],
+       [AS_HELP_STRING([--enable-asan], [Support AddressSanitizer debug])],
+       [], [enable_asan="no"])
+
 ##### search for dependencies #####
 
 need_clock_gettime="no"
@@ -146,6 +150,14 @@ AS_IF([test "x$with_zlib" != "xno"], [
                                       [with_zlib="no"])])
 ], [])
 
+AC_ARG_VAR([ASAN_LIBS], [linker flags for lasan])
+AS_IF([test "x$enable_asan" = "xyes"], [
+       AC_CHECK_LIB([asan], [_init], [
+               ASAN_LIBS="-lasan -fsanitize=address -fsanitize-recover=address -g"], [
+               AC_MSG_ERROR([cannot find libasan])
+       ])
+])
+
 if test "x$need_uuid" = "xyes"; then
        PKG_CHECK_MODULES(UUID, [uuid], [],
                          [PKG_CHECK_MODULES_STATIC(UUID, [uuid], [], [uuid_missing="yes"])])
@@ -275,6 +287,7 @@ AM_CONDITIONAL([WITH_XATTR], [test "x$with_xattr" = "xyes"])
 AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" = "xyes"])
 AM_CONDITIONAL([WITH_CRYPTO], [test "x$with_crypto" = "xyes"])
 AM_CONDITIONAL([WITH_UBIHEALTHD], [test "x$enable_ubihealthd" = "xyes"])
+AM_CONDITIONAL([WITH_ASAN], [test "x$enable_asan" = "xyes"])
 
 AM_CONDITIONAL([BUILD_UBIFS], [test "x$with_ubifs" = "xyes"])
 AM_CONDITIONAL([BUILD_JFFSX], [test "x$with_jffs" = "xyes"])
@@ -321,6 +334,7 @@ AC_MSG_RESULT([
        compiler:          ${CC}
        cflags:            ${CFLAGS}
        ldflags:           ${LDFLAGS}
+       asan debug:        ${enable_asan}
 
        lzo support:       ${with_lzo}
        zlib support:      ${with_zlib}
index a511c40d9e17e6fa87c3121f904aa31e458460fe..21ba0597d84a149fdc1a361e2bced5f6e4503551 100644 (file)
@@ -72,7 +72,7 @@ mkfs_ubifs_SOURCES = \
        ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
 
 mkfs_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(ZSTD_LIBS) $(UUID_LIBS) $(LIBSELINUX_LIBS) $(OPENSSL_LIBS) \
-                  $(DUMP_STACK_LD) -lm -lpthread
+                  $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread
 mkfs_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(ZSTD_CFLAGS) $(UUID_CFLAGS) $(LIBSELINUX_CFLAGS) \
        -I$(top_srcdir)/ubi-utils/include -I$(top_srcdir)/ubifs-utils/common -I $(top_srcdir)/ubifs-utils/libubifs
 
@@ -90,7 +90,7 @@ fsck_ubifs_SOURCES = \
        ubifs-utils/fsck.ubifs/handle_disconnected.c
 
 fsck_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(ZSTD_LIBS) $(UUID_LIBS) $(LIBSELINUX_LIBS) $(OPENSSL_LIBS) \
-                  $(DUMP_STACK_LD) -lm -lpthread
+                  $(DUMP_STACK_LD) $(ASAN_LIBS) -lm -lpthread
 fsck_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(ZSTD_CFLAGS) $(UUID_CFLAGS) $(LIBSELINUX_CFLAGS) \
        -I$(top_srcdir)/ubi-utils/include -I$(top_srcdir)/ubifs-utils/common -I $(top_srcdir)/ubifs-utils/libubifs \
        -I$(top_srcdir)/ubifs-utils/fsck.ubifs