[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-bugs] #23558 [Core Tor/Tor]: sched: KIST schedule() bad cast on monotime_diff_msec()



#23558: sched: KIST schedule() bad cast on monotime_diff_msec()
------------------------------+--------------------------------
     Reporter:  dgoulet       |      Owner:  dgoulet
         Type:  defect        |     Status:  assigned
     Priority:  Very High     |  Milestone:  Tor: 0.3.2.x-final
    Component:  Core Tor/Tor  |    Version:
     Severity:  Normal        |   Keywords:  tor-sched
Actual Points:                |  Parent ID:
       Points:                |   Reviewer:  pastly
      Sponsor:                |
------------------------------+--------------------------------
 This code snippet creates a cast "overflow" from 64 bit to 32 bit:

 {{{
   diff = (int32_t) monotime_diff_msec(&scheduler_last_run, &now);
 }}}

 Because at boot time, `scheduler_last_run` is set to 0 (static value), the
 diff that comes out is simply bigger than `int32_t` everytime leading to a
 diff value that is negative.

 And then we would add the next run to libevent with a humongeous usec
 value (and remember that `diff` is big negative number):

 {{{
 next_run.tv_usec = (sched_run_interval - diff) * 1000;
 }}}

 Leading to libevent to fail to add the event and thus the scheduler never
 runs.

 The fix here is to use `int64_t` and `BUG()` the `event_add/active()` so
 we can catch such issue in the future.

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/23558>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs