-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: add memoryAllocationDos query #12663
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
base: main
Are you sure you want to change the base?
Conversation
Fix review problem, but i can't make sanitizer to sanitizer guard. Please help me to get an example, |
@smowton I try
I try debug
after quick query , I found that there is no |
ok, I used some tricks. It works, but I'm not sure if it's the right way to do it |
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.
Please can you add some tests? You can look at other experimental queries to see how they've done it. You can start with the two example .go
files here.
Looking at that unit test, the reason The test as expressed at the moment could be simplified like -- this sanitizes all uses of a given variable source when one is subject to a relational test. private SsaWithFields getAComparedVar() {
result.getAUse() = any(DataFlow::RelationalComparisonNode n).getAnOperand()
}
class CompSanitizer2 extends Sanitizer {
CompSanitizer2() {
this = getAComparedVar().similar().getAUse()
}
} If you wanted to be more ambitious, you could look at only uses that fall downstream of the checked use in the control-flow graph: private DataFlow::Node getAComparedNode() {
result = any(DataFlow::RelationalComparisonNode n).getAnOperand()
}
class CompSanitizer2 extends Sanitizer {
CompSanitizer2() {
exists(DataFlow::Node comparedNode, SsaWithFields var |
comparedNode = getAComparedNode() and comparedNode = var.getAUse()
|
this.asInstruction() = comparedNode.asInstruction().getASuccessor+() and
this = var.similar().getAUse()
)
}
} Finally you could go as far as distinguishing the less-than from the greater-than arm of the |
QHelp previews: go/ql/src/experimental/CWE-20/MemoryAllocationDos.qhelpUser-controlled size of a memory allocation operationMemory allocation size from user-controlled data can allow an attacker to uses a lot of server memory. This can result the server is unavailable or crash due to failure to allocate huge memory. References
|
What are |
Under CI the tests run with some consistency queries active, which check for some kinds of mistake against the test database. UnexpectedFrontendErrors reports on errors reported by the Go compiler -- you should be able to see them using |
For my most recent bug hunter, make some improvements |
hi, can you review it? |
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.
The sanitizers are strange:
The comparison sanitizer says that if an SsaWithFields instance x.y.z
is specifically the greater operand of a comparison (e.g. if x.y.z > 100
) then all other uses of x.y.z
are sanitized. But, there is no reason why x.y.z > 100
gives us more confidence than x.y.z < 100
; it depends on the context where x.y.z
is used to allocate memory.
Then FieldReadSanitizer
says that if we have if e.f > 100
then everything is sanitized that comes afterwards in the control-flow graph, whether or not is has anything to do with e.f
-- for example, it would sanitize if e.f > 100 { ... allocate(x)
or allocate(e.g)
, even though x
and e.g
are unrelated to the sanitized expression e.f.
.
Can we make these more regular / easier to explain / understand?
in a project , found the following pattern
|
Right, but we could also have had
That's why I don't think the direction of the comparison is relevant to sanitization if we're santizing all other uses of that SsaWithFields (contrast if we're trying to do something smarter, like look at whether a particular use is controlled by such a comparison, in which case the direction is significant) |
If it's not big enough, it won't be a problem. It is very common for a request to use 10-100MB of memory |
|
Right, but as a general matter they might use |
You are right, I missed the pattern
|
I wrongly assumed that development would fix the value instead of skip |
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.
Hi @blue-bird1 👋🏼 We appreciate your contribution efforts in this PR. Due to other maintainer commitments and priorities over the next few weeks, we will not have the capacity to continue the review of this work, or to move it forward. We might return to review and move this work forward in the future if it aligns with our priorities, but I can offer no guarantees on the timeline.
I realize this may not be the outcome you wanted. You are free to leave this PR open if you choose and we'll reengage with it on a best-effort basis when we have the capacity for it.
Try adding a new query. wip
I did not find a user-controlled int stream, and used another library sinker