-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: allow building with address sanitizer #4594
Conversation
(Continued in #4595) |
IIRC |
diff --git a/configure b/configure
index 33a4ca9f..a7628cf1 100755
--- a/configure
+++ b/configure
@@ -713,6 +713,7 @@ enable_option_checking
enable_analyzer
enable_apparmor
enable_selinux
+enable_asan
enable_dbusproxy
enable_output
enable_usertmpfs
@@ -1370,6 +1371,7 @@ Optional Features:
--enable-analyzer enable GCC static analyzer
--enable-apparmor enable apparmor
--enable-selinux SELinux labeling support
+ --enable-asan enable address sanitizer
--disable-dbusproxy disable dbus proxy
--disable-output disable --output logging
--disable-usertmpfs disable tmpfs as regular user
@@ -3532,6 +3534,19 @@ if test "x$enable_selinux" = "xyes"; then :
fi
+# Check whether --enable-asan was given.
+if test "${enable_asan+set}" = set; then :
+ enableval=$enable_asan;
+fi
+
+if test "x$enable_asan" = "xyes"; then :
+
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -fsanitize=address"
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fsanitize=address"
+
+fi
+
+
|
Hmm if I |
No, I don't get that error. It runs without output, procudes a seccomp file and exits with 0. |
I'm wondering whether the flag should be changed to be more flexible to support different sanitizers. |
Which flag(s) would
What does it do by itself? From the docs, to me it looks like each suboption https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html:
Or does it enable all the suboptions at once? |
For gcc I'm not sure. |
I've now changed it to allow selection of the sanitizer ( |
@reinerh neomutt uses a simpler setup with export variables: https://neomutt.org/dev/analysis/asan ASAN requires Having proper scripts looks cleaner though, mhm. How much do you expect things to change? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AC_ARG_ENABLE([sanitizer], AS_HELP_STRING([--enable-sanitizer=@<:@address,memory,undefined@:>@], [enable address/memory/undefined sanitizer (debug)])) AS_IF([test "x$enable_sanitizer" = "xaddress" -o "x$enable_sanitizer" = "xmemory" -o "x$enable_sanitizer" = "xundefined"], [AX_CHECK_COMPILE_FLAG([-fsanitize=$enable_sanitizer],[ EXTRA_CFLAGS="$EXTRA_CFLAGS -fsanitize=$enable_sanitizer -fno-omit-frame-pointer" EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fsanitize=$enable_sanitizer" ],[AC_MSG_ERROR([$enable_sanitizer sanitizer not supported])] )])
I personally avoid using -a
and -o
test
options, as they are less
portable than &&
and ||
and are also potentially more ambiguous. From
test(1p) of POSIX.1-2017[1]:
APPLICATION USAGE
The XSI extensions specifying the -a and -o binary primaries and the '(' and
')' operators have been marked obsolescent. (Many expressions using them are
ambiguously defined by the grammar depending on the specific expressions
being evaluated.) Scripts using these expressions should be converted to the
forms given below. Even though many implementations will continue to support
these obsolescent forms, scripts should be extremely careful when dealing
with user-supplied input that could be confused with these and other
primaries and operators. Unless the application developer knows all the
cases that produce input to the script, invocations like:test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
to avoid problems if a user supplied values such as $1 set to '!' and $2 set
to the null string. in the shell. [...]
I think that the following would be the more "autoconf way" to do it:
AS_IF([AS_CASE(["$enable_sanitizer"], [address], [], [memory], [], [undefined],
[], [false])], [
# ...
])
Though I don't think it's needed in this case since AX_CHECK_COMPILE_FLAG
is
already being used anyway.
By the way, from my testing in the current version, AX_CHECK_COMPILE_FLAG
is
not failing when it should:
$ autoconf && ./configure --enable-sanitizer=foobar >/dev/null
$
Note: It works on the "suggested changes" version.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
@reinerh Could you squash (or fixup) all commits in this PR (and the suggestion If not, then can I do it? Before merging, I would like to make sure that all amend commits (i.e.: all Commits which amend commits that aren't on master are unnecessary and make Note: The issue is not with adding amend commits to an existing PR per se, but Note2: This concern is not specific to this PR (I've seen amend commits merged Note3: This should probably be a discussion, but I'm putting it here first |
@kmk3 done, thanks for your sugggestions, I have applied them. |
Our configure script supports that as well:
But having a command line flag that is also shown in
I think that problem is more generic and does not only apply to sanitizer options. Also when other compiler flags change, everything should be rebuilt ideally. I need to investigate how that could be improved.
What do you mean by what I expect to change? For these specific sanitization flags I don't expect much more changes. |
This allows building firejail (and other binaries) with address sanitizer (with
--enable-asan
).I noticed that some were interested in this in #4592 (ping @rusty-snake @smitsohu).
I didn't rebuild
configure
, as I have a different autoconf version installed and it would only blow up the diff. If someone wants to test it, please runautoreconf -vfi
before. (In my humble opinion generated files likeconfigure
should anyway not be part of the repository.)Right now running some of the tools only finds memory leaks. Running firejail itself does not work for me, it fails with this error:
Running with
--noprofile
works, but I didn't figure out yet which setting is the one that breaks it.Also so far I only tested it with gcc. clang might give different results.