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

Manual poisoning for pool/heap when using address sanitizer #4584

Merged
merged 12 commits into from
Jan 22, 2025

Conversation

dipinhora
Copy link
Contributor

So the address sanitizer can better detect issues

Including adding an address and undefined behavior sanitizer CI build and a couple of minor fixes identified by the address sanitizer

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jan 14, 2025
@@ -1322,6 +1322,7 @@ void ponyint_cycle_terminate(pony_ctx_t* ctx)
ponyint_become(ctx, cycle_detector);
final(ctx, cycle_detector);
ponyint_destroy(ctx, cycle_detector);
ponyint_become(ctx, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the change. I'm on my phone so maybe I missed it, but I don't see it used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ponyint_become saves the cycle_detector pointer into the ctx on line 1322.. then final runs the finaliser/cleanup for the cycle detector.. then ponyint_destroy destroys the cycle_detector.. the new ponyint_become(ctx, NULL) is to ensure that the ctx don't retain a reference to the now invalid cycle_detector..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@dipinhora
Copy link
Contributor Author

i believe the missing header file:

/__w/ponyc/ponyc/src/libponyrt/mem/heap.c:12:10: fatal error: 'sanitizer/asan_interface.h' file not found
   12 | #include <sanitizer/asan_interface.h>

error can be resolved by installing the libclang-rt-dev package in the docker image ghcr.io/ponylang/ponyc-ci-x86-64-unknown-linux-ubuntu24.04-builder:20240425..

@SeanTAllen
Copy link
Member

i believe the missing header file:

/__w/ponyc/ponyc/src/libponyrt/mem/heap.c:12:10: fatal error: 'sanitizer/asan_interface.h' file not found
   12 | #include <sanitizer/asan_interface.h>

error can be resolved by installing the libclang-rt-dev package in the docker image ghcr.io/ponylang/ponyc-ci-x86-64-unknown-linux-ubuntu24.04-builder:20240425..

There's a different error now with that in a new builder that I ran with. Shall I push that change and you can continue working on getting this to pass CI?

@dipinhora
Copy link
Contributor Author

i believe the missing header file:

/__w/ponyc/ponyc/src/libponyrt/mem/heap.c:12:10: fatal error: 'sanitizer/asan_interface.h' file not found
   12 | #include <sanitizer/asan_interface.h>

error can be resolved by installing the libclang-rt-dev package in the docker image ghcr.io/ponylang/ponyc-ci-x86-64-unknown-linux-ubuntu24.04-builder:20240425..

There's a different error now with that in a new builder that I ran with. Shall I push that change and you can continue working on getting this to pass CI?

@SeanTAllen one more docker image change would be useful.. currently, ubsan can't find a symbolizer and the backtraces aren't very useful:

2025-01-15T16:48:07.3281792Z ==16475==WARNING: invalid path to external symbolizer!
2025-01-15T16:48:07.3282410Z ==16475==WARNING: Failed to use and restart external symbolizer!

i believe the llvm package includes the llvm-symbolizer for ubsan to use so it can print more useful backtraces..

as for the failure, i have a feeling that the ASAN_OPTIONS environment variable isn't being properly set.. that shouldn't hold up the docker image changes (with or without the symbolizer)..

@SeanTAllen
Copy link
Member

@dipinhora i wary of installing llvm in the image and then accidentally picking up the wrong one. if we build it as part of our llvm build, that should be able to work, yes?

@dipinhora
Copy link
Contributor Author

@dipinhora i wary of installing llvm in the image and then accidentally picking up the wrong one. if we build it as part of our llvm build, that should be able to work, yes?

i would assume so.. not sure how ubsan finds a symbolizer to use but i'm guessing it looks for it via the path.. maybe it's documented somewhere... 8*/

@SeanTAllen
Copy link
Member

SeanTAllen commented Jan 15, 2025

@dipinhora i wary of installing llvm in the image and then accidentally picking up the wrong one. if we build it as part of our llvm build, that should be able to work, yes?

i would assume so.. not sure how ubsan finds a symbolizer to use but i'm guessing it looks for it via the path.. maybe it's documented somewhere... 8*/

can you see if you can run that down? i think it is probably a better, less foot-gunny approach.

@dipinhora
Copy link
Contributor Author

@dipinhora i wary of installing llvm in the image and then accidentally picking up the wrong one. if we build it as part of our llvm build, that should be able to work, yes?

i would assume so.. not sure how ubsan finds a symbolizer to use but i'm guessing it looks for it via the path.. maybe it's documented somewhere... 8*/

can you see if you can run that down? i think it is probably a better, less foot-gunny approach.

yep.. the ubsan docs (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#stack-traces-and-report-symbolization) say:

Make sure llvm-symbolizer binary is in PATH.

@SeanTAllen
Copy link
Member

It appears we don't build llvm-sanitizer at the moment. If you need help figuring that part out, @chalcolith would be a good resource.

@dipinhora
Copy link
Contributor Author

It appears we don't build llvm-sanitizer at the moment. If you need help figuring that part out, @chalcolith would be a good resource.

we do build llvm-symbolizer already:

2025-01-15T16:46:14.9006145Z -- Installing: /__w/ponyc/ponyc/build/libs/bin/llvm-symbolizer

@SeanTAllen
Copy link
Member

I misread your comment. In particular, the binary name.

@SeanTAllen
Copy link
Member

@dipinhora when you have a chance, you should rebase against main which now has the updated ubuntu24 builders across the board.

@dipinhora
Copy link
Contributor Author

@dipinhora when you have a chance, you should rebase against main which now has the updated ubuntu24 builders across the board.

done

@SeanTAllen
Copy link
Member

@dipinhora is this good now? I believe everything we discussed is in place now. I wanted to verify.

@@ -43,6 +49,28 @@ size_t ponyint_pool_used_size(size_t index);

size_t ponyint_pool_adjust_size(size_t size);

#ifndef POOL_USE_DEFAULT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see the order reversed here.

Can you make this say #ifdef POOL_USE_DEFAULT and make the default case come first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched

Comment on lines 103 to 104
// must be at least the size of 3 or else we get a heap buffer overflow
if((2 * sizeof(LLVMTypeRef)) == tparam_size)
tparam_size += tparam_size + sizeof(LLVMTypeRef);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's going on here. Joe and I are trying to sort it out and we are very confused at the moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this, "if tparam_size was 0 so that it is now 2, we want to make it 3"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume this was found by the sanitizer?

either way, i find the logic confusing. is there a reason it feels so "obfuscated"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to ignore you @SeanTAllen because @jemc rewrote the code already..

src/libponyc/codegen/genfun.c Outdated Show resolved Hide resolved
@dipinhora
Copy link
Contributor Author

@dipinhora is this good now? I believe everything we discussed is in place now. I wanted to verify.

kind of.. the CI is no longer failing.. but ubsan is still having trouble with finding the symbolizer (https://github.com/ponylang/ponyc/actions/runs/12802214635/job/35693500329#step:11:451):

==1344==WARNING: invalid path to external symbolizer!
==1344==WARNING: Failed to use and restart external symbolizer!

even though i explicitly checked and it should be in the path correctly (https://github.com/ponylang/ponyc/actions/runs/12802214635/job/35693500329#step:11:70):

OVERVIEW: llvm-symbolizer

USAGE: llvm-symbolizer [options] addresses...

i'm planning on giving it another try to get it working but if it doesn't i'm going to give up on the symbolization from the sanitizers for now..

@dipinhora
Copy link
Contributor Author

@dipinhora is this good now? I believe everything we discussed is in place now. I wanted to verify.

@SeanTAllen this is now ready from my perspective..

@SeanTAllen SeanTAllen merged commit f8a2fee into ponylang:main Jan 22, 2025
22 checks passed
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants