-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[CPP][Linux Kernel]Add ql to detect CVE-2017-5123 #8423
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
Add query to detect CVE-2017-5123
Hi @4B5F5F4B, Thanks for your contribution! We'll get to review it soon, but in the meantime would you mind restructuring your PR so that your query is in the https://github.com/github/codeql/tree/main/cpp/ql/src/experimental/Security/CWE directory? I guess this query is an instance of You can move the existing code and tests in that folder into a new directory (maybe called |
commit by mistake
import semmle.code.cpp.dataflow.DataFlow | ||
|
||
|
||
class WrtieAccessCheckMacro extends Macro{ |
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.
Minor typo - Wrtie
for Write
Thanks for the contribution! This looks good as-is other than the typo and the folder (as Mathias mentioned, we arrange queries by CWE rather than CVE). If you want to extend it further, you might look at the global data flow library and the |
Hello, @rdmarsh2 |
Hello, @rdmarsh2 I've moved and renamed my query under experimental/security/CWE directory just as @MathiasVP suggested before, what's more I modified the typo you spotted:) Thanks a lot for your suggestion that BarrierGuard and global data flow library should be used, but frankly speaking as far as bugs like CVE-2017-5123 is concerned, intraprocedural analsis maybe good enough. Because security check for user-mode pointer in linux kernel codebase is not a function but marco, it's not common that a user mode pointer is checked by access_ok in function a, and passed to unsafe_put_user in function b. |
from ExploitableUserModePtrParam p, UnSafePutUserMacro unsafePutUser | ||
where | ||
DataFlow::localFlow(DataFlow::parameterNode(p), DataFlow::exprNode(unsafePutUser.getUserModePtr())) | ||
select p, unsafePutUser, "potential wrtie user mode ptr without check." |
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.
There's one more change I have to ask for, which is causing the test failure - for this to be an @kind problem
query, it needs to have an even number of columns, alternating between locations and string (see this page on defining query results), The easy fix is to just remove p
from the select, or you could use the $@
syntax to include the name of the parameter as well.
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.
Hello, @rdmarsh2
I Just modified the select clause to make CodeQL happy, please have a look. thx
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.
Did you want the parameter or the unsafe_put_user
invocation to be the alert location? After your change, it's the parameter, but I'd expect it to be the macro invocation. Looks good otherwise.
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.
Hello @rdmarsh2
After carefully consideration I prefer parameter to be the alert location, because the intention of my query is to detect vulnerability pattern that function's parameter abused in unsafe_put_user, and there maybe multiple unsafe_put_user invocations that abuse the same parameter in one function.
for example, consider the following buggy code
function vuln(struct something* __user ptr)
{
unsafe_put_user(0x41414141, ptr->foo, 4);
unsafe_put_user(0x42424242, ptr->bar, 4);
}
No description provided.