From 9a3002038e891237ff5b561f756a0ff6e32d1d2f Mon Sep 17 00:00:00 2001 From: Ethan Graham Date: Mon, 15 Sep 2025 12:56:38 +0000 Subject: pkg/kfuzztest: add pkg/kfuzztest Add a new package, pkg/kfuzztest, that implements dynamic discovery of KFuzzTest targets by parsing a vmlinux kernel binary. Signed-off-by: Ethan Graham --- pkg/kfuzztest/testdata/2/desc.txt | 15 +++++++++++++++ pkg/kfuzztest/testdata/2/prog.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pkg/kfuzztest/testdata/2/desc.txt create mode 100644 pkg/kfuzztest/testdata/2/prog.c (limited to 'pkg/kfuzztest/testdata/2') diff --git a/pkg/kfuzztest/testdata/2/desc.txt b/pkg/kfuzztest/testdata/2/desc.txt new file mode 100644 index 000000000..2705252dd --- /dev/null +++ b/pkg/kfuzztest/testdata/2/desc.txt @@ -0,0 +1,15 @@ +# This description was automatically generated with tools/kfuzztest-gen +bar { + a int32 + b int32 +} + +foo { + b ptr[in, bar] + str ptr[in, string] + data ptr[in, array[int8]] + datalen len[data, int64] + numbers ptr[in, array[int64]] +} + +syz_kfuzztest_run$some_target(name ptr[in, string["some_target"]], data ptr[in, foo], len bytesize[data]) (kfuzz_test) diff --git a/pkg/kfuzztest/testdata/2/prog.c b/pkg/kfuzztest/testdata/2/prog.c new file mode 100644 index 000000000..908ccd271 --- /dev/null +++ b/pkg/kfuzztest/testdata/2/prog.c @@ -0,0 +1,39 @@ +// 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. +#include "../common.h" + +#include + +struct bar { + int a; + int b; +}; + +struct foo { + struct bar* b; + const char* str; + const char* data; + size_t datalen; + uint64_t* numbers; +}; + +DEFINE_FUZZ_TARGET(some_target, struct foo); +/* Expect foo.bar != NULL. */ +DEFINE_CONSTRAINT(foo, bar, NULL, NULL, EXPECT_NE); +/* Expect foo.str != NULL. */ +DEFINE_CONSTRAINT(foo, str, NULL, NULL, EXPECT_NE); +/* Annotate foo.str as a string. */ +DEFINE_ANNOTATION(foo, str, , ATTRIBUTE_STRING); +/* Expect foo.data != NULL. */ +DEFINE_CONSTRAINT(foo, data, NULL, NULL, EXPECT_NE); +/* Annotate foo.data as an array. */ +DEFINE_ANNOTATION(foo, data, , ATTRIBUTE_ARRAY); +/* Annotate foo.datalen == len(foo.data). */ +DEFINE_ANNOTATION(foo, datalen, data, ATTRIBUTE_LEN); +/* Annotate foo.numbers as an array. */ +DEFINE_ANNOTATION(foo, numbers, , ATTRIBUTE_ARRAY); + +/* Define a main function, otherwise the compiler complains. */ +int main(void) +{ +} -- cgit mrf-deployment