Skip to content

Commit f2a9727

Browse files
dBranskymatankalina
authored andcommitted
syz-verifier, executor, pkg/flatrpc, pkg/rpcserver: introduce new syz-verifier and remove legacy rpcserver and executor
Remove the old verifier implementation, including the legacy rpcserver, executor, monitor, stats, and related utilities, in preparation for the new architecture. Introduce the initial prototype of the redesigned syz-verifier that uses the new rpcserver and fuzzer, along with the foundational comparison logic and a stable mismatch-detection mechanism that avoids memory comparison to reduce false positives. Part of the fix for issue google#5976.
1 parent cee4cb1 commit f2a9727

21 files changed

+1237
-1745
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ Jeongjun Park
143143
Nikita Zhandarovich
144144
Jiacheng Xu
145145
Kuzey Arda Bulut
146+
Daniel Bransky

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ kfuzztest:
226226
endif
227227

228228
verifier: descriptions
229-
# TODO: switch syz-verifier to use syz-executor.
230-
# GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-verifier github.com/google/syzkaller/syz-verifier
229+
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-verifier github.com/google/syzkaller/syz-verifier
231230

232231
# `extract` extracts const files from various kernel sources, and may only
233232
# re-generate parts of files.

executor/common.h

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ typedef signed int ssize_t;
5050
#if SYZ_EXECUTOR && !GOOS_linux
5151
#if !GOOS_windows
5252
#include <unistd.h>
53+
#include <sys/types.h>
54+
#include <sys/stat.h>
55+
#include <fcntl.h> /* Definition of AT_* constants */
56+
#include <sys/stat.h>
5357
#endif
5458
NORETURN void doexit(int status)
5559
{
60+
debug("doexit: pid:%d is exiting with status %d\n", getpid(), status);
5661
_exit(status); // prevent linter warning: doexit()
5762
for (;;) {
5863
}
@@ -656,11 +661,19 @@ static void loop(void)
656661
#if SYZ_EXECUTOR
657662
close(kOutPipeFd);
658663
#endif
664+
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == -1) {
665+
perror("ptrace TRACEME");
666+
_exit(1);
667+
}
668+
debug("worker is tracable pid %d\n", getpid());
659669
execute_one();
660670
#if !SYZ_EXECUTOR && SYZ_HAVE_CLOSE_FDS && !SYZ_THREADED
661671
// Executor's execute_one has already called close_fds.
662672
close_fds();
663673
#endif
674+
debug("worker is exiting stopping pid %d\n", getpid());
675+
raise(SIGSTOP);
676+
debug("worker is exiting pid %d\n", getpid());
664677
doexit(0);
665678
}
666679
debug("spawned worker pid %d\n", pid);
@@ -680,11 +693,53 @@ static void loop(void)
680693
#if SYZ_EXECUTOR
681694
uint64 last_executed = start;
682695
uint32 executed_calls = output_data->completed.load(std::memory_order_relaxed);
696+
int times_stopped = 0;
683697
#endif
684698
for (;;) {
685699
sleep_ms(10);
686-
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
687-
break;
700+
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid){
701+
if(WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP) {
702+
times_stopped++;
703+
// Child process has stopped after execution, calculate its memory hash
704+
if (times_stopped == 1)
705+
debug("child pid %d stopped after snap shot, calculating memory hash\n", pid);
706+
if (times_stopped == 2)
707+
debug("child pid %d stopped after program, calculating memory hash\n", pid);
708+
if (times_stopped > 2) {
709+
debug("child pid %d stopped more than twice, ERROR!!!\n", pid);
710+
}
711+
712+
// Remember time before memory hash calculation to adjust timeout
713+
uint64 hash_start_time = current_time_ms();
714+
uint32 child_memory_hash = calculate_child_memory_hash(pid);
715+
uint64 hash_end_time = current_time_ms();
716+
uint64 hash_duration = hash_end_time - hash_start_time;
717+
718+
if (times_stopped == 1)
719+
debug("child memory hash calculation completed,snapshot hash=0x%x (took %llums)\n", child_memory_hash, hash_duration);
720+
else
721+
debug("child memory hash calculation completed, hash=0x%x (took %llums)\n", child_memory_hash, hash_duration);
722+
723+
// Store the hash in output data for later use in finish_output
724+
if (output_data) {
725+
output_data->memory_hash = child_memory_hash;
726+
}
727+
728+
// Continue the child process after calculating memory hash
729+
if (ptrace(PTRACE_CONT, pid, NULL, NULL) == -1) {
730+
debug("ptrace CONT failed for pid %d: %s\n", pid, strerror(errno));
731+
} else {
732+
debug("child pid %d resumed after memory hash calculation\n", pid);
733+
// Update last_executed time to prevent timeout during memory hash calculation
734+
last_executed = current_time_ms();
735+
// Extend the program start time to account for memory hash calculation time
736+
// This prevents the program timeout from triggering due to hash calculation delay
737+
start += hash_duration;
738+
}
739+
}
740+
else
741+
break;
742+
}
688743
#if SYZ_EXECUTOR
689744
// Even though the test process executes exit at the end
690745
// and execution time of each syscall is bounded by syscall_timeout_ms (~50ms),

0 commit comments

Comments
 (0)