Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
c502d78
Radsan initial commit
Sep 4, 2023
39914f5
Remove accidental retest.sh commit
Oct 31, 2023
7c56929
Add preinit stage to radsan interception [skip ci]
davidtrevelyan Oct 24, 2023
80f07f4
Allow symbolizer to be specified as environment variable [skip ci]
davidtrevelyan Oct 25, 2023
6c81641
Init test commit
Oct 31, 2023
75f3346
Add (de)allocation radsan tests
davidtrevelyan Oct 31, 2023
3ab8b4a
Organise tests and increase coverage
davidtrevelyan Nov 1, 2023
885862e
Implement creat interceptor
Nov 1, 2023
1072144
Intercept POSIX filesystem methods
davidtrevelyan Nov 1, 2023
ad7deff
Add radsan unit test headers to cmake
Nov 1, 2023
7ce0ae2
Add fclose interceptor
davidtrevelyan Nov 1, 2023
b9ad516
Add pthread interceptors
Nov 1, 2023
4bf21b7
Add more pthread API interceptors
davidtrevelyan Nov 2, 2023
45c6302
Complete pthread interceptors v0
davidtrevelyan Nov 2, 2023
e899400
Add high-level tests for mutex interception
davidtrevelyan Nov 2, 2023
e4193d9
Get tests passing on macOS again
davidtrevelyan Nov 2, 2023
f09315f
Only exit during free if arg is not null
davidtrevelyan Nov 2, 2023
39fa1c4
Initialize Context properly
Nov 2, 2023
a0c5890
Use Context ctor instead of init
Nov 3, 2023
db14c50
Add interceptor and more high-level tests
davidtrevelyan Nov 6, 2023
c0885c6
Merge remote-tracking branch 'origin/radsan' into radsan
davidtrevelyan Nov 6, 2023
463adfa
Add socket interceptors
davidtrevelyan Nov 6, 2023
51d4383
Re-enable Context construction
davidtrevelyan Nov 7, 2023
e54c756
Add radsan bypass functionality
davidtrevelyan Nov 7, 2023
6094dc5
Add context tests
Nov 7, 2023
c53f0f4
Merge branches 'radsan' and 'radsan' of github.com:realtime-sanitizer…
Nov 7, 2023
f73bf55
Fix instrumented tests not building
Nov 8, 2023
0d2ee5c
Add test coverage for bypass push and pop
Nov 8, 2023
d209238
Fix compiler warnings
Nov 8, 2023
356cf3c
Make C++ accessible in radsan lib
davidtrevelyan Nov 8, 2023
1a4d484
Merge remote-tracking branch 'origin/radsan' into radsan
davidtrevelyan Nov 8, 2023
1c0aec8
Add interactive mode
davidtrevelyan Nov 8, 2023
c2703a2
Fix linux build issue
Nov 8, 2023
63feb77
Make radsan Context stack-only
davidtrevelyan Nov 9, 2023
2a0e59e
Get tests building and passing on Linux again
davidtrevelyan Nov 9, 2023
4418ea9
Update RADSan error message
davidtrevelyan Nov 9, 2023
b7c48f1
Add fread, fwrite and posix_memalign interceptors
davidtrevelyan Nov 13, 2023
6bc52ba
Add license headers
davidtrevelyan Nov 13, 2023
04613f6
Move includes to be local style, not system style
cjappl Dec 1, 2023
37831b4
Merge pull request #2 from cjappl/fix_quotes
davidtrevelyan Dec 1, 2023
3499f9e
Fix in-place Context construction
davidtrevelyan Dec 1, 2023
b4bbc41
Merge remote-tracking branch 'origin/radsan' into radsan
davidtrevelyan Dec 1, 2023
826918b
Add aligned alloc behind 10.15 flag
cjappl Dec 4, 2023
ae1988c
Added tests, fixed compilation errors for older version of OSX
cjappl Dec 4, 2023
67f4bbc
All tests pass on 10.15
cjappl Dec 4, 2023
2713b43
Fix 'at least' macros, test
cjappl Dec 4, 2023
27842a0
Moving aligned_alloc out of the higher level tests
cjappl Dec 4, 2023
d6b6a42
Review comments pt. 1
cjappl Dec 5, 2023
5189f45
Merge pull request #4 from cjappl/alignedalloc_2
davidtrevelyan Dec 5, 2023
e393f9e
Fix typo in gcc realtime attribute
cjappl Dec 8, 2023
42f6b1a
Clean up radsan test files
davidtrevelyan Dec 12, 2023
e4e721e
Use tmp filepath in creat interceptor unit test
davidtrevelyan Dec 12, 2023
cd47d2d
Remove duplication of test file path in interceptors tests
davidtrevelyan Dec 13, 2023
e5eb2a7
Merge pull request #5 from cjappl/Attribute
davidtrevelyan Dec 13, 2023
75cff6b
Revert to traditional return type style in test
davidtrevelyan Dec 18, 2023
e8c42da
Merge pull request #7 from realtime-sanitizer/radsan-clean-up-test-files
davidtrevelyan Dec 18, 2023
7758e8c
Allow for running just the supported arch tests on darwin (#10)
cjappl Dec 18, 2023
7a9595e
Fix lit test to have proper string match (#8)
cjappl Dec 18, 2023
be58d11
Attribute to disable RADSan (#6)
cjappl Dec 19, 2023
a3d5eda
Add a few more lit tests (#12)
cjappl Dec 21, 2023
bf10edd
Remove hard reset of radsan test arch (#11)
davidtrevelyan Dec 21, 2023
e76dec4
Intercept memalign and pvalloc (#16)
davidtrevelyan Mar 7, 2024
fd40d88
Add all read/write functions to the interceptors list (#17)
cjappl Mar 9, 2024
0cc523f
Revert "Add all read/write functions to the interceptors list (#17)" …
davidtrevelyan Mar 9, 2024
6a1fe86
Merge branch 'main' into upstream-radsan-v0
cjappl Mar 11, 2024
676f98d
Merge remote-tracking branch 'doug/nolock' into chris-first-PR
cjappl May 1, 2024
0cb6c6c
CHRISA: fixed cmake error preventing build, notified doug
cjappl May 1, 2024
35bb095
Findall clang::realtime->clang::nonblocking
cjappl May 1, 2024
bb0459c
Move attribute after function
cjappl May 1, 2024
58ae8e9
FIXME: Remove realtime attribute, how to get nonblocking in there??
cjappl May 1, 2024
2fa9eeb
Merge branch 'nolock' of https://github.com/dougsonos/llvm-project in…
cjappl May 2, 2024
2ccba1f
All tests working, looking for function effects properly.
cjappl May 2, 2024
e82483d
Merge branch 'radsan_plus_doug' into adapt_radsan_doug
cjappl May 2, 2024
80dcb34
No longer need the cmake 'hack' for the thing doug fixed
cjappl May 2, 2024
483abcf
Adding TODO question about blocking(false)
cjappl May 2, 2024
6d0ec7c
Merge remote-tracking branch 'doug/nolock' into radsan_plus_doug
cjappl May 2, 2024
8cda137
Merge branch 'radsan_plus_doug' into adapt_radsan_doug
cjappl May 2, 2024
e415392
Small const correctness/auto fix
cjappl May 2, 2024
96d8bec
Merge remote-tracking branch 'doug/nolock' into radsan_plus_doug
cjappl May 2, 2024
e7be521
Merge branch 'radsan_plus_doug' into adapt_radsan_doug
cjappl May 2, 2024
f31917b
Merge remote-tracking branch 'doug/nolock' into radsan_plus_doug
cjappl May 4, 2024
1c2a9bc
Merge branch 'radsan_plus_doug' into adapt_radsan_doug
cjappl May 4, 2024
7ad3393
Merge remote-tracking branch 'doug/nolock' into radsan_plus_doug
cjappl May 6, 2024
b106e6a
Merge branch 'radsan_plus_doug' into adapt_radsan_doug
cjappl May 6, 2024
ada2081
Move to cleaner for-loop for effects
cjappl May 6, 2024
e75fcc3
Get rid of nosanitize_realtime
cjappl May 6, 2024
0e49d10
Remove all front end code
cjappl May 6, 2024
1a7c2e9
Remove exit modes, make default mode `exit` (#20)
cjappl Apr 4, 2024
c48baad
Fix small style issue
cjappl May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Sanitizers.def
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#endif


// RealtimeSanitizer
SANITIZER("realtime", Realtime)

// AddressSanitizer
SANITIZER("address", Address)

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/SanitizerArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class SanitizerArgs {
bool needsStableAbi() const { return StableABI; }

bool needsMemProfRt() const { return NeedsMemProfRt; }
bool needsRadsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
bool needsHwasanRt() const {
return Sanitizers.has(SanitizerKind::HWAddress);
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
if (!Args.hasArg(options::OPT_shared))
HelperStaticRuntimes.push_back("hwasan-preinit");
}
if (SanArgs.needsRadsanRt() && SanArgs.linkRuntimes())
SharedRuntimes.push_back("radsan");
}

// The stats_client library is also statically linked into DSOs.
Expand All @@ -1382,6 +1384,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
StaticRuntimes.push_back("asan_cxx");
}

if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt() && SanArgs.linkRuntimes()) {
StaticRuntimes.push_back("radsan");
}

if (!SanArgs.needsSharedRt() && SanArgs.needsMemProfRt()) {
StaticRuntimes.push_back("memprof");
if (SanArgs.linkCXXRuntimes())
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,8 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
const char *sanitizer = nullptr;
if (Sanitize.needsUbsanRt()) {
sanitizer = "UndefinedBehaviorSanitizer";
} else if (Sanitize.needsRadsanRt()) {
sanitizer = "RealtimeSanitizer";
} else if (Sanitize.needsAsanRt()) {
sanitizer = "AddressSanitizer";
} else if (Sanitize.needsTsanRt()) {
Expand All @@ -1509,6 +1511,11 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
}
}
if(Sanitize.needsRadsanRt())
{
assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
AddLinkSanitizerLibArgs(Args, CmdArgs, "radsan");
}
if (Sanitize.needsLsanRt())
AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
if (Sanitize.needsUbsanRt()) {
Expand Down Expand Up @@ -3393,6 +3400,7 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64;
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Realtime;
Res |= SanitizerKind::PointerCompare;
Res |= SanitizerKind::PointerSubtract;
Res |= SanitizerKind::Leak;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon;
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Realtime;
Res |= SanitizerKind::PointerCompare;
Res |= SanitizerKind::PointerSubtract;
Res |= SanitizerKind::Fuzzer;
Expand Down
1 change: 1 addition & 0 deletions clang/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
check-lsan
check-msan
check-profile
check-radsan
check-safestack
check-sanitizer
check-tsan
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${LOONGARCH64})
set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
set(ALL_RADSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
${LOONGARCH64})

if(ANDROID)
set(OS_NAME "Android")
Expand Down
12 changes: 11 additions & 1 deletion compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ if(APPLE)
list_intersect(ASAN_SUPPORTED_ARCH
ALL_ASAN_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(RADSAN_SUPPORTED_ARCH
ALL_RADSAN_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(DFSAN_SUPPORTED_ARCH
ALL_DFSAN_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
Expand Down Expand Up @@ -674,6 +677,7 @@ else()
filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
${SANITIZER_COMMON_SUPPORTED_ARCH})
filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
filter_available_targets(RADSAN_SUPPORTED_ARCH ${ALL_RADSAN_SUPPORTED_ARCH})
filter_available_targets(FUZZER_SUPPORTED_ARCH ${ALL_FUZZER_SUPPORTED_ARCH})
filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
Expand Down Expand Up @@ -726,7 +730,7 @@ if(COMPILER_RT_SUPPORTED_ARCH)
endif()
message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")

set(ALL_SANITIZERS asan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;asan_abi)
set(ALL_SANITIZERS asan;radsan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;asan_abi)
set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
"sanitizers to build if supported on the target (all;${ALL_SANITIZERS})")
list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
Expand Down Expand Up @@ -757,6 +761,12 @@ else()
set(COMPILER_RT_HAS_ASAN FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND RADSAN_SUPPORTED_ARCH)
set(COMPILER_RT_HAS_RADSAN TRUE)
else()
set(COMPILER_RT_HAS_RADSAN FALSE)
endif()

if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
else()
Expand Down
92 changes: 92 additions & 0 deletions compiler-rt/lib/radsan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
include_directories(..)

set(RADSAN_CXX_SOURCES
radsan.cpp
radsan_context.cpp
radsan_stack.cpp
radsan_interceptors.cpp)

set(RADSAN_PREINIT_SOURCES
radsan_preinit.cpp)

set(RADSAN_HEADERS
radsan.h
radsan_context.h
radsan_stack.h)

set(RADSAN_DEPS)

set(RADSAN_CFLAGS
${COMPILER_RT_COMMON_CFLAGS}
${COMPILER_RT_CXX_CFLAGS}
-DSANITIZER_COMMON_NO_REDEFINE_BUILTINS)
set(RADSAN_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS})
set(RADSAN_LINK_LIBS
${COMPILER_RT_UNWINDER_LINK_LIBS}
${COMPILER_RT_CXX_LINK_LIBS})

if(APPLE)
add_compiler_rt_object_libraries(RTRadsan
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${RADSAN_SUPPORTED_ARCH}
SOURCES ${RADSAN_CXX_SOURCES}
ADDITIONAL_HEADERS ${RADSAN_HEADERS}
CFLAGS ${RADSAN_CFLAGS}
DEPS ${RADSAN_DEPS})
else()
add_compiler_rt_object_libraries(RTRadsan
ARCHS ${RADSAN_SUPPORTED_ARCH}
SOURCES ${RADSAN_CXX_SOURCES}
ADDITIONAL_HEADERS ${RADSAN_HEADERS}
CFLAGS ${RADSAN_CFLAGS}
DEPS ${RADSAN_DEPS})
add_compiler_rt_object_libraries(RTRadsan_preinit
ARCHS ${RADSAN_SUPPORTED_ARCH}
SOURCES ${RADSAN_PREINIT_SOURCES}
ADDITIONAL_HEADERS ${RADSAN_HEADERS}
CFLAGS ${RADSAN_CFLAGS})
endif()

set(RADSAN_COMMON_RUNTIME_OBJECT_LIBS
RTInterception
RTSanitizerCommon
RTSanitizerCommonLibc
RTSanitizerCommonCoverage
RTSanitizerCommonSymbolizer)

append_list_if(COMPILER_RT_HAS_LIBDL dl RADSAN_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBRT rt RADSAN_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBM m RADSAN_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread RADSAN_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBLOG log RADSAN_LINK_LIBS)

add_compiler_rt_component(radsan)

if (APPLE)
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
set(RADSAN_LINK_FLAGS ${RADSAN_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS})

add_compiler_rt_runtime(clang_rt.radsan
SHARED
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${RADSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTRadsan
${RADSAN_COMMON_RUNTIME_OBJECT_LIBS}
LINK_FLAGS ${RADSAN_LINK_FLAGS}
LINK_LIBS ${RADSAN_LINK_LIBS}
PARENT_TARGET radsan)
else()
add_compiler_rt_runtime(clang_rt.radsan
STATIC
ARCHS ${RADSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTRadsan_preinit
RTRadsan
${RADSAN_COMMON_RUNTIME_OBJECT_LIBS}
LINK_FLAGS ${RADSAN_LINK_FLAGS}
CFLAGS ${RADSAN_CFLAGS}
PARENT_TARGET radsan)
endif()

if(COMPILER_RT_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
32 changes: 32 additions & 0 deletions compiler-rt/lib/radsan/radsan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
This file is part of the RealtimeSanitizer (RADSan) project.
https://github.com/realtime-sanitizer/radsan

Copyright 2023 David Trevelyan & Alistair Barker
Subject to GNU General Public License (GPL) v3.0
*/

#include <radsan/radsan.h>
#include <radsan/radsan_context.h>
#include <radsan/radsan_interceptors.h>
#include <unistd.h>

extern "C" {
RADSAN_EXPORT void radsan_init() { radsan::initialiseInterceptors(); }

RADSAN_EXPORT void radsan_realtime_enter() {
radsan::getContextForThisThread().realtimePush();
}

RADSAN_EXPORT void radsan_realtime_exit() {
radsan::getContextForThisThread().realtimePop();
}

RADSAN_EXPORT void radsan_off() {
radsan::getContextForThisThread().bypassPush();
}

RADSAN_EXPORT void radsan_on() {
radsan::getContextForThisThread().bypassPop();
}
}
73 changes: 73 additions & 0 deletions compiler-rt/lib/radsan/radsan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
This file is part of the RealtimeSanitizer (RADSan) project.
https://github.com/realtime-sanitizer/radsan

Copyright 2023 David Trevelyan & Alistair Barker
Subject to GNU General Public License (GPL) v3.0
*/

#pragma once

#define RADSAN_EXPORT __attribute__((visibility("default")))

extern "C" {

/**
Initialise radsan interceptors. A call to this method is added to the
preinit array on Linux systems.

@warning Do not call this method as a user.
*/
RADSAN_EXPORT void radsan_init();

/** Enter real-time context.

When in a real-time context, RADSan interceptors will error if realtime
violations are detected. Calls to this method are injected at the code
generation stage when RADSan is enabled.

@warning Do not call this method as a user
*/
RADSAN_EXPORT void radsan_realtime_enter();

/** Exit the real-time context.

When not in a real-time context, RADSan interceptors will simply forward
intercepted method calls to the real methods.

@warning Do not call this method as a user
*/
RADSAN_EXPORT void radsan_realtime_exit();

/** Disable all RADSan error reporting.

This method might be useful to you if RADSan is presenting you with an error
for some code you are confident is realtime safe. For example, you might
know that a mutex is never contested, and that locking it will never block
on your particular system. Be careful!

A call to `radsan_off()` MUST be paired with a corresponding `radsan_on()`
to reactivate interception after the code in question. If you don't, radsan
will cease to work.

Example:

float process (float x) [[clang::nonblocking]]
{
auto const y = 2.0f * x;

radsan_off();
i_know_this_method_is_realtime_safe_but_radsan_complains_about_it();
radsan_on();
}

*/
RADSAN_EXPORT void radsan_off();

/** Re-enable all RADSan error reporting.

The counterpart to `radsan_off`. See the description for `radsan_off` for
details about how to use this method.
*/
RADSAN_EXPORT void radsan_on();
}
Loading