Skip to content

C++: Avoid partial chi flow to struct/class #3219

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

Merged

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Apr 7, 2020

Taint through partial chi-instruction operands was introduced to make definition-by-reference work, but its implementation also allowed all other partial writes to propagate. In particular, tainting a field would taint the whole struct, which in turn led to taint propagating across unrelated fields of a struct.

The security test CWE-134/semmle/argv/argvLocal.c shows that we also want to propagate taint from an array element to the whole array, and it also seems right to propagate taint from a union member to the whole union.

Flow through partial chi-instruction operands was introduced to make
definition-by-reference work, but its implementation also allowed all
other partial writes to propagate. In particular, tainting a field would
taint the whole struct, which in turn led to taint propagating across
unrelated fields of a struct.

The security test `CWE-134/semmle/argv/argvLocal.c` shows that we also
want to propagate taint from an array element to the whole array, and it
also seems right to propagate taint from a union member to the whole
union.
@jbj jbj added the C++ label Apr 7, 2020
@jbj jbj requested a review from a team as a code owner April 7, 2020 14:25
@jbj
Copy link
Contributor Author

jbj commented Apr 7, 2020

Started https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1021/

I'm hoping this will remove the FPs we have on git/git in (at least) cpp/path-injection and cpp/uncontrolled-allocation-size.

@jbj jbj added this to the 1.24 milestone Apr 7, 2020
@jbj jbj mentioned this pull request Apr 7, 2020
@jbj
Copy link
Contributor Author

jbj commented Apr 7, 2020

@jbj
Copy link
Contributor Author

jbj commented Apr 7, 2020

The WriteSideEffectInstction case in this PR can be removed if we merge #3220.

t instanceof ArrayType
or
// Buffers or unknown size
t instanceof UnknownType
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a struct pointer parameter, I think its chi nodes will have UnknownType. How can we find the struct type?

@jbj
Copy link
Contributor Author

jbj commented Apr 8, 2020

These are the result differences:

=== Changes per project (+new -fixed) ===

g/git/git                                                                   +0 -24
g/wireshark/wireshark                                                       +0 -10

=== Changes per query (+new -fixed) ===

cpp/path-injection                                                          +0 -13
cpp/tainted-format-string                                                   +0 -2
cpp/uncontrolled-allocation-size                                            +0 -19

I've looked through the path explanations for all three queries on both projects, and I'll claim that all the lost results are FPs due to field conflation, while all the remaining results are TPs (in the sense that the query is working as it's designed to work).

Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants