Skip to content

Comments

Adds multiple checks to avoid buffer over reads#5675

Closed
catenacyber wants to merge 1 commit intoopenssl:masterfrom
catenacyber:overread
Closed

Adds multiple checks to avoid buffer over reads#5675
catenacyber wants to merge 1 commit intoopenssl:masterfrom
catenacyber:overread

Conversation

@catenacyber
Copy link
Contributor

@catenacyber catenacyber commented Mar 19, 2018

Not a security issue as buffers are overgrown and overreads are two bytes at most.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

probably should go to the other releases, also. but would need to be re-implemented for those.

@richsalz richsalz added branch: master Applies to master branch approval: review pending This pull request needs review by a committer labels Mar 19, 2018
@catenacyber
Copy link
Contributor Author

probably should go to the other releases, also. but would need to be re-implemented for those.

Tell me if I need to do it for other branches (1.0.2 stable ?)

@richsalz
Copy link
Contributor

It would be awesome if you could create PR's for 1.0.2/1.1.0 yes, please!

Copy link
Contributor

@paulidale paulidale 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 even such a short overrun rates as a security concern. The shortest exploitable overrun I ever heard of was setting one byte beyond the end of a buffer to zero.

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 19, 2018
@catenacyber
Copy link
Contributor Author

I think even such a short overrun rates as a security concern. The shortest exploitable overrun I ever heard of was setting one byte beyond the end of a buffer to zero.

Sure off-by-1 are security problems, but I think that the buffer is overgrown as in
99bb59d
or in
ee76349

@levitte
Copy link
Member

levitte commented Mar 20, 2018

Is this not applicable on 1.1.0 as well?

@levitte
Copy link
Member

levitte commented Mar 20, 2018

CI failures are unrelated...

@catenacyber
Copy link
Contributor Author

Is this not applicable on 1.1.0 as well?

See #5686

@levitte
Copy link
Member

levitte commented Mar 20, 2018

Cool, and I noticed the 1.0.2 implementation as well. I took the liberty of editing the titles a bit so it would be easier to directly see what applies where. Having three PRs with exactly the same title can be confusing...

@mattcaswell mattcaswell added this to the 1.1.1 milestone Mar 20, 2018
ssl/t1_trce.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't tolerate declarations in the middle of code. I mean in this case hvers would have to be declared (but not assigned) prior if (msglen). Secondly it looks like you have to compare to 3, not 2. Indeed it's msg[2]. However, if one actually aims to ensure that there is not overstepping, then shouldn't one have to perform more checks even further down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, pushing a new version of the commit

ssl/t1_trce.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

While we are at it, one can wonder if it would be appropriate to check even for overlap. I mean suggested modifications try to ensure that there is no buffer overstepping by asserting upper limit for message length. And question is whether or not it would be appropriate to assert even lower limit. Disregard SSL_IS_DTLS for a moment, and imagine that msglen is permitted[!] 3. In such case length field will overlap version field. Would it be appropriate to check for this? Well, it might happen that these conditions will always be favourable, even upper limit check, because this function might be called with data that is vetted already. But if you start playing the game, then maybe one should play it wholeheartedly...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting.
I guess that we want to avoid overlap (even if it is not an over read).
Anyone voting up for this solution ?

ssl/t1_trce.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

On side note! (And side note means that no action is expected/required.) Original condition was not actually wrong, because len is verified to be even. With this in mind I'd say that while (len >= 2) would be more readable. One can even emphasize it with /* len is always even */.

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 did not see this check, so I guess I should remove this patch.
There are there loops with that kind of check.

@dot-asm dot-asm removed the approval: done This pull request has the required number of approvals label Mar 20, 2018
@dot-asm
Copy link
Contributor

dot-asm commented Mar 20, 2018

I've removed "ready" label, because there was code modification and it formally needs re-approval.

@catenacyber
Copy link
Contributor Author

I made some more changes, including not returning 0 in a function returning void

ssl/t1_trce.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't tolerate C++-style comments.

ssl/t1_trce.c Outdated
Copy link
Contributor

@dot-asm dot-asm Mar 21, 2018

Choose a reason for hiding this comment

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

If you consider overall purpose of this function, you'll have to conclude that it's debugging. And debugging by examining output, not single-stepping. Question is if just breaking (and consequently omitting emitting empty line) is something that would help debugging? Wouldn't user appreciate to note bad things happening (just as much as good ones)? And yes, if taken to the logical conclusion you'd also have to verify that encoded payload length matches (or doesn't exceed?) msglen. Once again, wholeheartedly...

[On side note there seems to be inconsistency on how lines are terminated. They all end with \n, except for two...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did I add the right debug messages in the next patch ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that you've got indentation right. I mean you used 4, but I don't think it's right. Though to be honest I don't actually know what's right, but it looks like it would be appropriate to align it with what applies in case in question, and it seems to be ... 0. But it's kind of odd that you can get "received" followed by "too short" in DTLS case. I'd say that following would be more appropriate:

int is_dtls = SSL_IS_DTLS(ssl);

BIO_puts(bio, write_p ? "Sent" : "Received");
if (msglen < is_dtls ? 13 : 5) {
    ssl_print_hex(bio, 1, "too short message", msg, msglen);
    break;
}
...
if (is_dtls) ...

@catenacyber catenacyber force-pushed the overread branch 2 times, most recently from e465a87 to c859c88 Compare March 21, 2018 14:37
ssl/t1_trce.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Direction is meaningful and presumably valuable even in "too short message" case. BTW, while you are at it, it's suggested to update coding style guide and say that declarations should be delimited by empty line. In other words could you add an empty line after "int hvers"? :-)

@dot-asm dot-asm added the approval: review pending This pull request needs review by a committer label Mar 22, 2018
@dot-asm
Copy link
Contributor

dot-asm commented Mar 22, 2018

As for remaining branches. Is it actually confirmed that this doesn't cherry-pick? I mean if something cherry-pick [without conflict], then it's actually the preferred way...

@catenacyber
Copy link
Contributor Author

As for remaining branches. Is it actually confirmed that this doesn't cherry-pick? I mean if something cherry-pick [without conflict], then it's actually the preferred way...

There is indeed a conflict with branch OpenSSL_1_1_0-stable
Have we reached a final patch ?
Should I update the patches and pull requests for 1.0.2 and 1.1.0 ?

@bernd-edlinger
Copy link
Member

Should I update the patches and pull requests for 1.0.2 and 1.1.0 ?

Yes, please do that.

@bernd-edlinger bernd-edlinger added approval: done This pull request has the required number of approvals approval: review pending This pull request needs review by a committer and removed approval: review pending This pull request needs review by a committer approval: done This pull request has the required number of approvals labels Mar 23, 2018
@bernd-edlinger
Copy link
Member

Oops, @richsalz after your approval there were changes, could you re-confirm please?

ssl/t1_trce.c Outdated
Copy link
Member

Choose a reason for hiding this comment

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

is this correct ? doesn't that evaluate to ( msglen < .... ) ? 13 : 5 ???

Copy link
Member

Choose a reason for hiding this comment

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

yes, indeed using recent gcc it triggers the following warning:

ssl/t1_trce.c: In function 'SSL_trace':
ssl/t1_trce.c:1503:48: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context]
             if (msglen < SSL_IS_DTLS(ssl) ? 13 : 5) {
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

And as the author of Wint-in-bool-context I may say it makes me a bit proud!

Copy link
Contributor

Choose a reason for hiding this comment

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

It is! Keen eye :-)

ssl/t1_trce.c Outdated
Copy link
Member

Choose a reason for hiding this comment

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

yes, indeed using recent gcc it triggers the following warning:

ssl/t1_trce.c: In function 'SSL_trace':
ssl/t1_trce.c:1503:48: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context]
             if (msglen < SSL_IS_DTLS(ssl) ? 13 : 5) {
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

And as the author of Wint-in-bool-context I may say it makes me a bit proud!

@richsalz
Copy link
Contributor

Reconfirm.

Copy link
Member

@bernd-edlinger bernd-edlinger left a comment

Choose a reason for hiding this comment

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

OK, for commit 9583ae3.

Everybody, please re-confirm one last time.
I can do the merge tomorrow.

@richsalz
Copy link
Contributor

reconfirm.

Copy link
Contributor

@dot-asm dot-asm left a comment

Choose a reason for hiding this comment

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

Re-confirmed

@bernd-edlinger bernd-edlinger added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 25, 2018
levitte pushed a commit that referenced this pull request Mar 25, 2018
Reviewed-by: Rich Salz <[email protected]>
Reviewed-by: Andy Polyakov <[email protected]>
Reviewed-by: Bernd Edlinger <[email protected]>
(Merged from #5675)
@bernd-edlinger
Copy link
Member

Merged to master as 161ff6c, so far...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants