Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pkg/aflow/action/crash/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2026 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package crash

import (
"encoding/json"

"github.com/google/syzkaller/pkg/aflow"
)

// TestPatch action does an in-tree kernel build in KernelScratchSrc dir,
// and runs the reproducer on the newly built kernel.
// If there are build/boot/test errors, a detailed error message is returned in TestError.
// The action also collects diff of the local changes, returns it in PatchDiff,
// and resets source code state to HEAD (removes all local edits).
var TestPatch = aflow.NewFuncAction("test-patch", testPatch)

type testArgs struct {
Syzkaller string
Image string
Type string
VM json.RawMessage
ReproOpts string
ReproSyz string
ReproC string
SyzkallerCommit string
KernelScratchSrc string
KernelCommit string
KernelConfig string
}

type testResult struct {
PatchDiff string
TestError string
}

func testPatch(ctx *aflow.Context, args testArgs) (testResult, error) {
return testResult{}, nil
}
51 changes: 40 additions & 11 deletions pkg/aflow/action/kernel/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
// outputs the source directory with the checkout.
var Checkout = aflow.NewFuncAction("kernel-checkouter", checkout)

// Checkout action checks out the Linux kernel on the given commit
// in a private temp dir that lives only for the duration of the workflow.
// It's supposed to be used for code edits.
var CheckoutScratch = aflow.NewFuncAction("kernel-scratch-checkouter", checkoutScratch)

type checkoutArgs struct {
KernelRepo string
KernelCommit string
Expand All @@ -28,6 +33,15 @@ type checkoutResult struct {
KernelSrc string
}

type checkoutScratchArgs struct {
KernelSrc string
}

type checkoutScratchResult struct {
// Temp dir with the checked out sources.
KernelScratchSrc string
}

func checkout(ctx *aflow.Context, args checkoutArgs) (checkoutResult, error) {
var res checkoutResult
err := UseLinuxRepo(ctx, func(kernelRepoDir string, repo vcs.Repo) error {
Expand Down Expand Up @@ -58,24 +72,39 @@ func checkout(ctx *aflow.Context, args checkoutArgs) (checkoutResult, error) {
}
}
}
if _, err := osutil.RunCmd(time.Hour, dir, "git", "init"); err != nil {
return err
}
if _, err := osutil.RunCmd(time.Hour, dir, "git", "remote", "add", "origin", kernelRepoDir); err != nil {
return err
}
if _, err := osutil.RunCmd(time.Hour, dir, "git", "pull", "origin", "HEAD", "--depth=1",
"--allow-unrelated-histories"); err != nil {
return err
}
return nil
return shallowGitClone(dir, kernelRepoDir)
})
res.KernelSrc = dir
return err
})
return res, err
}

func checkoutScratch(ctx *aflow.Context, args checkoutScratchArgs) (checkoutScratchResult, error) {
dir, err := ctx.TempDir()
if err != nil {
return checkoutScratchResult{}, err
}
if err := shallowGitClone(dir, args.KernelSrc); err != nil {
return checkoutScratchResult{}, err
}
return checkoutScratchResult{dir}, nil
}

func shallowGitClone(dir, remoteDir string) error {
if _, err := osutil.RunCmd(time.Hour, dir, "git", "init"); err != nil {
return err
}
if _, err := osutil.RunCmd(time.Hour, dir, "git", "remote", "add", "origin", remoteDir); err != nil {
return err
}
if _, err := osutil.RunCmd(time.Hour, dir, "git", "pull", "origin", "HEAD", "--depth=1",
"--allow-unrelated-histories"); err != nil {
return err
}
return nil
}

var repoMu sync.Mutex

func UseLinuxRepo(ctx *aflow.Context, fn func(string, vcs.Repo) error) error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/aflow/flow/patching/patching.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Inputs struct {
type Outputs struct {
PatchDescription string
PatchDiff string
KernelScratchSrc string // it's unused for now, but should be used by codeeditor tool later
}

func init() {
Expand All @@ -61,6 +62,7 @@ func init() {
Prompt: debuggingPrompt,
Tools: tools,
},
kernel.CheckoutScratch,
&aflow.LLMAgent{
Name: "diff-generator",
Model: aflow.BestExpensiveModel,
Expand Down
Loading