Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASan][libc++] Annotating std::basic_string with all allocators #75845

Merged

Commits on Jan 11, 2024

  1. [ASan][libc++] Annotating std::basic_string with all allocators

    This commit turns on ASan annotations in `std::basic_string` for all allocators by default.
    
    Originally suggested here: https://reviews.llvm.org/D146214
    
    This commit is part of our efforts to support container annotations with (almost) every allocator.
    Annotating `std::basic_string` with default allocator is implemented in llvm#72677.
    
    Support in ASan API exests since llvm@dd1b7b7.
    This patch removes the check in std::basic_string annotation member function (__annotate_contiguous_container) to support different allocators.
    
    You can turn off annotations for a specific allocator based on changes from llvm@2fa1bec.
    
    This PR is a part of a series of patches extending AddressSanitizer C++ container overflow detection capabilities by adding annotations, similar to those existing in `std::vector` and `std::deque` collections. These enhancements empower ASan to effectively detect instances where the instrumented program attempts to access memory within a collection's internal allocation that remains unused. This includes cases where access occurs before or after the stored elements in `std::deque`, or between the `std::basic_string`'s size (including the null terminator) and capacity bounds.
    
    The introduction of these annotations was spurred by a real-world software bug discovered by Trail of Bits, involving an out-of-bounds memory access during the comparison of two strings using the `std::equals` function. This function was taking iterators (`iter1_begin`, `iter1_end`, `iter2_begin`) to perform the comparison, using a custom comparison function. When the `iter1` object exceeded the length of `iter2`, an out-of-bounds read could occur on the `iter2` object. Container sanitization, upon enabling these annotations, would effectively identify and flag this potential vulnerability.
    
    If you have any questions, please email:
    - advenam.tacet@trailofbits.com
    - disconnect3d@trailofbits.com
    Advenam Tacet committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    7af271d View commit details
    Browse the repository at this point in the history
  2. Code review from EricWF

    This commit addresses some comments from a code review:
    - add size check,
    - add coments with context to a test,
    - add comments explaining what happens in the test,
    - remove volatile,
    - split an if to constexpr if and normal if.
    Advenam Tacet committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    1eea92e View commit details
    Browse the repository at this point in the history
  3. Remove constexpr magic

    Advenam Tacet committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    428a15f View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2024

  1. Mention CWG2523

    Advenam Tacet committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    a73df63 View commit details
    Browse the repository at this point in the history
  2. Remove a comment

    Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
    AdvenamTacet and ldionne authored Jan 12, 2024
    Configuration menu
    Copy the full SHA
    d6a2fcc View commit details
    Browse the repository at this point in the history
  3. Add arguments to main

    Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
    AdvenamTacet and ldionne authored Jan 12, 2024
    Configuration menu
    Copy the full SHA
    55980f5 View commit details
    Browse the repository at this point in the history
  4. Add return to main

    Also refactor one line.
    Advenam Tacet committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    200aaf2 View commit details
    Browse the repository at this point in the history