30enum Kind { NO_CHROOT, ROOT_CHANGED, JAIL_ENTERED };
32bool isRootChanged(
intptr_t k) {
return k == ROOT_CHANGED; }
42class ChrootChecker :
public Checker<eval::Call, check::PreCall> {
44 mutable std::unique_ptr<BugType> BT_BreakJail;
51 static void *getTag() {
67 if (Chroot.matches(
Call)) {
71 if (Chdir.matches(
Call)) {
85 state = Mgr.
addGDM(state, ChrootChecker::getTag(), (
void*) ROOT_CHANGED);
86 C.addTransition(state);
94 const void *k = state->FindGDM(ChrootChecker::getTag());
99 const Expr *ArgExpr =
Call.getArgExpr(0);
100 SVal ArgVal =
C.getSVal(ArgExpr);
104 if (
const StringRegion* StrRegion= dyn_cast<StringRegion>(R)) {
107 state = Mgr.
addGDM(state, ChrootChecker::getTag(),
108 (
void*) JAIL_ENTERED);
112 C.addTransition(state);
119 if (matchesAny(
Call, Chroot, Chdir))
123 void *
const* k =
C.getState()->FindGDM(ChrootChecker::getTag());
128 BT_BreakJail.reset(
new BugType(
this,
"Break out of jail"));
129 constexpr llvm::StringLiteral Msg =
130 "No call of chdir(\"/\") immediately after chroot";
132 std::make_unique<PathSensitiveBugReport>(*BT_BreakJail, Msg, N));
140bool ento::shouldRegisterChrootChecker(
const CheckerManager &mgr) {
This represents one expression.
StringLiteral - This represents a string literal expression, e.g.
StringRef getString() const
This class represents a description of a function call using the number of arguments and the name of ...
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
MemRegion - The root abstract class for all memory regions.
ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
const MemRegion * getAsRegion() const
StringRegion - Region associated with a StringLiteral.
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...