From: Ethan Graham Add a KFuzzTest fuzzer for the parse_xy() function, located in a new file under /drivers/auxdisplay/tests. To validate the correctness and effectiveness of this KFuzzTest target, a bug was injected into parse_xy() like so: drivers/auxdisplay/charlcd.c:179 - s = p; + s = p + 1; Although a simple off-by-one bug, it requires a specific input sequence in order to trigger it, thus demonstrating the power of pairing KFuzzTest with a coverage-guided fuzzer like syzkaller. Signed-off-by: Ethan Graham --- drivers/auxdisplay/charlcd.c | 8 ++++++++ drivers/auxdisplay/tests/charlcd_kfuzz.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 drivers/auxdisplay/tests/charlcd_kfuzz.c diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c index 09020bb8ad15..e079b5a9c93c 100644 --- a/drivers/auxdisplay/charlcd.c +++ b/drivers/auxdisplay/charlcd.c @@ -682,3 +682,11 @@ EXPORT_SYMBOL_GPL(charlcd_unregister); MODULE_DESCRIPTION("Character LCD core support"); MODULE_LICENSE("GPL"); + +/* + * When CONFIG_KFUZZTEST is enabled, we include this _kfuzz.c file to ensure + * that KFuzzTest targets are built. + */ +#ifdef CONFIG_KFUZZTEST +#include "tests/charlcd_kfuzz.c" +#endif /* CONFIG_KFUZZTEST */ diff --git a/drivers/auxdisplay/tests/charlcd_kfuzz.c b/drivers/auxdisplay/tests/charlcd_kfuzz.c new file mode 100644 index 000000000000..28ce7069c65c --- /dev/null +++ b/drivers/auxdisplay/tests/charlcd_kfuzz.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * charlcd KFuzzTest target + * + * Copyright 2025 Google LLC + */ +#include + +struct parse_xy_arg { + const char *s; +}; + +FUZZ_TEST(test_parse_xy, struct parse_xy_arg) +{ + unsigned long x, y; + + KFUZZTEST_EXPECT_NOT_NULL(parse_xy_arg, s); + KFUZZTEST_ANNOTATE_STRING(parse_xy_arg, s); + parse_xy(arg->s, &x, &y); +} -- 2.51.0.384.g4c02a37b29-goog