[all-commits] [llvm/llvm-project] 1b5765: tsan: tolerate munmap with invalid arguments

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Thu Dec 2 08:51:04 PST 2021

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1b576585eba4d08d5c97c39f5f43d0bf6eed4e4e
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2021-12-02 (Thu, 02 Dec 2021)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
    A compiler-rt/test/tsan/munmap_invalid.cpp

  Log Message:
  tsan: tolerate munmap with invalid arguments

We call UnmapShadow before the actual munmap, at that point we don't yet
know if the provided address/size are sane. We can't call UnmapShadow
after the actual munmap becuase at that point the memory range can
already be reused for something else, so we can't rely on the munmap
return value to understand is the values are sane.
While calling munmap with insane values (non-canonical address, negative
size, etc) is an error, the kernel won't crash. We must also try to not
crash as the failure mode is very confusing (paging fault inside of the
runtime on some derived shadow address).

Such invalid arguments are observed on Chromium tests:

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D114944

More information about the All-commits mailing list