Skip to content

Commit 2effa76

Browse files
committed
Added new control flow sanitizer option
Updated both the sanitizer file for adding the flag and the README.
1 parent 774a07e commit 2effa76

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ A quick rundown of the tools available, and what they do:
8484
- Division by zero
8585
- Unreachable code
8686
- [MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html) detects uninitialized reads.
87+
- [Control Flow Integrity](https://clang.llvm.org/docs/ControlFlowIntegrity.html) is designed to detect certain forms of undefined behaviour that can potentially allow attackers to subvert the program's control flow.
8788

8889
These are used by declaring the `USE_SANITIZER` CMake variable as string containing any of:
8990
- Address
@@ -92,6 +93,7 @@ These are used by declaring the `USE_SANITIZER` CMake variable as string contain
9293
- Undefined
9394
- Thread
9495
- Leak
96+
- CFI
9597

9698
Multiple values are allowed, e.g. `-DUSE_SANITIZER=Address,Leak` but some sanitizers cannot be combined together, e.g.`-DUSE_SANITIZER=Address,Memory` will result in configuration error. The delimeter character is not required and `-DUSE_SANITIZER=AddressLeak` would work as well.
9799

sanitizers.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2018 by George Cave - [email protected]
2+
# Copyright (C) 2018-2022 by George Cave - [email protected]
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
# use this file except in compliance with the License. You may obtain a copy of
@@ -19,7 +19,7 @@ set(USE_SANITIZER
1919
""
2020
CACHE
2121
STRING
22-
"Compile with a sanitizer. Options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'"
22+
"Compile with a sanitizer. Options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined', CFI"
2323
)
2424

2525
function(append value)
@@ -126,6 +126,18 @@ if(USE_SANITIZER)
126126
endif()
127127
endif()
128128

129+
if(USE_SANITIZER MATCHES "([Cc][Ff][Ii])")
130+
message(STATUS "Testing with Control Flow Integrity(CFI) sanitizer")
131+
set(SANITIZER_CFI_FLAG "-fsanitize=cfi")
132+
test_san_flags(SANITIZER_CFI_AVAILABLE ${SANITIZER_CFI_FLAG})
133+
if (SANITIZER_CFI_AVAILABLE)
134+
message(STATUS " Building with Control Flow Integrity(CFI) sanitizer")
135+
append("${SANITIZER_LEAK_FLAG}" SANITIZER_SELECTED_FLAGS)
136+
else()
137+
message(FATAL_ERROR "Control Flow Integrity(CFI) sanitizer not available for ${CMAKE_CXX_COMPILER}")
138+
endif()
139+
endif()
140+
129141
message(STATUS "Sanitizer flags: ${SANITIZER_SELECTED_FLAGS}")
130142
test_san_flags(SANITIZER_SELECTED_COMPATIBLE ${SANITIZER_SELECTED_FLAGS})
131143
if (SANITIZER_SELECTED_COMPATIBLE)

0 commit comments

Comments
 (0)