-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support -fsanitizer=address on ztest #6884
Conversation
Surprises:
In a little while I will push a revert to #6877 to see it in action on the buildbots. :) |
Buildbots failing becuase libasan is not installed by defualt. On CentOS 7 |
@DeHackEd thanks! You can add https://github.com/zfsonlinux/zfs-buildbot/blob/master/scripts/bb-dependencies.sh |
FYI @DeHackEd openzfs/zfs-buildbot#123 was just merged. |
Codecov Report
@@ Coverage Diff @@
## master #6884 +/- ##
=========================================
Coverage ? 71.67%
=========================================
Files ? 296
Lines ? 95015
Branches ? 0
=========================================
Hits ? 68098
Misses ? 26917
Partials ? 0
Continue to review full report at Codecov.
|
Thanks. I've pushed a rebase and fix for minor issues in the PR to kick off the buildbots again. |
f003d45
to
524c401
Compare
Update pushed. This version tries a full link in the configure script to detect systems where |
module/zfs/spa.c
Outdated
/* | ||
* -fsanitize in userspace will detect kmem_alloc(0, ...) | ||
* as a leak | ||
*/ |
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.
No comment needed, it is a leak and should be fixed.
module/zfs/spa.c
Outdated
* as a leak | ||
*/ | ||
if (sav->sav_count > 0) | ||
l2cache = kmem_alloc(sav->sav_count * sizeof (void *), |
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.
It looks like this same issue can occur on line 1588, I'm surprised it wasn't also flagged.
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.
It's good to see that enabling this functionality in ztest didn't expose any new issues. Since that went smoothly have you by chance looked in to enabling for all of user space for debug builds? We could do that right away by adding it to DEBUG_CFLAGS
assuming it doesn't identify a slew of issues which would need to be resolved first.
I'm not sure why but this patch appears to break the ZFS_ABORT
functionality, calling abort()
no longer generates a core causing several test cases to fail.
cmd/ztest/Makefile.am
Outdated
@@ -2,7 +2,7 @@ include $(top_srcdir)/config/Rules.am | |||
|
|||
# -Wnoformat-truncation to get rid of compiler warning for unchecked | |||
# truncating snprintfs on gcc 7.1.1. | |||
AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN) $(NO_FORMAT_TRUNCATION) | |||
AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN) $(NO_FORMAT_TRUNCATION) $(COMPILER_FSANITIZE_ADDRESS) |
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.
Let's pull $(COMPILER_FSANITIZE_ADDRESS)
down on to it's own line to mind the 80 character limit. Here and elsewhere.
AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN) $(NO_FORMAT_TRUNCATION)
AM_CFLAGS += $(COMPILER_FSANITIZE_ADDRESS)
config/user-compiler-options.m4
Outdated
]) | ||
|
||
CFLAGS="$saved_flags" | ||
AC_SUBST([FRAME_LARGER_THAN]) |
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.
No objection to consolidating these, but please fix the whitespace on this line while you're here. Let's also pull in user-no-format-truncation.m4
.
config/user-compiler-options.m4
Outdated
|
||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], | ||
[ | ||
if test -z "$COMPILER_FSANITIZE_ADDRESS" |
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.
The AS_IF
macro if available for the conditional. However, I think it'd be reasonable to simply bump this unconditionally to 4096 to cover both cases. This only applies to user space where we have headroom, and this was originally added before the kernel build system set -Wframe-larger-than
by default.
config/user-compiler-options.m4
Outdated
CFLAGS="$saved_flags" | ||
LDFLAGS="$saved_ldflags" | ||
fi | ||
AC_SUBST([COMPILER_FSANITIZE_ADDRESS]) |
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.
I'd suggest either dropping the COMPILER_
prefix, which isn't super useful and would be my preference. Or alternately adding it to NO_FORMAT_TRUNCATION and FRAME_LARGER_THAN for consistency.
config/zfs-build.m4
Outdated
@@ -27,7 +27,7 @@ AC_DEFUN([ZFS_AC_DEBUG], [ | |||
AC_MSG_CHECKING([whether assertion support will be enabled]) | |||
AC_ARG_ENABLE([debug], | |||
[AS_HELP_STRING([--enable-debug], | |||
[Enable assertion support @<:@default=no@:>@])], | |||
[Enable assertion support and compiler features where available @<:@default=no@:>@])], |
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.
The way you've implemented this setting --enable-debug
has no effect of this compiler feature. It only defines DEBUG and sets -Werror
, so I'm assuming this is an unrelated bit of clarification. In which case, how about the following message instead.
Enable assertions and -Werror @<:@default=no@:>@
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.
Actually it does. -fsanitize
is only checked for and hence enabled when a debug build is performed. The whole new m4 block is guarded with
if test "$enable_debug" = "yes"
This allows a normal build to operate without -fsanitize
even on systems which support it.
But I agree, this text needs rewording.
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.
Ahh, I see. I glossed over that in my initial reading. What do you think about moving the call points for these debug-only compiler checks in to ZFS_AC_DEBUG_ENABLE
. This way these M4 macro's will only run for debug builds where they're needed.
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.
I wanted to keep the stack size check together with this one for the sake of coherence and so that non-debug builds would still use a sane stack size check value. m4 is new to me so I'm sure my style is horrible.
kmem_alloc(0, ...) in userspace returns a leakable pointer. Signed-off-by: DHE <git@dehacked.net>
Regarding the memory leak, the That said I have been hitting another leak in the refcount code but I'm not getting much information about where the allocation is coming from yet. We still need that fixed before we push this branch. |
Requires minimum of gcc version 4.8. Only available to ztest right now, but easily added to other user applications. For kernel support use the Linux KASAN feature instead. Signed-off-by: DHE <git@dehacked.net>
Closing, replaced by #6941 |
Requires minimum of gcc version 4.8. Only available to ztest
right now, but easily added to other user applications. For
kernel support use the Linux KASAN feature instead.
Signed-off-by: DHE git@dehacked.net
Description
If your compiler supports
-fsanitize=address
and you configure with--enable-debug
most libraries,zdb
andztest
will be built with it enabled.Motivation and Context
By request from @behlendorf in #6877
How Has This Been Tested?
Build testing for the disabled path, full test of executable launch abilities for the debug path.
Types of changes
Checklist:
Signed-off-by
.