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 </div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I'm trying to skip <span>clang AddressSanitizer instrumentation for <span>isMatch(void *ptr) function. How to do this on FreeBSD? </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 <string.h></div><div>#include <stdio.h></div><div>#include <stdlib.h></div><div><br></div><div> #define PATTERN1 0x4ffcf694</div><div> static unsigned char pattern1[] = {0x4f,0xfc,0xf6,0x94};</div><div><br></div><div><br></div><div>__attribute__((no_sanitize("address"))) </div><div>int isMatch(void *ptr);</div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</div><div> int rv = 0;</div><div> void *ptr = NULL;</div><div><br></div><div> ptr = malloc(4);</div><div> if (!ptr)</div><div> {</div><div> printf("No memory.");</div><div> exit(1);</div><div> }</div><div> </div><div> /* Copy PATTERN1 marker to the allocated block */</div><div> memcpy(ptr, pattern1, sizeof(pattern1));</div><div><br></div><div> /*</div><div> TEST 1: Correct case.</div><div> */</div><div> printf("TEST 1: Correct case.\n");</div><div> rv = isMatch(ptr);</div><div> if (rv == 1)</div><div> printf("Matched\n");</div><div> else</div><div> printf("NOT Matched\n");</div><div><br></div><div><br></div><div> /*</div><div> TEST 2: ptr - 1000</div><div> */</div><div> printf("TEST 2: ptr - 1000\n");</div><div> rv = isMatch(ptr - 1000);</div><div> if (rv == 1)</div><div> printf("Matched\n");</div><div> else</div><div> printf("NOT Matched\n");</div><div><br></div><div>}</div><div><br></div><div>__attribute__((no_sanitize("address"))) </div><div>int isMatch(void *ptr)</div><div>{</div><div> if ((memcmp(ptr, (void *)pattern1, sizeof(pattern1)) == 0))</div><div> return 1;</div><div> </div><div> 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> #0 0x2bb794 in isMatch path/prog.c:67:7</div><div> #1 0x2bb73e in main path/prog.c:56:7</div><div> #2 0x236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7</div><div> #3 0x8002e2007 (<unknown module>)</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> </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>
