[Git][NTPsec/ntpsec][master] OSS-Fuzz: move the fuzz harnesses upstream
Matt Selsky (@selsky)
gitlab at mg.gitlab.com
Mon Nov 9 19:46:38 UTC 2026
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
b7839100 by arthurscchan at 2026-11-09T19:43:53+00:00
OSS-Fuzz: move the fuzz harnesses upstream
Move the four OSS-Fuzz harnesses (FuzzClient, FuzzExtens,
FuzzExtensClient, FuzzServer) into fuzz/, with fuzz/Makefile for the
OSS-Fuzz build and a setup.c of shared stubs.
Add --enable-fuzz-harnesses, which compiles the harnesses without
linking them (OSS-Fuzz links them against its fuzzing engine), and add
it to the feature CI matrix so the harnesses keep building.
Signed-off-by: Arthur Chan <arthur.chan at adalogics.com>
- - - - -
10 changed files:
- .gitlab-ci.yml
- + fuzz/FuzzClient.c
- + fuzz/FuzzExtens.c
- + fuzz/FuzzExtensClient.c
- + fuzz/FuzzServer.c
- + fuzz/Makefile
- + fuzz/setup.c
- + fuzz/wscript
- wafhelpers/options.py
- wscript
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -402,6 +402,7 @@ feature:
--enable-debug-timing,
--disable-droproot,
--enable-early-droproot,
+ --enable-fuzz-harnesses,
--enable-leap-smear,
--enable-mssntp,
]
=====================================
fuzz/FuzzClient.c
=====================================
@@ -0,0 +1,52 @@
+/*
+ * FuzzClient.c - OSS-Fuzz harness for NTS-KE client response processing
+ * Copyright the NTPsec project contributors
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Section references are to https://tools.ietf.org/html/rfc8915
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ntpd.h"
+
+#define kMinInputLength 20
+#define kMaxInputLength 1024
+
+bool nts_client_process_response_core(uint8_t *buff, int transferred, struct peer* peer);
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < kMinInputLength || Size > kMaxInputLength) {
+ return 0;
+ }
+
+ /* The parser may write into the buffer, so give it a writable copy
+ * instead of libFuzzer's read-only Data. */
+ uint8_t *buff = malloc(Size);
+ if (NULL == buff) {
+ return 0;
+ }
+ memcpy(buff, Data, Size);
+
+ struct peer peer;
+
+ ZERO(peer); /* Don't feed uninitialized memory to the parser */
+
+ peer.nts_state.aead = 42; /* Dummy init values */
+ peer.nts_state.cookielen = 0;
+ peer.nts_state.writeIdx = 0;
+ peer.nts_state.count = 0;
+
+ peer.srcadr.sa4.sin_family = AF_INET;
+ peer.srcadr.sa4.sin_port = htons(9999);
+ peer.srcadr.sa4.sin_addr.s_addr = htonl(0x04030201);
+
+ (void)nts_client_process_response_core(buff, Size, &peer);
+
+ free(buff);
+
+ return 0;
+}
=====================================
fuzz/FuzzExtens.c
=====================================
@@ -0,0 +1,39 @@
+/*
+ * FuzzExtens.c - OSS-Fuzz harness for NTS server extension-field parsing
+ * Copyright the NTPsec project contributors
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ntpd.h"
+#include "nts.h"
+
+#define kMinInputLength 20
+#define kMaxInputLength 1024
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < kMinInputLength || Size > kMaxInputLength) {
+ return 0;
+ }
+
+ /* The parser may write into the packet, so give it a writable copy
+ * instead of libFuzzer's read-only Data. */
+ uint8_t *pkt = malloc(Size);
+ if (NULL == pkt) {
+ return 0;
+ }
+ memcpy(pkt, Data, Size);
+
+ struct ntspacket_t ntspkt;
+ memset(&ntspkt, 0, sizeof(ntspkt));
+
+ (void)extens_server_recv(&ntspkt, pkt, Size);
+
+ free(pkt);
+
+ return 0;
+}
=====================================
fuzz/FuzzExtensClient.c
=====================================
@@ -0,0 +1,43 @@
+/*
+ * FuzzExtensClient.c - OSS-Fuzz harness for NTS client extension-field parsing
+ * Copyright the NTPsec project contributors
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ntpd.h"
+#include "nts.h"
+
+#define kMinInputLength 20
+#define kMaxInputLength 1024
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < kMinInputLength || Size > kMaxInputLength) {
+ return 0;
+ }
+
+ /* extens_client_recv decrypts in place, so give it a writable copy
+ * instead of libFuzzer's read-only Data. */
+ uint8_t *pkt = malloc(Size);
+ if (NULL == pkt) {
+ return 0;
+ }
+ memcpy(pkt, Data, Size);
+
+ struct peer peer;
+ memset(&peer, 0, sizeof(peer));
+
+ /* Stay reachable once upstream !1591 starts bailing out when
+ * peer->outcount is 0. */
+ peer.outcount = 1;
+
+ (void)extens_client_recv(&peer, pkt, Size);
+
+ free(pkt);
+
+ return 0;
+}
=====================================
fuzz/FuzzServer.c
=====================================
@@ -0,0 +1,45 @@
+/*
+ * FuzzServer.c - OSS-Fuzz harness for NTS-KE server record processing
+ * Copyright the NTPsec project contributors
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Section references are to https://tools.ietf.org/html/rfc8915
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "nts.h"
+
+#define kMinInputLength 20
+#define kMaxInputLength 1024
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < kMinInputLength || Size > kMaxInputLength) {
+ return 0;
+ }
+
+ /* The parser walks the buffer with a mutable cursor, so give it a
+ * writable copy instead of libFuzzer's read-only Data. */
+ uint8_t *buff = malloc(Size);
+ if (NULL == buff) {
+ return 0;
+ }
+ memcpy(buff, Data, Size);
+
+ NTS_Server_Info nsi;
+ struct BufCtl_t buf;
+
+ memset(&nsi, 0, sizeof(nsi));
+ nsi.aead = NO_AEAD; /* Dummy init value */
+ buf.next = buff;
+ buf.left = Size;
+
+ (void)nts_ke_process_receive(&nsi, &buf);
+
+ free(buff);
+
+ return 0;
+}
=====================================
fuzz/Makefile
=====================================
@@ -0,0 +1,57 @@
+# Copyright the NTPsec project contributors
+# SPDX-License-Identifier: BSD-2-Clause
+
+#main
+TARGET=Fuzzer
+
+#fuzzers
+CLIENTEXE=FuzzClient
+EXTENSEXE=FuzzExtens
+EXTENSCLIENTEXE=FuzzExtensClient
+SERVEREXE=FuzzServer
+
+#Flags
+SET=cd ../ &&
+EXTCFLAGS= -Wall -Wextra
+INC=-I../include/ -I../ntpd/ -I../build/ -I../tests/unity/ -I../tests/common/
+LIBINC=../build/main
+
+#library
+ntpd_lib=-L$(LIBINC)/ntpd/ -lntpd_lib
+libntp=-L$(LIBINC)/libntp/ -lntp
+libaes_siv=-L$(LIBINC)/libaes_siv/ -laes_siv
+extra_lib=-lssl -lcrypto
+setup_inc=setup.o
+# setup.o before ntpd_lib so its stubs win over the archive members
+LIB=$(setup_inc) $(ntpd_lib) $(libntp) $(libaes_siv) $(extra_lib)
+
+all: $(TARGET)
+
+INIT:
+ $(SET) ./buildprep -n
+CONF:
+ $(SET) CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(CFLAGS)" ./waf configure --enable-debug --disable-doc
+MAKEALL:
+ $(SET) ./waf build --notests
+SETUP:
+ $(CC) $(EXTCFLAGS) $(CFLAGS) $(INC) -c setup.c
+
+$(TARGET): INIT CONF MAKEALL SETUP
+ $(CC) $(EXTCFLAGS) $(CFLAGS) $(INC) -c $(CLIENTEXE).c
+ $(CC) $(EXTCFLAGS) $(CFLAGS) $(INC) -c $(EXTENSEXE).c
+ $(CC) $(EXTCFLAGS) $(CFLAGS) $(INC) -c $(EXTENSCLIENTEXE).c
+ $(CC) $(EXTCFLAGS) $(CFLAGS) $(INC) -c $(SERVEREXE).c
+
+# --wrap keeps Server Negotiation names away from the real resolver
+ $(CXX) $(LDFLAGS) $(CFLAGS) $(LIB_FUZZING_ENGINE) $(CLIENTEXE).o -o $(CLIENTEXE) $(LIB) -Wl,--wrap=nts_server_lookup
+ $(CXX) $(LDFLAGS) $(CFLAGS) $(LIB_FUZZING_ENGINE) $(EXTENSEXE).o -o $(EXTENSEXE) $(LIB)
+ $(CXX) $(LDFLAGS) $(CFLAGS) $(LIB_FUZZING_ENGINE) $(EXTENSCLIENTEXE).o -o $(EXTENSCLIENTEXE) $(LIB)
+ $(CXX) $(LDFLAGS) $(CFLAGS) $(LIB_FUZZING_ENGINE) $(SERVEREXE).o -o $(SERVEREXE) $(LIB)
+
+clean:
+ rm $(CLIENTEXE) $(EXTENSEXE) $(EXTENSCLIENTEXE) $(SERVEREXE) *.o
+
+reallyclean: clean
+ $(SET) ./waf clean
+
+.PHONY: all clean reallyclean
=====================================
fuzz/setup.c
=====================================
@@ -0,0 +1,64 @@
+/*
+ * setup.c - stubs and glue shared by the OSS-Fuzz harnesses in this directory
+ * Copyright the NTPsec project contributors
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ntpd.h"
+#include "ntp_dns.h"
+
+const char *progname = "ntpsecfuzz";
+
+/* Hack to keep linker happy */
+uint16_t extra_port = 0;
+struct peer *peer_list = NULL;
+
+void dns_take_server(struct peer *a, sockaddr_u *b);
+void dns_take_status(struct peer *a, DNS_Status b);
+void dns_take_pool(struct peer *a, sockaddr_u *b);
+
+void dns_take_server(struct peer *a, sockaddr_u *b) {
+ UNUSED_ARG(a);
+ UNUSED_ARG(b);
+ return;
+}
+
+void dns_take_status(struct peer *a, DNS_Status b) {
+ UNUSED_ARG(a);
+ UNUSED_ARG(b);
+ return;
+}
+
+void dns_take_pool(struct peer *a, sockaddr_u *b) {
+ UNUSED_ARG(a);
+ UNUSED_ARG(b);
+ return;
+}
+
+/* Stub the only daemon symbol the NTS parsers reference, to avoid pulling
+ * ntp_util/ntp_filegen/ntp_control out of libntpd_lib.a */
+void record_ntske_log(NTSKE_Status tag, const char *from, const char *msg,
+ double wall, double usr, double sys, int aead,
+ const char *errbuf)
+{
+ UNUSED_ARG(tag); UNUSED_ARG(from); UNUSED_ARG(msg);
+ UNUSED_ARG(wall); UNUSED_ARG(usr); UNUSED_ARG(sys);
+ UNUSED_ARG(aead); UNUSED_ARG(errbuf);
+ return;
+}
+
+/* Keep fuzzed responses from triggering real DNS lookups inside
+ * nts_client.c (see OSS-Fuzz issue 471591901). The FuzzClient link
+ * passes -Wl,--wrap=nts_server_lookup so calls to nts_server_lookup()
+ * land here. It is named __wrap_* because nts_client.o does get pulled
+ * out of libntpd_lib.a, so a same-named stub would collide with it. */
+bool __wrap_nts_server_lookup(char *server, sockaddr_u *addr, int af);
+
+bool __wrap_nts_server_lookup(char *server, sockaddr_u *addr, int af)
+{
+ UNUSED_ARG(server); UNUSED_ARG(addr); UNUSED_ARG(af);
+ return false;
+}
=====================================
fuzz/wscript
=====================================
@@ -0,0 +1,20 @@
+# Copyright the NTPsec project contributors
+#
+# SPDX-License-Identifier: BSD-2-Clause
+
+def build(ctx):
+ # Compile the OSS-Fuzz harnesses so that CI catches API drift.
+ # (Linking is done by fuzz/Makefile in the OSS-Fuzz environment,
+ # where LIB_FUZZING_ENGINE is available.)
+ ctx(
+ features="c",
+ includes=[ctx.bldnode.parent.abspath(), "../include", "../ntpd", "../libaes_siv"],
+ source=[
+ "setup.c",
+ "FuzzClient.c",
+ "FuzzExtens.c",
+ "FuzzExtensClient.c",
+ "FuzzServer.c",
+ ],
+ target="fuzz_obj",
+ )
=====================================
wafhelpers/options.py
=====================================
@@ -87,6 +87,10 @@ ext, ffi, or none. defaults to ffi.""", nargs=1)
grp.add_option('--disable-fuzz', action='store_true',
default=False,
help="Feature gone")
+ grp.add_option('--enable-fuzz-harnesses', action='store_true',
+ default=False,
+ help="Compile the OSS-Fuzz harnesses in fuzz/ "
+ "(compile only; linking happens in OSS-Fuzz)")
# This option group name needs to exactly match the name from
# waflib/Tools/python.py so this option groups with the other Python
=====================================
wscript
=====================================
@@ -757,6 +757,9 @@ int main(int argc, char **argv) {
if ctx.options.enable_attic:
ctx.env.ENABLE_ATTIC = True
+ if ctx.options.enable_fuzz_harnesses:
+ ctx.env.ENABLE_FUZZ_HARNESSES = True
+
if ctx.options.disable_nts:
ctx.env.DISABLE_NTS = True
ctx.define("DISABLE_NTS", 1,
@@ -1060,6 +1063,8 @@ def build(ctx):
ctx.recurse("attic")
ctx.recurse("etc")
ctx.recurse("tests")
+ if ctx.env.ENABLE_FUZZ_HARNESSES:
+ ctx.recurse("fuzz")
if ctx.env['PYTHON_GPS']:
python_scripts.add("ntpclients/ntploggps.py")
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/b78391004e8de7b5b2a249dd2b39db607ed54492
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/b78391004e8de7b5b2a249dd2b39db607ed54492
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261109/c3a8fee5/attachment-0001.htm>
More information about the vc
mailing list