-
Notifications
You must be signed in to change notification settings - Fork 149
Swift Taint Tests #592
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
base: development
Are you sure you want to change the base?
Swift Taint Tests #592
Changes from 19 commits
f41460c
3397f94
e068ca5
9fefb37
ec95a84
298061f
9b0c422
e0bbc70
cadc004
7df29d0
f4b8c9a
83d763a
eedd758
cfbfe70
1974ba9
494b053
41918e6
b5d9bef
1e6c03d
c709281
510e5f1
beecb60
23cd91f
948173a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/// a workaround here | ||
|
||
#ifndef HAS_MEMORY_RESOURCE | ||
#if !defined(__has_include) || __has_include(<memory_resource>) | ||
#if !defined(__has_include) || __has_include(<memory_resource>) && !defined(__APPLE__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably add a comment to describe why we exclude pmr on apple. Btw, are the feature-test macros |
||
#define HAS_MEMORY_RESOURCE 1 | ||
#include <memory_resource> | ||
#else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,23 +124,7 @@ IFDSTaintAnalysis::FlowFunctionPtrType IFDSTaintAnalysis::getNormalFlowFunction( | |
IFDSTaintAnalysis::n_t Curr, [[maybe_unused]] IFDSTaintAnalysis::n_t Succ) { | ||
// If a tainted value is stored, the store location must be tainted too | ||
if (const auto *Store = llvm::dyn_cast<llvm::StoreInst>(Curr)) { | ||
struct TAFF : FlowFunction<IFDSTaintAnalysis::d_t> { | ||
const llvm::StoreInst *Store; | ||
TAFF(const llvm::StoreInst *S) : Store(S){}; | ||
std::set<IFDSTaintAnalysis::d_t> | ||
computeTargets(IFDSTaintAnalysis::d_t Source) override { | ||
if (Store->getValueOperand() == Source) { | ||
return std::set<IFDSTaintAnalysis::d_t>{Store->getPointerOperand(), | ||
Source}; | ||
} | ||
if (Store->getValueOperand() != Source && | ||
Store->getPointerOperand() == Source) { | ||
return {}; | ||
} | ||
return {Source}; | ||
} | ||
}; | ||
return std::make_shared<TAFF>(Store); | ||
return strongUpdateStore(Store); | ||
} | ||
// If a tainted value is loaded, the loaded value is of course tainted | ||
if (const auto *Load = llvm::dyn_cast<llvm::LoadInst>(Curr)) { | ||
|
@@ -154,10 +138,13 @@ IFDSTaintAnalysis::FlowFunctionPtrType IFDSTaintAnalysis::getNormalFlowFunction( | |
// Check if a tainted value is extracted and taint the targets of | ||
// the extract operation accordingly | ||
if (const auto *Extract = llvm::dyn_cast<llvm::ExtractValueInst>(Curr)) { | ||
|
||
return generateFlow(Extract, Extract->getAggregateOperand()); | ||
} | ||
|
||
if (const auto *Insert = llvm::dyn_cast<llvm::InsertValueInst>(Curr)) { | ||
return generateFlow(Insert, Insert->getInsertedValueOperand()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also generate insert from |
||
} | ||
|
||
// Otherwise we do not care and leave everything as it is | ||
return Identity<IFDSTaintAnalysis::d_t>::getInstance(); | ||
} | ||
|
@@ -290,7 +277,6 @@ IFDSTaintAnalysis::getSummaryFlowFunction( | |
// result should be tainted | ||
if (DestFun->getName().equals("$sSS1poiyS2S_SStFZ")) { | ||
const auto *CS = llvm::cast<llvm::CallBase>(CallSite); | ||
|
||
return generateFlowIf<d_t>(CallSite, [CS](d_t Source) { | ||
return ((Source == CS->getArgOperand(1)) || | ||
(Source == CS->getArgOperand(3))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(linear_constant) | ||
add_subdirectory(taint_analysis) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
file(GLOB lca_files *.swift) | ||
|
||
set(SWIFT_COMPILE_IR_FLAGS -emit-ir -suppress-warnings -g -parse-as-library -Onone -Xfrontend -disable-llvm-optzns -Xfrontend -disable-swift-specific-llvm-optzns) | ||
set(SWIFT_COMPILE_IR_FLAGS -emit-ir -suppress-warnings -g -parse-as-library -Onone) | ||
|
||
foreach(TEST_SRC ${lca_files}) | ||
get_filename_component(TEST_SRC_FILE ${TEST_SRC} NAME_WE) | ||
add_executable(${TEST_SRC_FILE}.ll ${TEST_SRC}) | ||
target_compile_options(${TEST_SRC_FILE}.ll PRIVATE ${SWIFT_COMPILE_IR_FLAGS}) | ||
set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SRC_FILE}.ll") | ||
add_custom_command( | ||
OUTPUT ${TEST_OUTPUT} | ||
COMMAND swiftc ${SWIFT_COMPILE_IR_FLAGS} -o ${TEST_OUTPUT} ${TEST_SRC} | ||
DEPENDS ${TEST_SRC} | ||
) | ||
add_custom_target(${TEST_SRC_FILE} DEPENDS ${TEST_OUTPUT}) | ||
add_dependencies(PhasarUnitTests ${TEST_SRC_FILE}) | ||
endforeach(TEST_SRC) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@main | ||
struct MyMain { | ||
static func main() { | ||
var i = CommandLine.arguments.count | ||
var i = CommandLine.arguments.count | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
|
||
@main | ||
struct MyMain { | ||
static func main() { | ||
var a = 0 | ||
for i in 0...9 { | ||
a += i | ||
} | ||
var a = 0 | ||
for i in 0...9 { | ||
a += i | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var y = 42 | ||
@main | ||
struct MyMain { | ||
static func main() { | ||
y += 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ var g = 10 | |
@main | ||
struct MyMain { | ||
static func main() { | ||
var i = g | ||
i -= 20 | ||
g = i | ||
var i = g | ||
i -= 20 | ||
g = i | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these flags have to be env variables? Or can they also be supplied to cmake directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we could do is define it as a default variable in cmake and users could change it with a cmake flag like
-DPathToLLVM=/my/custom/llvm/install/llvm@14
I think this could make sense.