Skip to content

EVP: clear error when falling back from failed EVP_KEYMGMT_fetch()#10803

Closed
levitte wants to merge 4 commits intoopenssl:masterfrom
levitte:dont-err-on-keymgmt-fallback
Closed

EVP: clear error when falling back from failed EVP_KEYMGMT_fetch()#10803
levitte wants to merge 4 commits intoopenssl:masterfrom
levitte:dont-err-on-keymgmt-fallback

Conversation

@levitte
Copy link
Member

@levitte levitte commented Jan 10, 2020

Since we're falling back to legacy, this isn't an error any more.
Among others the failed EVP_KEYMGMT_fetch() error shadows other errors
produced by the legacy code, which disrupts our test/evp_test runs.

@slontis slontis 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 Jan 13, 2020
@slontis
Copy link
Member

slontis commented Jan 13, 2020

Looks like it needs a rebase..

Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

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

Needs rebase - otherwise it looks good.. The signature code got shifted into another file in a merged PR.

@levitte
Copy link
Member Author

levitte commented Jan 14, 2020

Ping

@t8m
Copy link
Member

t8m commented Jan 14, 2020

Should it be done via ERR_set_mark ERR_pop_to_mark? Or there cannot be any relevant error in the stack before the calls?

@levitte
Copy link
Member Author

levitte commented Jan 14, 2020

What's up wish the fetisch of old stale errors that are ignored? I don't get that.

In practice, though, what caused me to add this PR was that evp_test ran into cases where it couldn't see errors it expected at the start of the error queue because there were ignored errors before that.

@levitte levitte force-pushed the dont-err-on-keymgmt-fallback branch from f6263c6 to 833d9a5 Compare January 15, 2020 12:22
@romen
Copy link
Member

romen commented Jan 15, 2020

What's up wish the fetisch of old stale errors that are ignored? I don't get that.

In practice, though, what caused me to add this PR was that evp_test ran into cases where it couldn't see errors it expected at the start of the error queue because there were ignored errors before that.

Isn't the second sentence an answer to the first one? Shouldn't a test checking errors on the stack fail if any of the functions called in the test raises an error unexpected by the unit test? If we clear the whole stack, rather than just up to what is relevant for the function clearing errors, you are masking potential errors from function calls before the current one!

@levitte
Copy link
Member Author

levitte commented Jan 15, 2020

At that point, @romen, I take it that any previous error is unrelated and thereby ignored.

I think that there's a fundamental difference in the view of what the error queue is. I see it as a stack of current errors, i.e if the caller gets an indication of an error having happened (return value NULL, 0 or negative), the error queue holds information on errors that led to that error return and not stuff that are related to a previous error which has already been handled.
If the common view is that the error queue is a log, which isn't quite the same thing, then I can understand wanting to preserve earlier entries. But in that case, a ring implementation looks odd to me.

@levitte
Copy link
Member Author

levitte commented Jan 15, 2020

@t-j-h, can you remind us what the intent was with the error queue design? You are the better historian 😉

@t8m
Copy link
Member

t8m commented Jan 15, 2020

I understand the error queue is not a log. I am more concerned about the situation where such libcrypto calls where we invoke ERR_clear_error() are called internally from other libcrypto calls which could have produced some unhandled error before. Then these unhandled errors are lost by the clear call. If we are sure that in these concrete cases this cannot happen, I am OK with ERR_clear_error() calls.

@levitte
Copy link
Member Author

levitte commented Jan 15, 2020

Right now, I would only find this kind of sequence justifiable:

    ERR_set_mark(); /* to clear collection if none of them succeeds */
    if (try_this()
        || try_that()
        || try_harder())
        ERR_pop_to_mark();
    else
        ERR_clear_last_mark();

In other words, that's code where you do want to collect all the errors that happened down the call path, unless one of them succeeds, at which point none of the errors they generated is interesting any more.

This PR doesn't have that sort of situation in mind.

@romen
Copy link
Member

romen commented Jan 16, 2020

What if any of the functions you are proposing to use ERR_clear_error is called inside any of the try_this, try_that or try_harder functions?

Also, if all of the three attempts in your example fail, would we really clear the last mark or would we probably admit defeat and return a failure value to the caller and wish to leave on the error stack all the possible things that are wrong with handling the item that makes us fail no matter how hard we try?

@levitte
Copy link
Member Author

levitte commented Jan 16, 2020

What if any of the functions you are proposing to use ERR_clear_error is called inside any of the try_this, try_that or try_harder functions?

....
Hah. You got me there. OK, this convinces me.

@levitte
Copy link
Member Author

levitte commented Jan 16, 2020

As for ERR_clear_last_mark(), what do you think it does?

@romen
Copy link
Member

romen commented Jan 16, 2020

@levitte

As for ERR_clear_last_mark(), what do you think it does?

Good point! I think I should post less and look more at the code when I am unwell 😂

@levitte
Copy link
Member Author

levitte commented Jan 16, 2020

So I made a few changes, please have a look

@t-j-h
Copy link
Member

t-j-h commented Jan 16, 2020

The original concepts in the error stack (and it was always seen as a stack of errors) is that communication of the context of an error is one of the more interesting problems to tackle. You need to be able to add additional information and different levels and different places to be able to provide details to the user as to where and how things went wrong.

It wasn't see as a stack trace back mechanism - although it can provide effectively the same thing - as it isn't about a specific call chain - it is about collecting error status related to a set of activities.

There was very little use of internal ERR_clear_error within the library itself as it was up to the application to indicate it wanted a "fresh" start in collecting errors - so a few key points did the reset (like start of connection for client/server, start of verification, PEM processing).

@levitte
Copy link
Member Author

levitte commented Jan 17, 2020

Thanks, @t-j-h. That was very valuable to know.

@levitte levitte force-pushed the dont-err-on-keymgmt-fallback branch from e10347e to 2373d45 Compare January 17, 2020 08:23
@levitte
Copy link
Member Author

levitte commented Jan 17, 2020

Ping

romen
romen previously approved these changes Jan 17, 2020
Copy link
Member

@romen romen left a comment

Choose a reason for hiding this comment

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

LGTM I actually looked at it yesterday, but was leaving time for @t8m to review again!

@levitte levitte 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 Jan 17, 2020
t8m
t8m previously approved these changes Jan 17, 2020
Since we're falling back to legacy, this isn't an error any more.
Among others the failed EVP_KEYMGMT_fetch() error shadows other errors
produced by the legacy code, which disrupts our test/evp_test runs.
…tch()

Reminder: Clarify that we use ERR_set_mark() and ERR_pop_to_mark()
…n FIPS module

New narrative:

PROV: Add support for error queue marks and implement in FIPS module

This propagates ERR_set_mark(), and ERR_clear_last_mark() and
ERR_pop_to_mark() for provider use.
@levitte levitte force-pushed the dont-err-on-keymgmt-fallback branch from 2373d45 to 2b23f0b Compare January 18, 2020 04:53
@levitte
Copy link
Member Author

levitte commented Jan 18, 2020

Unfortunately, a bit of a rewrite was needed to adapt to other changes in the same files. It was complex enough that a re-approval is needed.

@levitte levitte dismissed t8m’s stale review January 18, 2020 04:56

Re-review, please

@levitte levitte requested a review from romen January 18, 2020 04:56
@levitte levitte dismissed romen’s stale review January 18, 2020 04:56

Re-review, please

@levitte levitte requested a review from t8m January 18, 2020 04:56
@levitte levitte added approval: review pending This pull request needs review by a committer and removed approval: done This pull request has the required number of approvals labels Jan 18, 2020
Copy link
Member

@romen romen left a comment

Choose a reason for hiding this comment

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

LGTM

@mattcaswell mattcaswell added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: review pending This pull request needs review by a committer labels Jan 21, 2020
@mattcaswell
Copy link
Member

Looks like this one is already "ready to merge"

openssl-machine pushed a commit that referenced this pull request Jan 21, 2020
Since we're falling back to legacy, this isn't an error any more.
Among others the failed EVP_KEYMGMT_fetch() error shadows other errors
produced by the legacy code, which disrupts our test/evp_test runs.

We use the error stack mark to restore the error stack just right,
i.e. ERR_set_mark(), ERR_clear_last_mark() and ERR_pop_to_mark()

Reviewed-by: Nicola Tuveri <[email protected]>
(Merged from #10803)
openssl-machine pushed a commit that referenced this pull request Jan 21, 2020
This propagates ERR_set_mark(), and ERR_clear_last_mark() and
ERR_pop_to_mark() for provider use.

Reviewed-by: Nicola Tuveri <[email protected]>
(Merged from #10803)
@levitte
Copy link
Member Author

levitte commented Jan 21, 2020

Right.

Merged.

0b9dd38 EVP: clear error when falling back from failed EVP_KEYMGMT_fetch()
7b131de PROV: Add support for error queue marks and implement in FIPS module

@levitte levitte closed this Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants