This is an archive of the discontinued LLVM Phabricator instance.

[clang][analyzer]Fix non-effective taint sanitation
ClosedPublic

Authored by dkrupp on Jul 20 2023, 8:12 AM.

Details

Summary

There was a bug in alpha.security.taint.TaintPropagation checker in Clang Static Analyzer.
Taint filtering could only sanitize const arguments.
After this patch, taint filtering is effective also on non-const parameters.

Diff Detail

Event Timeline

dkrupp created this revision.Jul 20 2023, 8:12 AM
Herald added a project: Restricted Project. · View Herald Transcript
dkrupp requested review of this revision.Jul 20 2023, 8:12 AM
steakhal added inline comments.Jul 20 2023, 9:35 AM
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
970

Is it only a formatting hunk?
I cannot really tell from my phone xd

996

"a a" -> "a"

1001

Why do we need this extra condition?

clang/test/Analysis/taint-generic.c
1014

Can you add a case where the parameter points to const?

1057

Wouldn't it make more sense if depending on the return value of this filter we early return like in the previous examples?

dkrupp updated this revision to Diff 542619.Jul 20 2023, 11:46 AM
dkrupp marked 3 inline comments as done.

-typo fixed in comment

@steakhal thanks for the review. I addressed/answered your comments.

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
970

yeap. formatting only.

970

Yes. Only formatting.

1001

That's the heart of the fix.

In case we are processing a filter rule, tthe PropDstArgs is empty. Then this part this part without the extra condition put the taintedness back to every pointed to non-const parameter. This is clearly an unwanted behaviour. See also the extra comment.

clang/test/Analysis/taint-generic.c
1014

The previous isOutOfRange(const int*) case is testing the sanitizing when we have a pointer to const.

1057

This test case simulates the case when the buffer is passed by reference and the sanitize command actually changes the contents of the buffer. For example removes shell escapes etc.

dkrupp marked 3 inline comments as not done.Jul 20 2023, 12:40 PM
steakhal accepted this revision.Jul 20 2023, 12:40 PM

Approved, modulo formatting hunks.
Unless you have really good reasons for having them as well.

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
970

I would suggest not mixing formatting changes with semantic changes in a single revision. Consider not doing the formatting, or at least format in a different revision.

Adding and updating comments are fine.

1001

Makes sense. It actually closely follows how we deal with sinks.

clang/test/Analysis/taint-generic.c
1014

Thanks. Good.

1057

Then have a void return type for it please.

This revision is now accepted and ready to land.Jul 20 2023, 12:40 PM
This revision was landed with ongoing or failed builds.Jul 21 2023, 6:11 AM
This revision was automatically updated to reflect the committed changes.
dkrupp marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2023, 6:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dkrupp updated this revision to Diff 542903.Jul 21 2023, 7:11 AM

-formatting issues fixed
-sanitizecCmd changed to void

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
970

Yes. I realized. I reverted the formatting change.

Thanks, all good!