30class MmapWriteExecChecker
31 :
public Checker<check::ASTDecl<TranslationUnitDecl>, check::PreCall> {
34 const BugType BT{
this,
"W^X check fails, Write Exec prot flags set",
38 mutable int ProtRead = 0x01;
39 mutable int ProtWrite = 0x02;
40 mutable int ProtExec = 0x04;
54 const std::optional<int> FoundProtWrite =
57 if (FoundProtRead && FoundProtWrite && FoundProtExec) {
58 ProtRead = *FoundProtRead;
59 ProtWrite = *FoundProtWrite;
60 ProtExec = *FoundProtExec;
66 if (matchesAny(
Call, MmapFn, MprotectFn)) {
71 int64_t Prot = ProtLoc->getValue().getSExtValue();
73 if ((Prot & ProtWrite) && (Prot & ProtExec)) {
78 auto Report = std::make_unique<PathSensitiveBugReport>(
80 "Both PROT_WRITE and PROT_EXEC flags are set. This can "
81 "lead to exploitable memory regions, which could be overwritten "
82 "with malicious code",
84 Report->addRange(
Call.getArgSourceRange(2));
85 C.emitReport(std::move(Report));
94bool ento::shouldRegisterMmapWriteExecChecker(
const CheckerManager &) {
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
The top declaration context.
Preprocessor & getPreprocessor() override
BugReporter is a utility class for generating PathDiagnostics for analysis.
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.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
Value representing integer constant.
std::optional< int > tryExpandAsInteger(StringRef Macro, const Preprocessor &PP)
Try to parse the value of a defined preprocessor macro.
The JSON file list parser is used to communicate input to InstallAPI.