Skip to content

Commit 817922d

Browse files
committed
syz-agent: add binary
Add server for running agentic workflows as part of syzbot.
1 parent 1c2019c commit 817922d

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

syz-agent/agent.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2025 syzkaller project authors. All rights reserved.
2+
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3+
4+
package main
5+
6+
import (
7+
"context"
8+
"encoding/json"
9+
"flag"
10+
"sync"
11+
12+
"github.com/google/syzkaller/dashboard/dashapi"
13+
"github.com/google/syzkaller/pkg/config"
14+
"github.com/google/syzkaller/pkg/log"
15+
"github.com/google/syzkaller/pkg/mgrconfig"
16+
"github.com/google/syzkaller/pkg/osutil"
17+
"github.com/google/syzkaller/pkg/tool"
18+
"github.com/google/syzkaller/pkg/updater"
19+
)
20+
21+
var (
22+
flagConfig = flag.String("config", "", "config file")
23+
flagExitOnUpgrade = flag.Bool("exit-on-upgrade", false,
24+
"exit after a syz-ci upgrade is applied; otherwise syz-ci restarts")
25+
)
26+
27+
type Config struct {
28+
DashboardAddr string `json:"dashboard_addr"`
29+
DashboardClient string `json:"dashboard_client"` // Namespace-specific.
30+
DashboardKey string `json:"dashboard_key"`
31+
SyzkallerRepo string `json:"syzkaller_repo"`
32+
SyzkallerBranch string `json:"syzkaller_branch"`
33+
VMs []VMConfig `json:"vms"`
34+
}
35+
36+
type VMConfig struct {
37+
// Same meaning as in the manager config.
38+
Target string `json:"target"`
39+
Image string `json:"image,omitempty"`
40+
KernelConfig string `json:"kernel_config"`
41+
Type string `json:"type"`
42+
VM json.RawMessage `json:"vm"`
43+
}
44+
45+
func main() {
46+
defer tool.Init()()
47+
log.SetName("syz-agent")
48+
49+
cfg := &Config{
50+
SyzkallerRepo: "https://github.com/google/syzkaller.git",
51+
SyzkallerBranch: "master",
52+
}
53+
if err := config.LoadFile(*flagConfig, cfg); err != nil {
54+
log.Fatalf("failed to load config: %v", err)
55+
}
56+
57+
dash, err := dashapi.New(cfg.DashboardClient, cfg.DashboardAddr, cfg.DashboardKey)
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
62+
updateTargets := make(map[updater.Target]bool)
63+
for _, vm := range cfg.VMs {
64+
os, vmarch, arch, _, _, err := mgrconfig.SplitTarget(vm.Target)
65+
if err != nil {
66+
log.Fatal(err)
67+
}
68+
updateTargets[updater.Target{
69+
OS: os,
70+
VMArch: vmarch,
71+
Arch: arch,
72+
}] = true
73+
}
74+
buildSem := osutil.NewSemaphore(1)
75+
updater, err := updater.New(&updater.Config{
76+
ExitOnUpdate: *flagExitOnUpgrade,
77+
BuildSem: buildSem,
78+
SyzkallerRepo: cfg.SyzkallerRepo,
79+
SyzkallerBranch: cfg.SyzkallerBranch,
80+
Targets: updateTargets,
81+
})
82+
if err != nil {
83+
log.Fatal(err)
84+
}
85+
86+
updatePending := make(chan struct{})
87+
shutdownPending := make(chan struct{})
88+
osutil.HandleInterrupts(shutdownPending)
89+
updater.UpdateOnStart(true, updatePending, shutdownPending)
90+
91+
ctx, stop := context.WithCancel(context.Background())
92+
var wg sync.WaitGroup
93+
wg.Add(1)
94+
go func() {
95+
defer wg.Done()
96+
loop(ctx, dash, cfg.VMs)
97+
}()
98+
99+
select {
100+
case <-shutdownPending:
101+
case <-updatePending:
102+
}
103+
stop()
104+
wg.Wait()
105+
106+
select {
107+
case <-shutdownPending:
108+
default:
109+
updater.UpdateAndRestart()
110+
}
111+
}

syz-agent/loop.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 syzkaller project authors. All rights reserved.
2+
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3+
4+
package main
5+
6+
import (
7+
"context"
8+
9+
"github.com/google/syzkaller/dashboard/dashapi"
10+
)
11+
12+
func loop(ctx context.Context, dash *dashapi.Dashboard, vms []VMConfig) {
13+
}

0 commit comments

Comments
 (0)