前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在使用asan的时候,如果我们想关闭/取消:use-after-poision 检测

在使用asan的时候,如果我们想关闭/取消:use-after-poision 检测

作者头像
Gxjun
发布2021-11-10 14:43:24
1.4K0
发布2021-11-10 14:43:24
举报
文章被收录于专栏:mlml

使用这个allow_user_poisoning=0,来取消

以这个例子为例:

// example1.cpp
// use-after-poison error
#include <stdlib.h>

extern "C" void __asan_poison_memory_region(void *, size_t);

int main(int argc, char **argv) {
    char *x = new char[16];
    x[10] = 0;
    __asan_poison_memory_region(x, 16);

    int res = x[argc * 10];              // Boom!
 
    delete [] x;
    return res;
}
gcc -fsanitize=address  eaxmple1.cpp -o ufpexe

运行会报错:

=================================================================
==9369==ERROR: AddressSanitizer: use-after-poison on address 0x60200000001a at pc 0x5635fbfa99f2 bp 0x7fffc5a981d0 sp 0x7fffc5a981c0
READ of size 1 at 0x60200000001a thread T0
    #0 0x5635fbfa99f1 in main (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x9f1)
    #1 0x7f5e429f5bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    #2 0x5635fbfa9859 in _start (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x859)

0x60200000001a is located 10 bytes inside of 16-byte region [0x602000000010,0x602000000020)
allocated by thread T0 here:
    #0 0x7f5e42ea5608 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0608)
    #1 0x5635fbfa9952 in main (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x952)
    #2 0x7f5e429f5bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)

SUMMARY: AddressSanitizer: use-after-poison (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x9f1) in main
Shadow bytes around the buggy address:
  0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa f7[f7]fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==9369==ABORTING

这样运行会取消掉:

ASAN_OPTIONS=allow_user_poisoning=0  ./exeamp
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-11-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档