C++: Improve the CleartextFileWrite query#6273
Conversation
|
A lot of the remaining results look like false positives or wontfix.
That leaves 5 projects with true positives, 2 where it's a wontfix (but presumably was thought about carefully), and one false positives. I think if we run it on a bigger set of projects, it will look better, but we should actually do that before raising the precision. |
|
The changes all LGTM! I agree with @rdmarsh2, though: We should either:
In the spirit of less friction, I say we just roll with it and run this PR on all of LGTM, and merge it if the results look good. |
|
Thanks for the detailed reviews. I'll run it on a bigger set of projects then we can decide whether to merge with or without the precision change... |
|
135 of 11,601 projects have results for this query (a little over 1%; we can add more data flow support if we want to find more results). Reviewing the first 20 projects with results:
So I'm going to make a few changes, test, and then probably start another big run. |
|
I've made the changes, I'll wait for any immediate suggestions before I do another big run. |
|
Update: 105 out of 11,628 projects now have results for this query. I'd like to find more results, but precision is the priority for now. Of the first 20 or so projects with results:
These are fairly rare FPs, but I think I'm going to make one more revision. |
|
I've pushed some more changes, and confirmed they work on the intended targets here: https://lgtm.com/query/1386328828902572629/ |
|
CPP-Differences job in progress: https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/2168/ (I'm mainly interested in checking that any performance cost is modest). |
| /** | ||
| * An operation on a filename. | ||
| */ | ||
| predicate filenameOperation(FunctionCall op, Expr path) { |
There was a problem hiding this comment.
Could this be shared with the TOCTOU query somehow, or are they too different?
There was a problem hiding this comment.
Yes, now that the TOCTOU changes are merged I should be able to do this...
There was a problem hiding this comment.
On reflection I think the right way to do this is to add a new 'FileOperation' or 'Files' model to 'models', with methods such as getAFilenameParameter (and perhaps getAFileDescriptorParameter) exposing the information we need. I'd rather do this in a separate PR, preferably after we've had the public/private model implementations discussion as well.
Alternatively I could just move the filenameOperation, accessCheck and stat predicates into a common library, but I'm not sure where is appropriate, and we'll end up maintaining this interface.
There was a problem hiding this comment.
Ticket for this: https://github.com/github/codeql-c-team/issues/607
There was a problem hiding this comment.
Let's wait for that discussion to finish and do it in a separate PR.
|
According to CPP-Differences there are some possible slowdowns: The changes for There are also two result changes, both in |
Yes. It does mean, however, that the |
|
Thanks. Then I think this is ready to merge, assuming agreement with my plans for |
Improve the
CleartextFileWrite.qlquery:SensitiveExprs.qll(reduces FPs in this query and a couple of others that also use the same library).CleartextFileWrite.ql(increases TPs).@precision high.I'm open to discussion about whether this is really enough to justify
@precision high. I've only spent a few hours on these improvements, but the results look good to me (https://lgtm.com/query/5235174286264674280/) and enabling it will modestly improve our SAMATE results as well as flagging this bad practice to users.