cpp: Add query to detect unsigned integer to signed integer conversio…#6409
cpp: Add query to detect unsigned integer to signed integer conversio…#6409rdmarsh2 merged 7 commits intogithub:mainfrom
Conversation
…ns used in pointer arithmetics
rdmarsh2
left a comment
There was a problem hiding this comment.
Thanks for this submission, it looks like a quite valuable query. I've suggested a few changes, and I'll be happy to merge this once those are made.
cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql
Outdated
Show resolved
Hide resolved
|
Thanks @rdmarsh2 ! Made the changes :D |
|
Hi, Thanks for the contribution, it looks really promising. I've just run the query on 132 projects: https://lgtm.com/query/5086856576900256424/ . The majority of results seem to be on calls to |
|
@JordyZomer seems to have forgotten to mention that he wrote up a detailed blog post about this query and how it found critical results on the Linux kernel codebase. It's an amazing story 🚀! tl;dr: this is the result of variant analysis on CVE-2021-33909 a.k.a. "the sequoia bug". |
cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql
Outdated
Show resolved
Hide resolved
…ointerArith.ql Co-authored-by: intrigus-lgtm <60750685+intrigus-lgtm@users.noreply.github.com>
Those ought to be converting to @JordyZomer do you think that filter makes sense? I'm happy to merge otherwise, although I think you'll also need to run the autoformatter (alt-shift-f in the VS Code extension, or |
|
Hey @rdmarsh2 ! Sorry for the delay, I was on a holiday and didn't have access to a PC :) The filter seems like a reasonable thing to do, I just added it, formatted the query and updated the PR :D |
rdmarsh2
left a comment
There was a problem hiding this comment.
Looks good now, thanks!
Hi!
I added a query to detect unsigned integer to signed integer conversions used in pointer arithmetic. This is a variant analysis of the recent 'Sequoia' bug.
So what we do here is obtain a FunctionCall to a Function with any parameter that requires a signed integer. Following that, we look for any function calls that provide an unsigned number to this function despite the fact that it expects a signed integer. After that, we will use the DataFlow library to “taint track” any use of this argument in pointer arithmetic. Running this query on the Linux kernel database successfully identifies the Sequoia vulnerability as well as hundreds of additional instances that may be vulnerable.
Because there are so many results, I decided to refine the query slightly, so I added three filters to narrow down the criteria.
Establish whether there is a size check where the source is more than something
Determine whether the sink is smaller than something
Identify whether the source is a constant.
I configured it such that it only displayed results if none of these filters matched.