Skip to content

Comments

Improve post-2038 compatibility of time_t usage#17778

Closed
kaduk wants to merge 1 commit intoopenssl:masterfrom
kaduk:timet
Closed

Improve post-2038 compatibility of time_t usage#17778
kaduk wants to merge 1 commit intoopenssl:masterfrom
kaduk:timet

Conversation

@kaduk
Copy link
Contributor

@kaduk kaduk commented Feb 28, 2022

The Unix epoch will overflow a signed 32-bit integer in the year 2038,
and many systems are updating time_t to be 64-bits or to treat the time
as an unsigned integer as a result. To protect openssl against such
issues:

  • update s_time's internal logic to consistently use time_t for tracking
    timeouts

  • update BIO_SSL to use a time_t to track the last renegotiation time,
    rather than the ad hoc 'unsigned long'. The structure is private to
    bio_ssl.c and so there is no external ABI breakage

The Unix epoch will overflow a signed 32-bit integer in the year 2038,
and many systems are updating time_t to be 64-bits or to treat the time
as an unsigned integer as a result.  To protect openssl against such
issues:

- update s_time's internal logic to consistently use time_t for tracking
  timeouts

- update BIO_SSL to use a time_t to track the last renegotiation time,
  rather than the ad hoc 'unsigned long'.  The structure is private to
  bio_ssl.c and so there is no external ABI breakage
@kaduk
Copy link
Contributor Author

kaduk commented Feb 28, 2022

Alternative to #17701

}
totalTime += tm_Time_F(STOP); /* Add the time for this iteration */

i = (int)((long)time(NULL) - finishtime + maxtime);
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 couldn't find anywhere that this value was used.
It seems plausible that at one point it was used in the printf call a couple lines later, but that the expression got duplicated as part of a cleanup change; I did not look into the history to try to confirm that.

@kaduk
Copy link
Contributor Author

kaduk commented Feb 28, 2022

I'll also note that I only looked at places that #17701 was already touching, and did not do an independent survey of other time(3) usage

@paulidale
Copy link
Contributor

This version seems clearer to me.

@paulidale paulidale added approval: review pending This pull request needs review by a committer branch: 3.0 Applies to openssl-3.0 branch branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug labels Mar 1, 2022
@rsbeckerca
Copy link
Contributor

Some systems are keeping time_t as 32-bit and moving to time64_t. I know of three. This is not a permanent fix, however (permanent being a relative term). I think having an OpenSSL-specific time type may be the only rational way to go - OpenSSL_time_t and have the platform implement whatever it must to deal with 2038. Given how fast people are moving off of 1.0.1m (really, it's still in production), this is somewhat urgent.

tm = (unsigned long)time(NULL);
if (tm > sb->last_time + sb->renegotiate_timeout) {
tm = time(NULL);
if (tm - sb->last_time > (time_t)sb->renegotiate_timeout) {
Copy link
Member

Choose a reason for hiding this comment

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

my approach had the nice added value that it is robust if the system time is set back,
that's why I rewrote the condition to tm - bs->last_time > bs->renegotiate_timeout
I thought that's obvious.

@tmshort
Copy link
Contributor

tmshort commented Mar 1, 2022

Alternative proposal: #17786 (it's a WIP, and could subsume this work).


bytes_read = 0;
finishtime = (long)time(NULL) + maxtime;
finishtime = time(NULL) + maxtime;
Copy link
Contributor

Choose a reason for hiding this comment

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

Overflow for 32-bit time_t systems in 2038.

Copy link
Contributor

Choose a reason for hiding this comment

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

#8687 includes timeoutcmp() for SSL_SESSION structures, that looks at overflow... It basically gives an extra bit of time (so on 32-bit systems, it's an extra 68 years...) Does that kick the can down the road? Yes, will 32-bit systems still exists after 2038? Probably? Will they have been updated with a 64-bit time_t? Who knows.

totalTime = 0.0;

finishtime = (long)time(NULL) + maxtime;
finishtime = time(NULL) + maxtime;
Copy link
Contributor

Choose a reason for hiding this comment

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

Again overflow.

In general, I believe that finishtimes should no longer be used. Better to subtract the timeout value from "now", and compare to the starttime. In other words, keep two values around (start and duration) rather than finishtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this as a better approach

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@rsbeckerca
Copy link
Contributor

Where are we with this particular PR?

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@t8m t8m closed this Jul 7, 2022
@t8m t8m reopened this Jul 7, 2022
@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 92 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 154 days ago

@levitte
Copy link
Member

levitte commented Oct 4, 2022

We have OSSL_TIME nowadays. That might otherwise be useful here.
It's internal, but almost entirely made of static in-line functions implemented in a header file, so...

@t8m t8m added the branch: 3.1 Applies to openssl-3.1 (EOL) label Oct 24, 2022
@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@rsbeckerca
Copy link
Contributor

@rsbeckerca isn't this a system level issue then? I can't imagine that nonstop will just require all applications to implement their own version of time_t to address the 2038 issue, will they?

I think any solution will have to take into account that there is no consistency between 32-bit and 64-bit time implementations on different platforms. It is consistent in gcc and some 64-bit builds, but not universal. The time_t on S/390 when I was last on it was 32-bit even when building for 64-bit, which made me a bit wonky. The application had to adapt to use time64_t when on S/390 no matter what.

@nhorman
Copy link
Contributor

nhorman commented May 30, 2024

@rsbeckerca ok, thats reasonable, but thats not what this PR does. My goal here was to motivate movement on this issue in some way, given that it has been idle for a year, be that to make arguments for its inclusion, or its rejection (either in favor of something else, or to close it entirely if there is not current interest to pursue it). So I suppose in my mind the first question is to @kaduk - do you want to address the comments made in this PR and continue to pursue its inclusion, or should we close this, and address the problem in a future issue?

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 92 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago

@kaduk
Copy link
Contributor Author

kaduk commented Oct 1, 2024

@rsbeckerca ok, thats reasonable, but thats not what this PR does. My goal here was to motivate movement on this issue in some way, given that it has been idle for a year, be that to make arguments for its inclusion, or its rejection (either in favor of something else, or to close it entirely if there is not current interest to pursue it). So I suppose in my mind the first question is to @kaduk - do you want to address the comments made in this PR and continue to pursue its inclusion, or should we close this, and address the problem in a future issue?

The discussion of what we want to do "in this space" (itself a vaguely defined matter) got split across quite a few PRs but after a brief survey it does seem like I should pick this one up again and we can get some small incremental improvements in even if we end up wanting to do a bigger cleanup pass later.

@nhorman
Copy link
Contributor

nhorman commented Oct 1, 2024

ack, assigning to you, @openssl/committers can we pick up reviewing this please

@nhorman nhorman requested a review from a team October 1, 2024 07:23
Copy link
Member

@hlandau hlandau left a comment

Choose a reason for hiding this comment

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

LGTM

@t8m t8m added branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 labels Oct 4, 2024
@t8m
Copy link
Member

t8m commented Oct 4, 2024

Please note that we explicitly added new public APIs with time_t arguments as the type for holding time values instead of long. I do not think we are going to fix issues on platforms where time_t cannot hold time after 2038.

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@t8m
Copy link
Member

t8m commented Dec 6, 2024

There are some unresolved comments from @tmshort and @bernd-edlinger .

@kaduk could you please respond to them?

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 92 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago

@t8m t8m added waiting-for: contributor response This pull request is awaiting a response by the contributor branch: 3.5 Applies to openssl-3.5 and removed approval: review pending This pull request needs review by a committer branch: 3.1 Applies to openssl-3.1 (EOL) labels Apr 30, 2025
@openssl-machine
Copy link
Collaborator

This PR is waiting for the creator to make requested changes but it has not been updated for 30 days. If you have made changes or commented to the reviewer please make sure you re-request a review (see icon in the 'reviewers' section).

@openssl-machine
Copy link
Collaborator

This PR is waiting for the creator to make requested changes but it has not been updated for 61 days. If you have made changes or commented to the reviewer please make sure you re-request a review (see icon in the 'reviewers' section).

@openssl-machine
Copy link
Collaborator

This PR has been closed. It was waiting for the creator to make requested changes but it has not been updated for 90 days.

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

Labels

branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch branch: 3.2 Applies to openssl-3.2 (EOL) branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 help wanted triaged: bug The issue/pr is/fixes a bug waiting-for: contributor response This pull request is awaiting a response by the contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.