This is an archive of the discontinued LLVM Phabricator instance.

[libasan] Remove 4Mb stack limit for swapcontext unpoisoning
ClosedPublic

Authored by itrofimow on Jul 6 2022, 10:18 AM.

Diff Detail

Event Timeline

itrofimow created this revision.Jul 6 2022, 10:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2022, 10:18 AM
Herald added a subscriber: Enna1. · View Herald Transcript
itrofimow requested review of this revision.Jul 6 2022, 10:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2022, 10:18 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Based on https://github.com/google/sanitizers/issues/1494

kMaxSaneContextStackSize was introduced 9 years ago, and with increasing popularity of coroutines in c++ world (be that std or boost coroutines) this limitation seems a bit off.
After all, is >4Mb coroutine stack actually insane in 2022?

Could you please add a test?

compiler-rt/lib/asan/asan_interceptors.cpp
251

It should probably a CHECK
e.g. CHECK_LE(ssize, 1<<28)

eugenis accepted this revision.Jul 6 2022, 10:41 AM
eugenis added a subscriber: eugenis.

LGTM

This revision is now accepted and ready to land.Jul 6 2022, 10:41 AM

I guess some sanity check would be good, but since we get are not guessing this value but getting it directly from the OS, it's fine either way?

I guess some sanity check would be good, but since we get are not guessing this value but getting it directly from the OS, it's fine either way?

In boost::Coroutine2 stack size might be user-provided and i am not sure if there is a limitation at all.

Could you please add a test?

Sure, but could you please suggest an appropriate place for that and where to look for references? - i'm not familiar with the codebase

I guess some sanity check would be good, but since we get are not guessing this value but getting it directly from the OS, it's fine either way?

In boost::Coroutine2 stack size might be user-provided and i am not sure if there is a limitation at all.

Could you please add a test?

Sure, but could you please suggest an appropriate place for that and where to look for references? - i'm not familiar with the codebase

Take a look at:
compiler-rt/test/asan/TestCases/Linux/swapcontext_test.cpp
compiler-rt/test/asan/TestCases/Linux/swapcontext_annotation.cpp

You may consider to modify them, or just fork and throw away unneeded stuff.
I expect new test is just simplest piece of code which use this function and fails without patch and passes with the patch.

I guess some sanity check would be good, but since we get are not guessing this value but getting it directly from the OS, it's fine either way?

In boost::Coroutine2 stack size might be user-provided and i am not sure if there is a limitation at all.

Right, same as ex. the size argument in memset. If it's wrong, we crash, but that's the user's fault. As opposed to some heuristic to detect stack limits, or that thing where we peek at glibc internals to parse the thread header which keeps changing between versions...

itrofimow updated this revision to Diff 443535.Jul 10 2022, 5:58 PM

making sure this test breaks on trunk

itrofimow updated this revision to Diff 443537.Jul 10 2022, 6:45 PM

now checking the test with a patch

itrofimow updated this revision to Diff 443539.Jul 10 2022, 7:16 PM

+ clang-format

I guess some sanity check would be good, but since we get are not guessing this value but getting it directly from the OS, it's fine either way?

In boost::Coroutine2 stack size might be user-provided and i am not sure if there is a limitation at all.

Could you please add a test?

Sure, but could you please suggest an appropriate place for that and where to look for references? - i'm not familiar with the codebase

Take a look at:
compiler-rt/test/asan/TestCases/Linux/swapcontext_test.cpp
compiler-rt/test/asan/TestCases/Linux/swapcontext_annotation.cpp

You may consider to modify them, or just fork and throw away unneeded stuff.
I expect new test is just simplest piece of code which use this function and fails without patch and passes with the patch.

Added a test, could you please have a look?
It's not exactly the simplest piece of code unfortunately, but i guess it's not that bad:
it resembles pretty close to what boost.Coroutine2 does, and fixing that was the motivation for the patch.

P.S. I did check that it fails without the patch, that could be seen in builds history

vitalybuka accepted this revision.Jul 11 2022, 10:28 AM

Thanks, LGTM.

compiler-rt/test/asan/TestCases/Linux/swapcontext_annotation.cpp
68

I moved formatting into a separate patch

This revision was landed with ongoing or failed builds.Jul 11 2022, 10:32 AM
This revision was automatically updated to reflect the committed changes.
vitalybuka reopened this revision.Jul 19 2022, 9:41 PM
This revision is now accepted and ready to land.Jul 19 2022, 9:41 PM

rebase

Hi! I see this got reverted, can i help with landing it once again?

rebase

Hi! I see this got reverted, can i help with landing it once again?

I uploaded it with slight modifications here. Hopefully it will work with D130218. Maybe you can check both, or even test in your environment.
It's not perfect, but better then we had before.

This revision was automatically updated to reflect the committed changes.