Skip to content

Commit cb93ddf

Browse files
committed
Complete PDG build revert
1 parent 0f292a9 commit cb93ddf

6 files changed

Lines changed: 22 additions & 53 deletions

File tree

include/ProgramDependencyGraph.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "Graph.hh"
55
#include "PDGCallGraph.hh"
66
#include "DataDependencyGraph.hh"
7-
// #include "ControlDependencyGraph.hh"
7+
#include "ControlDependencyGraph.hh"
88

99
namespace pdg
1010
{

src/DataAccessAnalysis.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool pdg::DataAccessAnalysis::runOnModule(Module &M)
3939
_module = &M;
4040
_SDA = &getAnalysis<SharedDataAnalysis>();
4141
_PDG = _SDA->getPDG();
42-
_callGraph = &PDGCallGraph::getInstance();
42+
_callGraph = &PDGCallGraph::getInstance();;
4343
_ksplitStats = &KSplitStats::getInstance();
4444
computeExportedFuncsPtrNameMap();
4545
readDriverDefinedGlobalVarNames("driver_globalvar_names");
@@ -65,8 +65,8 @@ bool pdg::DataAccessAnalysis::runOnModule(Module &M)
6565
// compute data access for function arguments, used later for IDL generation
6666
computeDataAccessForFuncArgs(F);
6767
// generate json object for eBPF enforcement
68-
if (_PDG->interfaceFuncs.find(f) != _PDG->interfaceFuncs.end())
69-
generateJSONObjectForFunc(F, moduleJsonObj);
68+
// if (_PDG->interfaceFuncs.find(f) != _PDG->interfaceFuncs.end())
69+
// generateJSONObjectForFunc(F, moduleJsonObj);
7070
total_num_funcs++;
7171
}
7272

@@ -1007,11 +1007,14 @@ void pdg::DataAccessAnalysis::computeDataAccessForFuncArgs(Function &F)
10071007
auto argRetTree = fw->getRetFormalInTree();
10081008
computeDataAccessForTree(argRetTree, true);
10091009
// compute arg access info
1010-
auto argTreeMap = fw->getArgFormalInTreeMap();
1011-
for (auto iter = argTreeMap.begin(); iter != argTreeMap.end(); iter++)
1010+
auto argFormalTreeMap = fw->getArgFormalInTreeMap();
1011+
for (auto iter = argFormalTreeMap.begin(); iter != argFormalTreeMap.end(); iter++)
10121012
{
10131013
Tree *argTree = iter->second;
10141014
computeDataAccessForTree(argTree);
1015+
// auto arg = iter->first;
1016+
// if (arg->getType()->isFunctionTy())
1017+
// errs() << "find function type in " << F.getName() << "\n";
10151018
}
10161019
}
10171020

@@ -1596,6 +1599,8 @@ void pdg::DataAccessAnalysis::generateRpcForFunc(Function &F, bool processExport
15961599
{
15971600
// need to use this wrapper to handle nescheck rewrittern funcs
15981601
FunctionWrapper *fw = getNescheckFuncWrapper(F);
1602+
if (fw == nullptr)
1603+
return;
15991604
std::string rpcStr = "";
16001605
// generate function rpc stub
16011606
// first generate for return value
@@ -1750,6 +1755,8 @@ void pdg::DataAccessAnalysis::generateIDLForFunc(Function &F, bool processingExp
17501755
// assert(func_iter != func_wrapper_map.end() && "no function wrapper found (IDL-GEN)!");
17511756
// auto fw = func_iter->second;
17521757
FunctionWrapper *fw = getNescheckFuncWrapper(F);
1758+
if (fw == nullptr)
1759+
return;
17531760
// process exported funcs later in special manner because of syntax requirement
17541761
if (isExportedFunc(F) && !processingExportedFunc)
17551762
{

src/DataDependencyGraph.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ char pdg::DataDependencyGraph::ID = 0;
77
// cl::opt<bool, true> SFA("sf", cl::desc("enable mode for analyzing only one function"), cl::value_desc("single-func"), cl::location(pdg::SingleFuncAnalysis), cl::init(false));
88
// cl::opt<std::string> TargetFuncName("tf", cl::desc("Target function to analyze"), cl::value_desc("string"), cl::location(pdg::TargetFuncNameStr));
99

10-
// specify interface function
11-
cl::opt<std::string> InterfaceFuncsPath("ifuncs",
12-
cl::desc("Specify the path of the instrumented binary"),
13-
cl::value_desc("target bin path to instrument"),
14-
cl::init(""));
15-
1610
bool pdg::DataDependencyGraph::runOnModule(Module &M)
1711
{
1812
_module = &M;
@@ -31,29 +25,16 @@ bool pdg::DataDependencyGraph::runOnModule(Module &M)
3125

3226
ProgramGraph &g = ProgramGraph::getInstance();
3327

34-
// read interface functions
35-
std::ifstream file(InterfaceFuncsPath);
36-
if (file.good())
37-
{
38-
pdgutils::readLinesFromFile(g.iFuncNames, InterfaceFuncsPath);
39-
file.close();
40-
}
41-
else
42-
{
43-
std::cerr << "File not found: " << InterfaceFuncsPath << std::endl;
44-
return false;
45-
}
46-
4728
if (!g.isBuild())
4829
{
4930
// setup the interface functions for PDG build
5031
g.build(M);
5132
g.bindDITypeToNodes(M);
5233
}
5334

54-
for (auto f : g.funcToBuild)
35+
// for (auto f : g.funcToBuild)
36+
for (auto &F : M)
5537
{
56-
Function &F = *f;
5738
if (F.isDeclaration() || F.empty())
5839
continue;
5940

src/Graph.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,6 @@ void pdg::ProgramGraph::build(Module &M)
227227
{
228228
auto &call_g = PDGCallGraph::getInstance();
229229
// setup functions to build
230-
for (auto fName : iFuncNames)
231-
{
232-
auto func = M.getFunction(StringRef(fName));
233-
interfaceFuncs.insert(func);
234-
auto callNode = call_g.getNode(*func);
235-
auto transFuncNodes = call_g.computeTransitiveClosure(*callNode);
236-
for (auto n : transFuncNodes)
237-
{
238-
if (!n->getValue())
239-
continue;
240-
if (auto f = dyn_cast<Function>(n->getValue()))
241-
funcToBuild.insert(f);
242-
}
243-
}
244-
245230
buildGlobalVariables(M);
246231
buildFunctions(M);
247232
buildCallGraphAndCallSites(M);
@@ -274,9 +259,8 @@ void pdg::ProgramGraph::buildGlobalVariables(Module &M)
274259

275260
void pdg::ProgramGraph::buildFunctions(Module &M)
276261
{
277-
for (auto f : funcToBuild)
262+
for (auto &F : M)
278263
{
279-
Function &F = *f;
280264
if (F.isDeclaration() || F.empty())
281265
continue;
282266
FunctionWrapper *func_w = new FunctionWrapper(&F);
@@ -311,12 +295,10 @@ void pdg::ProgramGraph::buildFunctionInstructions(Function &F, FunctionWrapper *
311295

312296
void pdg::ProgramGraph::buildCallGraphAndCallSites(Module &M)
313297
{
314-
for (auto func : funcToBuild)
298+
for (auto &F : M)
315299
{
316-
Function &F = *func;
317300
if (F.isDeclaration() || F.empty() || !hasFuncWrapper(F))
318301
continue;
319-
320302
FunctionWrapper *func_w = getFuncWrapper(F);
321303
auto call_insts = func_w->getCallInsts();
322304

@@ -349,9 +331,8 @@ void pdg::ProgramGraph::handleCallSites(Module &M, CallInst *ci)
349331

350332
void pdg::ProgramGraph::bindDITypeToNodes(Module &M)
351333
{
352-
for (auto f : funcToBuild)
334+
for (auto &F : M)
353335
{
354-
Function &F = *f;
355336
if (F.isDeclaration())
356337
continue;
357338
FunctionWrapper *fw = _func_wrapper_map[&F];

src/ProgramDependencyGraph.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool pdg::DEBUG;
1515
void pdg::ProgramDependencyGraph::getAnalysisUsage(AnalysisUsage &AU) const
1616
{
1717
AU.addRequired<DataDependencyGraph>();
18-
// AU.addRequired<ControlDependencyGraph>();
18+
AU.addRequired<ControlDependencyGraph>();
1919
AU.setPreservesAll();
2020
}
2121

@@ -48,9 +48,8 @@ bool pdg::ProgramDependencyGraph::runOnModule(Module &M)
4848
}
4949

5050
unsigned func_size = 0;
51-
for (auto f : _PDG->funcToBuild)
51+
for (Function &F : M)
5252
{
53-
Function &F = *f;
5453
if (F.isDeclaration() || !_PDG->hasFuncWrapper(F))
5554
continue;
5655
// if (!call_g.isBuildFuncNode(F))
@@ -206,7 +205,7 @@ void pdg::ProgramDependencyGraph::connectCallerAndCallee(CallWrapper &cw, Functi
206205
void pdg::ProgramDependencyGraph::connectIntraprocDependencies(Function &F)
207206
{
208207
// add control dependency edges
209-
// getAnalysis<ControlDependencyGraph>(F); // add data dependencies for nodes in F
208+
getAnalysis<ControlDependencyGraph>(F); // add data dependencies for nodes in F
210209
// connect formal tree with address variables
211210
FunctionWrapper *func_w = getFuncWrapper(F);
212211
Node *entry_node = func_w->getEntryNode();

src/RiskyBoundaryAPIAnalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ void pdg::RiskyBoundaryAPIAnalysis::analyzeRiskyBoundaryKernelAPIs(nlohmann::ord
257257
unsigned caseID = 0;
258258

259259
auto kernelFuncCalledUnderConditions = computeKernelInterfaceFuncCSUnderCondition();
260+
errs() << "size of kernel interface call under condition: " << kernelFuncCalledUnderConditions.size() << "\n";
260261
for (auto boundaryFunc : kernelFuncCalledUnderConditions)
261262
{
262263
// only analyze kernel boundary functions

0 commit comments

Comments
 (0)