[PATCH] D103562: [NFC][compiler-rt][hwasan] Refactor hwasan functions

Alexey Baturo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 5 12:18:19 PDT 2022


smd added a comment.

Hi folks,

I've been working on support hwasan for risc-v and I believe I've found an issue with the existing lit tests this commit causes.
Tests stack-{oob,uar,uas}.c check for correct backtrace being printed. From the code and comments the idea is to not to print any hwasan related frames(see the code and comments below).

  void HandleTagMismatch(AccessInfo ai, uptr pc, uptr frame, void *uc,                                
                         uptr *registers_frame) {                                                     
    InternalMmapVector<BufferedStackTrace> stack_buffer(1);                                           
    BufferedStackTrace *stack = stack_buffer.data();                                                  
    stack->Reset();                                                                                   
    stack->Unwind(pc, frame, uc, common_flags()->fast_unwind_on_fatal);                               
                                                                                                      
    // The second stack frame contains the failure __hwasan_check function, as                        
    // we have a stack frame for the registers saved in __hwasan_tag_mismatch that                    
    // we wish to ignore. This (currently) only occurs on AArch64, as x64                      
    // implementations use SIGTRAP to implement the failure, and thus do not go                       
    // through the stack saver.                                                                       
    if (registers_frame && stack->trace && stack->size > 0) {                                         
      stack->trace++;                                                                              
      stack->size--;                                                                               
    } 

Before this commit the return address and frame pointer to were taken directly from **hwasan_tag_mismatch4**, while after the commit those addresses are calculated after another function being called from hwasan_tag_mismatch4 (the **HwasanTagMismatch** one).
So, if I understand it correctly, now it looks like 2 stack frames must be ignored(for **hwasan_tag_mismatch4** and **HwasanTagMismatch**) to get a proper backtrace.
What do you think?

Thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103562/new/

https://reviews.llvm.org/D103562



More information about the cfe-commits mailing list