From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aq+SaV88; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 39F7A5A0269 for ; Mon, 28 Sep 2026 07:17:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790572662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ai+4Xp0K5Q80ETWiuJxoki/d03qWJZ0FWSEfrPywkiM=; b=aq+SaV886lCxAkJFknYmAi9uGANxGxTnmWByuTOlB0FBC77C1bqiyGXmFkpQyHFVdP3r4N UkY68Jj6ZZEnOOnCwYY5N2y4cwYway3iI/60TjpV+BFfD7TdbmtAG1roRuzbV3i1a9upRl 4yyGhpxSDGnfY2fgeCiJUc7uxQPn1Gk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-UfjeJWFxPzO9ZsLEJzgTgQ-1; Mon, 28 Sep 2026 01:17:39 -0400 X-MC-Unique: UfjeJWFxPzO9ZsLEJzgTgQ-1 X-Mimecast-MFC-AGG-ID: UfjeJWFxPzO9ZsLEJzgTgQ_1790572658 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A7E119774E7; Mon, 28 Sep 2026 05:17:38 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.80.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4064219560AB; Mon, 28 Sep 2026 05:17:35 +0000 (UTC) From: Anshu Kumari To: sbrivio@redhat.com, passt-dev@passt.top Subject: [PATCH v2 2/7] fuzz: Add deterministic wrappers for assert, clock and getsockopt Date: Mon, 28 Sep 2026 10:47:22 +0530 Message-ID: <20260928051727.2251281-3-anskuma@redhat.com> In-Reply-To: <20260928051727.2251281-1-anskuma@redhat.com> References: <20260928051727.2251281-1-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CBlSveRjk4iqU26NVJya04TLTW1-zE3kifRicN-qEY4_1790572658 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: KL6CRVICBNCFBAKWSEEHXVQV32GSOKBG X-Message-ID-Hash: KL6CRVICBNCFBAKWSEEHXVQV32GSOKBG X-MailFrom: anskuma@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: lvivier@redhat.com, anskuma@redhat.com, abdobngad@gmail.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add fuzz_assert() macro that calls _exit(0) instead of abort() so AFL++ treats assertion failures as normal exits rather than crashes. Add deterministic replacements for clock_gettime() and getsockopt() that eliminate non-determinism from kernel state: - fuzz_clock_gettime(): returns a monotonically incrementing timestamp from a fixed baseline, reset each AFL++ iteration - fuzz_getsockopt(): returns fuzzer-controlled TCP_INFO from AFL++ shared memory (region d), and fixed values for SO_ERROR/SO_RCVBUF/SO_SNDBUF Signed-off-by: Anshu Kumari --- Makefile | 17 ++++++---- fuzz.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fuzz.h | 37 ++++++++++++++++++++ 3 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 fuzz.c create mode 100644 fuzz.h diff --git a/Makefile b/Makefile index 97c27f7c..cce9ffd0 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,9 @@ PASST_SRCS = arch.c arp.c bitmap.c checksum.c conf.c dhcp.c dhcpv6.c \ parse.c passt.c pasta.c pcap.c pif.c repair.c serialise.c tap.c tcp.c \ tcp_buf.c tcp_splice.c tcp_vu.c udp.c udp_flow.c udp_vu.c util.c \ vhost_user.c virtio.c vu_common.c +ifneq ($(findstring FUZZING,$(CPPFLAGS)),) +PASST_SRCS += fuzz.c +endif PASST_REPAIR_SRCS = passt-repair.c PESTO_SRCS = pesto.c bitmap.c fwd_rule.c inany.c ip.c lineread.c parse.c \ serialise.c @@ -47,13 +50,13 @@ SRCS = $(PASST_SRCS) $(PASST_REPAIR_SRCS) $(PESTO_SRCS) MANPAGES = passt.1 pasta.1 pesto.1 passt-repair.1 PASST_HEADERS = arch.h arp.h bitmap.h checksum.h conf.h dhcp.h dhcpv6.h \ - epoll_ctl.h flow.h fwd.h fwd_rule.h flow_table.h fuzz-testbuf.h \ - icmp.h icmp_flow.h inany.h iov.h ip.h isolation.h lineread.h \ - linux_dep.h log.h migrate.h ndp.h netlink.h packet.h parse.h \ - passt.h pasta.h pcap.h pif.h repair.h serialise.h siphash.h tap.h \ - tcp.h tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h tcp_vu.h \ - udp.h udp_flow.h udp_internal.h udp_vu.h util.h vhost_user.h \ - virtio.h vu_common.h + epoll_ctl.h flow.h fwd.h fwd_rule.h flow_table.h fuzz.h \ + fuzz-testbuf.h icmp.h icmp_flow.h inany.h iov.h ip.h isolation.h \ + lineread.h linux_dep.h log.h migrate.h ndp.h netlink.h packet.h \ + parse.h passt.h pasta.h pcap.h pif.h repair.h serialise.h siphash.h \ + tap.h tcp.h tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h \ + tcp_vu.h udp.h udp_flow.h udp_internal.h udp_vu.h util.h \ + vhost_user.h virtio.h vu_common.h PASST_REPAIR_HEADERS = linux_dep.h PESTO_HEADERS = bitmap.h common.h fwd_rule.h inany.h ip.h log.h parse.h \ pesto.h serialise.h diff --git a/fuzz.c b/fuzz.c new file mode 100644 index 00000000..89a47d76 --- /dev/null +++ b/fuzz.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* fuzz.c - AFL++ fuzzing support: deterministic wrappers for + * clock_gettime() and getsockopt() + * + * Copyright Red Hat + * Author: Anshu Kumari + */ + +#include +#include +#include +#include +#include "passt.h" +#include "fuzz.h" + +/* Undo macros so definitions here call the real syscalls */ +#undef clock_gettime +#undef getsockopt + +#define FUZZ_CLOCK_BASE_SEC 10000 + +static struct timespec fuzz_clock; + +/** + * fuzz_clock_reset() - Reset clock to fixed baseline + * + * Called at the start of every __AFL_LOOP iteration so + * the clock is identical regardless of iteration number. + */ +void fuzz_clock_reset(void) +{ + fuzz_clock.tv_sec = FUZZ_CLOCK_BASE_SEC; + fuzz_clock.tv_nsec = 0; +} + +/** + * fuzz_clock_gettime() - Return deterministic time + * @clk: Clock ID + * @tp: Output timespec + * + * Return: 0 (always succeeds) + */ +int fuzz_clock_gettime(clockid_t clk, struct timespec *tp) +{ + (void)clk; + *tp = fuzz_clock; + + /* increment the timestamp by 1 micro sec monotonically */ + fuzz_clock.tv_nsec += 1000; + if (fuzz_clock.tv_nsec >= 1000000000) { + fuzz_clock.tv_sec++; + fuzz_clock.tv_nsec -= 1000000000; + } + return 0; +} + +/** + * fuzz_getsockopt() - Deterministic getsockopt wrapper + * @fd: Socket file descriptor + * @level: Protocol level + * @optname: Option name + * @optval: Output buffer + * @optlen: In/out option length + * + * For TCP_INFO: populates optval from the AFL++ shared memory buffer. + * For SO_RCVBUF, SO_SNDBUF: returns deterministic values. + * + * Return: 0 on success, -1 on error + */ +int fuzz_getsockopt(int fd, int level, int optname, void *optval, + socklen_t *optlen) +{ + if (level == SOL_SOCKET) { + if (optname == SO_RCVBUF || optname == SO_SNDBUF) { + *(int *)optval = 212992; /* default linux buff size */ + *optlen = sizeof(int); + return 0; + } + } + + if (level == SOL_TCP && optname == TCP_INFO) { + size_t fill = *optlen; + size_t copy_len; + + memset(optval, 0, fill); + + if (fuzz_sockopt_data && fuzz_sockopt_data_len > 0) { + copy_len = MIN(fill, (size_t)fuzz_sockopt_data_len); + memcpy(optval, fuzz_sockopt_data, copy_len); + fuzz_sockopt_data += copy_len; + fuzz_sockopt_data_len -= copy_len; + *optlen = copy_len; + } else { + *optlen = 0; + } + + return 0; + } + + return getsockopt(fd, level, optname, optval, optlen); +} diff --git a/fuzz.h b/fuzz.h new file mode 100644 index 00000000..311d7e79 --- /dev/null +++ b/fuzz.h @@ -0,0 +1,37 @@ +//SPDX-License-Identifier: GPL-2.0-or-later + +/* fuzz.h - AFL++ fuzzing support for passt + * + * Copyright Red Hat + * Author: Anshu Kumari + */ + +#ifndef FUZZ_H +#define FUZZ_H + +#ifdef FUZZING + +#include +#include +#include +#include "fuzz-testbuf.h" + +int fuzz_clock_gettime(clockid_t clk, struct timespec *tp); +void fuzz_clock_reset(void); +int fuzz_getsockopt(int fd, int level, int optname, void *optval, + socklen_t *optlen); + +extern const unsigned char *fuzz_sockopt_data; +extern int fuzz_sockopt_data_len; + +#define clock_gettime(clk, tp) fuzz_clock_gettime(clk, tp) +#define getsockopt(fd, level, name, val, len) \ + fuzz_getsockopt(fd, level, name, val, len) + +#define fuzz_assert(expr) do { if (!(expr)) _exit(0); } while (0) +#else /* !FUZZING */ +#include +#define fuzz_assert(expr) assert(expr) +#endif /* FUZZING */ + +#endif /* FUZZ_H */ -- 2.55.0