|
| 1 | +// Copyright 2026 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 assessmenet |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/google/syzkaller/pkg/aflow" |
| 10 | + "github.com/google/syzkaller/pkg/aflow/action/kernel" |
| 11 | + "github.com/google/syzkaller/pkg/aflow/ai" |
| 12 | + "github.com/google/syzkaller/pkg/aflow/tool/codesearcher" |
| 13 | + "github.com/google/syzkaller/pkg/report/crash" |
| 14 | +) |
| 15 | + |
| 16 | +type moderationInputs struct { |
| 17 | + BugTitle string |
| 18 | + CrashReport string |
| 19 | + KernelRepo string |
| 20 | + KernelCommit string |
| 21 | + KernelConfig string |
| 22 | + CodesearchToolBin string |
| 23 | +} |
| 24 | + |
| 25 | +type moderationOutputs struct { |
| 26 | + Confident bool |
| 27 | + Actionable bool |
| 28 | + Explanation string |
| 29 | +} |
| 30 | + |
| 31 | +func init() { |
| 32 | + aflow.Register[moderationInputs, moderationOutputs]( |
| 33 | + ai.WorkflowModeration, |
| 34 | + "assess if a bug report is consistent and actionable or not", |
| 35 | + &aflow.Flow{ |
| 36 | + Root: &aflow.Pipeline{ |
| 37 | + Actions: []aflow.Action{ |
| 38 | + aflow.NewFuncAction("extract-crash-type", extractCrashType), |
| 39 | + kernel.Checkout, |
| 40 | + kernel.Build, |
| 41 | + codesearcher.PrepareIndex, |
| 42 | + &aflow.LLMAgent{ |
| 43 | + Name: "expert", |
| 44 | + Reply: "Explanation", |
| 45 | + Outputs: aflow.LLMOutputs[struct { |
| 46 | + Confident bool `jsonschema:"If you are confident in the verdict of the analysis or not."` |
| 47 | + Actionable bool `jsonschema:"If the report is actionable or not."` |
| 48 | + }](), |
| 49 | + Temperature: 1, |
| 50 | + Instruction: moderationInstruction, |
| 51 | + Prompt: moderationPrompt, |
| 52 | + Tools: codesearcher.Tools, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | +const moderationInstruction = ` |
| 61 | +You are an experienced Linux kernel developer tasked with determining if the given kernel bug |
| 62 | +report is actionable or not. Actionable means that it contains enough info to root cause |
| 63 | +the underlying bug, and that the report is self-consistent and makes sense, rather than |
| 64 | +e.g. a one-off nonsensical crash induced by a previous memory corruption. |
| 65 | +
|
| 66 | +{{if .IsUAF}} |
| 67 | +The bug report is about a use-after-free bug generated by KASAN tool. |
| 68 | +It should contain 3 stack traces: the bad memory access stack, the heap block allocation stack, |
| 69 | +and the heap block free stack. If the report does not contain 3 stacks, it's not actionable. |
| 70 | +
|
| 71 | +All 3 stack traces should be related to the same object type, |
| 72 | +and usually be in the same kernel subsystem (at least leaf stack frames). |
| 73 | +An example of an actionable and consistent report would be: first access stack relates |
| 74 | +to an access to a field of struct Foo, allocation/free stacks relate to allocation/free |
| 75 | +of the struct Foo. |
| 76 | +In inconsistent/nonsensical reports an access may be to a struct Foo, but allocation |
| 77 | +stack allocates a different structure in a different subsystem. |
| 78 | +Look for other suspicious signals/inconsistencies that can make this report hard to |
| 79 | +debug/understand. |
| 80 | +{{end}} |
| 81 | +
|
| 82 | +In the final reply explain why you think the report is self-consistent and actionable, |
| 83 | +or why it's inconsistent and/or not actionable. |
| 84 | +
|
| 85 | +Use the provided tools to confirm any assumptions, variables/fields being accessed, etc. |
| 86 | +In particular, don't make assumptions about the kernel source code, |
| 87 | +use codesearch tools to read the actual source code. |
| 88 | +` |
| 89 | + |
| 90 | +const moderationPrompt = ` |
| 91 | +The bug report is: |
| 92 | +
|
| 93 | +{{.CrashReport}} |
| 94 | +` |
| 95 | + |
| 96 | +type extractArgs struct { |
| 97 | + BugTitle string |
| 98 | +} |
| 99 | + |
| 100 | +type extractResult struct { |
| 101 | + IsUAF bool |
| 102 | +} |
| 103 | + |
| 104 | +func extractCrashType(ctx *aflow.Context, args extractArgs) (extractResult, error) { |
| 105 | + var res extractResult |
| 106 | + typ := crash.TitleToType(args.BugTitle) |
| 107 | + switch { |
| 108 | + case typ.IsUAF(): |
| 109 | + res.IsUAF = true |
| 110 | + default: |
| 111 | + return res, fmt.Errorf("unsupported bug type") |
| 112 | + } |
| 113 | + return res, nil |
| 114 | +} |
0 commit comments