* [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
@ 2026-02-16 17:37 Aleksandr Nogikh
2026-02-23 12:42 ` Aleksandr Nogikh
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Aleksandr Nogikh @ 2026-02-16 17:37 UTC (permalink / raw)
To: tglx, mingo, bp
Cc: x86, linux-kernel, dvyukov, kasan-dev, Aleksandr Nogikh, stable
The load_segments() function changes segment registers, invalidating
GS base (which KCOV relies on for per-cpu data). When CONFIG_KCOV is
enabled, any subsequent instrumented C code call (e.g.
native_gdt_invalidate()) begins crashing the kernel in an
endless loop.
To reproduce the problem, it's sufficient to do kexec on a
KCOV-instrumented kernel:
$ kexec -l /boot/otherKernel
$ kexec -e
(additional problems arise when the kernel is booting into a crash
kernel)
Disabling instrumentation for the individual functions would be too
fragile, so let's fix the bug by disabling KCOV instrumentation for
the whole machine_kexec_64.c and physaddr.c.
The problem is not relevant for 32 bit kernels as CONFIG_KCOV is not
supported there.
Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
Cc: stable@vger.kernel.org
---
arch/x86/kernel/Makefile | 4 ++++
arch/x86/mm/Makefile | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index e9aeeeafad173..5703fa6027866 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -43,6 +43,10 @@ KCOV_INSTRUMENT_dumpstack_$(BITS).o := n
KCOV_INSTRUMENT_unwind_orc.o := n
KCOV_INSTRUMENT_unwind_frame.o := n
KCOV_INSTRUMENT_unwind_guess.o := n
+# When a kexec kernel is loaded, calling load_segments() breaks all
+# subsequent KCOV instrumentation until new kernel takes control.
+# Keep KCOV instrumentation disabled to prevent kernel crashes.
+KCOV_INSTRUMENT_machine_kexec_64.o := n
CFLAGS_head32.o := -fno-stack-protector
CFLAGS_head64.o := -fno-stack-protector
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
index 5b9908f13dcfd..a678a38a40266 100644
--- a/arch/x86/mm/Makefile
+++ b/arch/x86/mm/Makefile
@@ -4,6 +4,10 @@ KCOV_INSTRUMENT_tlb.o := n
KCOV_INSTRUMENT_mem_encrypt.o := n
KCOV_INSTRUMENT_mem_encrypt_amd.o := n
KCOV_INSTRUMENT_pgprot.o := n
+# When a kexec kernel is loaded, calling load_segments() breaks all
+# subsequent KCOV instrumentation until new kernel takes control.
+# Keep KCOV instrumentation disabled to prevent kernel crashes.
+KCOV_INSTRUMENT_physaddr.o := n
KASAN_SANITIZE_mem_encrypt.o := n
KASAN_SANITIZE_mem_encrypt_amd.o := n
--
2.53.0.273.g2a3d683680-goog
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-02-16 17:37 [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments() Aleksandr Nogikh
@ 2026-02-23 12:42 ` Aleksandr Nogikh
2026-02-27 13:25 ` Dmitry Vyukov
2026-03-15 12:18 ` Borislav Petkov
2 siblings, 0 replies; 7+ messages in thread
From: Aleksandr Nogikh @ 2026-02-23 12:42 UTC (permalink / raw)
To: tglx, mingo, bp
Cc: x86, linux-kernel, dvyukov, kasan-dev, stable, syzkaller,
linux-mm, Andrew Morton
On Mon, Feb 16, 2026 at 6:37 PM Aleksandr Nogikh <nogikh@google.com> wrote:
>
> The load_segments() function changes segment registers, invalidating
> GS base (which KCOV relies on for per-cpu data). When CONFIG_KCOV is
> enabled, any subsequent instrumented C code call (e.g.
> native_gdt_invalidate()) begins crashing the kernel in an
> endless loop.
>
> To reproduce the problem, it's sufficient to do kexec on a
> KCOV-instrumented kernel:
> $ kexec -l /boot/otherKernel
> $ kexec -e
>
> (additional problems arise when the kernel is booting into a crash
> kernel)
>
> Disabling instrumentation for the individual functions would be too
> fragile, so let's fix the bug by disabling KCOV instrumentation for
> the whole machine_kexec_64.c and physaddr.c.
>
> The problem is not relevant for 32 bit kernels as CONFIG_KCOV is not
> supported there.
>
> Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
> Cc: stable@vger.kernel.org
> ---
> arch/x86/kernel/Makefile | 4 ++++
> arch/x86/mm/Makefile | 4 ++++
> 2 files changed, 8 insertions(+)
A gentle ping on this patch.
Should it go through the x86 tree or the mm tree like other kcov patches?
>
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index e9aeeeafad173..5703fa6027866 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -43,6 +43,10 @@ KCOV_INSTRUMENT_dumpstack_$(BITS).o := n
> KCOV_INSTRUMENT_unwind_orc.o := n
> KCOV_INSTRUMENT_unwind_frame.o := n
> KCOV_INSTRUMENT_unwind_guess.o := n
> +# When a kexec kernel is loaded, calling load_segments() breaks all
> +# subsequent KCOV instrumentation until new kernel takes control.
> +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> +KCOV_INSTRUMENT_machine_kexec_64.o := n
>
> CFLAGS_head32.o := -fno-stack-protector
> CFLAGS_head64.o := -fno-stack-protector
> diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
> index 5b9908f13dcfd..a678a38a40266 100644
> --- a/arch/x86/mm/Makefile
> +++ b/arch/x86/mm/Makefile
> @@ -4,6 +4,10 @@ KCOV_INSTRUMENT_tlb.o := n
> KCOV_INSTRUMENT_mem_encrypt.o := n
> KCOV_INSTRUMENT_mem_encrypt_amd.o := n
> KCOV_INSTRUMENT_pgprot.o := n
> +# When a kexec kernel is loaded, calling load_segments() breaks all
> +# subsequent KCOV instrumentation until new kernel takes control.
> +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> +KCOV_INSTRUMENT_physaddr.o := n
>
> KASAN_SANITIZE_mem_encrypt.o := n
> KASAN_SANITIZE_mem_encrypt_amd.o := n
> --
> 2.53.0.273.g2a3d683680-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-02-16 17:37 [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments() Aleksandr Nogikh
2026-02-23 12:42 ` Aleksandr Nogikh
@ 2026-02-27 13:25 ` Dmitry Vyukov
2026-03-11 21:27 ` Aleksandr Nogikh
2026-03-15 12:18 ` Borislav Petkov
2 siblings, 1 reply; 7+ messages in thread
From: Dmitry Vyukov @ 2026-02-27 13:25 UTC (permalink / raw)
To: Aleksandr Nogikh; +Cc: tglx, mingo, bp, x86, linux-kernel, kasan-dev, stable
On Mon, 16 Feb 2026 at 18:37, Aleksandr Nogikh <nogikh@google.com> wrote:
>
> The load_segments() function changes segment registers, invalidating
> GS base (which KCOV relies on for per-cpu data). When CONFIG_KCOV is
> enabled, any subsequent instrumented C code call (e.g.
> native_gdt_invalidate()) begins crashing the kernel in an
> endless loop.
>
> To reproduce the problem, it's sufficient to do kexec on a
> KCOV-instrumented kernel:
> $ kexec -l /boot/otherKernel
> $ kexec -e
>
> (additional problems arise when the kernel is booting into a crash
> kernel)
>
> Disabling instrumentation for the individual functions would be too
> fragile, so let's fix the bug by disabling KCOV instrumentation for
> the whole machine_kexec_64.c and physaddr.c.
>
> The problem is not relevant for 32 bit kernels as CONFIG_KCOV is not
> supported there.
>
> Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
> Cc: stable@vger.kernel.org
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
> ---
> arch/x86/kernel/Makefile | 4 ++++
> arch/x86/mm/Makefile | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index e9aeeeafad173..5703fa6027866 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -43,6 +43,10 @@ KCOV_INSTRUMENT_dumpstack_$(BITS).o := n
> KCOV_INSTRUMENT_unwind_orc.o := n
> KCOV_INSTRUMENT_unwind_frame.o := n
> KCOV_INSTRUMENT_unwind_guess.o := n
> +# When a kexec kernel is loaded, calling load_segments() breaks all
> +# subsequent KCOV instrumentation until new kernel takes control.
> +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> +KCOV_INSTRUMENT_machine_kexec_64.o := n
>
> CFLAGS_head32.o := -fno-stack-protector
> CFLAGS_head64.o := -fno-stack-protector
> diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
> index 5b9908f13dcfd..a678a38a40266 100644
> --- a/arch/x86/mm/Makefile
> +++ b/arch/x86/mm/Makefile
> @@ -4,6 +4,10 @@ KCOV_INSTRUMENT_tlb.o := n
> KCOV_INSTRUMENT_mem_encrypt.o := n
> KCOV_INSTRUMENT_mem_encrypt_amd.o := n
> KCOV_INSTRUMENT_pgprot.o := n
> +# When a kexec kernel is loaded, calling load_segments() breaks all
> +# subsequent KCOV instrumentation until new kernel takes control.
> +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> +KCOV_INSTRUMENT_physaddr.o := n
>
> KASAN_SANITIZE_mem_encrypt.o := n
> KASAN_SANITIZE_mem_encrypt_amd.o := n
> --
> 2.53.0.273.g2a3d683680-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-02-27 13:25 ` Dmitry Vyukov
@ 2026-03-11 21:27 ` Aleksandr Nogikh
0 siblings, 0 replies; 7+ messages in thread
From: Aleksandr Nogikh @ 2026-03-11 21:27 UTC (permalink / raw)
To: Dmitry Vyukov
Cc: tglx, mingo, bp, x86, linux-kernel, kasan-dev, stable,
Andrew Morton, linux-mm
+Cc linux-mm
On Fri, Feb 27, 2026 at 2:26 PM Dmitry Vyukov <dvyukov@google.com> wrote:
>
> On Mon, 16 Feb 2026 at 18:37, Aleksandr Nogikh <nogikh@google.com> wrote:
> >
> > The load_segments() function changes segment registers, invalidating
> > GS base (which KCOV relies on for per-cpu data). When CONFIG_KCOV is
> > enabled, any subsequent instrumented C code call (e.g.
> > native_gdt_invalidate()) begins crashing the kernel in an
> > endless loop.
> >
> > To reproduce the problem, it's sufficient to do kexec on a
> > KCOV-instrumented kernel:
> > $ kexec -l /boot/otherKernel
> > $ kexec -e
> >
> > (additional problems arise when the kernel is booting into a crash
> > kernel)
> >
> > Disabling instrumentation for the individual functions would be too
> > fragile, so let's fix the bug by disabling KCOV instrumentation for
> > the whole machine_kexec_64.c and physaddr.c.
> >
> > The problem is not relevant for 32 bit kernels as CONFIG_KCOV is not
> > supported there.
> >
> > Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
> > Cc: stable@vger.kernel.org
>
> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
>
> > ---
> > arch/x86/kernel/Makefile | 4 ++++
> > arch/x86/mm/Makefile | 4 ++++
> > 2 files changed, 8 insertions(+)
> >
> > diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> > index e9aeeeafad173..5703fa6027866 100644
> > --- a/arch/x86/kernel/Makefile
> > +++ b/arch/x86/kernel/Makefile
> > @@ -43,6 +43,10 @@ KCOV_INSTRUMENT_dumpstack_$(BITS).o := n
> > KCOV_INSTRUMENT_unwind_orc.o := n
> > KCOV_INSTRUMENT_unwind_frame.o := n
> > KCOV_INSTRUMENT_unwind_guess.o := n
> > +# When a kexec kernel is loaded, calling load_segments() breaks all
> > +# subsequent KCOV instrumentation until new kernel takes control.
> > +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> > +KCOV_INSTRUMENT_machine_kexec_64.o := n
> >
> > CFLAGS_head32.o := -fno-stack-protector
> > CFLAGS_head64.o := -fno-stack-protector
> > diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
> > index 5b9908f13dcfd..a678a38a40266 100644
> > --- a/arch/x86/mm/Makefile
> > +++ b/arch/x86/mm/Makefile
> > @@ -4,6 +4,10 @@ KCOV_INSTRUMENT_tlb.o := n
> > KCOV_INSTRUMENT_mem_encrypt.o := n
> > KCOV_INSTRUMENT_mem_encrypt_amd.o := n
> > KCOV_INSTRUMENT_pgprot.o := n
> > +# When a kexec kernel is loaded, calling load_segments() breaks all
> > +# subsequent KCOV instrumentation until new kernel takes control.
> > +# Keep KCOV instrumentation disabled to prevent kernel crashes.
> > +KCOV_INSTRUMENT_physaddr.o := n
> >
> > KASAN_SANITIZE_mem_encrypt.o := n
> > KASAN_SANITIZE_mem_encrypt_amd.o := n
> > --
> > 2.53.0.273.g2a3d683680-goog
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-02-16 17:37 [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments() Aleksandr Nogikh
2026-02-23 12:42 ` Aleksandr Nogikh
2026-02-27 13:25 ` Dmitry Vyukov
@ 2026-03-15 12:18 ` Borislav Petkov
2026-03-16 10:07 ` Aleksandr Nogikh
2 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2026-03-15 12:18 UTC (permalink / raw)
To: Aleksandr Nogikh
Cc: tglx, mingo, x86, linux-kernel, dvyukov, kasan-dev, stable
On Mon, Feb 16, 2026 at 06:37:16PM +0100, Aleksandr Nogikh wrote:
> Disabling instrumentation for the individual functions would be too
> fragile, so let's fix the bug by disabling KCOV instrumentation for
> the whole machine_kexec_64.c and physaddr.c.
Seems like a whack-a-mole thing to me. Why not make KEXEC depend on !KCOV?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-03-15 12:18 ` Borislav Petkov
@ 2026-03-16 10:07 ` Aleksandr Nogikh
2026-03-16 10:31 ` Borislav Petkov
0 siblings, 1 reply; 7+ messages in thread
From: Aleksandr Nogikh @ 2026-03-16 10:07 UTC (permalink / raw)
To: Borislav Petkov
Cc: tglx, mingo, x86, linux-kernel, dvyukov, kasan-dev, stable
On Sun, Mar 15, 2026 at 1:19 PM Borislav Petkov <bp@alien8.de> wrote:
>
> On Mon, Feb 16, 2026 at 06:37:16PM +0100, Aleksandr Nogikh wrote:
> > Disabling instrumentation for the individual functions would be too
> > fragile, so let's fix the bug by disabling KCOV instrumentation for
> > the whole machine_kexec_64.c and physaddr.c.
>
> Seems like a whack-a-mole thing to me. Why not make KEXEC depend on !KCOV?
Some more context:
The problem I am trying to solve is enabling crash dump collection in
syzkaller. For this, the tool loads a panic kernel before fuzzing and
then calls makedumpfile after the panic (which fails due to the bug I
mentioned in the patch). It requires both KEXEC and KCOV.
The most whack-a-mole solution was to disable instrumentation for
several functions called after load_segments(); this particular patch
is more generic, but yes, it can still be fragile. Another approach
would be to add more checks to
__sanitizer_cov_trace_pc()/check_kcov_mode(), but this would also be
somewhat undesirable as it would slow KCOV down even further.
--
Aleksandr
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments()
2026-03-16 10:07 ` Aleksandr Nogikh
@ 2026-03-16 10:31 ` Borislav Petkov
0 siblings, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2026-03-16 10:31 UTC (permalink / raw)
To: Aleksandr Nogikh
Cc: tglx, mingo, x86, linux-kernel, dvyukov, kasan-dev, stable
On Mon, Mar 16, 2026 at 11:07:15AM +0100, Aleksandr Nogikh wrote:
> Some more context:
> The problem I am trying to solve is enabling crash dump collection in
> syzkaller. For this, the tool loads a panic kernel before fuzzing and
> then calls makedumpfile after the panic (which fails due to the bug I
> mentioned in the patch). It requires both KEXEC and KCOV.
>
> The most whack-a-mole solution was to disable instrumentation for
> several functions called after load_segments(); this particular patch
> is more generic, but yes, it can still be fragile. Another approach
> would be to add more checks to
> __sanitizer_cov_trace_pc()/check_kcov_mode(), but this would also be
> somewhat undesirable as it would slow KCOV down even further.
I guess...
So I'd like the *real* justification - the context you just gave - for this
to be put somewhere over the code, I guess in both Makefiles so that it is
clear why we're doing this.
I guess those two compilation units will be excluded from KCOV fuzzing and if
someone wants to do coverage-guided fuzzing for them, then someone would have
to come up with a different solution, like, I dunno, putting only the
relevant, simple functions into a separate compilation unit which would be the
only one excluded from KCOV instrumentation or something more clever and less
whack-a-mole-y...
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-03-16 10:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-16 17:37 [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments() Aleksandr Nogikh
2026-02-23 12:42 ` Aleksandr Nogikh
2026-02-27 13:25 ` Dmitry Vyukov
2026-03-11 21:27 ` Aleksandr Nogikh
2026-03-15 12:18 ` Borislav Petkov
2026-03-16 10:07 ` Aleksandr Nogikh
2026-03-16 10:31 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®