llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.75k stars 11.43k forks source link

ubsan doesn't honour exitcode #49510

Open llvmbot opened 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 50166
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@petrhosek,@zygoloid,@vitalybuka

Extended Description

sanitizer_common/sanitizer_flags.inc defines the "exitcode" option.

AFAICS it's honoured by all the sanitizers except ubsan. All the sanitizers also seem to set it to some !=0 default value in a InitializeFlags() function, except ubsan.

vitalybuka commented 3 years ago

so remaining issue:

  1. _exit() interceptor in ubsan
  2. ubsan+asan does not notify asan about error, so asan's _exit interceptor is also useless
llvmbot commented 3 years ago

Forget about the default exitcode part. I saw https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/asan/asan_flags.cpp#L60 and noticed the same is not there for ubsan. But I see now COMMON_FLAG already sets the default to 1, so it's not that it's missing in ubsan but that's redundant in asan.

vitalybuka commented 3 years ago

and memprof=1

If I change that, I'd rather change all to 1 for consistency.

vitalybuka commented 3 years ago

To make exitcode work you need -fno-sanitize-recover=undefined. Otherwise program continues execution and returns regular code.

Other sanitizers intercept _exit() and override programs code. It's possible and easy to do for ubsan too.

Regarding default exitcode, looks like we have inconsistency here which probably unsafe to change as it will break some users. exitcode for hwasan=99, lsan=23, tsan=66, ubsan=1, asan=1, msan=1