1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# Fuchsia support
For information about checking out and building Fuchsia see [Get started with
Fuchsia](https://fuchsia.dev/fuchsia-src/get-started) and [Download the Fuchsia
source code](https://fuchsia.dev/fuchsia-src/get-started/get_fuchsia_source).
## Caveat
Please note that Fuchsia support is currently incomplete, and may break at any
time due to changes in Fuchsia and/or Syzkaller.
Some known issues include:
* System call definitions require manual updates.
* Crash parsing does not work reliably.
* Coverage feedback is not supported.
## Prerequisites
To run Syzkaller with a Fuchsia target, you will need a checkout of the Fuchsia
source repository.
The rest of this document will use the environment variable `SOURCEDIR` to
identify the path to your Fuchsia checkout (e.g. `/home/you/fuchsia`). The
commands below assume you have set `SOURCEDIR`, like so:
```bash
export SOURCEDIR=/home/you/fuchsia
```
## Quick and easy version
The shell script [setup.sh](setup.sh) automates the building and running
`syz-manager` steps described below. Give it a try, and see if it works for you.
For usage help, invoke it with no arguments.
## Building Fuchsia
To build Fuchsia for x64, run:
```bash
fx --dir "out/x64" set core.x64 \
--with-base "//bundles/tools" \
--with-base "//src/testing/fuzzing/syzkaller" \
--args=syzkaller_dir='"/full/path/to/syzkaller"' \
--variant=kasan
fx build
```
Alternatively, for arm64, run:
```bash
fx --dir "out/arm64" set core.arm64 \
--with-base "//bundles/tools" \
--with-base "//src/testing/fuzzing/syzkaller" \
--args=syzkaller_dir='"/full/path/to/syzkaller"' \
--variant=kasan
fx clean-build
```
## Building binaries for Fuchsia
To build all the binaries required for running Syzkaller in Fuchsia, run this
from inside your Syzkaller checkout (assuming you built Fuchsia for x64):
```bash
make TARGETOS=fuchsia TARGETARCH=amd64 SOURCEDIR=${SOURCEDIR}
```
## Running syz-manager
Running syz-manager requires you to have built Fuchsia previously, and added the
ssh keys to the fuchsia.zbi image:
The output of the Fuchsia build is a _product bundle_. Look up the image files needed
via `ffx product get-image-path`:
```bash
product_bundle_path="$(ffx config get product.path | tr -d '"')"
fxfs_path="$(ffx product get-image-path "$product_bundle_path" --slot a --image-type fxfs)"
zbi_path="$(ffx product get-image-path "$product_bundle_path" --slot a --image-type zbi)"
multiboot_path="$(ffx product get-image-path "$product_bundle_path" --slot a --image-type qemu-kernel)"
```
Make sure the ssh keys exist and are properly configured:
```bash
# Make sure there are ssh keys available
ffx config check-ssh-keys
auth_keys_path="$(ffx config get ssh.pub | tr -d '"')"
priv_key_path="$(ffx config get ssh.priv | tr -d '"')"
```
Add the authorized keys to the zbi.
```bash
fx host-tool zbi -o "${SOURCEDIR}/out/x64/fuchsia-ssh.zbi" \
"${zbi_path}" \
--entry "data/ssh/authorized_keys=${auth_keys_path}"
```
Note: This needs to be repeated after each `fx build`.
Create a `syz-manager` configuration file, using this as a starting point:
```json
{
"name": "fuchsia",
"target": "fuchsia/amd64",
"http": ":12345",
"workdir": "/workdir.fuchsia",
"kernel_obj": "/fuchsia/out/syz/kernel_x64-kasan/obj/zircon/kernel",
"syzkaller": "/syzkaller",
"image": "$fxfs_path",
"sshkey": "$priv_key_path",
"reproduce": false,
"cover": false,
"procs": 8,
"type": "qemu",
"vm": {
"count": 10,
"cpu": 4,
"mem": 2048,
"kernel": "${multiboot_path}",
"initrd": " ${SOURCEDIR}/out/x64/fuchsia-ssh.zbi"
}
}
```
Run `syz-manager` with that config:
```bash
bin/syz-manager -config manager.cfg
```
Note: You may need to modify your `PATH` so that qemu can be found, e.g.
```bash
export `PATH="$SOURCEDIR/prebuilt/third_party/qemu/linux-x64/bin:$PATH"`
```
## Update syscall and FIDL definitions
Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you
need to modify the `.txt` file that contains it, make sure your new definition
matches the one in Zircon's
[syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen)
file. **If the syscall was used in `executor/common_fuchsia.h`, you need to
update the usages there as well.** FIDL definitions do not need manual updating
because they are extracted automatically when you run `make extract`, but they
require Fuchsia to be rebuilt for each architecture (see [Building
Fuchsia](#building-fuchsia) above).
Once you updated the syscall definitions, everything can be regenerated by
running (in your Syzkaller checkout):
```bash
make extract TARGETOS=fuchsia SOURCEDIR=${SOURCEDIR}
make generate
```
**Caveat:** This command does not currently work.
## How to generate syscall definitions from FIDL
TODO: This section is out of date.
Syscall descriptions for FIDL are automatically generated as part of `make
extract` as described above.
However, if you wish to manually generate syscall descriptions for a given
`.fidl` file, do the following.
FIDL files should first be compiled into FIDL intermediate representation (JSON)
files using `fidlc`:
```bash
${SOURCEDIR}/out/x64/host_x64/fidlc --json /tmp/io.json --files ${SOURCEDIR}/zircon/system/fidl/fuchsia-io/io.fidl
```
Then run the FIDL compiler backend `fidlgen` with the syzkaller generator, which
compiles a FIDL IR file into a syscall description file:
```bash
${SOURCEDIR}/out/x64/host_x64/fidlgen -generators syzkaller -json /tmp/io.json -output-base fidl_io -include-base fidl_io
```
## Running syz-ci locally
To run `syz-ci` locally for Fuchsia, you need:
- bootstrapped Fuchsia checkout (in `/bootstrap/fuchsia` dir in the example below)
- bootstrap `syz-ci` binary (in the current dir, build with `make ci`)
- `syz-ci` config similar to the one below (in `ci.cfg` file in the current dir)
```json
{
"name": "testci",
"http": ":50000",
"manager_port_start": 50001,
"syzkaller_repo": "https://github.com/google/syzkaller.git",
"managers": [
{
"name": "fuchsia",
"repo": "https://fuchsia.googlesource.com",
"manager_config": {
"target": "fuchsia/amd64",
"type": "qemu",
"cover": false,
"procs": 8,
"vm": {
"count": 4,
"cpu": 4,
"mem": 1024
}
}
}
]
}
```
Run `syz-ci` as:
```bash
SOURCEDIR=/bootstrap/fuchsia ./syz-ci -config ci.cfg
```
## Troubleshooting
While running the `make extract` step, it's possible that the FIDL definitions
are not up to date. It could happen that they have been removed or renamed.
If this is the case, you would see an error mentioning that the fidl.json file
could not be found:
```bash
go generate ./sys/fuchsia
cannot find /path-to-fuchsia/out/x64/fidling/gen/zircon/public/fidl/zircon-ethernet/zircon-ethernet.fidl.json
exit status 1
```
You can search for the string in [the Fuchsia code search
interface](https://cs.opensource.google/fuchsia/fuchsia/+/main:) or in [the
Gerrit code-review tool](https://fuchsia-review.googlesource.com/) to see what
happened to it. If the FIDL interface was renamed or removed, you should update
`sys/fuchsia/fidlgen/main.go` to reflect this change, and remove the stale
autogenerated files.
|