Commit d53a762
platform: posix: tear down IPC topology between fuzz testcases
Without an explicit teardown a fuzz testcase that successfully creates
components, buffers or pipelines leaves them registered in
global_ipc->comp_list. The next LLVMFuzzerTestOneInput() then sees a
non-empty topology it never asked for, which both hides bugs (crashes
that depend on freshly-empty state are missed) and fabricates them
(crashes that only occur because of carry-over from a previous case are
unreproducible when the artifact is replayed on its own).
Add a posix-only teardown helper, called from posix_fuzz_case_begin()
once at the start of every testcase before the input is staged. The
helper:
* Runs a pre-pass that forces every COMP_TYPE_COMPONENT to
COMP_STATE_READY and initialises any NULL bsource_list/bsink_list
pointers, because ipc_comp_free() returns -EINVAL (and silently
leaks the entry) for a component that is not READY or whose buffer
lists were never list_init()'d - the latter happens when a
component was registered but its init failed partway through. The
pre-pass also cancels any active pipeline pipe_task so
ipc_pipeline_free() does not stall waiting for it (up to 100 LL
periods on native_sim).
* Drains each type in batches: it snapshots up to POSIX_TEARDOWN_BATCH
ids, frees them with the typed helper, and repeats until no entry of
that type remains, so the number of objects a testcase creates is not
bounded by the snapshot size (walking and freeing comp_list in one
pass is unsafe because the SOF free helpers unlink each entry). A
batch that frees nothing ends the loop so it cannot spin forever.
* Frees in dependency order COMPONENT -> BUFFER -> PIPELINE so the
topology layer never dereferences an already-freed parent. The
BUFFER pass is compiled out for IPC4 because ipc4/helper.c never
stores COMP_TYPE_BUFFER and ipc_buffer_free() does not exist there.
* Ends with a force-drain pass that walks the whole residual list with
list_for_item_safe() and removes each entry with list_item_del() +
rfree(), so comp_list is guaranteed empty on return regardless of how
many objects remained or of any future COMP_TYPE_* the typed passes
do not cover.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent f5176b9 commit d53a762
1 file changed
Lines changed: 150 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
40 | 189 | | |
41 | 190 | | |
42 | 191 | | |
| |||
45 | 194 | | |
46 | 195 | | |
47 | 196 | | |
| 197 | + | |
48 | 198 | | |
49 | 199 | | |
50 | 200 | | |
| |||
0 commit comments