gh-156049: Add support for building with HWASAN - #156721
StanFromIreland wants to merge 4 commits into
Conversation
Co-authored-by: Florian Mayer <fmayer@google.com> Co-authored-by: Anna <araslanova.anna.a@gmail.com>
Documentation build overview
104 files changed ·
|
|
lgtm |
|
Hi. You asked me to review this change, but I don't know how to test it manually. Can you provide a way to introduce a bug on purpose and explain how to test that HWASAN detects it properly? |
| Note that on x86-64 this uses `page aliasing | ||
| <https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#supported-architectures>`_, | ||
| which only tags heap allocations and is unsafe for programs that ``fork()``, | ||
| including much of the test suite. |
There was a problem hiding this comment.
Do you know which GCC and clang versions added support for this sanitizer?
There was a problem hiding this comment.
LLVM (the reference implementation) supports it on AArch64, and additionally on x86-64 since LLVM 13 with page aliasing. GCC supports it only on AArch64, since GCC 11.
Hi, thanks for the review! If you mean just a trivial example, try for example applying this patch which adds a little heap-use-after-free: diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index a7fefb1fec5..e7fe3131052 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -1987,6 +1987,9 @@ static unsigned int
zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value)
/*[clinic end generated code: output=b217562e4fe6d6a6 input=1229cb2fb5ea948a]*/
{
+ volatile char *probe = PyMem_RawMalloc(1);
+ PyMem_RawFree((void *)probe);
+ *probe = '\0';
/* Releasing the GIL for very small buffers is inefficient
and may lower performance */
if (data->len > 1024*5) {Then compile Python with the flag: And run: Which for me results in: |
Co-authored-by: Victor Stinner <vstinner@python.org>
|
I pushed a commit which incorporates the fix in #157934 for MSan/ASan. |
This supersedes GH-149166 and GH-156050, pulling in their changes and adding a
--with-hwaddress-sanitizerconfigure option as well as a few little miscellaneous changes for better support. Note that x86-64 has to use clang's page aliasingmode, which shares the heap across
fork(), so the test suite is only reliableon AArch64.
@AnnaAr321 and @fmayer I'd appreciate your reviews :-)