linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/3] Add kernel config option for twisting kernel behavior.
@ 2020-04-21 13:19 Tetsuo Handa
  2020-04-21 13:19 ` [PATCH v4 2/3] twist: Allow disabling k_spec() function in drivers/tty/vt/keyboard.c Tetsuo Handa
  2020-04-21 13:19 ` [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing Tetsuo Handa
  0 siblings, 2 replies; 4+ messages in thread
From: Tetsuo Handa @ 2020-04-21 13:19 UTC (permalink / raw)
  To: Andrew Morton, Greg Kroah-Hartman, Steven Rostedt,
	Linus Torvalds, Dmitry Vyukov
  Cc: Matthew Garrett, Andi Kleen, Theodore Y . Ts'o,
	Alexander Viro, Petr Mladek, Sergey Senozhatsky, Arnd Bergmann,
	Jiri Slaby, Peter Zijlstra, LKML, syzkaller, Tetsuo Handa

Existing kernel config options are defined based on "whether you want to
enable this module/feature or not". And such granularity is sometimes
too rough-grained for fuzzing tools which try to find bugs inside each
module/feature.

While syzkaller (one of fuzzing tools) is finding many bugs, sometimes
syzkaller examines stupid operations. Some examples of such operations
are: changing console loglevel which in turn makes it impossible to get
kernel messages when a crash happens, freezing filesystems which in turn
causes khungtaskd to needlessly complain, programmatically sending
Ctrl-Alt-Del which in turn causes the system to needlessly reboot.
Currently we prevent syzkaller from examining stupid operations by
blacklisting syscall arguments and/or disabling whole functionality
using existing kernel config options. But such approach is difficult to
maintain and needlessly prevents fuzzers from testing kernel code. [1]

We want fuzzers to test as much coverage as possible while we want
fuzzers not to try stupid operations. To achieve this goal, we want
cooperation from kernel side, and build-time branching (i.e. kernel
config options) will be the simplest and the most reliable.

Therefore, this patch introduces a kernel config option which allows
selecting fine-grained kernel config options for twisting kernel's
behavior. Each fine-grained kernel config option will be added by future
patches. For ease of management, grouping kernel config options for
allowing e.g. syzkaller to select all fine-grained kernel config options
which e.g. syzkaller wants would be added by future patches.

[1] https://lkml.kernel.org/r/CACT4Y+a6KExbggs4mg8pvoD554PcDqQNW4sM15X-tc=YONCzYw@mail.gmail.com

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 lib/Kconfig.debug |  2 ++
 lib/Kconfig.twist | 13 +++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 lib/Kconfig.twist

Changes since v3 ( https://lkml.kernel.org/r/20200413063317.7164-1-penguin-kernel@I-love.SAKURA.ne.jp ):
  Use "twist" instead of "tweak".
  Add an instance of fine-grained kernel config option as patch 2 of 3.
  Add a grouping kernel config option for syzkaller as patch 3 of 3.

Changes since v2 ( https://lkml.kernel.org/r/20200307135822.3894-1-penguin-kernel@I-love.SAKURA.ne.jp ):
  Reduce the role of this kernel config option from "enable everything
  which would be useful for fuzz testing" to "simply serve as a gate for
  hiding individual kernel config option", for we should use individual
  kernel config option for tweaking individual kernel behavior.

Changes since v1 ( https://lkml.kernel.org/r/20191216095955.9886-1-penguin-kernel@I-love.SAKURA.ne.jp ):
  Drop users of this kernel config option.
  Update patch description.

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 21d9c5f6e7ec..e6162595ef9d 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2225,4 +2225,6 @@ config HYPERV_TESTING
 
 endmenu # "Kernel Testing and Coverage"
 
+source "lib/Kconfig.twist"
+
 endmenu # Kernel hacking
diff --git a/lib/Kconfig.twist b/lib/Kconfig.twist
new file mode 100644
index 000000000000..a5ce0db67f28
--- /dev/null
+++ b/lib/Kconfig.twist
@@ -0,0 +1,13 @@
+menuconfig TWIST_KERNEL_BEHAVIOR
+	bool "Twist kernel behavior"
+	help
+	  Saying Y here allows modifying kernel behavior via kernel
+	  config options which will become visible by selecting this
+	  config option. Since these kernel config options are intended
+	  for helping e.g. fuzz testing, behavior twisted by this kernel
+	  option might be unstable. Userspace applications should not
+	  count on this option being selected.
+
+if TWIST_KERNEL_BEHAVIOR
+
+endif # TWIST_KERNEL_BEHAVIOR
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/3] twist: Allow disabling k_spec() function in drivers/tty/vt/keyboard.c
  2020-04-21 13:19 [PATCH v4 1/3] Add kernel config option for twisting kernel behavior Tetsuo Handa
@ 2020-04-21 13:19 ` Tetsuo Handa
  2020-04-21 13:19 ` [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing Tetsuo Handa
  1 sibling, 0 replies; 4+ messages in thread
From: Tetsuo Handa @ 2020-04-21 13:19 UTC (permalink / raw)
  To: Andrew Morton, Greg Kroah-Hartman, Steven Rostedt,
	Linus Torvalds, Dmitry Vyukov
  Cc: Matthew Garrett, Andi Kleen, Theodore Y . Ts'o,
	Alexander Viro, Petr Mladek, Sergey Senozhatsky, Arnd Bergmann,
	Jiri Slaby, Peter Zijlstra, LKML, syzkaller, Tetsuo Handa

syzbot is reporting unexpected kernel reboots [1]. This seems to be
caused by triggering Ctrl-Alt-Del event via k_spec() function in
drivers/tty/vt/keyboard.c file, for the console output includes normal
restart sequence.

  [   97.727327][    T1] systemd-shutdown[1]: Unmounting file systems.
  [   97.734278][    T1] systemd-shutdown[1]: Remounting '/' read-only with options ''.
  [   97.747758][   T21] usb 2-1: device descriptor read/8, error -71
  [   97.747850][ T3116] usb 1-1: device descriptor read/8, error -71
  [   97.764818][    T1] EXT4-fs (sda1): re-mounted. Opts: 
  [   97.777551][    T1] systemd-shutdown[1]: Remounting '/' read-only with options ''.
  [   97.785448][    T1] EXT4-fs (sda1): re-mounted. Opts: 
  [   97.790920][    T1] systemd-shutdown[1]: All filesystems unmounted.
  [   97.797352][    T1] systemd-shutdown[1]: Deactivating swaps.
  [   97.803451][    T1] systemd-shutdown[1]: All swaps deactivated.
  [   97.809626][    T1] systemd-shutdown[1]: Detaching loop devices.
  [   97.890294][    T1] systemd-shutdown[1]: All loop devices detached.
  [   98.967832][ T3116] usb 1-1: device descriptor read/8, error -71
  [  100.108406][    T1] sd 0:0:1:0: [sda] Synchronizing SCSI cache
  [  100.116036][    T1] reboot: Restarting system
  [  100.120636][    T1] reboot: machine restart
  SeaBIOS (version 1.8.2-20200402_173431-google)
  Total RAM Size = 0x00000001e0000000 = 7680 MiB
  CPUs found: 2     Max CPUs supported: 2
  Comparing RSDP and RSDP

Therefore, allow disabling only k_spec() function in order to allow
fuzzers to examine the remaining part in that file.

[1] https://syzkaller.appspot.com/bug?id=321861b1588b44d064b779b92293c5d55cfe8430

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 drivers/tty/vt/keyboard.c | 2 ++
 lib/Kconfig.twist         | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 15d33fa0c925..f08855c4c5ba 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -633,6 +633,8 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
 	     kbd->kbdmode == VC_OFF) &&
 	     value != KVAL(K_SAK))
 		return;		/* SAK is allowed even in raw mode */
+	if (IS_ENABLED(CONFIG_TWIST_DISABLE_KBD_K_SPEC_HANDLER))
+		return;
 	fn_handler[value](vc);
 }
 
diff --git a/lib/Kconfig.twist b/lib/Kconfig.twist
index a5ce0db67f28..a1d038bcc2a5 100644
--- a/lib/Kconfig.twist
+++ b/lib/Kconfig.twist
@@ -10,4 +10,11 @@ menuconfig TWIST_KERNEL_BEHAVIOR
 
 if TWIST_KERNEL_BEHAVIOR
 
+config TWIST_DISABLE_KBD_K_SPEC_HANDLER
+       bool "Disable k_spec() function in drivers/tty/vt/keyboard.c"
+       help
+	 k_spec() function allows triggering e.g. Ctrl-Alt-Del event.
+	 Such event is annoying for fuzz testing which wants to test
+	 kernel code without rebooting the system.
+
 endif # TWIST_KERNEL_BEHAVIOR
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing
  2020-04-21 13:19 [PATCH v4 1/3] Add kernel config option for twisting kernel behavior Tetsuo Handa
  2020-04-21 13:19 ` [PATCH v4 2/3] twist: Allow disabling k_spec() function in drivers/tty/vt/keyboard.c Tetsuo Handa
@ 2020-04-21 13:19 ` Tetsuo Handa
  2020-04-21 16:00   ` Dmitry Vyukov
  1 sibling, 1 reply; 4+ messages in thread
From: Tetsuo Handa @ 2020-04-21 13:19 UTC (permalink / raw)
  To: Andrew Morton, Greg Kroah-Hartman, Steven Rostedt,
	Linus Torvalds, Dmitry Vyukov
  Cc: Matthew Garrett, Andi Kleen, Theodore Y . Ts'o,
	Alexander Viro, Petr Mladek, Sergey Senozhatsky, Arnd Bergmann,
	Jiri Slaby, Peter Zijlstra, LKML, syzkaller, Tetsuo Handa

When a kernel developer adds a kernel config option, they will not go
and update configs on all external testing systems. This problem is also
common for "enable all boot tests that can run on this kernel", or
"configure a 'standard' debug build". Currently doing these things
require all of expertise, sacred knowledge, checking all configs
one-by-one as well as checking every new kernel patch and that needs to
be done by everybody doing any kernel testing.

In order to reduce the burden of maintaining kernel config options, this
patch introduces a kernel config option which will select twist options
when building kernels for syzkaller's testing.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
---
 lib/Kconfig.twist | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/Kconfig.twist b/lib/Kconfig.twist
index a1d038bcc2a5..95020a56bbfc 100644
--- a/lib/Kconfig.twist
+++ b/lib/Kconfig.twist
@@ -10,6 +10,12 @@ menuconfig TWIST_KERNEL_BEHAVIOR
 
 if TWIST_KERNEL_BEHAVIOR
 
+config TWIST_FOR_SYZKALLER_TESTING
+       bool "Select all twist options suitable for syzkaller testing"
+       select TWIST_DISABLE_KBD_K_SPEC_HANDLER
+       help
+	 Say N unless you are building kernels for syzkaller's testing.
+
 config TWIST_DISABLE_KBD_K_SPEC_HANDLER
        bool "Disable k_spec() function in drivers/tty/vt/keyboard.c"
        help
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing
  2020-04-21 13:19 ` [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing Tetsuo Handa
@ 2020-04-21 16:00   ` Dmitry Vyukov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Vyukov @ 2020-04-21 16:00 UTC (permalink / raw)
  To: Tetsuo Handa
  Cc: Andrew Morton, Greg Kroah-Hartman, Steven Rostedt,
	Linus Torvalds, Matthew Garrett, Andi Kleen,
	Theodore Y . Ts'o, Alexander Viro, Petr Mladek,
	Sergey Senozhatsky, Arnd Bergmann, Jiri Slaby, Peter Zijlstra,
	LKML, syzkaller

On Tue, Apr 21, 2020 at 3:22 PM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> When a kernel developer adds a kernel config option, they will not go
> and update configs on all external testing systems. This problem is also
> common for "enable all boot tests that can run on this kernel", or
> "configure a 'standard' debug build". Currently doing these things
> require all of expertise, sacred knowledge, checking all configs
> one-by-one as well as checking every new kernel patch and that needs to
> be done by everybody doing any kernel testing.
>
> In order to reduce the burden of maintaining kernel config options, this
> patch introduces a kernel config option which will select twist options
> when building kernels for syzkaller's testing.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> ---
>  lib/Kconfig.twist | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/Kconfig.twist b/lib/Kconfig.twist
> index a1d038bcc2a5..95020a56bbfc 100644
> --- a/lib/Kconfig.twist
> +++ b/lib/Kconfig.twist
> @@ -10,6 +10,12 @@ menuconfig TWIST_KERNEL_BEHAVIOR
>
>  if TWIST_KERNEL_BEHAVIOR
>
> +config TWIST_FOR_SYZKALLER_TESTING


One nice side effect of this is that this can replace
CONFIG_DEBUG_AID_FOR_SYZBOT, which we need to manually bolt and
carefully carry:
https://github.com/google/syzkaller/blob/master/dashboard/config/upstream-kasan.config#L12-L14
Since it's not defined in most kernel trees, any olddefconfig will wipe it out.
Having a config that we can enable that is "officially" in the kernel
will make it much less problematic. Then any custom debugging patches
can use TWIST_FOR_SYZKALLER_TESTING.





> +       bool "Select all twist options suitable for syzkaller testing"
> +       select TWIST_DISABLE_KBD_K_SPEC_HANDLER
> +       help
> +        Say N unless you are building kernels for syzkaller's testing.
> +
>  config TWIST_DISABLE_KBD_K_SPEC_HANDLER
>         bool "Disable k_spec() function in drivers/tty/vt/keyboard.c"
>         help
> --
> 2.18.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-21 16:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 13:19 [PATCH v4 1/3] Add kernel config option for twisting kernel behavior Tetsuo Handa
2020-04-21 13:19 ` [PATCH v4 2/3] twist: Allow disabling k_spec() function in drivers/tty/vt/keyboard.c Tetsuo Handa
2020-04-21 13:19 ` [PATCH v4 3/3] twist: Add option for selecting twist options for syzkaller's testing Tetsuo Handa
2020-04-21 16:00   ` Dmitry Vyukov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).