[all-commits] [llvm/llvm-project] c76045: [compiler-rt][ASan] Add function copying annotatio...

Tacet via All-commits all-commits at lists.llvm.org
Tue Oct 15 04:27:02 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c76045d9bf3bd1c7a381dc85d1db63a38fd69aa4
      https://github.com/llvm/llvm-project/commit/c76045d9bf3bd1c7a381dc85d1db63a38fd69aa4
  Author: Tacet <advenam.tacet at gmail.com>
  Date:   2024-10-15 (Tue, 15 Oct 2024)

  Changed paths:
    M compiler-rt/include/sanitizer/common_interface_defs.h
    M compiler-rt/lib/asan/asan_errors.cpp
    M compiler-rt/lib/asan/asan_errors.h
    M compiler-rt/lib/asan/asan_poisoning.cpp
    M compiler-rt/lib/asan/asan_report.cpp
    M compiler-rt/lib/asan/asan_report.h
    M compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
    M compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h
    A compiler-rt/test/asan/TestCases/copy_container_annotations.cpp

  Log Message:
  -----------
  [compiler-rt][ASan] Add function copying annotations (#91702)

This PR adds a `__sanitizer_copy_contiguous_container_annotations`
function, which copies annotations from one memory area to another. New
area is annotated in the same way as the old region at the beginning
(within limitations of ASan).

Overlapping case: The function supports overlapping containers, however
no assumptions should be made outside of no false positives in new
buffer area. (It doesn't modify old container annotations where it's not
necessary, false negatives may happen in edge granules of the new
container area.) I don't expect this function to be used with
overlapping buffers, but it's designed to work with them and not result
in incorrect ASan errors (false positives).

If buffers have granularity-aligned distance between them (`old_beg %
granularity == new_beg % granularity`), copying algorithm works faster.
If the distance is not granularity-aligned, annotations are copied byte
after byte.

```cpp
void __sanitizer_copy_contiguous_container_annotations(
    const void *old_storage_beg_p, const void *old_storage_end_p,
    const void *new_storage_beg_p, const void *new_storage_end_p) {
```

This function aims to help with short string annotations and similar
container annotations. Right now we change trait types of
`std::basic_string` when compiling with ASan and this function purpose
is reverting that change as soon as possible.


https://github.com/llvm/llvm-project/blob/87f3407856e61a73798af4e41b28bc33b5bf4ce6/libcxx/include/string#L738-L751

The goal is to not change `__trivially_relocatable` when compiling with
ASan. If this function is accepted and upstreamed, the next step is
creating a function like `__memcpy_with_asan` moving memory with ASan.
And then using this function instead of `__builtin__memcpy` while moving
trivially relocatable objects.


https://github.com/llvm/llvm-project/blob/11a6799740f824282650aa9ec249b55dcf1a8aae/libcxx/include/__memory/uninitialized_algorithms.h#L644-L646

---

I'm thinking if there is a good way to address fact that in a container
the new buffer is usually bigger than the previous one. We may add two
more arguments to the functions to address it (the beginning and the end
of the whole buffer.

Another potential change is removing `new_storage_end_p` as it's
redundant, because we require the same size.

Potential future work is creating a function `__asan_unsafe_memmove`,
which will be basically memmove, but with turned off instrumentation
(therefore it will allow copy data from poisoned area).

---------

Co-authored-by: Vitaly Buka <vitalybuka at google.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list