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

timer: fix oss-fuzz issue #11852 #6982

Merged
merged 5 commits into from
May 31, 2019
Merged

Conversation

ipuustin
Copy link
Member

Description:

Fix a time conversion signed int overflow (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11852).

Risk Level: low
Testing: fuzz

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks @ipuustin! A couple of comments, but this is a good fix.
/wait

@@ -23,7 +23,17 @@ void TimerImpl::enableTimer(const std::chrono::milliseconds& d) {
event_active(&raw_event_, EV_TIMEOUT, 0);
} else {
// TODO(#4332): use duration_cast more nicely to clean up this code.
std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(d);

Copy link
Member

Choose a reason for hiding this comment

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

Should we try and follow the above TODO and try and make parts of this calculation more duration_cast based? If that's done, does this math change a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

The method described in the TODO seems to work fine, and removes the need for clamping the value. Using that now!

@@ -0,0 +1,2 @@
static_resources { clusters { name: " " connect_timeout { nanos: 4 } hosts {
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add a unit test for this new clamping or conversion boundary behavior somewhere, e.g. https://github.com/envoyproxy/envoy/blob/master/test/common/event/dispatcher_impl_test.cc#L189? The corpus entries are useful, but they are hard to reason about when trying to understand behavior, and are subject to fuzzer rot.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some tests. I refactored the timeval conversion to a separate function to make testing easier.

@stale
Copy link

stale bot commented May 27, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label May 27, 2019
@htuch
Copy link
Member

htuch commented May 28, 2019

@ipuustin friendly ping on this one.

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label May 28, 2019
The approach proposed in envoyproxy#4332 indeed solves the integer overflow issue
(and results in nicer code). Refactor the conversion in a separate
function for testing and add some basic tests.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

@ipuustin thanks for the test and cleanups. A couple of small nits but otherwise looks great.
/wait

@@ -18,25 +18,21 @@ TimerImpl::TimerImpl(Libevent::BasePtr& libevent, TimerCb cb) : cb_(cb) {

void TimerImpl::disableTimer() { event_del(&raw_event_); }

void TimerImpl::millisecondsToTimeval(timeval* tv, const std::chrono::milliseconds& d) {
Copy link
Member

Choose a reason for hiding this comment

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

Tiny nit: Envoy tends to have the order be input parameters followed by output parameters, and to use mutable ref. So, can this be TimerImpl::millisecondsToTimeval(const std::chrono::milliseconds& d, timeval& tv)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! This is good advice regarding the code conventions.

@@ -18,25 +18,21 @@ TimerImpl::TimerImpl(Libevent::BasePtr& libevent, TimerCb cb) : cb_(cb) {

void TimerImpl::disableTimer() { event_del(&raw_event_); }

void TimerImpl::millisecondsToTimeval(timeval* tv, const std::chrono::milliseconds& d) {
ASSERT(tv);
Copy link
Member

Choose a reason for hiding this comment

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

This can be skipped

@@ -22,6 +22,9 @@ class TimerImpl : public Timer, ImplBase {
void enableTimer(const std::chrono::milliseconds& d) override;
bool enabled() override;

// Public for testing.
void millisecondsToTimeval(timeval* tv, const std::chrono::milliseconds& d);
Copy link
Member

Choose a reason for hiding this comment

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

Suggest putting in a utility class, e.g. TimerUtils and making static

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. I was originally aiming to do "minimal" changes but a separate class makes sense.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
@ipuustin
Copy link
Member Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: coverage (failed build)

🐱

Caused by: a #6982 (comment) was created by @ipuustin.

see: more, trace.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@htuch htuch merged commit be6a483 into envoyproxy:master May 31, 2019
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.

None yet

2 participants