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

使用这个allow_user_poisoning=0,来取消

以这个例子为例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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;
}
1
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
复制代码

这样运行会取消掉:

1
ASAN_OPTIONS=allow_user_poisoning=0  ./exeamp

  

posted @   龚细军  阅读(706)  评论(1编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
历史上的今天:
2014-11-05 hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)
2014-11-05 杂记(编程style)----google code style!
点击右上角即可分享
微信分享提示