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 const BugType BT_BreakJail{
this,
"Break out of jail"};
47 Chdir{CDM::CLibrary, {
"chdir"}, 1};
52 static void *getTag() {
68 if (Chroot.matches(
Call)) {
72 if (Chdir.matches(
Call)) {
86 state = Mgr.
addGDM(state, ChrootChecker::getTag(), (
void*) ROOT_CHANGED);
87 C.addTransition(state);
95 const void *k = state->FindGDM(ChrootChecker::getTag());
100 const Expr *ArgExpr =
Call.getArgExpr(0);
101 SVal ArgVal =
C.getSVal(ArgExpr);
105 if (
const StringRegion* StrRegion= dyn_cast<StringRegion>(R)) {
108 state = Mgr.
addGDM(state, ChrootChecker::getTag(),
109 (
void*) JAIL_ENTERED);
113 C.addTransition(state);
120 if (matchesAny(
Call, Chroot, Chdir))
124 void *
const* k =
C.getState()->FindGDM(ChrootChecker::getTag());
128 constexpr llvm::StringLiteral Msg =
129 "No call of chdir(\"/\") immediately after chroot";
131 std::make_unique<PathSensitiveBugReport>(BT_BreakJail, Msg, N));
139bool ento::shouldRegisterChrootChecker(
const CheckerManager &mgr) {
This represents one expression.
StringLiteral - This represents a string literal expression, e.g.
StringRef getString() const
A CallDescription is a pattern that can be used to match calls based on the qualified name and the ar...
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.
The JSON file list parser is used to communicate input to InstallAPI.
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...