2023-07-31 03:57:18

by Pengfei Xu

[permalink] [raw]
Subject: [PATCH RESEND v1 1/1] x86/kernel: Increase kcov coverage under arch/x86/kernel folder

Currently kcov instrument is disabled for object files under arch/x86/kernel
folder.
For object files under arch/x86/kernel, actually just disabling the kcov
instrument of files:"head32.o or head64.o and sev.o" could achieve
successful booting and provide kcov coverage for object files that do not
disable kcov instrument.
The additional kcov coverage collected from arch/x86/kernel folder helps
kernel fuzzing efforts to find bugs.

Link to related improvement discussion is below:
https://groups.google.com/g/syzkaller/c/Dsl-RYGCqs8/m/x-tfpTyFBAAJ
Related ticket is as follow:
https://bugzilla.kernel.org/show_bug.cgi?id=198443

Reviewed-by: Dmitry Vyukov <[email protected]>
Tested-by: Dmitry Vyukov <[email protected]>
Signed-off-by: Pengfei Xu <[email protected]>
---
arch/x86/kernel/Makefile | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 4070a01c11b7..00df34c263cc 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -33,11 +33,10 @@ KCSAN_SANITIZE := n
KMSAN_SANITIZE_head$(BITS).o := n
KMSAN_SANITIZE_nmi.o := n

-# If instrumentation of this dir is enabled, boot hangs during first second.
-# Probably could be more selective here, but note that files related to irqs,
-# boot, dumpstack/stacktrace, etc are either non-interesting or can lead to
-# non-deterministic coverage.
-KCOV_INSTRUMENT := n
+# If instrumentation of the following files is enabled, boot hangs during
+# first second.
+KCOV_INSTRUMENT_head$(BITS).o := n
+KCOV_INSTRUMENT_sev.o := n

CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace

--
2.31.1



2023-08-07 21:15:26

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH RESEND v1 1/1] x86/kernel: Increase kcov coverage under arch/x86/kernel folder

On Mon, 31 Jul 2023 11:04:18 +0800 Pengfei Xu <[email protected]> wrote:

> Currently kcov instrument is disabled for object files under arch/x86/kernel
> folder.
> For object files under arch/x86/kernel, actually just disabling the kcov
> instrument of files:"head32.o or head64.o and sev.o" could achieve
> successful booting and provide kcov coverage for object files that do not
> disable kcov instrument.
> The additional kcov coverage collected from arch/x86/kernel folder helps
> kernel fuzzing efforts to find bugs.
>
> Link to related improvement discussion is below:
> https://groups.google.com/g/syzkaller/c/Dsl-RYGCqs8/m/x-tfpTyFBAAJ
> Related ticket is as follow:
> https://bugzilla.kernel.org/show_bug.cgi?id=198443
>
> ...
>
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -33,11 +33,10 @@ KCSAN_SANITIZE := n
> KMSAN_SANITIZE_head$(BITS).o := n
> KMSAN_SANITIZE_nmi.o := n
>
> -# If instrumentation of this dir is enabled, boot hangs during first second.
> -# Probably could be more selective here, but note that files related to irqs,
> -# boot, dumpstack/stacktrace, etc are either non-interesting or can lead to
> -# non-deterministic coverage.
> -KCOV_INSTRUMENT := n
> +# If instrumentation of the following files is enabled, boot hangs during
> +# first second.
> +KCOV_INSTRUMENT_head$(BITS).o := n
> +KCOV_INSTRUMENT_sev.o := n
>
> CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace

This patch exposes (but probably doesn't cause) an objtool warning:

arch/x86/kernel/traps.o: warning: objtool: ibt_selftest+0x18: sibling call from callable instruction with modified stack frame

gcc-12.2.0, x86_64 allmodconfig.


2023-08-09 08:23:38

by Pengfei Xu

[permalink] [raw]
Subject: Re: [PATCH RESEND v1 1/1] x86/kernel: Increase kcov coverage under arch/x86/kernel folder

Hi Andrew,

On 2023-08-07 at 12:58:03 -0700, Andrew Morton wrote:
> On Mon, 31 Jul 2023 11:04:18 +0800 Pengfei Xu <[email protected]> wrote:
>
> > Currently kcov instrument is disabled for object files under arch/x86/kernel
> > folder.
> > For object files under arch/x86/kernel, actually just disabling the kcov
> > instrument of files:"head32.o or head64.o and sev.o" could achieve
> > successful booting and provide kcov coverage for object files that do not
> > disable kcov instrument.
> > The additional kcov coverage collected from arch/x86/kernel folder helps
> > kernel fuzzing efforts to find bugs.
> >
> > Link to related improvement discussion is below:
> > https://groups.google.com/g/syzkaller/c/Dsl-RYGCqs8/m/x-tfpTyFBAAJ
> > Related ticket is as follow:
> > https://bugzilla.kernel.org/show_bug.cgi?id=198443
> >
> > ...
> >
> > --- a/arch/x86/kernel/Makefile
> > +++ b/arch/x86/kernel/Makefile
> > @@ -33,11 +33,10 @@ KCSAN_SANITIZE := n
> > KMSAN_SANITIZE_head$(BITS).o := n
> > KMSAN_SANITIZE_nmi.o := n
> >
> > -# If instrumentation of this dir is enabled, boot hangs during first second.
> > -# Probably could be more selective here, but note that files related to irqs,
> > -# boot, dumpstack/stacktrace, etc are either non-interesting or can lead to
> > -# non-deterministic coverage.
> > -KCOV_INSTRUMENT := n
> > +# If instrumentation of the following files is enabled, boot hangs during
> > +# first second.
> > +KCOV_INSTRUMENT_head$(BITS).o := n
> > +KCOV_INSTRUMENT_sev.o := n
> >
> > CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace
>
> This patch exposes (but probably doesn't cause) an objtool warning:
>
> arch/x86/kernel/traps.o: warning: objtool: ibt_selftest+0x18: sibling call from callable instruction with modified stack frame

Thanks for pointing out the problem!
I found: v6.5-rc5 mainline kernel met the problem also:
"
vmlinux.o: warning: objtool: ibt_selftest+0x11: sibling call from callable instruction with modified stack frame
"

Yes, it has something to do with the patch above, becasue after installed
above patch on top of v6.5-rc5 kernel, the offset changed from 0x11 to 0x1d:
"
vmlinux.o: warning: objtool: ibt_selftest+0x1d: sibling call from callable instruction with modified stack frame
"

I'm still not quite sure the reason of warning from ibt_selftest function.
Anyway, I will keep looking into this issue.

Best Regards,
Thanks!

>
> gcc-12.2.0, x86_64 allmodconfig.
>