gccaddress-sanitizersanitizer

gcc (4.8.3) sanitizer options to blacklist functions


I am compiling my code on gcc 4.8.3. I have enabled -fsanitize=address option. But my program exits during startup throwing global buffer overflow error in 3rd party library code. So i am trying to skip sanitizer for this function (or caller function). I tried __attribute__((no_sanitize("address"))) but compiler throws warning that ‘no_sanitize’ attribute directive ignored even tried -fsanitize-recover=address but recovery doesn't seem to be supported on address. Can any one help me with how to make my program continue after first error, or black list function to skip sanitizing?

EDIT

template <class T>
void __attribute__((no_sanitize_address)) OID_CB<T>::Init(s8_t* name, s8_t* data, u32_t entryNum, u32_t start,  u32_t end, u32_t entrySize, bool ViewFlag, bool WholeTableFlag)
{
        strcpy(mName,name);
        mName[strlen(name)]='\0';
        mData         = data;
        mEntryNum     = entryNum;
        mStart        = start;
        mEnd          = end;
        mEntrySize    = entrySize;
        mIsView       = ViewFlag;
        mIsWholeTable = WholeTableFlag;
}


==22247== ERROR: AddressSanitizer: global-buffer-overflow on address 0x000002ca57bf at pc 0x1020cc2 bp 0x7ffdd93b7070 sp 0x7ffdd93b7060
READ of size 1 at 0x000002ca57bf thread T0
    #0 0x1020cc1 in OID_CB<causeCodeMgr>::Init(char*, char*, unsigned int, unsigned int, unsigned int, unsigned int, bool, bool) /xxxx/xxxx/common/causeCodeMgr/../../../xxx/oam/include/cm_interface.h:457
    #1 0x1020cc1 in CMI<causeCodeMgr>::addOID(char*, unsigned long long, char*, unsigned int, unsigned int, unsigned int, unsigned int, bool, bool) /xxxx/xxx/common/causeCodeMgr/../../../xxx/oam/include/cm_interface.h:1289

    0x000002ca57bf is located 45 bytes to the right of global variable '*.LC670 (causeCodeMgr.cpp)' (0x2ca5780) of size 18
  '*.LC670 (causeCodeMgr.cpp)' is ascii string 'causeCodeInternal'
0x000002ca57bf is located 1 bytes to the left of global variable '*.LC671 (causeCodeMgr.cpp)' (0x2ca57c0) of size 26
  '*.LC671 (causeCodeMgr.cpp)' is ascii string 'internalCauseCodeToAction'
SUMMARY: AddressSanitizer: global-buffer-overflow /xxxx/rhel_7_1_x86_64/xxxx/common/causeCodeMgr/../../../xxxx/oam/include/cm_interface.h:457 OID_CB<causeCodeMgr>::Init(char*, char*, unsigned int, unsigned int, unsigned int, unsigned int, bool, bool)
Shadow bytes around the buggy address:
  0x00008058caa0: f9 f9 f9 f9 00 07 f9 f9 f9 f9 f9 f9 00 06 f9 f9
  0x00008058cab0: f9 f9 f9 f9 00 03 f9 f9 f9 f9 f9 f9 00 04 f9 f9
  0x00008058cac0: f9 f9 f9 f9 00 00 02 f9 f9 f9 f9 f9 00 00 06 f9
  0x00008058cad0: f9 f9 f9 f9 00 00 00 00 02 f9 f9 f9 f9 f9 f9 f9
  0x00008058cae0: 00 00 06 f9 f9 f9 f9 f9 00 00 f9 f9 f9 f9 f9 f9
=>0x00008058caf0: 00 00 02 f9 f9 f9 f9[f9]00 00 00 02 f9 f9 f9 f9
  0x00008058cb00: 00 00 00 f9 f9 f9 f9 f9 00 07 f9 f9 f9 f9 f9 f9
  0x00008058cb10: 00 00 00 f9 f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9
  0x00008058cb20: 00 03 f9 f9 f9 f9 f9 f9 00 07 f9 f9 f9 f9 f9 f9
  0x00008058cb30: 00 00 02 f9 f9 f9 f9 f9 00 07 f9 f9 f9 f9 f9 f9
  0x00008058cb40: 00 04 f9 f9 f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:     fa
  Heap righ redzone:     fb
  Freed Heap region:     fd
  Stack left redzone:    f1
  Stack mid redzone:     f2
  Stack right redzone:   f3
  Stack partial redzone: f4
  Stack after return:    f5
  Stack use after scope: f8
  Global redzone:        f9
  Global init order:     f6
  Poisoned by user:      f7
  ASan internal:         fe

Solution

  • I tried attribute((no_sanitize("address"))) but compiler throws warning that ‘no_sanitize’ attribute directive ignored

    I'm afraid GCC does not support this syntax (there's even a bug in their Bugzilla). You should be able to use no_sanitize_address though (read about it in docs).

    even tried -fsanitize-recover=address but recovery doesn't seem to be supported on address.

    This only appeared in GCC 6.