hunter-ht-2018 / ptfuzzer

Improving AFL by using Intel PT to collect branch information
291 stars 56 forks source link

problems about pt decoder #5

Closed jacky-wilson closed 5 years ago

jacky-wilson commented 5 years ago

First of all, the idea of this project is pretty cool and I love it very much. But I also found several problems when I tried to use run_pt.

  1. pt filter setting I can only obtain 64 packets when I try the program "run_with_pt.py". However, I can get the right trace if I comment the following lines in pt_decoder.cpp

    if(perf_support_ip_filter) {
        if(ioctl(perf_fd, PERF_EVENT_IOC_SET_FILTER, "filter 0x580/580@/bin/bash") < 0){
            std::cerr << "Warning: set filter for fd " << perf_fd  << " failed, hardware ip filter may not supported." << std::endl;
            std::cerr << "We stop trying to set ip filter again." << std::endl;
            perf_support_ip_filter = false;
        }
    }

    I'm confused about "ioctl(perf_fd, PERF_EVENT_IOC_SET_FILTER, "filter 0x580/580@/bin/bash")". Could you please explain what it does?

  2. tip_pgd_handler in pt.h assertation failed in line 364 of tip_pgd_handler(as shown below). Is there any problem if I uncomment line 363?

        if(this->branch_info_mode == TNT_MODE) {
            decode_tnt(this->last_tip);
        }
        //tnt_cache_reset(tnt_cache_state); 
        assert(count_tnt(tnt_cache_state) == 0);
zhanggenex commented 5 years ago

@jacky-wilson for question 1, please refer to Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3 (3A, 3B, 3C & 3D): System Programming Guide: chapter35.2.4.3 question 2, we are still working on the assertation failure in line 364. You could check issue 2 about this problem.

jacky-wilson commented 5 years ago

hi, I read the doc you mentioned but still cann't understand the pt filter, especially the the parameter "filter 0x580/580@/bin/bash". Could you please explain a bit more?

zhanggenex commented 5 years ago

@jacky-wilson I think you need to understand ioctl() filter 0x580/580@/bin/bash is just a parameter of PERF_EVENT_IOC_SET_FILTER, which sets MSR register 0x00005800 to filter ip addresses. In Intel PT, you just need to set a certain MSR resgister to filter tracing addresses. If you want to know the internal archietecture of Intel PT ip filter, I just recommend you to thoroughly read the Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3 (3A, 3B, 3C & 3D): System Programming Guide: chapter35.2.4.3. And you could refer to #4 .

zhouxucs commented 5 years ago

@jacky-wilson I think you can change @/bin/bash to any other binary in your OS, because we only use this function to open the IP filtering, but do not use it to set the filtering addresses. The filter addresses are set by writing MSR registers directly. We do this because perf seems only work for opening IP filtering, but be not able to set IP filtering addresses.

BinLeeBit commented 5 years ago

你好,我之前提问过相同的问题,关于以下的错误问题: pt/pt.h:274: void pt_packet_decoder::tip_pge_handler(uint8_t**, uint8_t**): Assertion "this->last_tip == 0"failed. 经过仔细的查找之后发现以下位置的代码存在问题。 pt_decoder.cpp 中第754行代码如下: uint64_t len = this->aux_head - this->aux_tail - 1; 此处的减1运算应该为加1,当该为+1之后上面的问题也解决了。 在此向您核对一下这样修改可以吗?

zhouxucs commented 5 years ago

@BinLeeBit 你好,此处代码

uint64_t len = this->aux_head - this->aux_tail - 1;

是用来计算PT所产生数据块的大小的。而tip_pge_handler那个断言的意思是在pge包解析中last_tip应该为0,也就是说当遇到一个pge包时,所有的跳转指令都应该被解析完成。

我个人觉得 -1 和 +1 不应该影响对pge包的解析,所以你说的这个情况比较奇怪,我认为可能是其他地方除了问题。你能提供更详细的一些信息吗?