-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[analyzer] Split TaintPropagation checker into reporting and modeling checkers #98157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7567541
97e36db
cb6b539
37e50af
4456f02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" | ||
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/YAMLTraits.h" | ||
|
||
#include <limits> | ||
|
@@ -391,9 +392,10 @@ class GenericTaintChecker : public Checker<check::PreCall, check::PostCall> { | |
bool generateReportIfTainted(const Expr *E, StringRef Msg, | ||
CheckerContext &C) const; | ||
|
||
private: | ||
const BugType BT{this, "Use of Untrusted Data", categories::TaintedData}; | ||
bool isTaintReporterCheckerEnabled = false; | ||
std::optional<BugType> BT; | ||
|
||
private: | ||
bool checkUncontrolledFormatString(const CallEvent &Call, | ||
CheckerContext &C) const; | ||
|
||
|
@@ -1033,20 +1035,23 @@ bool GenericTaintRule::UntrustedEnv(CheckerContext &C) { | |
bool GenericTaintChecker::generateReportIfTainted(const Expr *E, StringRef Msg, | ||
CheckerContext &C) const { | ||
assert(E); | ||
if (!isTaintReporterCheckerEnabled) | ||
return false; | ||
std::optional<SVal> TaintedSVal = | ||
getTaintedPointeeOrPointer(C.getState(), C.getSVal(E)); | ||
|
||
if (!TaintedSVal) | ||
return false; | ||
|
||
// Generate diagnostic. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Perhaps add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are there, maybe we should also assert that inside the register call, before emplacing it was empty. |
||
if (ExplodedNode *N = C.generateNonFatalErrorNode()) { | ||
auto report = std::make_unique<PathSensitiveBugReport>(BT, Msg, N); | ||
assert(BT); | ||
static CheckerProgramPointTag Tag(BT->getCheckerName(), Msg); | ||
if (ExplodedNode *N = C.generateNonFatalErrorNode(C.getState(), &Tag)) { | ||
auto report = std::make_unique<PathSensitiveBugReport>(*BT, Msg, N); | ||
report->addRange(E->getSourceRange()); | ||
for (auto TaintedSym : getTaintedSymbols(C.getState(), *TaintedSVal)) { | ||
report->markInteresting(TaintedSym); | ||
} | ||
|
||
C.emitReport(std::move(report)); | ||
return true; | ||
} | ||
|
@@ -1122,10 +1127,21 @@ void GenericTaintChecker::taintUnsafeSocketProtocol(const CallEvent &Call, | |
} | ||
|
||
/// Checker registration | ||
void ento::registerGenericTaintChecker(CheckerManager &Mgr) { | ||
void ento::registerTaintPropagationChecker(CheckerManager &Mgr) { | ||
Mgr.registerChecker<GenericTaintChecker>(); | ||
} | ||
|
||
bool ento::shouldRegisterTaintPropagationChecker(const CheckerManager &mgr) { | ||
return true; | ||
} | ||
|
||
void ento::registerGenericTaintChecker(CheckerManager &Mgr) { | ||
GenericTaintChecker *checker = Mgr.getChecker<GenericTaintChecker>(); | ||
checker->isTaintReporterCheckerEnabled = true; | ||
checker->BT.emplace(Mgr.getCurrentCheckerName(), "Use of Untrusted Data", | ||
categories::TaintedData); | ||
} | ||
|
||
bool ento::shouldRegisterGenericTaintChecker(const CheckerManager &mgr) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit strange that the
TaintPropagation
checker is hidden from the user and e.g. it doesn't have a documentation, but it still mentioned on this page and it still appears in the name ofalpha.security.taint.TaintPropagation:Config
.I don't think that this is a blocking issue for this commit, but I think that it would be important to resolve this in the future. I can imagine two main solutions:
TaintPropagation
and convertalpha.security.taint.TaintPropagation:Config
into an option of the analyzer itself.@haoNoQ @Xazax-hun @steakhal What do you think about this? Which direction would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd prefer accepting modeling checkers as a thing and have configs for them. I'd rather not make this as an option to the analyzer itself.