>> Hi Dmitry,
>>
>>> On 16. Oct 2018, at 11:36, Dmitry Vyukov <
dvy...@google.com> wrote:
>>>
>>> Hi Timo,
>>>
>>> Sorry for your experience. I think you were generally on the right
>>> track. FreeBSD support is not finished, and in particular we don't
>>> have testing so things fall apart.
>>> I've added some people who were involved in FreeBSD support to CC. As
>>> far as I understand syzkaller is working on FreeBSD somehow for some
>>> people, but I don't know if they have local patches, or use an old
>>> version, or something else:
>>>
https://twitter.com/ed_maste/status/1045409421973753858
>>>
>>> One quick thing you may try is to add:
>>> "cover": false
>>> to syz-manager config. This will disable (well, at least should,
>>> because it's also not tested for FreeBSD at the moment) everything
>>> related to coverage. If that works, at least we know that coverage is
>>> the only missing piece in the equation.
>>
>> It does not work out of the box with "cover":false. It seems syzkaller tries to use mmap for a quick test. This crashes, because the flag MAP_ANONYMOUS is used, which is not defined in the mmap description for freebsd (sys/freebsd/posix_mm.txt).
>
> Okay, so there are more breakages.
> I've pushed this change that fixes MAP_ANONYMOUS, and hopefully should
> prevent such cases in future:
>
https://github.com/google/syzkaller/commit/ecb386fe6f6849c451955e16556d04b388b1fde1
Great, that works.
>
>
>> If I add it and run
>>
>> make extract TARGETOS=freebsd SOURCEDIR=~/src/freebsd/
>> (~/src/freebsd/ contains the FreeBSD sources
>>
>> the flag is added as comment to posix_mm_amd64.const with the note: "is not set". I couldn't find the reason for that.
>
> That's because MAP_ANONYMOUS is defined in kernel headers under
> #ifndef _KERNEL and we define _KERNEL in sys/syz-extract/freebsd.go
OK, thats probably the reason.
>
>> For a test, I changed the flag MAP_ANONYMOUS in sys/targets/common.go to MAP_ANON. After that, fuzzing with "cover":false worked.
>>
>>>
>>> Do you mind to send a pull request with the docs update and missing
>>> include? That would be useful.
>>
>> I created a fork from main syzkaller repository, created a branch in that fork, and pushed my changes in small commits. However, I was not able to successfully run make presubmit. It failed with the following message.
>>
>> powerpc64le-linux-gnu-gcc -o ./bin/linux_ppc64le/syz-executor executor/executor.cc \
>> -pthread -Wall -Wframe-larger-than=8192 -Wparentheses -Werror -O2 -D__powerpc64__ -static \
>> -DGOOS_linux=1 -DGOARCH_ppc64le=1 -DGIT_REVISION=\"4b2418d456189b6c1182a452b89fbc66395bc01a\"
>> GOOS=linux GOARCH=amd64 go build "-ldflags=-s -w -X
github.com/google/syzkaller/sys.GitRevision=4b2418d456189b6c1182a452b89fbc66395bc01a" -o ./bin/syz-manager
github.com/google/syzkaller/syz-manager
>> ...
>> GOOS=openbsd GOARCH=amd64 go build "-ldflags=-s -w -X
github.com/google/syzkaller/sys.GitRevision=4b2418d456189b6c1182a452b89fbc66395bc01a" -o ./bin/syz-upgrade
github.com/google/syzkaller/tools/syz-upgrade
>> In file included from executor/executor.cc:137:0:
>> executor/common.h:19:10: fatal error: sys/endian.h: No such file or directory
>> #include <sys/endian.h> // for htobe*.
>> ^~~~~~~~~~~~~~
>> compilation terminated.
>> Makefile:108: recipe for target 'executor' failed
>
> This happens because we build freebsd version on linux too, to give it
> at least some testing. I understand that strictly saying, it does not
> have to work. But it worked to date and was useful for testing.
>
> Perhaps we can do:
>
> #if GOOS_freebsd && !__linux__
> #include <sys/endian.h> // for htobe*.
>
> This will exclude building freebsd version on linux.
I added !__linux__. Also, I had to change pkg/csource/csource_test.go in order to skip tests, when target is freebsd.
For my fix in executor/executor_bsd.h, I had to change the Makefile in order to skip build executor for freebsd. For both, I created a pull request (#777).
I made no process in debugging FreeBSD with kcov (when cover is set to true in syzkaller config). Still, the following lines is the last output I see before syz-manager restarts the VM. Looks like a FreeBSD kernel panic. Do you have any idea whether this is a bigger problem or not?
[10ms] exec opts: procid=0 threaded=1 collide=1 cover=0 comps=0 dedup=1 fault=0/0/0 prog=0
spawned worker pid 728
#0 [15ms] -> mmap(0x20000000, 0x1000, 0x3, 0x1012, 0xffffffffffffffff, 0x0)
SIGSEGV on 0xffffffffffffffff, exiting
panic: kcov_mmap_cleanup: Cleanup while running
cpuid = 0
time = 1540209971
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x47/frame 0xfffffe0000446480
vpanic() at vpanic+0x1ff/frame 0xfffffe00004464e0
panic() at panic+0x43/frame 0xfffffe0000446540
kcov_mmap_cleanup() at kcov_mmap_cleanup+0x68/frame 0xfffffe0000446560
devfs_destroy_cdevpriv() at devfs_destroy_cdevpriv+0xb5/frame 0xfffffe0000446590
devfs_close_f() at devfs_close_f+0x7b/frame 0xfffffe00004465c0
_fdrop() at _fdrop+0x3a/frame 0xfffffe00004465f0
closef() at closef+0x27d/frame 0xfffffe0000446680
fdescfree_fds() at fdescfree_fds+0xb6/frame 0xfffffe00004466d0
fdescfree() at fdescfree+0x59a/frame 0xfffffe0000446790
exit1() at exit1+0x781/frame 0xfffffe0000446800
sigexit() at sigexit+0xcdf/frame 0xfffffe0000446ae0
postsig() at postsig+0x413/frame 0xfffffe0000446bb0
ast() at ast+0x47d/frame 0xfffffe0000446bf0
doreti_ast() at doreti_ast+0x1f/frame 0x7fffffffec80
KDB: enter: panic
[ thread pid 727 tid 100083 ]
Stopped at kdb_enter+0x6b: movq $0,kdb_why
db>
2018/10/22 14:06:21 vm-0: crash: panic: kcov_mmap_cleanup: Cleanup while running