| From 385b5ec1f31dd39297578eed42be74b07ae74017 Mon Sep 17 00:00:00 2001 | |
| From: Hungyu Lin <dennylin0707@gmail.com> | |
| Date: Fri, 30 Oct 2026 05:42:26 +0000 | |
| Subject: timekeeping: Read getboottime64() offsets under the sequence counter | |
| From: Hungyu Lin <dennylin0707@gmail.com> | |
| commit 385b5ec1f31dd39297578eed42be74b07ae74017 upstream. | |
| getboottime64() computes the wall-clock boot timestamp from offs_real | |
| minus offs_boot without checking tk_core.seq. A concurrent timekeeping | |
| update can leave the reader with an inconsistent pair of offsets or, | |
| on 32-bit systems, a torn 64-bit offset, producing an incorrect boot | |
| timestamp. | |
| Read both offsets under tk_core.seq and retry if an update overlaps | |
| the sample. Convert the resulting local value to a timespec64 afterward. | |
| Fixes: 7c3f1a573237 ("Introduce boot based time") | |
| Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> | |
| Signed-off-by: Thomas Gleixner <tglx@kernel.org> | |
| Acked-by: John Stultz <jstultz@google.com> | |
| Cc: stable@vger.kernel.org | |
| Link: https://patch.msgid.link/20261030054227.35453-2-dennylin0707@gmail.com | |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
| --- | |
| kernel/time/timekeeping.c | 8 +++++++- | |
| 1 file changed, 7 insertions(+), 1 deletion(-) | |
| --- a/kernel/time/timekeeping.c | |
| +++ b/kernel/time/timekeeping.c | |
| @@ -2698,7 +2698,13 @@ void update_wall_time(void) | |
| void getboottime64(struct timespec64 *ts) | |
| { | |
| struct timekeeper *tk = &tk_core.timekeeper; | |
| - ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot); | |
| + unsigned int seq; | |
| + ktime_t t; | |
| + | |
| + do { | |
| + seq = read_seqcount_begin(&tk_core.seq); | |
| + t = ktime_sub(tk->offs_real, tk->offs_boot); | |
| + } while (read_seqcount_retry(&tk_core.seq, seq)); | |
| *ts = ktime_to_timespec64(t); | |
| } |