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.
==== run-regress-explicit_bzero ====
cc -O2 -pipe -MD -MP -c
/usr/src/regress/lib/libc/explicit_bzero/explicit_bzero.c
/usr/src/regress/lib/libc/explicit_bzero/explicit_bzero.c:149: warning:
'no_sanitize_address' attribute directive ignored
/usr/src/regress/lib/libc/explicit_bzero/explicit_bzero.c:160: warning:
'no_sanitize_address' attribute directive ignored
cc -o explicit_bzero explicit_bzero.o
./explicit_bzero
> /* 128 bits of random data. */
> static const char secret[16] = {
> 0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c,
> @@ -138,7 +144,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 +155,7 @@ test_without_bzero(void)
> return (res);
> }
>
> -static char *
> +ATTRIBUTE_NO_SANITIZE_ADDRESS static char *
> test_with_bzero(void)
> {
> char buf[SECRETBYTES];
>
>