-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ AI patch generation #6433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
✨ AI patch generation #6433
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9747570
pkg/osutil: add DiskUsage function
dvyukov 315e011
pkg/aflow: add package for agentic workflows
dvyukov e2dc3f8
pkg/aflow/tool/codesearcher: add package
dvyukov 1cee580
tools/clang/codesearch: add README.md
dvyukov 802dd95
pkg/aflow/action/crash: add crash repro tool
dvyukov d62e46c
pkg/aflow/action/kernel: add checkout action
dvyukov bed3713
pkg/aflow/action/kernel: add build action
dvyukov cabaa5c
pkg/aflow/flow/assessment: add KCSAN bug assessment workflow
dvyukov 879acd3
pkg/aflow/flow/patching: add bug fix patching workflow
dvyukov 216c857
pkg/aflow/flow: add package
dvyukov 23a4bf6
tools/syz-aflow: add command line tool for agentic workflows
dvyukov 000975d
syz-agent: add agentic server
dvyukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright 2025 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 aflow | ||
|
|
||
| type Action interface { | ||
| verify(*verifyContext) | ||
| execute(*Context) error | ||
| } | ||
|
|
||
| type Pipeline struct { | ||
| // These actions are invoked sequentially, | ||
| // but dataflow across actions is specified by their use | ||
| // of variables in args/instructions/prompts. | ||
| Actions []Action | ||
| } | ||
|
|
||
| func NewPipeline(actions ...Action) *Pipeline { | ||
| return &Pipeline{ | ||
| Actions: actions, | ||
| } | ||
| } | ||
|
|
||
| func (p *Pipeline) execute(ctx *Context) error { | ||
| for _, sub := range p.Actions { | ||
| if err := sub.execute(ctx); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (p *Pipeline) verify(ctx *verifyContext) { | ||
| for _, a := range p.Actions { | ||
| a.verify(ctx) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright 2025 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" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/google/syzkaller/pkg/aflow" | ||
| "github.com/google/syzkaller/pkg/build" | ||
| "github.com/google/syzkaller/pkg/hash" | ||
| "github.com/google/syzkaller/pkg/instance" | ||
| "github.com/google/syzkaller/pkg/mgrconfig" | ||
| "github.com/google/syzkaller/pkg/osutil" | ||
| "github.com/google/syzkaller/sys/targets" | ||
| ) | ||
|
|
||
| // Reproduce action tries to reproduce a crash with the given reproducer, | ||
| // and outputs the resulting crash report. | ||
| // If the reproducer does not trigger a crash, action fails. | ||
| var Reproduce = aflow.NewFuncAction("crash-reproducer", reproduce) | ||
|
|
||
| type reproduceArgs struct { | ||
| Syzkaller string | ||
| Image string | ||
| Type string | ||
| VM json.RawMessage | ||
| ReproOpts string | ||
| ReproSyz string | ||
| ReproC string | ||
| SyzkallerCommit string | ||
| KernelSrc string | ||
| KernelObj string | ||
| KernelCommit string | ||
| KernelConfig string | ||
| } | ||
|
|
||
| type reproduceResult struct { | ||
| CrashReport string | ||
| } | ||
|
|
||
| func reproduce(ctx *aflow.Context, args reproduceArgs) (reproduceResult, error) { | ||
| if args.Type != "qemu" { | ||
| // Since we use injected kernel boot, and don't build full disk image. | ||
| return reproduceResult{}, errors.New("only qemu VM type is supported") | ||
| } | ||
| imageData, err := os.ReadFile(args.Image) | ||
| if err != nil { | ||
| return reproduceResult{}, err | ||
| } | ||
| desc := fmt.Sprintf("kernel commit %v, kernel config hash %v, image hash %v,"+ | ||
| " vm %v, vm config hash %v, C repro hash %v", | ||
| args.KernelCommit, hash.String(args.KernelConfig), hash.String(imageData), | ||
| args.Type, hash.String(args.VM), hash.String(args.ReproC)) | ||
| dir, err := ctx.Cache("repro", desc, func(dir string) error { | ||
| var vmConfig map[string]any | ||
| if err := json.Unmarshal(args.VM, &vmConfig); err != nil { | ||
| return fmt.Errorf("failed to parse VM config: %w", err) | ||
| } | ||
| vmConfig["kernel"] = filepath.Join(args.KernelObj, filepath.FromSlash(build.LinuxKernelImage(targets.AMD64))) | ||
| vmCfg, err := json.Marshal(vmConfig) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to serialize VM config: %w", err) | ||
| } | ||
| cfg := mgrconfig.DefaultValues() | ||
| cfg.RawTarget = "linux/amd64" | ||
| cfg.Workdir = filepath.Join(dir, "workdir") | ||
| cfg.Syzkaller = args.Syzkaller | ||
| cfg.KernelObj = args.KernelObj | ||
| cfg.KernelSrc = args.KernelSrc | ||
| cfg.Image = args.Image | ||
| cfg.Type = args.Type | ||
| cfg.VM = vmCfg | ||
| if err := mgrconfig.SetTargets(cfg); err != nil { | ||
| return err | ||
| } | ||
| if err := mgrconfig.Complete(cfg); err != nil { | ||
| return err | ||
| } | ||
| env, err := instance.NewEnv(cfg, nil, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| results, err := env.Test(1, nil, nil, []byte(args.ReproC)) | ||
dvyukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return err | ||
| } | ||
| os.RemoveAll(cfg.Workdir) | ||
| if results[0].Error == nil { | ||
| results[0].Error = errors.New("reproducer did not crash") | ||
| } | ||
| file, data := "", []byte(nil) | ||
| var crashErr *instance.CrashError | ||
| if errors.As(results[0].Error, &crashErr) { | ||
| file, data = "report", crashErr.Report.Report | ||
| } else { | ||
| file, data = "error", []byte(results[0].Error.Error()) | ||
| } | ||
| return osutil.WriteFile(filepath.Join(dir, file), data) | ||
| }) | ||
| if err != nil { | ||
| return reproduceResult{}, err | ||
| } | ||
| if data, err := os.ReadFile(filepath.Join(dir, "error")); err == nil { | ||
| return reproduceResult{}, errors.New(string(data)) | ||
| } | ||
| data, err := os.ReadFile(filepath.Join(dir, "report")) | ||
| return reproduceResult{ | ||
| CrashReport: string(data), | ||
| }, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright 2025 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 kernel | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/fs" | ||
| "os" | ||
| "path" | ||
| "path/filepath" | ||
| "runtime" | ||
| "time" | ||
|
|
||
| "github.com/google/syzkaller/pkg/aflow" | ||
| "github.com/google/syzkaller/pkg/build" | ||
| "github.com/google/syzkaller/pkg/hash" | ||
| "github.com/google/syzkaller/pkg/osutil" | ||
| "github.com/google/syzkaller/sys/targets" | ||
| ) | ||
|
|
||
| // Build action builds the Linux kernel from the given sources, | ||
| // outputs directory with build artifacts. | ||
| var Build = aflow.NewFuncAction("kernel-builder", buildKernel) | ||
|
|
||
| type buildArgs struct { | ||
| KernelSrc string | ||
| KernelCommit string | ||
| KernelConfig string | ||
| } | ||
|
|
||
| type buildResult struct { | ||
| KernelObj string // Directory with build artifacts. | ||
| } | ||
|
|
||
| func buildKernel(ctx *aflow.Context, args buildArgs) (buildResult, error) { | ||
| desc := fmt.Sprintf("kernel commit %v, kernel config hash %v", | ||
| args.KernelCommit, hash.String(args.KernelConfig)) | ||
| dir, err := ctx.Cache("build", desc, func(dir string) error { | ||
| if err := osutil.WriteFile(filepath.Join(dir, ".config"), []byte(args.KernelConfig)); err != nil { | ||
| return err | ||
| } | ||
| target := targets.List[targets.Linux][targets.AMD64] | ||
| image := filepath.FromSlash(build.LinuxKernelImage(targets.AMD64)) | ||
| makeArgs := build.LinuxMakeArgs(target, targets.DefaultLLVMCompiler, targets.DefaultLLVMLinker, | ||
| "ccache", dir, runtime.NumCPU()) | ||
| makeArgs = append(makeArgs, path.Base(image), "compile_commands.json") | ||
| if _, err := osutil.RunCmd(time.Hour, args.KernelSrc, "make", makeArgs...); err != nil { | ||
| return err | ||
| } | ||
| // Remove main intermediate build files, we don't need them anymore | ||
| // and they take lots of space. Keep generated source files. | ||
| keepExt := map[string]bool{"h": true, "c": true, "s": true, "S": true} | ||
| keepFiles := map[string]bool{image: true} | ||
| return filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil || d.IsDir() || keepFiles[path] || keepExt[filepath.Ext(d.Name())] { | ||
| return err | ||
| } | ||
| return os.Remove(path) | ||
| }) | ||
| }) | ||
| return buildResult{KernelObj: dir}, err | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.