Tetsuo Handa
a2fb8222cd
kcov: fix data corruption and race conditions on PREEMPT_RT
commit 2eed77fdcb upstream.
syzbot is reporting KCOV state corruption on PREEMPT_RT kernels, for the
temporary storage used for saving/restoring remote KCOV state is currently
allocated as the per-CPU area.
On PREEMPT_RT kernels, softirq handlers run as preemptible task threads
(e.g., ksoftirqd). If a softirq context preempts a task running a remote
KCOV session, it safely saves the task's state into the per-CPU area.
However, if that softirq thread is subsequently preempted by a higher-
priority softirq thread on the same CPU, the second softirq will overwrite
the same per-CPU area, permanently destroying the original task's KCOV
state.
Fix this data corruption by moving the temporary storage from the per-CPU
area to the per-thread area. Since each softirq thread now owns its own
task context, nested softirq preemption no longer causes data overwrites.
Note that while the temporary storage is now on a per-thread basis, the
per-CPU kcov_percpu_data.lock must be retained, for we need to ensure that
kcov_remote_start() and kcov_remote_stop() operate atomically without
racing against asynchronous interrupts that manipulate the current task's
KCOV state.
It is likely that GFP_KERNEL allocation by vmalloc_node() in kcov_init()
has already called panic() before returning NULL, for there will be no
OOM-killable userspace processes when __init function of built-in module
runs. But this patch also fixes crashing the kernel when vmalloc_node()
in kcov_init() returned NULL, for kcov_init() left per-CPU irq_area == NULL
but kcov_remote_start() depends on per-CPU irq_area != NULL, resulting in
(1) doing vmalloc() in kcov_remote_start() despite !in_task() context
(2) out-of-array-bounds access if (1) succeeded but
kcov->remote_size < CONFIG_KCOV_IRQ_AREA_SIZE
(3) always leak memory allocated by (1), eventually killing all
OOM-killable userspace processes
problems.
Link: https://lore.kernel.org/43552d09-2ce2-4b19-b0d3-a2d1ab952145@I-love.SAKURA.ne.jp
Reported-by: syzbot+3f51ad7ac3ae57a6fdcc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3f51ad7ac3ae57a6fdcc
Reported-by: syzbot+47cf95ca1f9dcca872c8@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=47cf95ca1f9dcca872c8
Reported-by: syzbot+8a173e13208949931dc7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8a173e13208949931dc7
Reported-by: syzbot+90984d3713722683112e@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=90984d3713722683112e
Analyzed-by: AI Mode in Google Search (no mail address)
Fixes: 5ff3b30ab5 ("kcov: collect coverage from interrupts")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Clark Williams <williams@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Marco Elver <elver@google.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-08-27 14:29:45 +02:00
..
2024-12-09 10:32:02 +01:00
2026-08-09 20:22:03 +02:00
2026-08-09 20:22:04 +02:00
2026-06-01 17:43:04 +02:00
2026-08-09 20:21:53 +02:00
2024-12-19 18:11:29 +01:00
2025-11-02 22:14:42 +09:00
2024-12-14 19:59:46 +01:00
2026-07-24 16:03:46 +02:00
2026-03-25 11:05:52 +01:00
2026-03-04 07:19:34 -05:00
2025-06-04 14:42:09 +02:00
2026-06-19 13:39:30 +02:00
2026-08-09 20:22:03 +02:00
2026-03-04 07:20:03 -05:00
2026-08-19 18:13:05 +02:00
2025-05-09 09:43:58 +02:00
2026-08-03 11:15:39 +02:00
2026-01-11 15:21:30 +01:00
2026-08-19 18:13:08 +02:00
2026-06-01 17:43:15 +02:00
2025-12-07 06:18:50 +09:00
2026-08-03 11:15:37 +02:00
2026-04-02 13:07:16 +02:00
2025-06-27 11:08:52 +01:00
2025-08-28 16:28:42 +02:00
2025-06-19 15:28:08 +02:00
2025-12-01 11:41:47 +01:00
2025-12-01 11:41:40 +01:00
2025-09-04 15:30:21 +02:00
2026-08-03 11:15:34 +02:00
2026-08-03 11:15:34 +02:00
2026-07-24 16:03:49 +02:00
2025-04-25 10:45:45 +02:00
2026-01-11 15:22:28 +01:00
2025-02-17 09:40:03 +01:00
2025-06-19 15:28:44 +02:00
2026-07-24 16:03:47 +02:00
2025-11-02 22:14:42 +09:00
2026-01-11 15:21:38 +01:00
2025-02-21 13:57:09 +01:00
2024-12-09 10:32:56 +01:00
2026-08-03 11:15:39 +02:00
2026-07-24 16:03:50 +02:00
2026-08-03 11:15:33 +02:00
2026-07-04 13:42:19 +02:00
2025-09-09 18:56:18 +02:00
2026-07-24 16:03:50 +02:00
2025-02-08 09:52:26 +01:00
2025-06-19 15:28:44 +02:00
2026-03-04 07:20:22 -05:00
2026-03-04 07:19:49 -05:00
2026-05-23 13:03:27 +02:00
2025-02-21 13:57:17 +01:00
2025-11-24 10:29:21 +01:00
2025-01-09 13:31:53 +01:00
2026-03-04 07:20:08 -05:00
2025-03-13 12:58:27 +01:00
2026-06-19 13:39:25 +02:00
2026-06-19 13:39:19 +02:00
2026-06-19 13:39:25 +02:00
2026-06-19 13:39:25 +02:00
2025-10-02 13:42:55 +02:00
2025-07-06 11:00:10 +02:00
2025-04-10 14:37:36 +02:00
2025-06-04 14:42:24 +02:00
2025-04-10 14:37:32 +02:00
2026-03-04 07:20:34 -05:00
2025-09-11 17:20:27 +02:00
2025-10-23 16:16:26 +02:00
2026-05-23 13:03:11 +02:00
2026-07-24 16:02:43 +02:00
2026-05-23 13:03:20 +02:00
2026-07-24 16:02:59 +02:00
2026-04-02 13:07:19 +02:00
2026-05-23 13:03:06 +02:00
2024-12-14 20:00:16 +01:00
2025-02-21 13:57:17 +01:00
2025-08-28 16:28:42 +02:00
2026-07-04 13:42:25 +02:00
2026-07-24 16:02:38 +02:00
2024-12-14 19:59:58 +01:00
2025-07-10 16:03:18 +02:00
2026-07-24 16:02:36 +02:00
2024-12-14 20:00:05 +01:00
2026-05-17 17:13:49 +02:00
2025-11-24 10:29:11 +01:00
2026-07-04 13:42:22 +02:00
2026-07-24 16:02:57 +02:00
2026-08-03 11:15:38 +02:00
2025-08-15 12:08:39 +02:00
2026-08-23 14:20:03 +02:00
2026-08-03 11:15:33 +02:00
2026-05-17 17:13:38 +02:00
2026-03-04 07:19:45 -05:00
2026-07-24 16:02:36 +02:00
2026-01-11 15:22:07 +01:00
2026-07-24 16:02:54 +02:00
2026-06-19 13:39:24 +02:00
2026-07-24 16:02:49 +02:00
2026-07-24 16:03:50 +02:00
2025-06-04 14:42:21 +02:00
2024-12-09 10:31:48 +01:00
2026-07-24 16:03:03 +02:00
2025-06-04 14:42:22 +02:00
2026-06-19 13:39:42 +02:00
2025-07-06 11:00:09 +02:00
2025-08-28 16:28:11 +02:00
2025-03-22 12:50:37 -07:00
2026-01-11 15:21:30 +01:00
2026-01-11 15:22:25 +01:00
2026-07-24 16:02:38 +02:00
2025-08-28 16:28:23 +02:00
2026-06-19 13:39:14 +02:00
2026-03-25 11:05:40 +01:00
2026-07-24 16:03:28 +02:00
2024-12-09 10:32:59 +01:00
2025-04-10 14:37:26 +02:00
2025-06-19 15:28:44 +02:00
2024-12-27 13:58:55 +01:00
2026-03-25 11:05:31 +01:00
2025-08-28 16:28:47 +02:00
2025-07-06 11:00:16 +02:00
2025-08-01 09:47:29 +01:00
2026-01-11 15:21:56 +01:00
2026-07-24 16:03:53 +02:00
2025-02-08 09:52:27 +01:00
2026-01-11 15:22:17 +01:00
2025-12-01 11:41:47 +01:00
2026-01-30 10:27:25 +01:00
2025-10-19 16:30:58 +02:00
2026-08-03 11:15:40 +02:00
2024-12-14 20:00:12 +01:00
2026-08-09 20:21:52 +02:00
2024-12-09 10:32:45 +01:00
2026-07-04 13:42:23 +02:00
2026-07-04 13:42:23 +02:00
2026-08-03 11:15:36 +02:00
2025-06-04 14:42:01 +02:00
2026-03-25 11:05:33 +01:00
2026-03-25 11:05:34 +01:00
2025-11-24 10:30:07 +01:00
2025-07-17 18:35:22 +02:00
2025-06-19 15:28:19 +02:00
2025-01-09 13:31:40 +01:00
2025-11-24 10:30:13 +01:00
2025-08-28 16:28:39 +02:00
2025-11-24 10:30:14 +01:00
2025-10-02 13:42:56 +02:00
2026-08-23 14:20:01 +02:00
2026-02-19 16:28:26 +01:00
2026-06-19 13:39:42 +02:00
2026-08-23 14:20:04 +02:00
2024-12-09 10:32:59 +01:00
2026-03-04 07:19:45 -05:00
2026-05-23 13:03:06 +02:00
2025-02-08 09:52:02 +01:00
2025-06-04 14:42:06 +02:00
2025-01-09 13:31:41 +01:00
2026-08-03 11:15:33 +02:00
2026-07-24 16:02:38 +02:00
2026-08-23 14:20:07 +02:00
2025-11-24 10:30:10 +01:00
2026-01-17 16:30:00 +01:00
2026-01-11 15:21:37 +01:00
2026-03-25 11:05:59 +01:00
2026-07-24 16:03:16 +02:00
2026-01-11 15:21:37 +01:00
2025-04-25 10:45:46 +02:00
2025-11-24 10:30:04 +01:00
2025-01-17 13:36:09 +01:00
2025-03-22 12:50:43 -07:00
2026-01-30 10:27:42 +01:00
2025-02-27 04:10:47 -08:00
2024-12-09 10:31:56 +01:00
2025-02-08 09:51:51 +01:00
2024-12-09 10:32:59 +01:00
2025-10-15 11:57:54 +02:00
2026-05-23 13:03:11 +02:00
2025-06-04 14:42:21 +02:00
2025-09-25 11:00:10 +02:00
2026-08-23 14:20:04 +02:00
2026-06-19 13:39:16 +02:00
2026-08-27 14:29:43 +02:00
2026-07-24 16:03:48 +02:00
2025-06-04 14:42:13 +02:00
2025-09-19 16:32:01 +02:00
2025-09-19 16:32:01 +02:00
2026-06-01 17:43:13 +02:00
2026-06-01 17:43:04 +02:00
2025-10-23 16:16:39 +02:00
2025-01-23 17:21:14 +01:00
2026-01-30 10:27:30 +01:00
2026-08-03 11:15:22 +02:00
2026-05-23 13:03:24 +02:00
2025-08-15 12:08:42 +02:00
2026-05-23 13:03:22 +02:00
2025-08-15 12:08:54 +02:00
2025-01-23 17:21:12 +01:00
2025-08-15 12:08:46 +02:00
2026-03-04 07:20:00 -05:00
2026-02-06 16:48:29 +01:00
2025-10-23 16:16:41 +02:00
2026-05-23 13:03:15 +02:00
2026-05-17 17:13:30 +02:00
2026-01-11 15:21:14 +01:00
2025-06-04 14:42:13 +02:00
2025-03-07 16:45:47 +01:00
2025-06-04 14:42:13 +02:00
2026-01-11 15:21:52 +01:00
2026-07-04 13:42:19 +02:00
2026-07-24 16:03:05 +02:00
2025-04-25 10:45:06 +02:00
2025-01-09 13:31:41 +01:00
2024-12-14 19:59:50 +01:00
2026-08-27 14:29:45 +02:00
2025-02-01 18:37:51 +01:00
2026-07-04 13:42:23 +02:00
2025-01-09 13:32:05 +01:00
2026-08-03 11:15:10 +02:00
2026-06-19 13:39:40 +02:00
2025-02-27 04:10:45 -08:00
2025-11-24 10:29:32 +01:00
2026-02-06 16:48:29 +01:00
2026-03-04 07:19:53 -05:00
2026-07-04 13:42:25 +02:00
2024-12-09 10:32:10 +01:00
2026-05-23 13:03:06 +02:00
2026-06-01 17:43:15 +02:00
2025-08-01 09:47:30 +01:00
2024-12-19 18:11:37 +01:00
2026-03-25 11:06:01 +01:00
2026-06-01 17:43:15 +02:00
2025-11-24 10:30:14 +01:00
2026-04-11 14:19:35 +02:00
2026-06-19 13:39:25 +02:00
2026-08-09 20:22:03 +02:00
2026-08-19 18:13:08 +02:00
2026-01-30 10:27:25 +01:00
2026-08-09 20:21:44 +02:00
2026-05-17 17:13:30 +02:00
2026-01-11 15:22:20 +01:00
2026-03-04 07:21:20 -05:00
2026-03-25 11:06:00 +01:00
2025-06-04 14:41:54 +02:00
2025-06-04 14:41:54 +02:00
2026-01-11 15:22:33 +01:00
2025-05-18 08:24:09 +02:00
2026-03-04 07:19:51 -05:00
2026-03-25 11:06:01 +01:00
2026-05-17 17:13:25 +02:00
2026-08-23 14:20:01 +02:00
2024-12-09 10:33:06 +01:00
2026-07-24 16:02:42 +02:00
2026-04-11 14:19:30 +02:00
2026-01-11 15:21:32 +01:00
2025-08-28 16:28:25 +02:00
2025-11-24 10:30:12 +01:00
2026-07-24 16:03:08 +02:00
2025-01-02 10:32:00 +01:00
2026-08-03 11:15:15 +02:00
2025-08-15 12:09:01 +02:00
2024-12-27 13:58:57 +01:00
2026-08-03 11:15:38 +02:00
2026-07-24 16:03:49 +02:00