Skip to content

Can Phasar be used to identify control-dependent instructions #685

@Mohannadcse

Description

@Mohannadcse

I'm using phasar taint analysis to identify data-dependent and control-dependent instructions on argv.

psr::IDEExtendedTaintAnalysis<1, false> TaintAnalysis(&IR, &T, &I, &P,
                                                          Config);
    TaintAnalysis.setIFDSIDESolverConfig(SolverConfig);
    std::stringstream SolverConfigStr;
    SolverConfigStr << "Using solver config: "
                    << TaintAnalysis.getIFDSIDESolverConfig() << '\n';
    llvm::outs() << SolverConfigStr.str();
    psr::IDESolver Solver(TaintAnalysis);
    llvm::outs() << "Solving data-flow analysis ...\n";
    Solver.solve();
    llvm::outs() << "Data-flow analysis has been solved.\n";
   
    auto SolverRes = Solver.getSolverResults();
    auto AllResEntries = SolverRes.getAllResultEntries();

    for (auto &Res : AllResEntries) {
      const llvm::Instruction *Inst = Res.getRowKey();
      auto ResAtInst = SolverRes.resultsAt(Inst);
     
      for ([[maybe_unused]] const auto &Op : Inst->operands()) {
        for (auto &[Fact, Value] : ResAtInst) {
          llvm::Value *PotentialGepPointerOp = nullptr;
          if (auto *Gep = llvm::dyn_cast<llvm::GetElementPtrInst>(Op)) {
            PotentialGepPointerOp = Gep->getPointerOperand();
          }
          if (Op == Fact->base() || (PotentialGepPointerOp &&
                                     PotentialGepPointerOp == Fact->base())) {
            NeckCandidates.push_back(
                const_cast<llvm::Instruction *>(Inst)); // NOLINT ;-)
          }
        }
      }

The IDESolver results are as follows:

***************************************************************
*                  Raw IDESolver results                      *
***************************************************************


============ Results for function '__psrCRuntimeGlobalCtorsModel' ============


N: ret void | ID: -1
--------------------
	D: (<ZERO>; Offsets={ } #0) | V: Top


N: call void @__psrCRuntimeGlobalDtorsModel() | ID: -1
------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Top


============ Results for function 'main' ============


N: %3 = alloca i32, align 4, !psr.id !20 | ID: 124
--------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %4 = alloca i32, align 4, !psr.id !21 | ID: 125
--------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %5 = alloca i8**, align 8, !psr.id !22 | ID: 126
---------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %6 = alloca i32, align 4, !psr.id !23 | ID: 127
--------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %7 = alloca i32, align 4, !psr.id !24 | ID: 128
--------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %8 = alloca i32, align 4, !psr.id !25 | ID: 129
--------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %9 = alloca i32, align 4, !psr.id !26 | ID: 130
--------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %10 = alloca i32, align 4, !psr.id !27 | ID: 131
---------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %11 = alloca [1024 x i8], align 16, !psr.id !28 | ID: 132
------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: store i32 0, i32* %3, align 4, !psr.id !29 | ID: 133
-------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: store i32 %0, i32* %4, align 4, !psr.id !30 | ID: 134
--------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: store i8** %1, i8*** %5, align 8, !psr.id !34 | ID: 136
----------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: store i32 0, i32* %6, align 4, !dbg !39, !psr.id !41 | ID: 139
-----------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: store i32 0, i32* %7, align 4, !dbg !43, !psr.id !45 | ID: 141
-----------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: store i32 0, i32* %8, align 4, !dbg !47, !psr.id !49 | ID: 143
-----------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: store i32 0, i32* %9, align 4, !dbg !51, !psr.id !53 | ID: 145
-----------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: store i32 1, i32* %10, align 4, !dbg !56, !psr.id !58 | ID: 147
------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: br label %12, !dbg !59, !psr.id !60 | ID: 148
------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %13 = load i32, i32* %10, align 4, !dbg !61, !psr.id !63 | ID: 149
---------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: %14 = load i32, i32* %4, align 4, !dbg !64, !psr.id !65 | ID: 150
--------------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %15 = icmp slt i32 %13, %14, !dbg !66, !psr.id !67 | ID: 151
---------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: br i1 %15, label %16, label %51, !dbg !68, !psr.id !69 | ID: 152
-------------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %17 = load i8**, i8*** %5, align 8, !dbg !70, !psr.id !73 | ID: 153
----------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: %18 = load i32, i32* %10, align 4, !dbg !74, !psr.id !75 | ID: 154
---------------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %19 = sext i32 %18 to i64, !dbg !70, !psr.id !76 | ID: 155
-------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %20 = getelementptr inbounds i8*, i8** %17, i64 %19, !dbg !70, !psr.id !77 | ID: 156
---------------------------------------------------------------------------------------
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %21 = load i8*, i8** %20, align 8, !dbg !70, !psr.id !78 | ID: 157
---------------------------------------------------------------------
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %22 = getelementptr inbounds i8, i8* %21, i64 0, !dbg !70, !psr.id !79 | ID: 158
-----------------------------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom


N: %23 = load i8, i8* %22, align 1, !dbg !70, !psr.id !80 | ID: 159
-------------------------------------------------------------------
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %24 = sext i8 %23 to i32, !dbg !70, !psr.id !81 | ID: 160
------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %25 = icmp eq i32 %24, 45, !dbg !82, !psr.id !83 | ID: 161
-------------------------------------------------------------
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom



N: br i1 %25, label %26, label %45, !dbg !84, !psr.id !85 | ID: 162
-------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized


N: %27 = load i8**, i8*** %5, align 8, !dbg !86, !psr.id !88 | ID: 163
----------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %28 = load i32, i32* %10, align 4, !dbg !89, !psr.id !90 | ID: 164
---------------------------------------------------------------------
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


N: %29 = sext i32 %28 to i64, !dbg !86, !psr.id !91 | ID: 165
-------------------------------------------------------------
	D: (i8*** %5 | ID: 126; Offsets={ 0 } #0) | V: NotSanitized
	D: (<ZERO>; Offsets={ } #0) | V: Bottom
	D: (i8** %1 | ID: main.1; Offsets={ 0 } #0) | V: NotSanitized


how to interpret IDESolver raw results to identify control-dependent instructions. For example, N: %17 = load i8**, i8*** %5, align 8, !dbg !70, !psr.id !73 | ID: 153 uses %5 = alloca i8**, align 8, !psr.id !22 | ID: 126, which uses argv, but how can I determine that %25 = icmp eq i32 %24, 45, !dbg !82, !psr.id !83 | ID: 161 is also depends on %17?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions