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

Contrived integer overflows #1094

Merged
merged 4 commits into from
Nov 8, 2018
Merged

Contrived integer overflows #1094

merged 4 commits into from
Nov 8, 2018

Conversation

i-rinat
Copy link
Contributor

@i-rinat i-rinat commented Nov 7, 2018

In some cases it's possible to specify numbers in the configuration file that may cause integer overflows. In such cases timeouts, for example, may be different from expected. Explicit up-casting before multiplications should prevent that.

fixes #1091

If it was 0 for some reason, we force it to be UINT_MAX instead, exactly
to avoid such checks at run time.
Some variable values come from a configuration file, and can be arbitrary.
Then, some additional care is needed to prevent overflows.
Since time_t is a 64-bit type, in some contrived cases it's possible to
overflow 32-bit integer. Let's use 64-bit instead.
It's compared to tfw_http_req_t::retries, which is unsigned short. So there
are no sense in values larger than USHRT_MAX
i-rinat added a commit that referenced this pull request Nov 7, 2018
This is a backport of #1094
@@ -1909,9 +1909,11 @@ tfw_vhost_start(void)
if (!tfw_runstate_is_reconfig()) {
/* Convert Frang global timeouts to jiffies for convenience */
frang_cfg.clnt_hdr_timeout =
*(unsigned int *)&frang_cfg.clnt_hdr_timeout * HZ;
*(unsigned int *)&frang_cfg.clnt_hdr_timeout *
Copy link
Contributor

Choose a reason for hiding this comment

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

First I wanted to write, that:

  • it's rather hacky to work with unsigned long as *(unsigned int *)&, no problems on x86, but still not good,
  • actual code that parses client_header_timeout directive is split into two functions without any need,
  • there is no allowed range specified for client_header_timeout directive and negative values are possible,
  • the code in http_limits.c expect jiffies in all cases, not only for global limits.

But then I've looked more, why only global timeout is converted to jiffes, but not for the other locations. It turns out, that per-vhost clnt_hdr_timeout limit is never used. It's architectural feature: we can't choose target vhost until the whole header is parsed, and this global limit will be applied to all vhosts. In the same time clnt_body_timeout limit for non-default locations will be much more strict that required.

Don't need to fix this issues in this PR, let's revise the correctness of all the frang limits in #1028

@i-rinat i-rinat merged commit 91d6959 into master Nov 8, 2018
@i-rinat i-rinat deleted the ri-integer-overflows branch November 8, 2018 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible unsigned overflows in session life time calculation
3 participants