Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jan 2022 13:03:46 +0000 (UTC)
From:      Sagara Wijetunga <sagarawmw@yahoo.com>
To:        "freebsd-questions@FreeBSD.org" <freebsd-questions@FreeBSD.org>
Subject:   How to disable clang AddressSanitizer instrumentation for a function on FreeBSD?
Message-ID:  <366091554.1057409.1642511026145@mail.yahoo.com>
References:  <366091554.1057409.1642511026145.ref@mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi 
I'm trying to skip clang AddressSanitizer instrumentation for isMatch(void *ptr) function. How to do this on FreeBSD? 
My test program:
#include <string.h>#include <stdio.h>#include <stdlib.h>
 #define  PATTERN1   0x4ffcf694 static unsigned char pattern1[] = {0x4f,0xfc,0xf6,0x94};

__attribute__((no_sanitize("address"))) int isMatch(void *ptr);
int main(int argc, char *argv[]){ int rv = 0; void *ptr = NULL;
 ptr = malloc(4); if (!ptr)    {     printf("No memory.");     exit(1);    }  /* Copy PATTERN1 marker to the allocated block */ memcpy(ptr, pattern1, sizeof(pattern1));
 /*  TEST 1: Correct case. */ printf("TEST 1: Correct case.\n"); rv = isMatch(ptr); if (rv == 1)    printf("Matched\n"); else    printf("NOT Matched\n");

 /*  TEST 2: ptr - 1000 */ printf("TEST 2: ptr - 1000\n"); rv = isMatch(ptr - 1000); if (rv == 1)    printf("Matched\n"); else    printf("NOT Matched\n");
}
__attribute__((no_sanitize("address"))) int isMatch(void *ptr){ if ((memcmp(ptr, (void *)pattern1, sizeof(pattern1)) == 0))    return 1;  return 0;}

/usr/local/bin/clang13 prog.c -O1 -g -fsanitize=address -fno-omit-frame-pointer -Wall -O -I. -I/usr/local/include -L. -L/usr/local/lib -o prog

When run I get following:./progTEST 1: Correct case.MatchedTEST 2: ptr - 1000AddressSanitizer:DEADLYSIGNAL===================================================================29072==ERROR: AddressSanitizer: SEGV on unknown address 0x601ffff00010 (pc 0x0000002bb794 bp 0x7fffffffea30 sp 0x7fffffffea30 T0)==29072==The signal is caused by a READ memory access.    #0 0x2bb794 in isMatch path/prog.c:67:7    #1 0x2bb73e in main path/prog.c:56:7    #2 0x236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7    #3 0x8002e2007  (<unknown module>)
AddressSanitizer can not provide additional info.SUMMARY: AddressSanitizer: SEGV path/prog.c:67:7 in isMatch==29072==ABORTING
Appreciate any help.
Best regardsSagara
 


[-- Attachment #2 --]
<html><head></head><body><div class="yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div dir="ltr" data-setdir="false">Hi&nbsp;</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I'm trying to skip&nbsp;<span>clang AddressSanitizer instrumentation for&nbsp;<span>isMatch(void *ptr) function. How to do this on FreeBSD?&nbsp;</span></span></div><div dir="ltr" data-setdir="false"><span><span><br></span></span></div><div dir="ltr" data-setdir="false">My test program:</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><div><div>#include &lt;string.h&gt;</div><div>#include &lt;stdio.h&gt;</div><div>#include &lt;stdlib.h&gt;</div><div><br></div><div>&nbsp;#define&nbsp; PATTERN1&nbsp; &nbsp;0x4ffcf694</div><div>&nbsp;static unsigned char pattern1[] = {0x4f,0xfc,0xf6,0x94};</div><div><br></div><div><br></div><div>__attribute__((no_sanitize("address")))&nbsp;</div><div>int isMatch(void *ptr);</div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</div><div>&nbsp;int rv = 0;</div><div>&nbsp;void *ptr = NULL;</div><div><br></div><div>&nbsp;ptr = malloc(4);</div><div>&nbsp;if (!ptr)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp;printf("No memory.");</div><div>&nbsp; &nbsp; &nbsp;exit(1);</div><div>&nbsp; &nbsp; }</div><div>&nbsp;</div><div>&nbsp;/* Copy PATTERN1 marker to the allocated block */</div><div>&nbsp;memcpy(ptr, pattern1, sizeof(pattern1));</div><div><br></div><div>&nbsp;/*</div><div>&nbsp; TEST 1: Correct case.</div><div>&nbsp;*/</div><div>&nbsp;printf("TEST 1: Correct case.\n");</div><div>&nbsp;rv = isMatch(ptr);</div><div>&nbsp;if (rv == 1)</div><div>&nbsp; &nbsp; printf("Matched\n");</div><div>&nbsp;else</div><div>&nbsp; &nbsp; printf("NOT Matched\n");</div><div><br></div><div><br></div><div>&nbsp;/*</div><div>&nbsp; TEST 2: ptr - 1000</div><div>&nbsp;*/</div><div>&nbsp;printf("TEST 2: ptr - 1000\n");</div><div>&nbsp;rv = isMatch(ptr - 1000);</div><div>&nbsp;if (rv == 1)</div><div>&nbsp; &nbsp; printf("Matched\n");</div><div>&nbsp;else</div><div>&nbsp; &nbsp; printf("NOT Matched\n");</div><div><br></div><div>}</div><div><br></div><div>__attribute__((no_sanitize("address")))&nbsp;</div><div>int isMatch(void *ptr)</div><div>{</div><div>&nbsp;if ((memcmp(ptr, (void *)pattern1, sizeof(pattern1)) == 0))</div><div>&nbsp; &nbsp; return 1;</div><div>&nbsp;</div><div>&nbsp;return 0;</div><div>}</div><div><br></div></div><div><br></div></div><div dir="ltr" data-setdir="false"><span>/usr/local/bin/clang13 prog.c -O1 -g -fsanitize=address -fno-omit-frame-pointer -Wall -O -I. -I/usr/local/include -L. -L/usr/local/lib -o prog</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>When run I get following:</span></div><div dir="ltr" data-setdir="false"><div><div>./prog</div><div>TEST 1: Correct case.</div><div>Matched</div><div>TEST 2: ptr - 1000</div><div>AddressSanitizer:DEADLYSIGNAL</div><div>=================================================================</div><div>==29072==ERROR: AddressSanitizer: SEGV on unknown address 0x601ffff00010 (pc 0x0000002bb794 bp 0x7fffffffea30 sp 0x7fffffffea30 T0)</div><div>==29072==The signal is caused by a READ memory access.</div><div>&nbsp; &nbsp; #0 0x2bb794 in isMatch path/prog.c:67:7</div><div>&nbsp; &nbsp; #1 0x2bb73e in main path/prog.c:56:7</div><div>&nbsp; &nbsp; #2 0x236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7</div><div>&nbsp; &nbsp; #3 0x8002e2007&nbsp; (&lt;unknown module&gt;)</div><div><br></div><div>AddressSanitizer can not provide additional info.</div><div>SUMMARY: AddressSanitizer: SEGV path/prog.c:67:7 in isMatch</div><div>==29072==ABORTING</div><div><br></div></div><div dir="ltr" data-setdir="false">Appreciate any help.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Best regards</div><div dir="ltr" data-setdir="false">Sagara</div><div dir="ltr" data-setdir="false"><br></div></div><div dir="ltr" data-setdir="false"><span>&nbsp;</span><br></div><div dir="ltr" data-setdir="false"><br></div></div></body></html>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?366091554.1057409.1642511026145>