From d3747c722655480e783b482c959331238997733f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 25 Oct 2020 12:12:10 +0100 Subject: pkg/csource: setup sysctl's in C reproducers Sysctl's are not captured as part of reproducers. This can result in failure to reproduce a bug on developer machine. Include sysctl setup as part of C reproducers. --- executor/common.h | 3 +++ executor/common_linux.h | 40 ++++++++++++++++++++++++++++++++++++++++ executor/executor.cc | 3 +-- executor/executor_bsd.h | 2 +- executor/executor_linux.h | 40 +--------------------------------------- 5 files changed, 46 insertions(+), 42 deletions(-) (limited to 'executor') diff --git a/executor/common.h b/executor/common.h index e054cf434..0a943a88f 100644 --- a/executor/common.h +++ b/executor/common.h @@ -740,6 +740,9 @@ int main(void) /*{{{MMAP_DATA}}}*/ #endif +#if SYZ_SYSCTL + setup_sysctl(); +#endif #if SYZ_BINFMT_MISC setup_binfmt_misc(); #endif diff --git a/executor/common_linux.h b/executor/common_linux.h index 1d372af7f..11ce0a6e9 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -4578,6 +4578,46 @@ static void setup_usb() } #endif +#if SYZ_EXECUTOR || SYZ_SYSCTL +static void setup_sysctl() +{ + static struct { + const char* name; + const char* data; + } files[] = { + // nmi_check_duration() prints "INFO: NMI handler took too long" on slow debug kernels. + // It happens a lot in qemu, and the messages are frequently corrupted + // (intermixed with other kernel output as they are printed from NMI) + // and are not matched against the suppression in pkg/report. + // This write prevents these messages from being printed. + {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, + // This is part of deterministic hang/stall detection. + // Don't change this without considering workqueue.watchdog_thresh, + // CONFIG_RCU_CPU_STALL_TIMEOUT and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT. + {"/proc/sys/kernel/watchdog_thresh", "55"}, + {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, + // This gives more interesting coverage. + {"/proc/sys/net/core/bpf_jit_enable", "1"}, + // bpf_jit_kallsyms and disabling bpf_jit_harden are required + // for unwinding through bpf functions. + {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, + {"/proc/sys/net/core/bpf_jit_harden", "0"}, + // This is to provide more useful info in crash reports. + {"/proc/sys/kernel/kptr_restrict", "0"}, + {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, + // This is to restrict effects of recursive exponential mounts, for details see + // "mnt: Add a per mount namespace limit on the number of mounts" commit. + {"/proc/sys/fs/mount-max", "100"}, + // Dumping all tasks to console can take too long. + {"/proc/sys/vm/oom_dump_tasks", "0"}, + }; + for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { + if (!write_file(files[i].name, files[i].data)) + printf("write to %s failed: %s\n", files[i].name, strerror(errno)); + } +} +#endif + #if GOARCH_s390x #include // Ugly way to work around gcc's "error: function called through a non-compatible type". diff --git a/executor/executor.cc b/executor/executor.cc index e759a7083..b221c2070 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -1465,8 +1465,7 @@ void setup_features(char** enable, int n) // This does any one-time setup for the requested features on the machine. // Note: this can be called multiple times and must be idempotent. #if SYZ_HAVE_FEATURES - // Note: this is not executed in C reproducers. - setup_machine(); + setup_sysctl(); #endif for (int i = 0; i < n; i++) { bool found = false; diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h index ac062d5cc..65d9fd925 100644 --- a/executor/executor_bsd.h +++ b/executor/executor_bsd.h @@ -188,7 +188,7 @@ static feature_t features[] = { {"fault", setup_fault}, }; -static void setup_machine(void) +static void setup_sysctl(void) { } #endif diff --git a/executor/executor_linux.h b/executor/executor_linux.h index 48269fe83..8f0dc579a 100644 --- a/executor/executor_linux.h +++ b/executor/executor_linux.h @@ -246,43 +246,5 @@ static feature_t features[] = { {"binfmt_misc", setup_binfmt_misc}, {"kcsan", setup_kcsan}, {"usb", setup_usb}, + {"sysctl", setup_sysctl}, }; - -// Note: this is not executed in C reproducers. -static void setup_machine() -{ - static struct { - const char* name; - const char* data; - } files[] = { - // nmi_check_duration() prints "INFO: NMI handler took too long" on slow debug kernels. - // It happens a lot in qemu, and the messages are frequently corrupted - // (intermixed with other kernel output as they are printed from NMI) - // and are not matched against the suppression in pkg/report. - // This write prevents these messages from being printed. - {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, - // This is part of deterministic hang/stall detection. - // Don't change this without considering workqueue.watchdog_thresh, - // CONFIG_RCU_CPU_STALL_TIMEOUT and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT. - {"/proc/sys/kernel/watchdog_thresh", "55"}, - {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, - // This gives more interesting coverage. - {"/proc/sys/net/core/bpf_jit_enable", "1"}, - // bpf_jit_kallsyms and disabling bpf_jit_harden are required - // for unwinding through bpf functions. - {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, - {"/proc/sys/net/core/bpf_jit_harden", "0"}, - // This is to provide more useful info in crash reports. - {"/proc/sys/kernel/kptr_restrict", "0"}, - {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, - // This is to restrict effects of recursive exponential mounts, for details see - // "mnt: Add a per mount namespace limit on the number of mounts" commit. - {"/proc/sys/fs/mount-max", "100"}, - // Dumping all tasks to console can take too long. - {"/proc/sys/vm/oom_dump_tasks", "0"}, - }; - for (size_t i = 0; i < ARRAY_SIZE(files); i++) { - if (!write_file(files[i].name, files[i].data)) - printf("write to %s failed: %s\n", files[i].name, strerror(errno)); - } -} -- cgit mrf-deployment