Re: [PATCH] timekeeping: Use data_race() and READ_ONCE() in ktime_get_real_seconds()
From: Thomas Gleixner
Date: Mon Jul 20 2026 - 10:08:17 EST
On Mon, Jul 20 2026 at 09:40, Dennis Moshegov wrote:
> From: Dennis M <dennismoshegov@xxxxxxxxx>
This from line mail address is not matching the
> Subject: [PATCH v3] timekeeping: Use READ_ONCE/WRITE_ONCE for
> xtime_sec to prevent tearing
>
> The timekeeper update path uses a bulk memcpy() to
> synchronize the timekeeper structure, which is not guaranteed to be atomic.
> This allows for torn reads in ktime_get_real_seconds() on 64-bit systems,
> where the sequence counter protection is bypassed for performance.
>
> To prevent reading a torn 64-bit xtime_sec value, enforce atomic-like
> access by using WRITE_ONCE() for the critical field before the bulk
> memcpy() in timekeeping_update_from_shadow(). Correspondingly, use
> READ_ONCE() in ktime_get_real_seconds() to ensure a fresh, consistent
> load from memory.
>
> Reported-by: syzbot+72789cd1697965e714ca@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspotmail.com/bug?extid=72789cd1697965e714ca
> Signed-off-by: Dennis Moshegov <dennis@xxxxxxxx>
one used here. Please make your mind up which of your personalities you
awant to use.
> ---
> timekeeping.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index c493a40..461a68e 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -826,6 +826,7 @@ static void timekeeping_update_from_shadow(struct
> tk_data *tkd, unsigned int action)
> * the cacheline optimized data layout of the timekeeper and requires
> * another indirection.
> */
> + WRITE_ONCE(tkd->timekeeper.xtime_secy, tk->xtime_sec);
> memcpy(&tkd->timekeeper, tk, sizeof(*tk));
> write_seqcount_end(&tkd->seq);
Again you used copy & paste to get the patch into your mail client or
imported it and gmail mangled it.
patching file kernel/time/timekeeping.c
patch: **** malformed patch at line 34: tk_data *tkd, unsigned int action)
See Documentation/process/email-clients.rst
The only known way to send patches with the gmail web client is as
attachment, but that's a pain for reviewing, replying and applying.
But you can use git send-email with gmail smtp and that will do the
right thing.
Thanks,
tglx