Skip to content

Commit 7d0e60c

Browse files
authored
Merge pull request #6476 from trailofbits/fix_docker_jq
Fixes `jq` docker example
2 parents 01eb572 + 183f354 commit 7d0e60c

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

examples/Dockerfile-jq.demo

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
FROM trailofbits/polytracker
2-
MAINTAINER Evan Sultanik <[email protected]>
1+
FROM trailofbits/polytracker:latest
2+
LABEL org.opencontainers.image.authors="[email protected]"
33

44
WORKDIR /polytracker/the_klondike
55

6-
#ENV CC=clang
7-
#ENV CXX=clang++
6+
RUN apt-get update && apt-get install -y flex bison libtool make automake autoconf build-essential
87

9-
RUN apt-get update && apt-get install -y flex bison libtool make automake autoconf
10-
11-
RUN git clone https://github.com/stedolan/jq.git
8+
RUN git clone --recursive https://github.com/stedolan/jq.git
129

1310
WORKDIR /polytracker/the_klondike/jq
14-
15-
RUN git submodule update --init
1611
RUN autoreconf -fi
17-
RUN ./configure --with-oniguruma=builtin --disable-valgrind --enable-all-static --prefix=/usr/local \
18-
CFLAGS="-DNDEBUG" LDFLAGS=-all-static
19-
RUN make LDFLAGS=-all-static -j`nproc`
20-
# && make check
21-
RUN get-bc -b jq && ${CC} --lower-bitcode -i jq.bc -o jq_track --libs m && mv jq_track /usr/local/bin/jq
22-
23-
# Note, the /workdir directory is intended to be mounted at runtime
24-
VOLUME ["/workdir"]
25-
WORKDIR /workdir
12+
RUN ./configure --with-oniguruma=builtin CC=clang
13+
RUN polytracker build make -j$((`nproc`+1))
14+
RUN polytracker instrument-targets jq

polytracker/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ def _instrument_bitcode(
187187
for item in ignore_lists:
188188
cmd.append(f"-dfsan-abilist={ABI_PATH}/{item}")
189189

190+
cmd.append("-fn_attr_remove")
191+
190192
cmd += [str(input_bitcode), "-o", str(output_bitcode)]
191193
subprocess.check_call(cmd)
192194

polytracker/include/polytracker/polytracker_pass.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ struct PolytrackerPass : public llvm::ModulePass,
6767
std::unordered_map<std::string, bool> ignore_funcs;
6868
};
6969

70+
struct FnAttrRemovePass : public llvm::ModulePass,
71+
public llvm::InstVisitor<FnAttrRemovePass> {
72+
static char ID;
73+
FnAttrRemovePass() : ModulePass(ID) {}
74+
bool runOnModule(llvm::Module &module) override;
75+
void visitCallInst(llvm::CallInst &ci);
76+
};
77+
7078
}; // namespace polytracker
7179

7280
#endif /* POLYTRACKER_INCLUDE_POLYTRACKER_PASS_H_ */

polytracker/src/passes/polytracker_pass.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,44 @@ bool PolytrackerPass::runOnModule(llvm::Module &mod) {
668668

669669
char PolytrackerPass::ID = 0;
670670

671+
void FnAttrRemovePass::visitCallInst(llvm::CallInst &ci) {
672+
auto fn = ci.getCalledFunction();
673+
if (!fn) {
674+
return;
675+
}
676+
auto fname = fn->getName();
677+
if (fname.startswith("__dfsw") || fname.startswith("dfs$")) {
678+
ci.removeAttribute(llvm::AttributeList::FunctionIndex,
679+
llvm::Attribute::InaccessibleMemOnly);
680+
ci.removeAttribute(llvm::AttributeList::FunctionIndex,
681+
llvm::Attribute::InaccessibleMemOrArgMemOnly);
682+
ci.removeAttribute(llvm::AttributeList::FunctionIndex,
683+
llvm::Attribute::ReadOnly);
684+
}
685+
}
686+
687+
bool FnAttrRemovePass::runOnModule(llvm::Module &module) {
688+
for (auto &fn : module) {
689+
auto fname = fn.getName();
690+
if (fname.startswith("__dfsw") || fname.startswith("dfs$")) {
691+
fn.removeFnAttr(llvm::Attribute::InaccessibleMemOnly);
692+
fn.removeFnAttr(llvm::Attribute::InaccessibleMemOrArgMemOnly);
693+
fn.removeFnAttr(llvm::Attribute::ReadOnly);
694+
}
695+
visit(fn);
696+
}
697+
return false;
698+
}
699+
700+
char FnAttrRemovePass::ID = 0;
701+
671702
}; // namespace polytracker
672703

673704
static llvm::RegisterPass<polytracker::PolytrackerPass>
674705
X("ptrack", "Adds runtime monitoring calls to polytracker runtime",
675706
false /* Only looks at CFG */, false /* Analysis Pass */);
707+
708+
static llvm::RegisterPass<polytracker::FnAttrRemovePass>
709+
Y("fn_attr_remove",
710+
"Removes memory-related function attributes from dfsan wrappers",
711+
false /* Only looks at CFG */, false /* Analysis Pass */);

0 commit comments

Comments
 (0)