Skip to content

CPP: Add query for CWE-670: Always-Incorrect Control Flow Implementation when use SSL_shutdown #9087

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
merged 3 commits into from
Jun 23, 2022

Conversation

ihsinme
Copy link
Contributor

@ihsinme ihsinme commented May 9, 2022

this query looks for improperly closed connections.

CVE-2008-1531

when the situations of calling the second function to close are not processed.

@ihsinme ihsinme requested a review from a team as a code owner May 9, 2022 13:09
@geoffw0 geoffw0 self-requested a review May 11, 2022 12:00
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution.

The code and tests LGTM, though comments in the code would have made it easier to read and understand.

fc.getASuccessor+() = fc1 and
fc.getTarget().hasName("SSL_shutdown") and
fc1.getTarget().hasName("SSL_shutdown") and
fc1 instanceof ExprInVoidContext and
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that we're looking for two calls to SSL_Shutdown on the same SSL object (without a call to SSL_Free in between), where the return value of the second call is not checked. Why is it OK for the return value of the first call to be unchecked but not the second?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right, the first check also needs to be checked.

  1. I want to avoid situations with only one call.
  2. It seems to me that when the first call check is skipped, and the second one is checked, this is a very rare case.

but if you find grain in it, I will add this detector.

Copy link
Contributor

Choose a reason for hiding this comment

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

I want to avoid situations with only one call.

Are they problematic? Is it sometimes OK for the developer to ignore the return value of SSL_shutdown in these simpler cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sure that you should always check the return value of this function. however, we are talking about the problem of ambiguous understanding of states on the part of the server and the client, in this case, the presence of one call indicates that the developer does not consider this a problem.

the addition of this detection, in my opinion, will lead to an increase in hits and will correlate with the situation in these PRs 6950 6947.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, checking for an error on the first call to SSL_shutdown suggests that the program needs to handle the error to behave correctly, so an error on the second SSL_shutdown should be handled as well. But its also possible the program doesn't need to handle any errors (perhaps its about to exit anyway), so you're reluctant to catch the case of a single call to SSL_shutdown with no error handling.

@geoffw0
Copy link
Contributor

geoffw0 commented May 12, 2022

A run of this query on LGTM: https://lgtm.com/query/1680253232874044114/

@ihsinme
Copy link
Contributor Author

ihsinme commented May 15, 2022

A run of this query on LGTM: https://lgtm.com/query/1680253232874044114/

https://lgtm.com/query/4523088424855036098/

@ihsinme
Copy link
Contributor Author

ihsinme commented May 15, 2022

could you show me what kind of errors are generated during checks.

@geoffw0
Copy link
Contributor

geoffw0 commented May 16, 2022

Great, that's three real world results between our two LGTM runs!

Running the checks now...

…hutdown.ql

Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
@geoffw0
Copy link
Contributor

geoffw0 commented May 16, 2022

I'm happy with this, when the checks pass. And I believe it would have caught the issue described in https://redmine.lighttpd.net/issues/285#comment:18 .

@ihsinme
Copy link
Contributor Author

ihsinme commented May 16, 2022

I'm happy with this, when the checks pass. And I believe it would have caught the issue described in https://redmine.lighttpd.net/issues/285#comment:18 .

this is a very interesting point.
but it is difficult to determine correctly.
there's a non-null error here, and it's used elsewhere.
to work with this goal, we will need to determine that the client will continue after it is possible to close the connection, and ensure that it uses the shared error store.

I really like this item in the description, but I'm afraid that it will complicate the query very much, and narrow the detection very much.

@ihsinme
Copy link
Contributor Author

ihsinme commented May 16, 2022

if you still think it's reasonable, I am ready to agree with you. let's just talk about what you mean

  1. detection of situations when the first or only call is made without checking.
  2. detection of a situation when the accumulated error is not reset and can be used in another place, which can lead to a connection break.

@geoffw0
Copy link
Contributor

geoffw0 commented May 17, 2022

I'm not advising any changes at this time, I'm just trying to better understand why the query works the way it does. I think I'm happy with the QL and the real world (lgtm.com) results we have seen so far.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

I think its about time I approve this. It does what its supposed to do and finds a few good results. 👍

@ihsinme
Copy link
Contributor Author

ihsinme commented May 23, 2022

I think its about time I approve this. It does what its supposed to do and finds a few good results. 👍

thanks

@ihsinme
Copy link
Contributor Author

ihsinme commented Jun 20, 2022

What do I need to do for this PR?

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 22, 2022

I believe the bug bounty process concluded that this PR is not eligible for a bounty award. I'm happy to accept the code into experimental, with that understanding.

@ihsinme
Copy link
Contributor Author

ihsinme commented Jun 22, 2022

despite the bounty decision, I still find the request useful.
so I will be glad if you accept it and it will be used)

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 23, 2022

Great, thanks for your contribution!

@geoffw0 geoffw0 merged commit 20c3182 into github:main Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants