Opened 2 years ago

Closed 2 years ago

#23558 closed defect (fixed)

sched: KIST schedule() bad cast on monotime_diff_msec()

Reported by: dgoulet Owned by: dgoulet
Priority: Very High Milestone: Tor: 0.3.2.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords: tor-sched
Cc: Actual Points:
Parent ID: Points:
Reviewer: pastly Sponsor:

Description

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.

Child Tickets

Change History (2)

comment:1 Changed 2 years ago by dgoulet

Status: assignedneeds_review

See branch: bug23558_032_01

comment:2 Changed 2 years ago by nickm

Resolution: fixed
Status: needs_reviewclosed

lgtm; merged.

Note: See TracTickets for help on using tickets.