diff --git a/CODING b/CODING index 1bd62baf08..aff53f91e7 100644 --- a/CODING +++ b/CODING @@ -339,6 +339,8 @@ external/heimdal/hcrypto/evp.c: cast-function-type : Linux kernel build uses -Wcast-function-type external/heimdal/hcrypto/evp-algs.c: cast-function-type : Linux kernel build uses -Wcast-function-type +external/heimdal/krb5/crypto.c: use-after-free : False postive on certain GCC + compilers kauth/admin_tools.c : strict-proto : ubik_Call kauth/authclient.c : strict-proto : ubik_Call nonsense libadmin/kas/afs_kasAdmin.c: strict-proto : ubik_Call nonsense diff --git a/src/cf/gcc.m4 b/src/cf/gcc.m4 new file mode 100644 index 0000000000..7747807893 --- /dev/null +++ b/src/cf/gcc.m4 @@ -0,0 +1,51 @@ +dnl Checks for specific gcc behavior + +dnl Helper to test for UAF warning message +dnl _OPENAFS_UAF_COMPILE_IFELSE([success], [fail]) +AC_DEFUN([_OPENAFS_UAF_COMPILE_IFELSE],[ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #include + struct gcc_check { + char *ptr; + }; + void test(struct gcc_check *p, char *cp, int size) + { + p->ptr = realloc(cp, size); + if (p->ptr == NULL && size != 0) { + free(cp); /* If compiler has UAF bug this will be flagged */ + } + } + ]] + )], + [$1], + [$2] + ) +]) + +dnl Check to see if the GCC compiler incorrectly flags use-after-free (UAF). +dnl This false positive has been observed with gcc 12 when +dnl optimization is disabled (-O0) and gcc 13. +AC_DEFUN([OPENAFS_GCC_UAF_BUG_CHECK],[ + CFLAGS_USE_AFTER_FREE_GCCBUG= + AS_IF([test "x$GCC" = "xyes"], [ + AC_MSG_CHECKING([gcc use-after-free warning bug]) + ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wall -Werror -O0" + _OPENAFS_UAF_COMPILE_IFELSE( + [AC_MSG_RESULT(no)], + [ + dnl Compiler flagged an error. Run one more check to ensure + dnl the error was only the false positive for a UAF. + AX_APPEND_COMPILE_FLAGS([-Wno-use-after-free], + [CFLAGS_USE_AFTER_FREE_GCCBUG], [-Werror]) + CFLAGS=" $CFLAGS $CFLAGS_USE_AFTER_FREE_GCCBUG" + _OPENAFS_UAF_COMPILE_IFELSE( + [AC_MSG_RESULT(yes)], + [AC_MSG_ERROR([Unexpected compiler error while testing for gcc use-after-free bug])]) + ] + ) + CFLAGS="$ac_save_CFLAGS" + ]) + AC_SUBST([CFLAGS_USE_AFTER_FREE_GCCBUG]) +]) diff --git a/src/cf/osconf.m4 b/src/cf/osconf.m4 index d08f45f7c2..c4bbe281cb 100644 --- a/src/cf/osconf.m4 +++ b/src/cf/osconf.m4 @@ -644,6 +644,7 @@ if test "x$GCC" = "xyes"; then [CFLAGS_NOIMPLICIT_FALLTHROUGH], [-Werror]) AX_APPEND_COMPILE_FLAGS([-Wno-dangling-pointer], [CFLAGS_NODANGLING_POINTER], [-Werror]) + OPENAFS_GCC_UAF_BUG_CHECK AC_DEFINE(IGNORE_SOME_GCC_WARNINGS, 1, [define to disable some gcc warnings in warnings-as-errors mode]) else CFLAGS_NOSTRICT= diff --git a/src/crypto/rfc3961/Makefile.in b/src/crypto/rfc3961/Makefile.in index 6fce447ad9..e389048716 100644 --- a/src/crypto/rfc3961/Makefile.in +++ b/src/crypto/rfc3961/Makefile.in @@ -48,6 +48,7 @@ ${TOP_LIBDIR}/libafsrfc3961.a: libafsrfc3961.a CFLAGS_crypto-arcfour.lo=@CFLAGS_NOERROR@ CFLAGS_crypto-des-common.lo=@CFLAGS_NOERROR@ +CFLAGS_crypto.lo=@CFLAGS_USE_AFTER_FREE_GCCBUG@ context.lo: context.c ${HEADERS} copy.lo: copy.c ${HEADERS}