From bebca8b73c0c4bc5151de9575a4a8a1ea609eb19 Mon Sep 17 00:00:00 2001 From: Space Meyer Date: Tue, 8 Nov 2022 18:03:50 +0000 Subject: syz-kconf: execute shell snippets in reverse loading order Background: - syz-kconf loads and overlays config fragments to form a final kernel config. Fragments are loaded top to bottom as defined in the includes section of main.yml or your downstream syz-kconf config. - A config fragment loaded later can override kconf options set by an earlier loaded fragment. However the override keyword can only be used if an earlier fragment really did set the same option. Otherweise an error is raised. - With this in mind it makes sense to load fragments from broadest scope to most specific e.g. base -> x86_64 -> chromeos, so that chromeos can override a setting usually enabled on x86_64 machines. The Problem: - Before this change shell snippets were executed in order they were loaded from the fragments. - This is unfortunate as the broad fragments like x86_64.yml expect to operate on an existing .config with their shell snippets. Meanwhile some downstream distros like icebreaker generate their config using such a shell snippet. - Hence ordering the fragments like base -> x86_64 -> icebreaker results in an error about the x86_64 not finding a .config without this change. Meanwhile ordering icebreaker -> base -> x86_64 works, but means the icebreaker fragment can't override x86_64 kconf options. The Solution: - This change resolves the problem outlined above by reversing the order shell snippets are executed. Now shell snippets will be executed starting with the most recently loaded fragment. This way the proposed fragment order base -> x86_64 -> icebreaker becomes viable. - Luckily the shell section isn't heavily used, so this change didn't result in meaningfull final config changes. --- dashboard/config/linux/android-5.15-base.config | 2 +- dashboard/config/linux/android-5.15.config | 2 +- dashboard/config/linux/main.yml | 21 +++++++++++---------- tools/syz-kconf/parser.go | 4 +++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/dashboard/config/linux/android-5.15-base.config b/dashboard/config/linux/android-5.15-base.config index 6d8aec5d7..3c98c43b9 100644 --- a/dashboard/config/linux/android-5.15-base.config +++ b/dashboard/config/linux/android-5.15-base.config @@ -474,7 +474,7 @@ CONFIG_LEGACY_VSYSCALL_EMULATE=y # CONFIG_LEGACY_VSYSCALL_XONLY is not set # CONFIG_LEGACY_VSYSCALL_NONE is not set CONFIG_CMDLINE_BOOL=y -CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off root=/dev/sda console=ttyS0 vsyscall=native numa=fake=2 kvm-intel.nested=1 spec_store_bypass_disable=prctl nopcid vivid.n_devs=16 vivid.multiplanar=1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 netrom.nr_ndevs=16 rose.rose_ndevs=16 smp.csd_lock_timeout=100000 watchdog_thresh=55 workqueue.watchdog_thresh=140 sysctl.net.core.netdev_unregister_timeout_secs=140 dummy_hcd.num=8 cgroup_disable=pressure cgroup.memory=nokmem" +CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off coredump_filter=0xffff root=/dev/sda console=ttyS0 vsyscall=native numa=fake=2 kvm-intel.nested=1 spec_store_bypass_disable=prctl nopcid vivid.n_devs=16 vivid.multiplanar=1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 netrom.nr_ndevs=16 rose.rose_ndevs=16 smp.csd_lock_timeout=100000 watchdog_thresh=55 workqueue.watchdog_thresh=140 sysctl.net.core.netdev_unregister_timeout_secs=140 dummy_hcd.num=8 cgroup_disable=pressure cgroup.memory=nokmem" # CONFIG_CMDLINE_OVERRIDE is not set CONFIG_MODIFY_LDT_SYSCALL=y CONFIG_HAVE_LIVEPATCH=y diff --git a/dashboard/config/linux/android-5.15.config b/dashboard/config/linux/android-5.15.config index 41bde7dd5..7bd322909 100644 --- a/dashboard/config/linux/android-5.15.config +++ b/dashboard/config/linux/android-5.15.config @@ -475,7 +475,7 @@ CONFIG_LEGACY_VSYSCALL_EMULATE=y # CONFIG_LEGACY_VSYSCALL_XONLY is not set # CONFIG_LEGACY_VSYSCALL_NONE is not set CONFIG_CMDLINE_BOOL=y -CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off root=/dev/sda console=ttyS0 vsyscall=native numa=fake=2 kvm-intel.nested=1 spec_store_bypass_disable=prctl nopcid vivid.n_devs=16 vivid.multiplanar=1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 netrom.nr_ndevs=16 rose.rose_ndevs=16 smp.csd_lock_timeout=100000 watchdog_thresh=55 workqueue.watchdog_thresh=140 sysctl.net.core.netdev_unregister_timeout_secs=140 dummy_hcd.num=8 cgroup_disable=pressure cgroup.memory=nokmem" +CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off coredump_filter=0xffff root=/dev/sda console=ttyS0 vsyscall=native numa=fake=2 kvm-intel.nested=1 spec_store_bypass_disable=prctl nopcid vivid.n_devs=16 vivid.multiplanar=1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 netrom.nr_ndevs=16 rose.rose_ndevs=16 smp.csd_lock_timeout=100000 watchdog_thresh=55 workqueue.watchdog_thresh=140 sysctl.net.core.netdev_unregister_timeout_secs=140 dummy_hcd.num=8 cgroup_disable=pressure cgroup.memory=nokmem" # CONFIG_CMDLINE_OVERRIDE is not set CONFIG_MODIFY_LDT_SYSCALL=y CONFIG_HAVE_LIVEPATCH=y diff --git a/dashboard/config/linux/main.yml b/dashboard/config/linux/main.yml index 04b5c010e..2e46c00a7 100644 --- a/dashboard/config/linux/main.yml +++ b/dashboard/config/linux/main.yml @@ -27,17 +27,9 @@ instances: - chromeos-5.10: [chromeos, chromeos-5.10, nodefconfig, x86_64, timeouts_native, onlyusb, kasan] - chromeos-5.15: [chromeos, chromeos-5.15, nodefconfig, x86_64, timeouts_native, onlyusb, kasan] -# These files are included from the bits/ dir. +# Note: fragments are included top to bottom from this list. When a config fragments overrides +# another, the override has to be loaded second. These files are included from the bits/ dir. includes: - - linux-upstream.yml: [upstream] - - linux-next.yml: [linux-next] - - stable-5.4.yml: [stable-5.4] - - android-5.4.yml: [android-5.4] - - android-5.10.yml: [android-5.10] - - android-5.15.yml: [android-5.15] - - chromeos-5.4.yml: [chromeos-5.4] - - chromeos-5.10.yml: [chromeos-5.10] - - chromeos-5.15.yml: [chromeos-5.15] - base.yml: [] - x86_64.yml: [x86_64] - arm64.yml: [arm64] @@ -72,8 +64,17 @@ includes: - kcsan.yml: [kcsan] - kmsan.yml: [kmsan] - kfence.yml: [kfence] + - linux-upstream.yml: [upstream] + - linux-next.yml: [linux-next] + - stable-5.4.yml: [stable-5.4] - android.yml: [android] - android-subsystems.yml: [android, -baseline] + - android-5.4.yml: [android-5.4] + - android-5.10.yml: [android-5.10] - android-5.10-late.yml: [android-5.10] + - android-5.15.yml: [android-5.15] - chromeos.yml: [chromeos] - chromeos-subsystems.yml: [chromeos, -baseline] + - chromeos-5.4.yml: [chromeos-5.4] + - chromeos-5.10.yml: [chromeos-5.10] + - chromeos-5.15.yml: [chromeos-5.15] diff --git a/tools/syz-kconf/parser.go b/tools/syz-kconf/parser.go index 00455c3e5..b2ac82e74 100644 --- a/tools/syz-kconf/parser.go +++ b/tools/syz-kconf/parser.go @@ -197,16 +197,18 @@ func mergeFile(inst *Instance, raw *rawFile, file string, errs *Errors) { } inst.Linker = raw.Linker } + prependShell := []Shell{} for _, node := range raw.Shell { cmd, _, constraints, err := parseNode(node) if err != nil { errs.push("%v:%v: %v", file, node.Line, err) } - inst.Shell = append(inst.Shell, Shell{ + prependShell = append(prependShell, Shell{ Cmd: cmd, Constraints: constraints, }) } + inst.Shell = append(prependShell, inst.Shell...) if raw.Verbatim != "" { inst.Verbatim = append(append(inst.Verbatim, strings.TrimSpace(raw.Verbatim)...), '\n') } -- cgit mrf-deployment