On Wed, Feb 09, 2022 at 08:45:09PM +1100, Jonathan Gray wrote:
> On Wed, Feb 09, 2022 at 09:09:35AM +0100, Theo Buehler wrote:
> > In libressl-portable we run the explicit_bzero tests as part of the
> > builds. If we enable ASAN on linux, this test segfaults in
> > __interceptor_memmem() in the two test_with{,out}_bzero() functions,
> > presumably because the sigaltstack magic is too low level for ASAN to
> > grok.
> > 
> > Would the patch below that disables ASAN for these functions be
> > acceptable or shold we maintain it in the libressl-portable repo?
> > 
> > https://github.com/google/sanitizers/wiki/AddressSanitizer#turning-off-instrumentation
> > 
> > Index: explicit_bzero.c
> > ===================================================================
> > RCS file: /cvs/src/regress/lib/libc/explicit_bzero/explicit_bzero.c,v
> > retrieving revision 1.8
> > diff -u -p -r1.8 explicit_bzero.c
> > --- explicit_bzero.c        9 Feb 2022 07:48:15 -0000       1.8
> > +++ explicit_bzero.c        9 Feb 2022 07:56:43 -0000
> > @@ -26,6 +26,12 @@
> >  #define ASSERT_NE(a, b) assert((a) != (b))
> >  #define ASSERT_GE(a, b) assert((a) >= (b))
> >  
> > +#if defined(__clang__) || defined (__GNUC__)
> > +#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
> > +#else
> > +#define ATTRIBUTE_NO_SANITIZE_ADDRESS
> > +#endif
> > +
> 
> clang also defines __GNUC__, not sure if clang-cl is different
> 
> with clang 13.0.0 still 4.2.1
> 
> #define __GNUC__ 4
> #define __GNUC_MINOR__ 2
> #define __GNUC_PATCHLEVEL__ 1
> 
> I was curious how actual gcc 4.2.1 would handle this so I tried on
> sparc64.  The test still passes but there is a warning about an unknown
> attribute.

Thanks. The below is based on a suggestion by Ilya Shipitsin.

On clang we can use __has_feature(), but that doesn't exist on
gcc which defines __SANITIZE_ADDRESS__ if it compiles with
-fsanitize=address.

This doesn't warn on sparc64 and works in my test setups.

Index: explicit_bzero.c
===================================================================
RCS file: /cvs/src/regress/lib/libc/explicit_bzero/explicit_bzero.c,v
retrieving revision 1.8
diff -u -p -r1.8 explicit_bzero.c
--- explicit_bzero.c    9 Feb 2022 07:48:15 -0000       1.8
+++ explicit_bzero.c    9 Feb 2022 10:32:00 -0000
@@ -1,4 +1,4 @@
-/*     $OpenBSD: explicit_bzero.c,v 1.8 2022/02/09 07:48:15 tb Exp $   */
+/*     $OpenBSD: explicit_bzero.c,v 1.6 2014/07/11 01:10:35 matthew Exp $      
*/
 /*
  * Copyright (c) 2014 Google Inc.
  *
@@ -26,6 +26,17 @@
 #define ASSERT_NE(a, b) assert((a) != (b))
 #define ASSERT_GE(a, b) assert((a) >= (b))
 
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+#define __SANITIZE_ADDRESS__
+#endif
+#endif
+#ifdef __SANITIZE_ADDRESS__
+#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
+#else
+#define ATTRIBUTE_NO_SANITIZE_ADDRESS
+#endif
+
 /* 128 bits of random data. */
 static const char secret[16] = {
        0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c,
@@ -138,7 +149,7 @@ count_secrets(const char *buf)
        return (res);
 }
 
-static char *
+ATTRIBUTE_NO_SANITIZE_ADDRESS static char *
 test_without_bzero(void)
 {
        char buf[SECRETBYTES];
@@ -149,7 +160,7 @@ test_without_bzero(void)
        return (res);
 }
 
-static char *
+ATTRIBUTE_NO_SANITIZE_ADDRESS static char *
 test_with_bzero(void)
 {
        char buf[SECRETBYTES];

Reply via email to