time, ntp: Do not update time_state in middle of leap second
PATCH 1/1 time, ntp: Do not update time_state in middle of leap second
During leap second insertion testing it was noticed that a small window exists where the time_state could be reset such that time_state = TIME_OK, which then causes the leap second to not occur, or causes the entire leap second state machine to fail.
While this is highly unlikely to ever happen in the real world it is still something we should protect against, as breaking the state machine is obviously bad.
If the time_state == TIME_OOP (ie, the leap second is in progress) do not allow an external update to time_state.
[v2]: Only block time_state change when TIME_OOP
--- kernel/time/ntp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/ntp.c +2 -1
@@ -535,7 +535,8 @@ void ntp_notify_cmos_timer(void) { }static inline void process_adj_status (struct timex *txc,struct timespec64 *ts) {if ((time_status &STA_PLL ) && !(txc->status &STA_PLL )) { - time_state =TIME_OK ; +if (time_state !=TIME_OOP ) + time_state =TIME_OK ; time_status =STA_UNSYNC ;/* restart PPS frequency calibration */ pps_reset_freq_interval ();
Signature · 1 line
1.7.9.3
Quoted 12 lines · Prarit Bhargava
During leap second insertion testing it was noticed that a small window exists where the
time_statecould be reset such thattime_state=TIME_OK, which then causes the leap second to not occur, or causes the entire leap second state machine to fail.While this is highly unlikely to ever happen in the real world it is still something we should protect against, as breaking the state machine is obviously bad.
If the
time_state==TIME_OOP(ie, the leap second is in progress) do not allow an external update totime_state.
Quoted 6 lines
[v2]: Only block
time_statechange whenTIME_OOPSigned-off-by Prarit Bhargava <[email protected]>Cc John Stultz <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Miroslav Lichvar <[email protected]>
John, ACK?
Quoted 4 lines · Prarit Bhargava
During leap second insertion testing it was noticed that a small window exists where the
time_statecould be reset such thattime_state=TIME_OK, which then causes the leap second to not occur, or causes the entire leap second state machine to fail.
I think this description is fairly opaque, and probably needs the specific example of the state change transitions that motivates this patch.
Quoted 3 lines
While this is highly unlikely to ever happen in the real world it is still something we should protect against, as breaking the state machine is obviously bad.
In this case it was a test-case bug where uninitialized data being passed to adjtimex (when the test intended to only read the time state) was causing an unexpected state change transition. So its not immediately obvious that resetting the state machine when the root called adjtimex is invalid, so it would be good to make this more clear and explicit (ie: show the expected state transitions and the command that caused the strange transition you saw).
Sorry for the slow response here, I've been on the fence as to if this is the right thing or not, and have needed to get some time to stare at this a bit more to see if I can convince myself its the right thing, so improving the commit message might make it more obvious to me and others. :)
thanks
-john
Quoted 23 lines · John Stultz
Quoted 4 lines · Prarit Bhargava
During leap second insertion testing it was noticed that a small window exists where the
time_statecould be reset such thattime_state=TIME_OK, which then causes the leap second to not occur, or causes the entire leap second state machine to fail.I think this description is fairly opaque, and probably needs the specific example of the state change transitions that motivates this patch.
Quoted 3 lines
While this is highly unlikely to ever happen in the real world it is still something we should protect against, as breaking the state machine is obviously bad.
In this case it was a test-case bug where uninitialized data being passed to adjtimex (when the test intended to only read the time state) was causing an unexpected state change transition. So its not immediately obvious that resetting the state machine when the root called adjtimex is invalid, so it would be good to make this more clear and explicit (ie: show the expected state transitions and the command that caused the strange transition you saw).
Quoted 5 lines
Sorry for the slow response here, I've been on the fence as to if this is the right thing or not, and have needed to get some time to stare at this a bit more to see if I can convince myself its the right thing, so improving the commit message might make it more obvious to me and others. :)
Will do :) I'll write up a proper and detailed description. My bad.
P.
Quoted 4 lines
thanks
-john