| 0/0 |
2026/05/30 17:33 |
flow |
assessment-security |
45m
Results: map[DenialOfService:false Explanation:Based on the analysis of the provided bug report and the kernel source code,
here is the assessment:
**Bug Analysis:**
The report describes a KCSAN (Kernel Concurrency Sanitizer) data-race between a
read in `ktime_get_coarse_ts64` (via `tk_xtime_coarse`) and a write in
`timekeeping_update_from_shadow`.
Looking at the source code for `ktime_get_coarse_ts64`:
```c
do {
seq = read_seqcount_begin(&tk_core.seq);
now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
now.tv_nsec + mono.tv_nsec);
```
The read of `tk->coarse_nsec` inside `tk_xtime_coarse` is performed using a
plain C memory access. Concurrently, `timekeeping_update_from_shadow` updates
the timekeeper data using `memcpy()`, protected by `write_seqcount_begin()` and
`write_seqcount_end()`.
Because the reader does not use `READ_ONCE()` or `data_race()` annotations,
KCSAN correctly detects that a concurrent read and write can happen at the same
memory location and flags it as a data race.
However, this is a **benign data race** by design. The read is enclosed within a
standard sequence counter (`seqcount`) retry loop. If a concurrent write occurs
while the reader is fetching the data, the `read_seqcount_retry()` check will
fail, and the loop will simply re-execute to fetch the consistent data. The
potentially torn or inconsistent values of `now` and `mono` read during the
collision are strictly kept as local variables and are only utilized *after* the
seqcount loop has successfully verified that no concurrent modification took
place.
**Security Impact:**
- **Exploitable:** No. The data race is benign and handled correctly by the
seqcount synchronization mechanism. It cannot lead to memory corruption,
out-of-bounds accesses, or privilege escalation.
- **Denial of Service:** No. The kernel state remains perfectly consistent.
KCSAN reports do not halt the kernel in production environments, and the
underlying condition does not violate any actual kernel safety assumptions.
- **Unprivileged Access:** Yes. The read path can be trivially reached by any
unprivileged user-space application by invoking the `clock_gettime()` syscall
with `CLOCK_MONOTONIC_COARSE` or `CLOCK_REALTIME_COARSE`. (The bug report shows
it being reached via a BPF test run, but the syscall is the most direct path).
In conclusion, this is a false positive from the perspective of kernel safety
and security, stemming from missing data race annotations (`data_race()` or
`READ_ONCE()`) in the timekeeping seqcount reader path. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/30 17:33 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/30 17:33 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/068d86cbbb435164b715cde66713d3b7d36e930b]
|
| 3/1 |
2026/05/30 17:35 |
action |
kernel-builder |
21m
Results: map[KernelObj:/app/workdir/cache/build/410b02c3513f9a6db8a7343ec01c377ddc88d8b5]
|
| 4/1 |
2026/05/30 17:57 |
action |
codesearch-prepare |
9m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/30 18:06 |
agent |
expert |
12m
Model:
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
==================================================================
BUG: KCSAN: data-race in ktime_get_coarse_ts64 / timekeeping_update_from_shadow
write to 0xffffffff895d8488 of 304 bytes by interrupt on cpu 1:
timekeeping_update_from_shadow+0x40d/0x440 kernel/time/timekeeping.c:829
__timekeeping_advance+0xa5d/0xc10 kernel/time/timekeeping.c:2532
timekeeping_advance kernel/time/timekeeping.c:2540 [inline]
update_wall_time+0x21/0x50 kernel/time/timekeeping.c:2550
tick_do_update_jiffies64+0x169/0x1c0 kernel/time/tick-sched.c:149
tick_sched_do_timer kernel/time/tick-sched.c:253 [inline]
tick_nohz_handler+0x8d/0x3d0 kernel/time/tick-sched.c:312
__run_hrtimer kernel/time/hrtimer.c:1930 [inline]
__hrtimer_run_queues+0x276/0x4f0 kernel/time/hrtimer.c:1994
hrtimer_interrupt+0x261/0x850 kernel/time/hrtimer.c:2113
local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1050 [inline]
__sysvec_apic_timer_interrupt+0x5f/0x1c0 arch/x86/kernel/apic/apic.c:1067
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1061 [inline]
sysvec_apic_timer_interrupt+0x6f/0x80 arch/x86/kernel/apic/apic.c:1061
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
native_safe_halt arch/x86/include/asm/irqflags.h:48 [inline]
pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:62
arch_safe_halt arch/x86/kernel/process.c:766 [inline]
default_idle+0x9/0x20 arch/x86/kernel/process.c:767
default_idle_call+0x3b/0x60 kernel/sched/idle.c:122
cpuidle_idle_call kernel/sched/idle.c:199 [inline]
do_idle+0x17f/0x2b0 kernel/sched/idle.c:352
cpu_startup_entry+0x24/0x30 kernel/sched/idle.c:451
start_secondary+0x95/0xa0 arch/x86/kernel/smpboot.c:312
common_startup_64+0x13e/0x147
read to 0xffffffff895d84f8 of 4 bytes by task 4851 on cpu 0:
tk_xtime_coarse kernel/time/timekeeping.c:212 [inline]
ktime_get_coarse_ts64+0x6d/0x120 kernel/time/timekeeping.c:2685
ktime_get_coarse include/linux/timekeeping.h:133 [inline]
ktime_get_coarse_ns include/linux/timekeeping.h:139 [inline]
____bpf_ktime_get_coarse_ns kernel/bpf/helpers.c:204 [inline]
bpf_ktime_get_coarse_ns+0x39/0xb0 kernel/bpf/helpers.c:202
bpf_prog_ce3dfd7f9330a559+0x1e/0x29
bpf_dispatcher_nop_func include/linux/bpf.h:1402 [inline]
__bpf_prog_run include/linux/filter.h:722 [inline]
bpf_prog_run include/linux/filter.h:729 [inline]
bpf_prog_run_pin_on_cpu include/linux/filter.h:746 [inline]
bpf_flow_dissect+0x158/0x350 net/core/flow_dissector.c:1024
bpf_prog_test_run_flow_dissector+0x25d/0x360 net/bpf/test_run.c:1525
bpf_prog_test_run+0x204/0x340 kernel/bpf/syscall.c:4742
__sys_bpf+0x52e/0x7e0 kernel/bpf/syscall.c:6266
__do_sys_bpf kernel/bpf/syscall.c:6361 [inline]
__se_sys_bpf kernel/bpf/syscall.c:6359 [inline]
__x64_sys_bpf+0x41/0x50 kernel/bpf/syscall.c:6359
x64_sys_call+0x10cb/0x3020 arch/x86/include/generated/asm/syscalls_64.h:322
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x1972605a -> 0x1a0c2809
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 4851 Comm: syz.6.270 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/18/2026
==================================================================
Reply: Based on the analysis of the provided bug report and the kernel source code, here is the assessment:
**Bug Analysis:**
The report describes a KCSAN (Kernel Concurrency Sanitizer) data-race between a read in `ktime_get_coarse_ts64` (via `tk_xtime_coarse`) and a write in `timekeeping_update_from_shadow`.
Looking at the source code for `ktime_get_coarse_ts64`:
```c
do {
seq = read_seqcount_begin(&tk_core.seq);
now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
now.tv_nsec + mono.tv_nsec);
```
The read of `tk->coarse_nsec` inside `tk_xtime_coarse` is performed using a plain C memory access. Concurrently, `timekeeping_update_from_shadow` updates the timekeeper data using `memcpy()`, protected by `write_seqcount_begin()` and `write_seqcount_end()`.
Because the reader does not use `READ_ONCE()` or `data_race()` annotations, KCSAN correctly detects that a concurrent read and write can happen at the same memory location and flags it as a data race.
However, this is a **benign data race** by design. The read is enclosed within a standard sequence counter (`seqcount`) retry loop. If a concurrent write occurs while the reader is fetching the data, the `read_seqcount_retry()` check will fail, and the loop will simply re-execute to fetch the consistent data. The potentially torn or inconsistent values of `now` and `mono` read during the collision are strictly kept as local variables and are only utilized *after* the seqcount loop has successfully verified that no concurrent modification took place.
**Security Impact:**
- **Exploitable:** No. The data race is benign and handled correctly by the seqcount synchronization mechanism. It cannot lead to memory corruption, out-of-bounds accesses, or privilege escalation.
- **Denial of Service:** No. The kernel state remains perfectly consistent. KCSAN reports do not halt the kernel in production environments, and the underlying condition does not violate any actual kernel safety assumptions.
- **Unprivileged Access:** Yes. The read path can be trivially reached by any unprivileged user-space application by invoking the `clock_gettime()` syscall with `CLOCK_MONOTONIC_COARSE` or `CLOCK_REALTIME_COARSE`. (The bug report shows it being reached via a BPF test run, but the syscall is the most direct path).
In conclusion, this is a false positive from the perspective of kernel safety and security, stemming from missing data race annotations (`data_race()` or `READ_ONCE()`) in the timekeeping seqcount reader path.
|
| 6/2 |
2026/05/30 18:06 |
llm |
expert |
0m
Model:
Tokens:
input: 7044
output: 37
thoughts: 191
Thoughts: **Analyzing a KCSAN Data-Race in Timekeeping**
Okay, so this bug report is pointing to a KCSAN data-race. The crux of the issue seems to be centered around the interaction between `ktime_get_coarse_ts64` and `timekeeping_update_from_shadow`. Specifically, a write is occurring within `timekeeping_update_from_shadow` on CPU 1, while a read is happening concurrently in `ktime_get_coarse_ts64` on CPU 0. We need to dissect the code.
My initial thought is to examine the read side first. I'll need to look at the definitions of `tk_xtime_coarse` at line 212 and `ktime_get_coarse_ts64` itself at line 2685, both within `kernel/time/timekeeping.c`. This will likely reveal how the shared data is being accessed and hopefully, what data is being read.
Next, I need to understand the write side. I'll need to examine `timekeeping_update_from_shadow` at line 829 in `kernel/time/timekeeping.c` and confirm that it is indeed the source of the write and the exact data that's being written.
After that, I'll focus on the area around these lines in `kernel/time/timekeeping.c`. The race probably involves some shared state accessed between the read and write functions. I'll want to trace through the code, looking for any missing synchronization primitives or incorrect usage of atomic operations.
|
| 7/2 |
2026/05/30 18:06 |
tool |
read-file |
0m
Args: map[File:kernel/time/timekeeping.c FirstLine:200 LineCount:100]
Results: map[Contents: 200: struct timespec64 ts;
201:
202: ts.tv_sec = tk->xtime_sec;
203: ts.tv_nsec = (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift);
204: return ts;
205: }
206:
207: static inline struct timespec64 tk_xtime_coarse(const struct timekeeper *tk)
208: {
209: struct timespec64 ts;
210:
211: ts.tv_sec = tk->xtime_sec;
212: ts.tv_nsec = tk->coarse_nsec;
213: return ts;
214: }
215:
216: /*
217: * Update the nanoseconds part for the coarse time keepers. They can't rely
218: * on xtime_nsec because xtime_nsec could be adjusted by a small negative
219: * amount when the multiplication factor of the clock is adjusted, which
220: * could cause the coarse clocks to go slightly backwards. See
221: * timekeeping_apply_adjustment(). Thus we keep a separate copy for the coarse
222: * clockids which only is updated when the clock has been set or we have
223: * accumulated time.
224: */
225: static inline void tk_update_coarse_nsecs(struct timekeeper *tk)
226: {
227: tk->coarse_nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
228: }
229:
230: static void tk_set_xtime(struct timekeeper *tk, const struct timespec64 *ts)
231: {
232: tk->xtime_sec = ts->tv_sec;
233: tk->tkr_mono.xtime_nsec = (u64)ts->tv_nsec << tk->tkr_mono.shift;
234: tk_update_coarse_nsecs(tk);
235: }
236:
237: static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts)
238: {
239: tk->xtime_sec += ts->tv_sec;
240: tk->tkr_mono.xtime_nsec += (u64)ts->tv_nsec << tk->tkr_mono.shift;
241: tk_normalize_xtime(tk);
242: tk_update_coarse_nsecs(tk);
243: }
244:
245: static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm)
246: {
247: struct timespec64 tmp;
248:
249: /*
250: * Verify consistency of: offset_real = -wall_to_monotonic
251: * before modifying anything
252: */
253: set_normalized_timespec64(&tmp, -tk->wall_to_monotonic.tv_sec,
254: -tk->wall_to_monotonic.tv_nsec);
255: WARN_ON_ONCE(tk->offs_real != timespec64_to_ktime(tmp));
256: tk->wall_to_monotonic = wtm;
257: set_normalized_timespec64(&tmp, -wtm.tv_sec, -wtm.tv_nsec);
258: /* Paired with READ_ONCE() in ktime_mono_to_any() */
259: WRITE_ONCE(tk->offs_real, timespec64_to_ktime(tmp));
260: WRITE_ONCE(tk->offs_tai, ktime_add(tk->offs_real, ktime_set(tk->tai_offset, 0)));
261: }
262:
263: static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta)
264: {
265: /* Paired with READ_ONCE() in ktime_mono_to_any() */
266: WRITE_ONCE(tk->offs_boot, ktime_add(tk->offs_boot, delta));
267: /*
268: * Timespec representation for VDSO update to avoid 64bit division
269: * on every update.
270: */
271: tk->monotonic_to_boot = ktime_to_timespec64(tk->offs_boot);
272: }
273:
274: #ifdef CONFIG_ARCH_WANTS_CLOCKSOURCE_READ_INLINE
275: #include <asm/clock_inlined.h>
276:
277: static DEFINE_STATIC_KEY_FALSE(clocksource_read_inlined);
278:
279: /*
280: * tk_clock_read - atomic clocksource read() helper
281: *
282: * This helper is necessary to use in the read paths because, while the
283: * seqcount ensures we don't return a bad value while structures are updated,
284: * it doesn't protect from potential crashes. There is the possibility that
285: * the tkr's clocksource may change between the read reference, and the
286: * clock reference passed to the read function. This can cause crashes if
287: * the wrong clocksource is passed to the wrong read function.
288: * This isn't necessary to use when holding the tk_core.lock or doing
289: * a read of the fast-timekeeper tkrs (which is protected by its own locking
290: * and update logic).
291: */
292: static __always_inline u64 tk_clock_read(const struct tk_read_base *tkr)
293: {
294: struct clocksource *clock = READ_ONCE(tkr->clock);
295:
296: if (static_branch_likely(&clocksource_read_inlined))
297: return arch_inlined_clocksource_read(clock);
298:
299: return clock->read(clock);
]
|
| 8/2 |
2026/05/30 18:06 |
llm |
expert |
0m
Model:
Tokens:
input: 9377
output: 37
thoughts: 42
Thoughts: Here's a summary of my thought process, as requested:
**Navigating a Timestamp Assignment**
Okay, I'm currently focused on a specific point in this code, line 212: `ts.tv_nsec = tk->coarse_nsec;`. This is where a timestamp's nanosecond component is being set. My immediate concern is the relationship between this read and a potential write to `tk->coarse_nsec`. I need to understand if there are any race conditions or data dependencies here, especially considering the potential for this to impact timing accuracy or introduce subtle bugs. My next step is to locate the write operation to `tk->coarse_nsec`. I'll jump to line 829. Once I find it, I'll analyze how the write interacts with this read. I'll need to consider factors like synchronization mechanisms, potential interrupts, and the overall context of these operations within the larger timing subsystem. I'm looking for any clues about how `tk->coarse_nsec` is initialized, updated, and used to determine if the timestamp assignment on line 212 could lead to issues. I'm especially interested in how the "coarse" nanosecond value is managed.
|
| 9/2 |
2026/05/30 18:06 |
tool |
read-file |
0m
Args: map[File:kernel/time/timekeeping.c FirstLine:800 LineCount:100]
Results: map[Contents: 800: ntp_clear(tk->id);
801: }
802:
803: tk_update_leap_state(tk);
804: tk_update_ktime_data(tk);
805: tk->tkr_mono.base_real = tk->tkr_mono.base + tk->offs_real;
806:
807: if (tk->id == TIMEKEEPER_CORE) {
808: tk_update_ns_to_cyc(tk, &tkd->timekeeper);
809: update_vsyscall(tk);
810: update_pvclock_gtod(tk, action & TK_CLOCK_WAS_SET);
811:
812: update_fast_timekeeper(&tk->tkr_mono, &tk_fast_mono);
813: update_fast_timekeeper(&tk->tkr_raw, &tk_fast_raw);
814: } else if (tk_is_aux(tk)) {
815: vdso_time_update_aux(tk);
816: }
817:
818: if (action & TK_CLOCK_WAS_SET)
819: tk->clock_was_set_seq++;
820:
821: /*
822: * Update the real timekeeper.
823: *
824: * We could avoid this memcpy() by switching pointers, but that has
825: * the downside that the reader side does not longer benefit from
826: * the cacheline optimized data layout of the timekeeper and requires
827: * another indirection.
828: */
829: memcpy(&tkd->timekeeper, tk, sizeof(*tk));
830: write_seqcount_end(&tkd->seq);
831: }
832:
833: /**
834: * timekeeping_forward_now - update clock to the current time
835: * @tk: Pointer to the timekeeper to update
836: *
837: * Forward the current clock to update its state since the last call to
838: * update_wall_time(). This is useful before significant clock changes,
839: * as it avoids having to deal with this time offset explicitly.
840: */
841: static void timekeeping_forward_now(struct timekeeper *tk)
842: {
843: u64 cycle_now, delta;
844:
845: cycle_now = tk_clock_read(&tk->tkr_mono);
846: delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask,
847: tk->tkr_mono.clock->max_raw_delta);
848: tk->tkr_mono.cycle_last = cycle_now;
849: tk->tkr_raw.cycle_last = cycle_now;
850:
851: while (delta > 0) {
852: u64 max = tk->tkr_mono.clock->max_cycles;
853: u64 incr = delta < max ? delta : max;
854:
855: tk->tkr_mono.xtime_nsec += incr * tk->tkr_mono.mult;
856: tk->tkr_raw.xtime_nsec += incr * tk->tkr_raw.mult;
857: tk_normalize_xtime(tk);
858: delta -= incr;
859: }
860: tk_update_coarse_nsecs(tk);
861: }
862:
863: /*
864: * ktime_expiry_to_cycles - Convert a expiry time to clocksource cycles
865: * @id: Clocksource ID which is required for validity
866: * @expires_ns: Absolute CLOCK_MONOTONIC expiry time (nsecs) to be converted
867: * @cycles: Pointer to storage for corresponding absolute cycles value
868: *
869: * Convert a CLOCK_MONOTONIC based absolute expiry time to a cycles value
870: * based on the correlated clocksource of the clockevent device by using
871: * the base nanoseconds and cycles values of the last timekeeper update and
872: * converting the delta between @expires_ns and base nanoseconds to cycles.
873: *
874: * This only works for clockevent devices which are using a less than or
875: * equal comparator against the clocksource.
876: *
877: * Utilizing this avoids two clocksource reads for such devices, the
878: * ktime_get() in clockevents_program_event() to calculate the delta expiry
879: * value and the readout in the device::set_next_event() callback to
880: * convert the delta back to a absolute comparator value.
881: *
882: * Returns: True if @id matches the current clocksource ID, false otherwise
883: */
884: bool ktime_expiry_to_cycles(enum clocksource_ids id, ktime_t expires_ns, u64 *cycles)
885: {
886: struct timekeeper *tk = &tk_core.timekeeper;
887: struct tk_read_base *tkrm = &tk->tkr_mono;
888: ktime_t base_ns, delta_ns, max_ns;
889: u64 base_cycles, delta_cycles;
890: unsigned int seq;
891: u32 mult, shift;
892:
893: /*
894: * Racy check to avoid the seqcount overhead when ID does not match. If
895: * the relevant clocksource is installed concurrently, then this will
896: * just delay the switch over to this mechanism until the next event is
897: * programmed. If the ID is not matching the clock events code will use
898: * the regular relative set_next_event() callback as before.
899: */
]
|
| 10/2 |
2026/05/30 18:06 |
llm |
expert |
0m
Model:
Tokens:
input: 11427
output: 37
thoughts: 87
Thoughts: Here's my analysis of the code, presented as if it were my thought process:
**Analyzing Potential Data Races in Timekeeping**
Okay, let's break this down. Line 829, that `memcpy(&tkd->timekeeper, tk, sizeof(*tk));`, is a write to `tkd->timekeeper`. I need to figure out where the corresponding reads are happening. It looks like a `ktime` structure is being copied, which is a common pattern, but potential data races are what I'm focused on.
The read that jumps out is on line 212: `ts.tv_nsec = tk->coarse_nsec;`. This is inside of `ktime_get_coarse_ts64`. So the crucial question is, are these write and read operations synchronized? I need to dig into the `ktime_get_coarse_ts64` function and trace how `tk->coarse_nsec` is accessed and whether there's any concurrent access happening without proper locking. We're dealing with timekeeping, which is *extremely* sensitive to race conditions. I'll need to meticulously analyze the surrounding code to ensure these accesses are atomic, or protected by appropriate synchronization primitives.
|
| 11/2 |
2026/05/30 18:06 |
tool |
read-file |
0m
Args: map[File:kernel/time/timekeeping.c FirstLine:2670 LineCount:50]
Results: map[Contents:2670: * is enough to effect a change to ctime. Accept it.
2671: */
2672: *ts = ktime_to_timespec64(ktime_add(old, offset));
2673: }
2674: }
2675:
2676: void ktime_get_coarse_ts64(struct timespec64 *ts)
2677: {
2678: struct timekeeper *tk = &tk_core.timekeeper;
2679: struct timespec64 now, mono;
2680: unsigned int seq;
2681:
2682: do {
2683: seq = read_seqcount_begin(&tk_core.seq);
2684:
2685: now = tk_xtime_coarse(tk);
2686: mono = tk->wall_to_monotonic;
2687: } while (read_seqcount_retry(&tk_core.seq, seq));
2688:
2689: set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
2690: now.tv_nsec + mono.tv_nsec);
2691: }
2692: EXPORT_SYMBOL(ktime_get_coarse_ts64);
2693:
2694: /*
2695: * Must hold jiffies_lock
2696: */
2697: void do_timer(unsigned long ticks)
2698: {
2699: jiffies_64 += ticks;
2700: calc_global_load();
2701: }
2702:
2703: /**
2704: * ktime_get_update_offsets_now - hrtimer helper
2705: * @cwsseq: pointer to check and store the clock was set sequence number
2706: * @offs_real: pointer to storage for monotonic -> realtime offset
2707: * @offs_boot: pointer to storage for monotonic -> boottime offset
2708: * @offs_tai: pointer to storage for monotonic -> clock tai offset
2709: *
2710: * Returns current monotonic time and updates the offsets if the
2711: * sequence number in @cwsseq and timekeeper.clock_was_set_seq are
2712: * different.
2713: *
2714: * Called from hrtimer_interrupt() or retrigger_next_event()
2715: */
2716: ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real,
2717: ktime_t *offs_boot, ktime_t *offs_tai)
2718: {
2719: struct timekeeper *tk = &tk_core.timekeeper;
]
|
| 12/2 |
2026/05/30 18:06 |
llm |
expert |
0m
Model:
Tokens:
input: 12617
output: 36
thoughts: 119
Thoughts: Okay, let's break this down.
**Analyzing the Timekeeper Synchronization**
Right, so I'm looking at this code and immediately I see the use of `read_seqcount_begin` and `read_seqcount_retry` to protect the read access to the `timekeeper` data. Standard stuff for concurrent access; the sequence counter approach is generally quite efficient for read-mostly data. I'd expect this approach.
Now, the write side… that's where things get interesting. The code mentions `write_seqcount_begin` and `write_seqcount_end`, which are also expected. But that `memcpy` on line 829—that's the actual *data transfer*. I need to be sure the memory copy is handled correctly!
I wonder how the shadow copy is implemented in `timekeeping_update_from_shadow`. I better check that function to verify that the time is updated properly! This will determine how robust this synchronization scheme is. A lot depends on how the shadow copy works.
|
| 13/2 |
2026/05/30 18:07 |
tool |
read-file |
0m
Args: map[File:kernel/time/timekeeping.c FirstLine:780 LineCount:50]
Results: map[Contents: 780: memcpy(&tkd->shadow_timekeeper, &tkd->timekeeper, sizeof(tkd->timekeeper));
781: }
782:
783: static void timekeeping_update_from_shadow(struct tk_data *tkd, unsigned int action)
784: {
785: struct timekeeper *tk = &tkd->shadow_timekeeper;
786:
787: lockdep_assert_held(&tkd->lock);
788:
789: /*
790: * Block out readers before running the updates below because that
791: * updates VDSO and other time related infrastructure. Not blocking
792: * the readers might let a reader see time going backwards when
793: * reading from the VDSO after the VDSO update and then reading in
794: * the kernel from the timekeeper before that got updated.
795: */
796: write_seqcount_begin(&tkd->seq);
797:
798: if (action & TK_CLEAR_NTP) {
799: tk->ntp_error = 0;
800: ntp_clear(tk->id);
801: }
802:
803: tk_update_leap_state(tk);
804: tk_update_ktime_data(tk);
805: tk->tkr_mono.base_real = tk->tkr_mono.base + tk->offs_real;
806:
807: if (tk->id == TIMEKEEPER_CORE) {
808: tk_update_ns_to_cyc(tk, &tkd->timekeeper);
809: update_vsyscall(tk);
810: update_pvclock_gtod(tk, action & TK_CLOCK_WAS_SET);
811:
812: update_fast_timekeeper(&tk->tkr_mono, &tk_fast_mono);
813: update_fast_timekeeper(&tk->tkr_raw, &tk_fast_raw);
814: } else if (tk_is_aux(tk)) {
815: vdso_time_update_aux(tk);
816: }
817:
818: if (action & TK_CLOCK_WAS_SET)
819: tk->clock_was_set_seq++;
820:
821: /*
822: * Update the real timekeeper.
823: *
824: * We could avoid this memcpy() by switching pointers, but that has
825: * the downside that the reader side does not longer benefit from
826: * the cacheline optimized data layout of the timekeeper and requires
827: * another indirection.
828: */
829: memcpy(&tkd->timekeeper, tk, sizeof(*tk));
]
|
| 14/2 |
2026/05/30 18:07 |
llm |
expert |
0m
Model:
Tokens:
input: 13806
output: 35
thoughts: 275
Thoughts: **Analyzing the Timekeeping Data Structures**
Okay, so I'm looking at this timekeeping code, and it's using sequence counters, specifically `write_seqcount_begin` and `write_seqcount_end` to protect the write operations, and `read_seqcount_begin` and `read_seqcount_retry` for the reads. The code seems pretty standard, employing the `seqcount` mechanism to handle potential data races. Let me see... `tk_core` is a `struct tk_data`, right? So `tk_core.seq` is, in essence, the same sequence counter as `tkd->seq` when `tkd` points to `tk_core`. Yep, I see that `timekeeping_update_from_shadow` is called with `tkd = &tk_core`, which confirms my assumption. Thus, the read and write are indeed protected by the *very same* sequence counter.
Now, a KCSAN report of a data race when both read and write are sequence counter protected is *expected* if the read isn't using `READ_ONCE` or a similar atomic primitive. It's essentially detecting a concurrent memory access. The reader could be reading data while the writer is, potentially, modifying it. The retry loop handles the collision, retrying until the sequence counter is valid, but KCSAN picks up on the access itself. But wait... doesn't KCSAN understand sequence counters if they're properly annotated? So, I need to check something important. Is `tk_core.seq` a `seqcount_t` or a `seqcount_raw_spinlock_t`? That's the crux of this. Let's dig deeper and see what's actually declared.
|
| 15/2 |
2026/05/30 18:07 |
tool |
read-file |
0m
Args: map[File:kernel/time/timekeeping.c FirstLine:40 LineCount:50]
Results: map[Contents: 40: /* Update timekeeper on a direct frequency change */
41: TK_ADV_FREQ
42: };
43:
44: /*
45: * The most important data for readout fits into a single 64 byte
46: * cache line.
47: */
48: struct tk_data {
49: seqcount_raw_spinlock_t seq;
50: struct timekeeper timekeeper;
51: struct timekeeper shadow_timekeeper;
52: raw_spinlock_t lock;
53: } ____cacheline_aligned;
54:
55: static struct tk_data timekeeper_data[TIMEKEEPERS_MAX];
56:
57: /* The core timekeeper */
58: #define tk_core (timekeeper_data[TIMEKEEPER_CORE])
59:
60: #ifdef CONFIG_POSIX_AUX_CLOCKS
61: static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
62: {
63: return ktime_get_aux_ts64(CLOCK_AUX + tkid - TIMEKEEPER_AUX_FIRST, ts);
64: }
65:
66: static inline bool tk_is_aux(const struct timekeeper *tk)
67: {
68: return tk->id >= TIMEKEEPER_AUX_FIRST && tk->id <= TIMEKEEPER_AUX_LAST;
69: }
70: #else
71: static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
72: {
73: return false;
74: }
75:
76: static inline bool tk_is_aux(const struct timekeeper *tk)
77: {
78: return false;
79: }
80: #endif
81:
82: static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)
83: {
84: tk->offs_aux = offs;
85: tk->monotonic_to_aux = ktime_to_timespec64(offs);
86: }
87:
88: /* flag for if timekeeping is suspended */
89: int __read_mostly timekeeping_suspended;
]
|
| 16/2 |
2026/05/30 18:07 |
llm |
expert |
0m
Model:
Tokens:
input: 15170
output: 29
thoughts: 1066
Thoughts: **Analyzing a Benign Seqcount Data Race**
Okay, here's the breakdown of my thought process. I'm looking at this code and immediately see `seqcount_raw_spinlock_t seq;`. It's a seqcount, so I need to consider KCSAN implications. My first thought is: if the access is properly annotated or if the reader uses `data_race()` or `READ_ONCE()`, then KCSAN should be okay with it. However, with seqcounts, the readers *do* have concurrent reads with the writer, and simple C reads will trigger a KCSAN data race report.
Hmm, let me check – `read_seqcount_begin` doesn't suppress KCSAN, so what's going on here? In Linux, readers typically need explicit `data_race()` or `READ_ONCE()` calls, or KCSAN must have special handling for this. I thought maybe `read_seqcount_begin()` had some KCSAN magic but it does not.
Ah, I see this code:
```c
do {
seq = read_seqcount_begin(&tk_core.seq);
now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
```
and `tk_xtime_coarse` is:
```c
ts.tv_sec = tk->xtime_sec;
ts.tv_nsec = tk->coarse_nsec;
```
These are plain reads! The writer is doing a `memcpy` (likely instrumented) of the `timekeeper` struct. Classic seqcount data race; the reader grabs data while the writer's changing it. If it's inconsistent, the `read_seqcount_retry` loop will detect it and retry.
Okay, let's think about this. The compiler *could* theoretically do something nasty, but practically, this is fine. The kernel has tons of these seqcount data races. They're only considered dangerous if the compiler creates a situation where a crash happens *before* the retry can save the day – like reading and dereferencing a bad pointer. But here, `tk->xtime_sec` and `tk->coarse_nsec` are just integers. They get read into a `struct timespec64` on the stack and then used later in `set_normalized_timespec64`.
Wait a sec... `set_normalized_timespec64` is called *after* the retry loop!
```c
do {
seq = read_seqcount_begin(&tk_core.seq);
now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
now.tv_nsec + mono.tv_nsec);
```
So any potential for torn values from `now` and `mono` are only used *after* the seqcount's retry loop has made sure everything is consistent. Inside the loop, `now` and `mono` are just assigned. There's no way this causes a crash.
Therefore, this is a completely benign data race.
Now, just to be thorough, is there any way to exploit this? No. Benign data races are not exploitable. Could it cause a Denial of Service? No. This is just a KCSAN report. KCSAN warnings don't cause kernel panics by default. Even with `panic_on_warn`, that's a debug feature, not something you'd enable in production.
Wait, I need to check the prompt. "Determine if the bug can result in denial-of-service." Okay, most bugs *can*, since they cause system crash, hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash in production. For these think what will be consequences of the violation of the kernel assumptions flagged by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow (e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled, then it may or may not cause denial-of-service."
Since this is a KCSAN report of a benign data race, there's no violation of any kernel assumption that affects production. The seqcount logic is handling the concurrent modification perfectly. So, DenialOfService = false
|
| 17/2 |
2026/05/30 18:07 |
tool |
grepper |
0m
Error:
Args: map[Expression:data-race in ktime_get_coarse_ts64]
Results:
|
| 18/2 |
2026/05/30 18:07 |
llm |
expert |
0m
Model:
Tokens:
input: 17304
output: 32
thoughts: 15
Thoughts: Here's my thought process, summarized as you requested:
**Hunting Down Timekeeping Data Races**
Okay, so I need to find commits that address data races within the `timekeeping.c` file. That seems like a logical starting point for my investigation. Timekeeping is notoriously tricky, and concurrency issues there can be subtle and devastating. I'll need to use a search strategy that's precise enough to avoid drowning in irrelevant results, but broad enough to catch potential variations in commit messages. I'm thinking I'll start with a search using keywords related to "data race" along with "timekeeping.c", or perhaps variations of this such as "race condition", "concurrency bug", and "timekeeping". I'll also want to look for specific locking mechanisms they might use in that file, so phrases like 'spinlock', 'mutex', or even 'read-write locks' in relation to `timekeeping.c` could be useful. The goal is to identify commits that directly *fix* these problems, rather than simply mentioning them, so I should filter my search terms accordingly. I'll need to pay close attention to the context of any commit, not just the keywords.
|
| 19/2 |
2026/05/30 18:07 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:data_race.*tk_xtime_coarse Count:10]
Results:
|
| 20/2 |
2026/05/30 18:17 |
llm |
expert |
0m
Model:
Tokens:
input: 17635
output: 44
thoughts: 29
Thoughts: Here's my thought process, summarized as you requested:
**Investigating Potential Data Races in Timekeeping.c**
Okay, so I need to dig into `kernel/time/timekeeping.c`. Given my expertise, I suspect that area is prone to some delicate threading issues. I want to specifically look for evidence of potential data races or any related issues. To do this efficiently, I'll search the commit history for mentions of "data-race" or "KCSAN" within that specific file. These keywords should help me quickly identify patches that address concurrency concerns or bug reports related to this specific area of the kernel. This focused approach will hopefully illuminate any past or present vulnerabilities related to data access contention in the timekeeping subsystem. This should give me a good head start on understanding the current state and any areas that might require further investigation.
|
| 21/2 |
2026/05/30 18:17 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[KCSAN timekeeping] PathPrefix:kernel/time/timekeeping.c]
Results:
|
| 22/2 |
2026/05/30 18:17 |
llm |
expert |
0m
Model:
Tokens:
input: 17897
output: 39
thoughts: 21
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Kernel Timekeeping: A Focused Debugging Approach**
Alright, so I'm thinking, instead of a broad sweep, let's zero in on a potential culprit within the timekeeping subsystem. I'm going to start with a very targeted search. Specifically, I want to try and see if I can trigger anything, or find an issue, by focusing on "KCSAN" right inside `kernel/time/timekeeping.c`. A specific, narrow focus can often yield better results than a shotgun approach, especially when dealing with the intricacies of timing and the potential for subtle data races or memory corruption. This way, I'm isolating the core timekeeping code and the static analysis tools to see if I can find a vulnerability.
|
| 23/2 |
2026/05/30 18:17 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[KCSAN] PathPrefix:kernel/time/timekeeping.c]
Results: map[Output:d16317de9b41 seqlock/latch: Provide raw_read_seqcount_latch_retry()
]
|
| 24/2 |
2026/05/30 18:17 |
llm |
expert |
0m
Model:
Tokens:
input: 18173
output: 26
thoughts: 18
Thoughts: Okay, here's my attempt at summarizing the thought process, as if it were my own, assuming I'm an expert in the field:
**Initial Assessment: Examining a Specific Commit**
Right, let's take a look at commit `d16317de9b41`. Anytime I'm diving into a specific commit, the first thing I do is get a quick sense of the scope. Is this a minor fix, a significant feature addition, or something in-between? I'm already mentally preparing for what I might find. Is it isolated, or could it touch on multiple areas of the codebase? What kind of potential impact are we dealing with here? I'll probably start by just looking at the `git log` and see the author and commit message to get a context for what's inside. Then I'll dive in, but I'm trying to be methodical. Need to keep my head screwed on.
|
| 25/2 |
2026/05/30 18:17 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d16317de9b412aa7bd3598c607112298e36b4352
Author: Peter Zijlstra <peterz@infradead.org>
Date: Fri May 19 12:20:59 2023 +0200
seqlock/latch: Provide raw_read_seqcount_latch_retry()
The read side of seqcount_latch consists of:
do {
seq = raw_read_seqcount_latch(&latch->seq);
...
} while (read_seqcount_latch_retry(&latch->seq, seq));
which is asymmetric in the raw_ department, and sure enough,
read_seqcount_latch_retry() includes (explicit) instrumentation where
raw_read_seqcount_latch() does not.
This inconsistency becomes a problem when trying to use it from
noinstr code. As such, fix it by renaming and re-implementing
raw_read_seqcount_latch_retry() without the instrumentation.
Specifically the instrumentation in question is kcsan_atomic_next(0)
in do___read_seqcount_retry(). Loosing this annotation is not a
problem because raw_read_seqcount_latch() does not pass through
kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Michael Kelley <mikelley@microsoft.com> # Hyper-V
Link: https://lore.kernel.org/r/20230519102715.233598176@infradead.org
diff --git a/include/linux/rbtree_latch.h b/include/linux/rbtree_latch.h
index 3d1a9e716b80..6a0999c26c7c 100644
--- a/include/linux/rbtree_latch.h
+++ b/include/linux/rbtree_latch.h
@@ -206,7 +206,7 @@ latch_tree_find(void *key, struct latch_tree_root *root,
do {
seq = raw_read_seqcount_latch(&root->seq);
node = __lt_find(key, root, seq & 1, ops->comp);
- } while (read_seqcount_latch_retry(&root->seq, seq));
+ } while (raw_read_seqcount_latch_retry(&root->seq, seq));
return node;
}
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 3926e9027947..987a59d977c5 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -671,9 +671,9 @@ typedef struct {
*
* Return: sequence counter raw value. Use the lowest bit as an index for
* picking which data copy to read. The full counter must then be checked
- * with read_seqcount_latch_retry().
+ * with raw_read_seqcount_latch_retry().
*/
-static inline unsigned raw_read_seqcount_latch(const seqcount_latch_t *s)
+static __always_inline unsigned raw_read_seqcount_latch(const seqcount_latch_t *s)
{
/*
* Pairs with the first smp_wmb() in raw_write_seqcount_latch().
@@ -683,16 +683,17 @@ static inline unsigned raw_read_seqcount_latch(const seqcount_latch_t *s)
}
/**
- * read_seqcount_latch_retry() - end a seqcount_latch_t read section
+ * raw_read_seqcount_latch_retry() - end a seqcount_latch_t read section
* @s: Pointer to seqcount_latch_t
* @start: count, from raw_read_seqcount_latch()
*
* Return: true if a read section retry is required, else false
*/
-static inline int
-read_seqcount_latch_retry(const seqcount_latch_t *s, unsigned start)
+static __always_inline int
+raw_read_seqcount_latch_retry(const seqcount_latch_t *s, unsigned start)
{
- return read_seqcount_retry(&s->seqcount, start);
+ smp_rmb();
+ return unlikely(READ_ONCE(s->seqcount.sequence) != start);
}
/**
@@ -752,7 +753,7 @@ read_seqcount_latch_retry(const seqcount_latch_t *s, unsigned start)
* entry = data_query(latch->data[idx], ...);
*
* // This includes needed smp_rmb()
- * } while (read_seqcount_latch_retry(&latch->seq, seq));
+ * } while (raw_read_seqcount_latch_retry(&latch->seq, seq));
*
* return entry;
* }
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 6a333adce3b3..357a4d18f638 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -528,7 +528,7 @@ static u64 latched_seq_read_nolock(struct latched_seq *ls)
seq = raw_read_seqcount_latch(&ls->latch);
idx = seq & 0x1;
val = ls->val[idx];
- } while (read_seqcount_latch_retry(&ls->latch, seq));
+ } while (raw_read_seqcount_latch_retry(&ls->latch, seq));
return val;
}
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index 8464c5acc913..e8f2fb09a214 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -77,7 +77,7 @@ notrace struct clock_read_data *sched_clock_read_begin(unsigned int *seq)
notrace int sched_clock_read_retry(unsigned int seq)
{
- return read_seqcount_latch_retry(&cd.seq, seq);
+ return raw_read_seqcount_latch_retry(&cd.seq, seq);
}
unsigned long long notrace sched_clock(void)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 09d594900ee0..266d02809dbb 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -450,7 +450,7 @@ static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf)
tkr = tkf->base + (seq & 0x01);
now = ktime_to_ns(tkr->base);
now += fast_tk_get_delta_ns(tkr);
- } while (read_seqcount_latch_retry(&tkf->seq, seq));
+ } while (raw_read_seqcount_latch_retry(&tkf->seq, seq));
return now;
}
@@ -566,7 +566,7 @@ static __always_inline u64 __ktime_get_real_fast(struct tk_fast *tkf, u64 *mono)
basem = ktime_to_ns(tkr->base);
baser = ktime_to_ns(tkr->base_real);
delta = fast_tk_get_delta_ns(tkr);
- } while (read_seqcount_latch_retry(&tkf->seq, seq));
+ } while (raw_read_seqcount_latch_retry(&tkf->seq, seq));
if (mono)
*mono = basem + delta;
]
|
| 26/2 |
2026/05/30 18:17 |
llm |
expert |
0m
Model:
Tokens:
input: 20651
output: 46
thoughts: 58
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating `ktime_get_coarse_ts64` Implementation**
Hmm, hold on a second. I was under the impression that the code utilizing the `read_seqcount_latch_retry` mechanism was employed. But a closer look, especially focusing on `ktime_get_coarse_ts64`, tells me it actually leverages `read_seqcount_begin` and `read_seqcount_retry`. That's a key distinction and could impact performance assumptions I've made in the past. It means a different flavor of read-side locking is used here compared to what I initially thought, potentially influencing the level of contention we might see. This requires a deeper dive. The sequential counter in this instance may not be employing the same optimistic locking strategy that the latch version affords. Time to dig further. Before I go too far down that path, let me cross reference this and see if the team is working in other areas. Let's see if anyone else has touched this code and if there are any related commits or discussions. Let me quickly check the relevant git history or code repository.
|
| 27/2 |
2026/05/30 18:17 |
tool |
git-log |
0m
Args: map[CodeRegexp:data_race.*tk_xtime_coarse Count:10 PathPrefix:kernel/time/timekeeping.c]
Results:
|
| 28/2 |
2026/05/30 18:17 |
llm |
expert |
0m
Model:
Tokens:
input: 21023
output: 42
thoughts: 22
Thoughts: Okay, here's my summary, taking the perspective of someone deeply familiar with kernel internals and threading issues:
**Checking for Data Race Mitigation in tk_xtime_coarse**
Right, let's dive in. I need to quickly ascertain whether `tk_xtime_coarse` has been updated to incorporate the `data_race` handling. This is crucial. This time keeping function is a frequent target for data races, and it's a vital piece of the system. I need to quickly verify that the fix, presumably utilizing the defined `data_race` mechanisms, has been correctly applied. If it's still running without it, we are opening ourselves up for some pretty nasty problems. Let's see if this critical change was made.
|
| 29/2 |
2026/05/30 18:17 |
tool |
git-log |
0m
Args: map[CodeRegexp:data_race.*tk_xtime_coarse Count:10 PathPrefix:kernel/time/]
Results:
|
| 30/2 |
2026/05/30 18:18 |
llm |
expert |
0m
Model:
Tokens:
input: 21257
output: 46
thoughts: 21
Thoughts: Okay, here's my summary, taking the perspective of someone deeply familiar with kernel internals and system performance analysis:
**Investigating a Potential Kernel Timekeeping Change**
Alright, before I dive too deep into this performance anomaly, let's just make sure we're covering our bases. My initial thought is to quickly verify if there's been any recent modification to the `ktime_get_coarse_ts64` function. This is a critical component for fetching coarse-grained timestamps, and any change here, however seemingly minor, *could* have cascading effects on observed performance characteristics, especially if we're seeing some unexpected time dilation or discrepancies in time measurements. I need to know if this function is behaving as expected before I consider any more complex explanations. A quick check of the relevant commits will set the foundation for subsequent troubleshooting.
|
| 31/2 |
2026/05/30 18:18 |
tool |
git-log |
0m
Error:
Args: map[Count:10 PathPrefix:kernel/time/timekeeping.c SymbolName:ktime_get_coarse_ts64]
Results:
|
| 32/2 |
2026/05/30 18:18 |
llm |
expert |
0m
Model:
Tokens:
input: 21521
output: 46
thoughts: 12
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**`-L` Flag and the Role of `SourcePath`**
Alright, so I'm looking at this code or command, and my immediate thought is that `SourcePath` is directly tied to the `-L` flag. It's a key piece of information. That's not groundbreaking, but it's the connection I'm zeroing in on. The use of `-L` instantly triggers an association with the configuration or operational path that `SourcePath` provides. I would assume the `-L` flag is related to the linking process of a library or other file path. It's the essential variable I need to understand what this process is designed to accomplish. Now, I need to know how that `SourcePath` is being used in conjunction with `-L`. What's the specific implementation? I am curious to see where `SourcePath` will need modification as the underlying system evolves.
|
| 33/2 |
2026/05/30 18:18 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:kernel/time/timekeeping.c SymbolName:ktime_get_coarse_ts64]
Results: map[Output:b71f9804f66c timekeeping: Prevent coarse clocks going backwards
e1e41b6ce5f9 timekeeping: Consistently use unsigned int for seqcount snapshot
fb7fcc96a86c timekeeping: Standardize on ktime_get_*() naming
334334b5f577 time: Expose get_monotonic_coarse64() for in-kernel uses
3fdb14fd1df7 timekeeping: Cache optimize struct timekeeper
7d489d15ce4b timekeeping: Convert timekeeping core to use timespec64s
9a7a71b1d096 timekeeping: Split timekeeper_lock into lock and seqcount
7e40672d930b timekeeping: Move lock out of timekeeper struct
4e250fdde9be time: Remove all direct references to timekeeper
1e75fa8be9fb time: Condense timekeeper.xtime into xtime_sec
]
|
| 34/2 |
2026/05/30 18:18 |
llm |
expert |
0m
Model:
Tokens:
input: 22041
output: 27
thoughts: 18
Thoughts: Okay, here's my attempt at summarizing the thought process, as if it were my own, assuming I'm an expert in the field:
**Initial Assessment: Examining a Specific Commit**
Alright, time to dive in. My first instinct is to zero in on this commit: `b71f9804f66c`. Knowing my typical workflow, I'd immediately want to see the context. What's the surrounding history? What branches is this merged into? Are there any associated pull requests or issues linked to it? The SHA itself doesn't tell me *anything* without this critical context. I need to understand *why* this specific commit is being flagged or brought to my attention. Is it part of an investigation? A regression analysis? Or perhaps a routine audit? My initial check will depend on that context.
|
| 35/2 |
2026/05/30 18:18 |
tool |
git-show |
0m
Args:
Results: map[Output:commit b71f9804f66c2592d4c3a2397b7374a4039005a5
Author: Thomas Gleixner <tglx@kernel.org>
Date: Fri Apr 18 22:46:52 2025 -0700
timekeeping: Prevent coarse clocks going backwards
Lei Chen raised an issue with CLOCK_MONOTONIC_COARSE seeing time
inconsistencies. Lei tracked down that this was being caused by the
adjustment:
tk->tkr_mono.xtime_nsec -= offset;
which is made to compensate for the unaccumulated cycles in offset when the
multiplicator is adjusted forward, so that the non-_COARSE clockids don't
see inconsistencies.
However, the _COARSE clockid getter functions use the adjusted xtime_nsec
value directly and do not compensate the negative offset via the
clocksource delta multiplied with the new multiplicator. In that case the
caller can observe time going backwards in consecutive calls.
By design, this negative adjustment should be fine, because the logic run
from timekeeping_adjust() is done after it accumulated approximately
multiplicator * interval_cycles
into xtime_nsec. The accumulated value is always larger then the
mult_adj * offset
value, which is subtracted from xtime_nsec. Both operations are done
together under the tk_core.lock, so the net change to xtime_nsec is always
always be positive.
However, do_adjtimex() calls into timekeeping_advance() as well, to
apply the NTP frequency adjustment immediately. In this case,
timekeeping_advance() does not return early when the offset is smaller
then interval_cycles. In that case there is no time accumulated into
xtime_nsec. But the subsequent call into timekeeping_adjust(), which
modifies the multiplicator, subtracts from xtime_nsec to correct for the
new multiplicator.
Here because there was no accumulation, xtime_nsec becomes smaller than
before, which opens a window up to the next accumulation, where the
_COARSE clockid getters, which don't compensate for the offset, can
observe the inconsistency.
This has been tried to be fixed by forwarding the timekeeper in the case
that adjtimex() adjusts the multiplier, which resets the offset to zero:
757b000f7b93 ("timekeeping: Fix possible inconsistencies in _COARSE clockids")
That works correctly, but unfortunately causes a regression on the
adjtimex() side. There are two issues:
1) The forwarding of the base time moves the update out of the original
period and establishes a new one.
2) The clearing of the accumulated NTP error is changing the behaviour as
well.
User-space expects that multiplier/frequency updates are in effect, when the
syscall returns, so delaying the update to the next tick is not solving the
problem either.
Commit 757b000f7b93 was reverted so that the established expectations of
user space implementations (ntpd, chronyd) are restored, but that obviously
brought the inconsistencies back.
One of the initial approaches to fix this was to establish a separate
storage for the coarse time getter nanoseconds part by calculating it from
the offset. That was dropped on the floor because not having yet another
state to maintain was simpler. But given the result of the above exercise,
this solution turns out to be the right one. Bring it back in a slightly
modified form.
Thus introduce timekeeper::coarse_nsec and store that nanoseconds part in
it, switch the time getter functions and the VDSO update to use that value.
coarse_nsec is set on operations which forward or initialize the timekeeper
and after time was accumulated during a tick. If there is no accumulation
the timestamp is unchanged.
This leaves the adjtimex() behaviour unmodified and prevents coarse time
from going backwards.
[ jstultz: Simplified the coarse_nsec calculation and kept behavior so
coarse clockids aren't adjusted on each inter-tick adjtimex
call, slightly reworked the comments and commit message ]
Fixes: da15cfdae033 ("time: Introduce CLOCK_REALTIME_COARSE")
Reported-by: Lei Chen <lei.chen@smartx.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/all/20250419054706.2319105-1-jstultz@google.com
Closes: https://lore.kernel.org/lkml/20250310030004.3705801-1-lei.chen@smartx.com/
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index e39d4d563b19..785048a3b3e6 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -51,7 +51,7 @@ struct tk_read_base {
* @offs_real: Offset clock monotonic -> clock realtime
* @offs_boot: Offset clock monotonic -> clock boottime
* @offs_tai: Offset clock monotonic -> clock tai
- * @tai_offset: The current UTC to TAI offset in seconds
+ * @coarse_nsec: The nanoseconds part for coarse time getters
* @tkr_raw: The readout base structure for CLOCK_MONOTONIC_RAW
* @raw_sec: CLOCK_MONOTONIC_RAW time in seconds
* @clock_was_set_seq: The sequence number of clock was set events
@@ -76,6 +76,7 @@ struct tk_read_base {
* ntp shifted nano seconds.
* @ntp_err_mult: Multiplication factor for scaled math conversion
* @skip_second_overflow: Flag used to avoid updating NTP twice with same second
+ * @tai_offset: The current UTC to TAI offset in seconds
*
* Note: For timespec(64) based interfaces wall_to_monotonic is what
* we need to add to xtime (or xtime corrected for sub jiffy times)
@@ -100,7 +101,7 @@ struct tk_read_base {
* which results in the following cacheline layout:
*
* 0: seqcount, tkr_mono
- * 1: xtime_sec ... tai_offset
+ * 1: xtime_sec ... coarse_nsec
* 2: tkr_raw, raw_sec
* 3,4: Internal variables
*
@@ -121,7 +122,7 @@ struct timekeeper {
ktime_t offs_real;
ktime_t offs_boot;
ktime_t offs_tai;
- s32 tai_offset;
+ u32 coarse_nsec;
/* Cacheline 2: */
struct tk_read_base tkr_raw;
@@ -144,6 +145,7 @@ struct timekeeper {
u32 ntp_error_shift;
u32 ntp_err_mult;
u32 skip_second_overflow;
+ s32 tai_offset;
};
#ifdef CONFIG_GENERIC_TIME_VSYSCALL
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 1e67d076f195..a009c91f7b05 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -164,10 +164,34 @@ static inline struct timespec64 tk_xtime(const struct timekeeper *tk)
return ts;
}
+static inline struct timespec64 tk_xtime_coarse(const struct timekeeper *tk)
+{
+ struct timespec64 ts;
+
+ ts.tv_sec = tk->xtime_sec;
+ ts.tv_nsec = tk->coarse_nsec;
+ return ts;
+}
+
+/*
+ * Update the nanoseconds part for the coarse time keepers. They can't rely
+ * on xtime_nsec because xtime_nsec could be adjusted by a small negative
+ * amount when the multiplication factor of the clock is adjusted, which
+ * could cause the coarse clocks to go slightly backwards. See
+ * timekeeping_apply_adjustment(). Thus we keep a separate copy for the coarse
+ * clockids which only is updated when the clock has been set or we have
+ * accumulated time.
+ */
+static inline void tk_update_coarse_nsecs(struct timekeeper *tk)
+{
+ tk->coarse_nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
+}
+
static void tk_set_xtime(struct timekeeper *tk, const struct timespec64 *ts)
{
tk->xtime_sec = ts->tv_sec;
tk->tkr_mono.xtime_nsec = (u64)ts->tv_nsec << tk->tkr_mono.shift;
+ tk_update_coarse_nsecs(tk);
}
static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts)
@@ -175,6 +199,7 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts)
tk->xtime_sec += ts->tv_sec;
tk->tkr_mono.xtime_nsec += (u64)ts->tv_nsec << tk->tkr_mono.shift;
tk_normalize_xtime(tk);
+ tk_update_coarse_nsecs(tk);
}
static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm)
@@ -708,6 +733,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
tk_normalize_xtime(tk);
delta -= incr;
}
+ tk_update_coarse_nsecs(tk);
}
/**
@@ -804,8 +830,8 @@ EXPORT_SYMBOL_GPL(ktime_get_with_offset);
ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs)
{
struct timekeeper *tk = &tk_core.timekeeper;
- unsigned int seq;
ktime_t base, *offset = offsets[offs];
+ unsigned int seq;
u64 nsecs;
WARN_ON(timekeeping_suspended);
@@ -813,7 +839,7 @@ ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs)
do {
seq = read_seqcount_begin(&tk_core.seq);
base = ktime_add(tk->tkr_mono.base, *offset);
- nsecs = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
+ nsecs = tk->coarse_nsec;
} while (read_seqcount_retry(&tk_core.seq, seq));
@@ -2161,7 +2187,7 @@ static bool timekeeping_advance(enum timekeeping_adv_mode mode)
struct timekeeper *real_tk = &tk_core.timekeeper;
unsigned int clock_set = 0;
int shift = 0, maxshift;
- u64 offset;
+ u64 offset, orig_offset;
guard(raw_spinlock_irqsave)(&tk_core.lock);
@@ -2172,7 +2198,7 @@ static bool timekeeping_advance(enum timekeeping_adv_mode mode)
offset = clocksource_delta(tk_clock_read(&tk->tkr_mono),
tk->tkr_mono.cycle_last, tk->tkr_mono.mask,
tk->tkr_mono.clock->max_raw_delta);
-
+ orig_offset = offset;
/* Check if there's really nothing to do */
if (offset < real_tk->cycle_interval && mode == TK_ADV_TICK)
return false;
@@ -2205,6 +2231,14 @@ static bool timekeeping_advance(enum timekeeping_adv_mode mode)
*/
clock_set |= accumulate_nsecs_to_secs(tk);
+ /*
+ * To avoid inconsistencies caused adjtimex TK_ADV_FREQ calls
+ * making small negative adjustments to the base xtime_nsec
+ * value, only update the coarse clocks if we accumulated time
+ */
+ if (orig_offset != offset)
+ tk_update_coarse_nsecs(tk);
+
timekeeping_update_from_shadow(&tk_core, clock_set);
return !!clock_set;
@@ -2248,7 +2282,7 @@ void ktime_get_coarse_real_ts64(struct timespec64 *ts)
do {
seq = read_seqcount_begin(&tk_core.seq);
- *ts = tk_xtime(tk);
+ *ts = tk_xtime_coarse(tk);
} while (read_seqcount_retry(&tk_core.seq, seq));
}
EXPORT_SYMBOL(ktime_get_coarse_real_ts64);
@@ -2271,7 +2305,7 @@ void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts)
do {
seq = read_seqcount_begin(&tk_core.seq);
- *ts = tk_xtime(tk);
+ *ts = tk_xtime_coarse(tk);
offset = tk_core.timekeeper.offs_real;
} while (read_seqcount_retry(&tk_core.seq, seq));
@@ -2350,12 +2384,12 @@ void ktime_get_coarse_ts64(struct timespec64 *ts)
do {
seq = read_seqcount_begin(&tk_core.seq);
- now = tk_xtime(tk);
+ now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
- now.tv_nsec + mono.tv_nsec);
+ now.tv_nsec + mono.tv_nsec);
}
EXPORT_SYMBOL(ktime_get_coarse_ts64);
diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c
index 01c2ab1e8971..32ef27c71b57 100644
--- a/kernel/time/vsyscall.c
+++ b/kernel/time/vsyscall.c
@@ -98,12 +98,12 @@ void update_vsyscall(struct timekeeper *tk)
/* CLOCK_REALTIME_COARSE */
vdso_ts = &vc[CS_HRES_COARSE].basetime[CLOCK_REALTIME_COARSE];
vdso_ts->sec = tk->xtime_sec;
- vdso_ts->nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
+ vdso_ts->nsec = tk->coarse_nsec;
/* CLOCK_MONOTONIC_COARSE */
vdso_ts = &vc[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC_COARSE];
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
- nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
+ nsec = tk->coarse_nsec;
nsec = nsec + tk->wall_to_monotonic.tv_nsec;
vdso_ts->sec += __iter_div_u64_rem(nsec, NSEC_PER_SEC, &vdso_ts->nsec);
]
|
| 36/2 |
2026/05/30 18:18 |
llm |
expert |
0m
Model:
Tokens:
input: 26539
output: 24
thoughts: 1667
Thoughts: **Analyzing a KCSAN Report: A Deep Dive into Timekeeping**
Okay, so this KCSAN report is flagging a potential data race with `tk_xtime_coarse` and the `coarse_nsec` field. Right, `coarse_nsec` was introduced in `b71f9804f66c` to deal with coarse clocks possibly going backwards. And `tk_xtime_coarse` came along in that commit as well. The report's highlighting how a read of `tk->coarse_nsec` within `tk_xtime_coarse` is happening concurrently with a write to `tkd->timekeeper` via `memcpy` in `timekeeping_update_from_shadow`. And the read isn't protected by `READ_ONCE`, which KCSAN picks up as a potential issue, it's just a classic seqcount reader issue. It's reading, then checking the seqcount, and retrying if necessary. KCSAN's detecting the race, but it doesn't necessarily mean it's a *bug*.
My immediate thought is to verify if there's an exploitable scenario here. The read is `ts.tv_nsec = tk->coarse_nsec;`, the write is `memcpy(&tkd->timekeeper, tk, sizeof(*tk));`. The value `tk->coarse_nsec` is a `u32`, which gets read into `ts.tv_nsec` (a `long`). The `ts` struct is then returned from `tk_xtime_coarse`. That then feeds into `now = tk_xtime_coarse(tk);` and `set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec, now.tv_nsec + mono.tv_nsec);` after the retry loop. Wait, `now` is local and assigned *inside* the loop. If the read is torn, the value of `now.tv_nsec` *could* be garbage. But the seqcount is checked, so if the retry loop succeeds, it means no concurrent write happened.
Hold on, could the compiler be hoisting that read of `tk->coarse_nsec` *outside* the loop? The code has a `do...while` loop with `read_seqcount_begin` and `read_seqcount_retry` calls. Inside, it reads the data and returns it, and then checks the seqcount. If the read gets hoisted, it only reads it once. I see, but `read_seqcount_begin` and `read_seqcount_retry` contain memory barriers – specifically, `smp_rmb()` – which should prevent that kind of hoisting. Right, the compiler can't hoist the read.
Okay, can the compiler tear the read? It's a `u32`. On x86_64, a 32-bit read is atomic. Even if it *were* torn, the seqcount retry would catch it because of the concurrent write. If it's not concurrent, it's not torn. So, the value used *after* the loop is consistent. No actual bug here, just a missing `data_race()` annotation to silence KCSAN.
Let me just quickly check if `tk_core.seq` is properly protecting the write. Looking at `timekeeping_update_from_shadow`, `write_seqcount_begin` and `write_seqcount_end` *are* used around the `memcpy`. Yep, it's protected.
So, this is a KCSAN false positive. Not exploitable, no denial of service, and not unprivileged, although it is reachable from unprivileged. Wait a second, the prompt is asking if this can be reached by an *unprivileged* user... Okay, `bpf_ktime_get_coarse_ns` is reachable from unprivileged BPF, or `clock_gettime(CLOCK_MONOTONIC_COARSE, ...)` is a syscall.
Hang on, the stack trace... `bpf_prog_test_run` via `bpf_ktime_get_coarse_ns`, but it says "Determine if the bug can be reached from a typical (non-root) user process *that does NOT have any special capabilities*". `clock_gettime` is unprivileged... `clock_gettime(CLOCK_MONOTONIC_COARSE, ...)` does the exact same read, through `ktime_get_coarse_ts64`. Need to check `sys_clock_gettime` to be sure.
|
| 37/2 |
2026/05/30 18:18 |
tool |
grepper |
0m
Args: map[Expression:SYSCALL_DEFINE.*clock_gettime]
Results: map[Output:kernel/time/posix-stubs.c=39=static int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp)
--
kernel/time/posix-stubs.c-59-
kernel/time/posix-stubs.c:60:SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
kernel/time/posix-stubs.c-61- struct __kernel_timespec __user *, tp)
--
kernel/time/posix-stubs.c=129=SYSCALL_DEFINE2(clock_settime32, const clockid_t, which_clock,
--
kernel/time/posix-stubs.c-141-
kernel/time/posix-stubs.c:142:SYSCALL_DEFINE2(clock_gettime32, clockid_t, which_clock,
kernel/time/posix-stubs.c-143- struct old_timespec32 __user *, tp)
--
kernel/time/posix-timers.c=1108=SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
--
kernel/time/posix-timers.c-1126-
kernel/time/posix-timers.c:1127:SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
kernel/time/posix-timers.c-1128- struct __kernel_timespec __user *, tp)
--
kernel/time/posix-timers.c=1267=SYSCALL_DEFINE2(clock_settime32, clockid_t, which_clock,
--
kernel/time/posix-timers.c-1281-
kernel/time/posix-timers.c:1282:SYSCALL_DEFINE2(clock_gettime32, clockid_t, which_clock,
kernel/time/posix-timers.c-1283- struct old_timespec32 __user *, tp)
]
|
| 38/2 |
2026/05/30 18:19 |
llm |
expert |
0m
Model:
Tokens:
input: 29751
output: 39
thoughts: 24
Thoughts: Here's my thought process, focusing on the provided text:
**Digging into the Posix Timers Implementation**
Okay, so we're talking about something related to POSIX timers in the Linux kernel. That usually means we're dealing with the finer points of how timers are scheduled, delivered, and handled. I'm thinking specifically about `kernel/time/posix-timers.c` – that's the likely spot for the core implementation. Now, pinpointing the focus a bit, I want to zero in on the vicinity of line 1127. Without knowing the context yet, I'm expecting to find something specific in that area; perhaps it's an important function call, a data structure definition related to timer operations, or a key conditional statement within a timer-related function. Time to dive in and see what's happening.
|
| 39/2 |
2026/05/30 18:19 |
tool |
read-file |
0m
Args: map[File:kernel/time/posix-timers.c FirstLine:1115 LineCount:50]
Results: map[Contents:1115: return -EINVAL;
1116:
1117: if (get_timespec64(&new_tp, tp))
1118: return -EFAULT;
1119:
1120: /*
1121: * Permission checks have to be done inside the clock specific
1122: * setter callback.
1123: */
1124: return kc->clock_set(which_clock, &new_tp);
1125: }
1126:
1127: SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
1128: struct __kernel_timespec __user *, tp)
1129: {
1130: const struct k_clock *kc = clockid_to_kclock(which_clock);
1131: struct timespec64 kernel_tp;
1132: int error;
1133:
1134: if (!kc)
1135: return -EINVAL;
1136:
1137: error = kc->clock_get_timespec(which_clock, &kernel_tp);
1138:
1139: if (!error && put_timespec64(&kernel_tp, tp))
1140: error = -EFAULT;
1141:
1142: return error;
1143: }
1144:
1145: int do_clock_adjtime(const clockid_t which_clock, struct __kernel_timex * ktx)
1146: {
1147: const struct k_clock *kc = clockid_to_kclock(which_clock);
1148:
1149: if (!kc)
1150: return -EINVAL;
1151: if (!kc->clock_adj)
1152: return -EOPNOTSUPP;
1153:
1154: return kc->clock_adj(which_clock, ktx);
1155: }
1156:
1157: SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
1158: struct __kernel_timex __user *, utx)
1159: {
1160: struct __kernel_timex ktx;
1161: int err;
1162:
1163: if (copy_from_user(&ktx, utx, sizeof(ktx)))
1164: return -EFAULT;
]
|
| 40/2 |
2026/05/30 18:19 |
llm |
expert |
0m
Model:
Tokens:
input: 30697
output: 24
thoughts: 37
Thoughts: Okay, here's my interpretation of those thoughts, presented as a summary:
**Digging into CLOCK_MONOTONIC_COARSE Implementation**
Alright, time to dive into this. I need to refresh my understanding of how `CLOCK_MONOTONIC_COARSE` is being handled. I'm going to start by examining the functions `clockid_to_kclock` and `kc->clock_get_timespec`. Those are the usual suspects. I want to see exactly how the kernel maps that specific clock ID and then how it retrieves the associated time. I need to confirm the underlying mechanisms and ensure there aren't any potential surprises or subtle performance implications I'm missing. Understanding this is key to getting a good grasp on the overall design and any associated performance tradeoffs. Let's see what's actually going on under the hood.
|
| 41/2 |
2026/05/30 18:19 |
tool |
grepper |
0m
Args: map[Expression:CLOCK_MONOTONIC_COARSE]
Results: map[Output:Documentation/core-api/timekeeping.rst=100=Some additional variants exist for more specialized cases:
--
Documentation/core-api/timekeeping.rst-117- These are quicker than the non-coarse versions, but less accurate,
Documentation/core-api/timekeeping.rst:118: corresponding to CLOCK_MONOTONIC_COARSE and CLOCK_REALTIME_COARSE
Documentation/core-api/timekeeping.rst-119- in user space, along with the equivalent boottime/tai/raw
--
drivers/iio/industrialio-core.c=320=s64 iio_get_time_ns(const struct iio_dev *indio_dev)
--
drivers/iio/industrialio-core.c-332- return ktime_to_ns(ktime_get_coarse_real());
drivers/iio/industrialio-core.c:333: case CLOCK_MONOTONIC_COARSE:
drivers/iio/industrialio-core.c-334- ktime_get_coarse_ts64(&tp);
--
drivers/iio/industrialio-core.c=1455=static const char * const clock_names[] = {
--
drivers/iio/industrialio-core.c-1461- [CLOCK_REALTIME_COARSE] = "realtime_coarse",
drivers/iio/industrialio-core.c:1462: [CLOCK_MONOTONIC_COARSE] = "monotonic_coarse",
drivers/iio/industrialio-core.c-1463- [CLOCK_BOOTTIME] = "boottime",
--
drivers/iio/industrialio-core.c=1470=static ssize_t current_timestamp_clock_show(struct device *dev,
--
drivers/iio/industrialio-core.c-1481- case CLOCK_REALTIME_COARSE:
drivers/iio/industrialio-core.c:1482: case CLOCK_MONOTONIC_COARSE:
drivers/iio/industrialio-core.c-1483- case CLOCK_BOOTTIME:
--
drivers/iio/industrialio-core.c=1493=static ssize_t current_timestamp_clock_store(struct device *dev,
--
drivers/iio/industrialio-core.c-1509- case CLOCK_REALTIME_COARSE:
drivers/iio/industrialio-core.c:1510: case CLOCK_MONOTONIC_COARSE:
drivers/iio/industrialio-core.c-1511- case CLOCK_BOOTTIME:
--
include/uapi/linux/bpf.h=1510=union bpf_attr {
--
include/uapi/linux/bpf.h-5128- *
include/uapi/linux/bpf.h:5129: * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
include/uapi/linux/bpf.h-5130- * Return
--
include/uapi/linux/time.h=33=struct timezone {
--
include/uapi/linux/time.h-54-#define CLOCK_REALTIME_COARSE 5
include/uapi/linux/time.h:55:#define CLOCK_MONOTONIC_COARSE 6
include/uapi/linux/time.h-56-#define CLOCK_BOOTTIME 7
--
include/vdso/datapage.h=27=struct vdso_arch_data {
--
include/vdso/datapage.h-39-#define VDSO_COARSE (BIT(CLOCK_REALTIME_COARSE) | \
include/vdso/datapage.h:40: BIT(CLOCK_MONOTONIC_COARSE))
include/vdso/datapage.h-41-#define VDSO_RAW (BIT(CLOCK_MONOTONIC_RAW))
--
kernel/time/namespace_vdso.c=55=static void timens_setup_vdso_clock_data(struct vdso_clock *vc,
--
kernel/time/namespace_vdso.c-65- offset[CLOCK_MONOTONIC_RAW] = monotonic;
kernel/time/namespace_vdso.c:66: offset[CLOCK_MONOTONIC_COARSE] = monotonic;
kernel/time/namespace_vdso.c-67- offset[CLOCK_BOOTTIME] = boottime;
--
kernel/time/posix-timers.c=1157=SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
--
kernel/time/posix-timers.c-1220- *
kernel/time/posix-timers.c:1221: * For CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE the resolution
kernel/time/posix-timers.c-1222- * returned is always nanoseconds per tick.
--
kernel/time/posix-timers.c=1509=static const struct k_clock * const posix_clocks[] = {
--
kernel/time/posix-timers.c-1515- [CLOCK_REALTIME_COARSE] = &clock_realtime_coarse,
kernel/time/posix-timers.c:1516: [CLOCK_MONOTONIC_COARSE] = &clock_monotonic_coarse,
kernel/time/posix-timers.c-1517- [CLOCK_BOOTTIME] = &clock_boottime,
--
kernel/time/vsyscall.c=77=void update_vsyscall(struct timekeeper *tk)
--
kernel/time/vsyscall.c-101-
kernel/time/vsyscall.c:102: /* CLOCK_MONOTONIC_COARSE */
kernel/time/vsyscall.c:103: vdso_ts = &vc[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC_COARSE];
kernel/time/vsyscall.c-104- vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
--
tools/include/uapi/linux/bpf.h=1510=union bpf_attr {
--
tools/include/uapi/linux/bpf.h-5128- *
tools/include/uapi/linux/bpf.h:5129: * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
tools/include/uapi/linux/bpf.h-5130- * Return
--
tools/testing/selftests/proc/proc-maps-race.c=549=TEST_F(proc_maps_race, test_maps_tearing_from_split)
--
tools/testing/selftests/proc/proc-maps-race.c-577-
tools/testing/selftests/proc/proc-maps-race.c:578: clock_gettime(CLOCK_MONOTONIC_COARSE, &start_ts);
tools/testing/selftests/proc/proc-maps-race.c-579- start_test_loop(&start_ts, self->verbose);
--
tools/testing/selftests/proc/proc-maps-race.c-633-
tools/testing/selftests/proc/proc-maps-race.c:634: clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts);
tools/testing/selftests/proc/proc-maps-race.c-635- end_test_iteration(&end_ts, self->verbose);
--
tools/testing/selftests/proc/proc-maps-race.c=643=TEST_F(proc_maps_race, test_maps_tearing_from_resize)
--
tools/testing/selftests/proc/proc-maps-race.c-671-
tools/testing/selftests/proc/proc-maps-race.c:672: clock_gettime(CLOCK_MONOTONIC_COARSE, &start_ts);
tools/testing/selftests/proc/proc-maps-race.c-673- start_test_loop(&start_ts, self->verbose);
--
tools/testing/selftests/proc/proc-maps-race.c-713-
tools/testing/selftests/proc/proc-maps-race.c:714: clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts);
tools/testing/selftests/proc/proc-maps-race.c-715- end_test_iteration(&end_ts, self->verbose);
--
tools/testing/selftests/proc/proc-maps-race.c=723=TEST_F(proc_maps_race, test_maps_tearing_from_remap)
--
tools/testing/selftests/proc/proc-maps-race.c-751-
tools/testing/selftests/proc/proc-maps-race.c:752: clock_gettime(CLOCK_MONOTONIC_COARSE, &start_ts);
tools/testing/selftests/proc/proc-maps-race.c-753- start_test_loop(&start_ts, self->verbose);
--
tools/testing/selftests/proc/proc-maps-race.c-796-
tools/testing/selftests/proc/proc-maps-race.c:797: clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts);
tools/testing/selftests/proc/proc-maps-race.c-798- end_test_iteration(&end_ts, self->verbose);
--
tools/testing/selftests/timens/gettime_perf.c=65=int main(int argc, char *argv[])
--
tools/testing/selftests/timens/gettime_perf.c-76- test(CLOCK_MONOTONIC, "monotonic", false);
tools/testing/selftests/timens/gettime_perf.c:77: test(CLOCK_MONOTONIC_COARSE, "monotonic-coarse", false);
tools/testing/selftests/timens/gettime_perf.c-78- test(CLOCK_MONOTONIC_RAW, "monotonic-raw", false);
--
tools/testing/selftests/timens/gettime_perf.c-98- test(CLOCK_MONOTONIC, "monotonic", true);
tools/testing/selftests/timens/gettime_perf.c:99: test(CLOCK_MONOTONIC_COARSE, "monotonic-coarse", true);
tools/testing/selftests/timens/gettime_perf.c-100- test(CLOCK_MONOTONIC_RAW, "monotonic-raw", true);
--
tools/testing/selftests/timens/timens.c=37=static struct test_clock clocks[] = {
--
tools/testing/selftests/timens/timens.c-40- ct(CLOCK_MONOTONIC, -1),
tools/testing/selftests/timens/timens.c:41: ct(CLOCK_MONOTONIC_COARSE, 1),
tools/testing/selftests/timens/timens.c-42- ct(CLOCK_MONOTONIC_RAW, 1),
--
tools/testing/selftests/timens/timens.c=88=static int test_gettime(clockid_t clock_index, bool raw_syscall, time_t offset)
--
tools/testing/selftests/timens/timens.c-97- switch (clocks[clock_index].id) {
tools/testing/selftests/timens/timens.c:98: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timens/timens.c-99- case CLOCK_MONOTONIC_RAW:
--
tools/testing/selftests/timens/timens.h=64=static inline int _settime(clockid_t clk_id, time_t offset)
--
tools/testing/selftests/timens/timens.h-68-
tools/testing/selftests/timens/timens.h:69: if (clk_id == CLOCK_MONOTONIC_COARSE || clk_id == CLOCK_MONOTONIC_RAW)
tools/testing/selftests/timens/timens.h-70- clk_id = CLOCK_MONOTONIC;
--
tools/testing/selftests/timers/alarmtimer-suspend.c=43=char *clockstring(int clockid)
--
tools/testing/selftests/timers/alarmtimer-suspend.c-57- return "CLOCK_REALTIME_COARSE";
tools/testing/selftests/timers/alarmtimer-suspend.c:58: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timers/alarmtimer-suspend.c:59: return "CLOCK_MONOTONIC_COARSE";
tools/testing/selftests/timers/alarmtimer-suspend.c-60- case CLOCK_BOOTTIME:
--
tools/testing/selftests/timers/inconsistency-check.c=39=char *clockstring(int clockid)
--
tools/testing/selftests/timers/inconsistency-check.c-53- return "CLOCK_REALTIME_COARSE";
tools/testing/selftests/timers/inconsistency-check.c:54: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timers/inconsistency-check.c:55: return "CLOCK_MONOTONIC_COARSE";
tools/testing/selftests/timers/inconsistency-check.c-56- case CLOCK_BOOTTIME:
--
tools/testing/selftests/timers/nanosleep.c=38=char *clockstring(int clockid)
--
tools/testing/selftests/timers/nanosleep.c-52- return "CLOCK_REALTIME_COARSE";
tools/testing/selftests/timers/nanosleep.c:53: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timers/nanosleep.c:54: return "CLOCK_MONOTONIC_COARSE";
tools/testing/selftests/timers/nanosleep.c-55- case CLOCK_BOOTTIME:
--
tools/testing/selftests/timers/nsleep-lat.c=37=char *clockstring(int clockid)
--
tools/testing/selftests/timers/nsleep-lat.c-51- return "CLOCK_REALTIME_COARSE";
tools/testing/selftests/timers/nsleep-lat.c:52: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timers/nsleep-lat.c:53: return "CLOCK_MONOTONIC_COARSE";
tools/testing/selftests/timers/nsleep-lat.c-54- case CLOCK_BOOTTIME:
--
tools/testing/selftests/timers/set-timer-lat.c=46=char *clockstring(int clockid)
--
tools/testing/selftests/timers/set-timer-lat.c-60- return "CLOCK_REALTIME_COARSE";
tools/testing/selftests/timers/set-timer-lat.c:61: case CLOCK_MONOTONIC_COARSE:
tools/testing/selftests/timers/set-timer-lat.c:62: return "CLOCK_MONOTONIC_COARSE";
tools/testing/selftests/timers/set-timer-lat.c-63- case CLOCK_BOOTTIME:
--
tools/testing/selftests/timers/set-timer-lat.c=240=int main(void)
--
tools/testing/selftests/timers/set-timer-lat.c-259- (clock_id == CLOCK_REALTIME_COARSE) ||
tools/testing/selftests/timers/set-timer-lat.c:260: (clock_id == CLOCK_MONOTONIC_COARSE) ||
tools/testing/selftests/timers/set-timer-lat.c-261- (clock_id == CLOCK_HWSPECIFIC))
--
tools/testing/selftests/vDSO/vdso_test_abi.c=42=static const char * const vdso_clock_name[] = {
--
tools/testing/selftests/vDSO/vdso_test_abi.c-48- [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
tools/testing/selftests/vDSO/vdso_test_abi.c:49: [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
tools/testing/selftests/vDSO/vdso_test_abi.c-50- [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
--
tools/testing/selftests/vDSO/vdso_test_abi.c=266=int main(int argc, char **argv)
--
tools/testing/selftests/vDSO/vdso_test_abi.c-291- vdso_test_clock(CLOCK_MONOTONIC_RAW);
tools/testing/selftests/vDSO/vdso_test_abi.c:292: vdso_test_clock(CLOCK_MONOTONIC_COARSE);
tools/testing/selftests/vDSO/vdso_test_abi.c-293- vdso_test_clock(CLOCK_PROCESS_CPUTIME_ID);
--
tools/testing/selftests/vDSO/vdso_test_correctness.c=254=static char const * const clocknames[] = {
--
tools/testing/selftests/vDSO/vdso_test_correctness.c-260- [5] = "CLOCK_REALTIME_COARSE",
tools/testing/selftests/vDSO/vdso_test_correctness.c:261: [6] = "CLOCK_MONOTONIC_COARSE",
tools/testing/selftests/vDSO/vdso_test_correctness.c-262- [7] = "CLOCK_BOOTTIME",
]
|
| 42/2 |
2026/05/30 18:19 |
llm |
expert |
0m
Model:
Tokens:
input: 35671
output: 66
thoughts: 913
Thoughts: **My Assessment of the "Bug"**
Okay, let's break this down. First, `CLOCK_MONOTONIC_COARSE` *is* accessible from unprivileged processes, and that's the primary way to trigger whatever is being flagged. However, it seems this is a classic false positive from a data race detector, not an actual exploitable vulnerability or a denial-of-service condition. The core issue is likely KCSAN (or a similar tool) reporting a potential data race due to unsynchronized reads, even though the code uses a seqcount retry loop to handle the concurrent modification of the clock data.
Now, let's map this to the prompt's questions.
* **Can it be reached from a typical unprivileged user process?** Yes, definitely. `clock_gettime(CLOCK_MONOTONIC_COARSE)` does the trick.
* **Can it be reached within a user namespace with all capabilities?** Yes, again, the syscall is the access point.
* **Can it be triggered from a typical KVM guest?** No, this is userspace-triggered.
* **Can it be triggered in a confidential computing guest kernel from the context of a KVM host?** No, not from the host directly.
* **Can it be triggered by processing ingress network Ethernet traffic?** Well, the BPF test triggered it, but that was just the test setup. A BPF flow dissector *could* trigger it if attached to a network interface, but the *direct* trigger is the system call. Even if that BPF test run has called `bpf_ktime_get_coarse_ns`, the problem is in `clock_gettime`, which is much easier to reach.
* **Can it be triggered by processing remote traffic other than Ethernet?** No.
* **Can it be triggered via an untrusted peripheral device?** No.
* **Can it be triggered by the kernel mounting and parsing a malicious filesystem image?** No.
I needed to make sure I wasn't missing something. So, I went through the code to make sure that a torn read of `tk->coarse_nsec` could lead to an issue. But it can't. The seqcount loop *should* handle any concurrent modification of `tk->coarse_nsec`. My intuition tells me that the local variable `now` isn't used *inside* the loop. I've confirmed that this is correct. There's no way a torn value could be used. Therefore, it's a false positive, flagged by KCSAN because it doesn't understand the seqcount retry logic unless explicit annotations are used.
So to summarize again:
* **Exploitable:** False
* **DenialOfService:** False
* **Unprivileged:** True (via the `clock_gettime` syscall)
* **UserNamespace:** True
* **VMGuestTrigger:** False
* **VMHostTrigger:** False
* **NetworkTrigger:** False. Although BPF programs calling `bpf_ktime_get_coarse_ns` *could* be attached to network hooks, the primary trigger is the syscall.
Now I can call the `set-results` tool.
|
| 43/2 |
2026/05/30 18:19 |
tool |
set-results |
0m
Args: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 44/2 |
2026/05/30 18:19 |
llm |
expert |
0m
Model:
Tokens:
input: 37419
output: 671
thoughts: 325
Thoughts: **Final Response Analysis**
Okay, the results are in. Time to craft the definitive response.
This KCSAN report is targeting a data race within `ktime_get_coarse_ts64` and `timekeeping_update_from_shadow`. Specifically, the read is happening in `tk_xtime_coarse`: `ts.tv_nsec = tk->coarse_nsec;`. The concurrent write is taking place in `timekeeping_update_from_shadow`: `memcpy(&tkd->timekeeper, tk, sizeof(*tk));`.
The interesting point is the use of a seqcount to protect this access. We've got the standard read sequence – `read_seqcount_begin` / `read_seqcount_retry` – guarding the read, and the corresponding write lock, `write_seqcount_begin` / `write_seqcount_end`.
The issue, as KCSAN sees it, is that the read isn't using any of the memory barrier directives like `READ_ONCE` or `data_race`. Because KCSAN can't *see* the protection provided by the seqcount, it flags a data race. However, this is a textbook example of a *benign* data race. The seqcount retry loop is *designed* to handle these concurrent accesses. If a write happens concurrently, the loop retries, effectively discarding any inconsistent data read during the overlap. The read values are only considered valid *after* the loop completes without detecting a concurrent write.
Therefore, this is a KCSAN false positive. It has zero security implications. There's no risk of memory corruption, privilege escalation, or denial of service stemming from this. It's triggered by an unprivileged user calling `clock_gettime(CLOCK_MONOTONIC_COARSE, ...)`, which makes sense given the functions involved. Case closed.
|
| 45/1 |
2026/05/30 18:19 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the provided bug report and the kernel source code,
here is the assessment:
**Bug Analysis:**
The report describes a KCSAN (Kernel Concurrency Sanitizer) data-race between a
read in `ktime_get_coarse_ts64` (via `tk_xtime_coarse`) and a write in
`timekeeping_update_from_shadow`.
Looking at the source code for `ktime_get_coarse_ts64`:
```c
do {
seq = read_seqcount_begin(&tk_core.seq);
now = tk_xtime_coarse(tk);
mono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&tk_core.seq, seq));
set_normalized_timespec64(ts, now.tv_sec + mono.tv_sec,
now.tv_nsec + mono.tv_nsec);
```
The read of `tk->coarse_nsec` inside `tk_xtime_coarse` is performed using a
plain C memory access. Concurrently, `timekeeping_update_from_shadow` updates
the timekeeper data using `memcpy()`, protected by `write_seqcount_begin()` and
`write_seqcount_end()`.
Because the reader does not use `READ_ONCE()` or `data_race()` annotations,
KCSAN correctly detects that a concurrent read and write can happen at the same
memory location and flags it as a data race.
However, this is a **benign data race** by design. The read is enclosed within a
standard sequence counter (`seqcount`) retry loop. If a concurrent write occurs
while the reader is fetching the data, the `read_seqcount_retry()` check will
fail, and the loop will simply re-execute to fetch the consistent data. The
potentially torn or inconsistent values of `now` and `mono` read during the
collision are strictly kept as local variables and are only utilized *after* the
seqcount loop has successfully verified that no concurrent modification took
place.
**Security Impact:**
- **Exploitable:** No. The data race is benign and handled correctly by the
seqcount synchronization mechanism. It cannot lead to memory corruption,
out-of-bounds accesses, or privilege escalation.
- **Denial of Service:** No. The kernel state remains perfectly consistent.
KCSAN reports do not halt the kernel in production environments, and the
underlying condition does not violate any actual kernel safety assumptions.
- **Unprivileged Access:** Yes. The read path can be trivially reached by any
unprivileged user-space application by invoking the `clock_gettime()` syscall
with `CLOCK_MONOTONIC_COARSE` or `CLOCK_REALTIME_COARSE`. (The bug report shows
it being reached via a BPF test run, but the syscall is the most direct path).
In conclusion, this is a false positive from the perspective of kernel safety
and security, stemming from missing data race annotations (`data_race()` or
`READ_ONCE()`) in the timekeeping seqcount reader path.]
|