Skip to content
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

bugfix: a segmentation fault might occur when SSL renegotiation happens #1355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

bugfix: a segmentation fault might occur when SSL renegotiation happens #1355

wants to merge 1 commit into from

Conversation

tokers
Copy link
Contributor

@tokers tokers commented Jul 24, 2018

Please see #1354 for more details.

Since it is tough to distinguish whether current connection is upgraded
to HTTP/2 in the ngx_http_lua_ssl_cert_handler context. This PR just
returns 0 (marks failed) when SSL renegotiation happens. Nginx already
prohibited the SSL renegotiation, so it is safe.

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

@spacewander
Copy link
Member

AFAIK, server side SSL renegotiation is disable in Nginx.
Maybe you are using OpenSSL 1.1.0+, so the renegotiation is not disable yet.
This was fixed in the master branch of Nginx, see https://trac.nginx.org/nginx/ticket/1376

@tokers
Copy link
Contributor Author

tokers commented Jul 25, 2018

@spacewander The usage of SSL_OP_NO_RENEGOTIATION in Nginx was added recently.
It seems that the option can disable the SSL renegotiation completely. But for the Nginx older than 1.15.2, there is a time window between Nginx detects SSL renegotiation and takes the corresponding action, so this segmentation fault can still happens.

I don't know what is your new plan for compatible with the Nginx 1.15.x series, if there is no such plan, maybe it's better to fixup this?

@spacewander
Copy link
Member

@tokers

for the Nginx older than 1.15.2, there is a time window between Nginx detects SSL renegotiation and takes the corresponding action, so this segmentation fault can still happens.

Why not backport the patch to the Nginx older than 1.15.2? Server SSL renegotiation is disable with the intention to avoid security risk. Even if nobody is using SSL 3.0, work around a fixed bug is not so nice.

@tokers
Copy link
Contributor Author

tokers commented Jul 25, 2018

@spacewander The purpose is not "work around a fixed bug" but solves the segmentation fault problem. Of course put the patch for old Nginx is also ok.

@spacewander
Copy link
Member

@tokers
What about wrapping this change with specific version macro?
This change is only required for some versions of Nginx built with some versions of OpenSSL.

@@ -201,6 +201,10 @@ ngx_http_lua_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, void *data)

c = ngx_ssl_get_connection(ssl_conn);

if (c->ssl->renegotiation) {
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, we should return -1 and log with error message.
In the ideal world, in which Nginx and OpenSSL work perfectly, server side renegotiation is disable.
Also, skip the ssl_cert_by_lua phase and use the dummy ssl certificate is not always expected in the renegotiation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should we return -1? -1 represents the current stage is still in progress.

Copy link
Member

Choose a reason for hiding this comment

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

@tokers
My bad. Yes, it should return 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spacewander
I have updated this change.

@tokers
Copy link
Contributor Author

tokers commented Jul 25, 2018

@spacewander

What about wrapping this change with specific version macro?
This change is only required for some versions of Nginx built with some versions of OpenSSL.

Okay, I think we can check the Nginx version number and the SSL_OP_NO_RENEGOTIATION macro.

@agentzh
Copy link
Member

agentzh commented Jul 25, 2018

@tokers Is it possible to add a test case to cover this?

@tokers
Copy link
Contributor Author

tokers commented Jul 26, 2018

@agentzh

It seems difficult for me, I don't know how to manipulate Test::Nginx to perform the SSL renegotiation.

@spacewander
Copy link
Member

@tokers
What about running the OpenSSL client manually?
https://github.com/openresty/lua-resty-core/blob/master/t/ssl.t#L2176

@tokers
Copy link
Contributor Author

tokers commented Jul 26, 2018

@spacewander
Thanks! I will imitate it.

Please see #1354 for more details.

Since it is tough to distinguish whether current connection is upgraded
to HTTP/2 in the ngx_http_lua_ssl_cert_handler context. This PR just
returns 0 (marks failed) when SSL renegotiation happens. Nginx already
prohibited the SSL renegotiation, so it is safe.
@tokers
Copy link
Contributor Author

tokers commented Jul 27, 2018

@agentzh @spacewander test was added. This problem only occurs when OpenSSL version is between 1.1.0 to 1.1.0g.

@mergify
Copy link

mergify bot commented Jun 26, 2020

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Jun 26, 2020
@mergify mergify bot removed the conflict label Mar 20, 2023
@mergify
Copy link

mergify bot commented Mar 20, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 20, 2023
@mergify mergify bot removed the conflict label May 10, 2023
@mergify
Copy link

mergify bot commented May 10, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 10, 2023
@mergify mergify bot removed the conflict label Sep 23, 2023
@mergify
Copy link

mergify bot commented Sep 23, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Sep 23, 2023
Copy link

mergify bot commented Mar 6, 2024

This pull request is now in conflict :(

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.

3 participants