-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CPP: Add query for CWE-14 compiler removal of code to clear buffers. #4953
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
Conversation
|
Thanks for the submission. We'll find a reviewer. |
MathiasVP
left a comment
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.
Thanks for your contribution! This is indeed a problem that is worthy of a CodeQL query :)
I've attached the first round of review comments. If anything is unclear please let me know.
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.c
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.c
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.c
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.c
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-14/CompilerRemovalOfCodeToClearBuffers.ql
Show resolved
Hide resolved
|
thanks for your corrections. |
…odeToClearBuffers.ql Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.ql Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.c Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.c Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.c Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.c Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.ql Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.qhelp Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.qhelp Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
…odeToClearBuffers.ql Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
|
@ihsinme a small tip that also helped me: |
|
All these** commits have only one change. To do that, you would go to https://github.com/github/codeql/pull/4953/files and click on "Add suggestion to batch" for every suggestion as seen in step 3.2 ħere. Hope this is better to understand :) |
|
I cannot see what is the cause of the error. |
|
The error message is |
|
Thank you. |
I've restarted it now. |
|
but unfortunately the error has not gone away. |
Thanks for looking at the problem. I'll take a look at it later today. |
|
sorry Sorry sorry .... |
No worries! We've identified a problem with the PR check, so it's totally not your fault :) We'll have a fix on Monday and then we can merge your query! |
|
The failing PR check is still being fixed. I see you've opened github/securitylab#237 to get a bounty for getting the query merged, and the ambition level there is up to you. Until then, we'll continue to review any PRs you make to improve the query. It would be very helpful if you could explicitly state in github/securitylab#237 once you're done improving the query. |
|
good day. |
Yes. If you don't plan on doing further improvements to the query please say so in github/securitylab#237 |
|
This query has a lot of false positives. Click here for a typical example. That I have seen one good result. But I am puzzled why the query doesn't also tag the |
indeed this is a false detection. it probably comes from a rather long chain of heap bindings. when two or more variables recursively assign each other a heap value. I'll try to fix it using
this place |
|
I corrected, I expect your reaction. I consider myself a newbie in your environment, so thanks for the fixes, they add experience. |
|
good day. |
|
We are still evaluating the query. github/securitylab#237 shows the current state of the evaluation process. |
If you want to handle this case, you can do so by changing your characteristic predicate from this: CompilerRemovaMemset() {
this.getTarget().hasGlobalOrStdName("memset") and
exists(DataFlow::Node source, DataFlow::Node sink, LocalVariable isv, Expr exp |
DataFlow::localFlow(source, sink) and
this.getArgument(0) = isv.getAnAccess() and
source.asExpr() = exp and
exp.getLocation().getEndLine() < this.getArgument(0).getLocation().getStartLine() and
sink.asExpr() = this.getArgument(0)
)
}to this: CompilerRemovaMemset() {
this.getTarget().hasGlobalOrStdName("memset") and
exists(DataFlow::Node source, DataFlow::Node sink, LocalVariable isv, Expr exp |
DataFlow::localFlow(source, sink) and
this.getArgument(0) = isv.getAnAccess() and
(
source.asExpr() = exp
or
// handle the case where exp is defined by an address being passed into some function.
source.asDefiningArgument() = exp
) and
exp.getLocation().getEndLine() < this.getArgument(0).getLocation().getStartLine() and
sink.asExpr() = this.getArgument(0)
)
}I'll leave it up to you whether this change is worth it or not. |
|
thanks for the help. |
|
it really gives additional error detection. I definitely need to read more about |
|
@ihsinme: just by coincidence I am currently writing some code that handles passwords, so I tried using |
it is optimal to use compile flag a more hardcore method is organizing access to array elements after zeroing. |
|
There's a good USENIX paper on how to use |
Good day.
The error in question in this PR is quite common in projects, I tried to minimize the false detection. PR also takes into account the specifics of various compilers.
note that I had to add c.getArgument (2) .toString () = "--force-recompute" to keep the tests running. It was a surprise to me, but the "codeql test run" uses a different line when compiling than the "codeql query run".
I am also worried about your rule.
"Compilation
Compilation of the query and any associated libraries and tests must be resilient to future development of the supported libraries. This means that the functionality cannot use internal libraries, cannot depend on the output of getAQlClass, and cannot make use of regexp matching on toString.
The query and any associated libraries and tests must not cause any compiler warnings to be emitted (such as use of deprecated functionality or missing override annotations). "
if it is a problem then I am ready to weaken this detection.
I want to draw your attention to the following features in the presented PRs.
fix cleaning important data. lsh123/xmlsec#297
fix cleaning important data. google/jsonnet#856