From nobody Wed Nov 18 16:28:42 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jV6VM1g2Jz6w4g7 for ; Wed, 18 Nov 2026 16:28:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jV6VM0Hjlz4PqB for ; Wed, 18 Nov 2026 16:28:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795019323; 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; bh=da7VS1lOmO9t5JM+GRkMgnQnkX7JnYbERwCTe0eZKcA=; b=mYJUa4MHHtrl8fmhgoACcgrwvlPRxlvD016ftisO/Zz4Rw7VjweaMWdH+v1C5h9I8pWaTV 5Gi6j9bVNPsSdM3fmV+vB7P6H34tT/XKLnvYNh79JRgWt+R95DrRvOT7mkufyJgIBPV8It cEyiWVdXRAKxGC1fYGbrQGQlG5SYCUSN9dsu4oyomRPUHJeOrQuC5MKQeI2KbcGxcp0Leg 4A+coRtgbnGdOga1A+8aGGm0vpme1PNhWqEbhJ/ppfqzRLlfrBZCPuh0I14UxyUljQd7kL N8Lgou8x9qf5Ru/Azcvich5DVK6G6eOy2AhmXPhtW+x3YS43rUmuJJUmsxkOPw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795019323; b=sebPShKCf3/V+fWqSmVVbkK+UoanlAu8U+/DXYSrvJuRU7R0AfySRcwwkxe9rfvoVoSt7R jf3zXupx9+3+vvH4p9vhEd9LXG5PyF9dA7472/p2SFKqXKoF9wDjOUZ4Zx7VxCE5pWJwOT RWnFetoaEHMXRuesMUQ2um/ELpQ7L4muLtY1CseC4qlX276rAIYpViAK08ASQBvJbbg18H XOv7m+2YJqY1lz8ZeWv4exsrU7YQGzv3d7WUpkTJLOkYtfrUsa+iOV4CJh+BzxdBBMYSH3 arDwpS3Wit8DQiVOm3Krk8KJf/KQVCaD/FZtyBc+oida8DK73Y0VTrQhfUZWrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795019323; 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; bh=da7VS1lOmO9t5JM+GRkMgnQnkX7JnYbERwCTe0eZKcA=; b=SG6g0hTLYVbaOZlpbP/O5l+aqYr7YQ1TrUJjL6noOTzCYsIGrXv+Cc7PUNEtIVf3BgaMr6 TWmGnL2DuWlEGI8ghXuTsjD8/1vZ5QDpCBBlIwqc70i3WSc6Rz9YZlzpOtLk2JDET3pfIV hmW+en4R5YJgl4CPKeV39NEbPYCp7EL967vr7EYdMIDZuT+sG6hCX9pES3yRq9redY3eAQ 1p4/x0qcho7KW9hyUSWi2oc3Bd1PDzHRo0LVDwj6KOkbZnBfR9lHk3ssOCc8ygD6zZzd0Z Vn42MKPB0MVqgozfpyTr3OfW/o2S11intUtJNcPyWXnpNoFOFAjOtqO9aK+Oog== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jV6VL72KczLXC for ; Wed, 18 Nov 2026 16:28:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4486 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 16:28:42 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Osvaldo Janeri Filho From: Kristof Provost Subject: git: 42d358453d05 - main - dummynet: validate object length before fixed-size copies in do_config() List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 42d358453d056e70bd112c63247e89c1ecf575d5 Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 16:28:42 +0000 Message-Id: <6afdd23a.4486.2d5339eb@gitrepo.freebsd.org> The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=42d358453d056e70bd112c63247e89c1ecf575d5 commit 42d358453d056e70bd112c63247e89c1ecf575d5 Author: Osvaldo Janeri Filho AuthorDate: 2026-11-18 10:50:14 +0000 Commit: Kristof Provost CommitDate: 2026-11-18 16:28:22 +0000 dummynet: validate object length before fixed-size copies in do_config() do_config() checks that each command's o.len fits in the remaining buffer, but the DN_LINK, DN_PROFILE, DN_SCH and DN_FS cases then copy a fixed sizeof(struct) out of the command, which can be larger than o.len. A command with o.len == sizeof(struct dn_id) reads past the end of the sockopt buffer (DN_PROFILE copies about 4 KB). Reject a command whose o.len is shorter than the structure it carries. Add a test. Reviewed by: kp MFC after: 1 week Sponsored by: Advanced Micro Devices, Inc. Signed-off-by: Osvaldo Janeri Filho Differential Revision: https://reviews.freebsd.org/D61440 --- sys/netpfil/ipfw/ip_dummynet.c | 16 ++++ tests/sys/netpfil/common/Makefile | 2 + tests/sys/netpfil/common/dummynet_config_test.c | 119 ++++++++++++++++++++++++ 3 files changed, 137 insertions(+) diff --git a/sys/netpfil/ipfw/ip_dummynet.c b/sys/netpfil/ipfw/ip_dummynet.c index f834fb2b7ba6..7c0f4bd10cbd 100644 --- a/sys/netpfil/ipfw/ip_dummynet.c +++ b/sys/netpfil/ipfw/ip_dummynet.c @@ -2100,6 +2100,10 @@ do_config(void *p, size_t l) err = ENOMEM; break; } + if (o.len < sizeof(dn->link)) { + err = EINVAL; + break; + } memcpy(&dn->link, (char *)p + off, sizeof(dn->link)); err = config_link(&dn->link, arg); break; @@ -2110,6 +2114,10 @@ do_config(void *p, size_t l) err = ENOMEM; break; } + if (o.len < sizeof(dn->profile)) { + err = EINVAL; + break; + } memcpy(&dn->profile, (char *)p + off, sizeof(dn->profile)); err = config_profile(&dn->profile, arg); @@ -2121,6 +2129,10 @@ do_config(void *p, size_t l) err = ENOMEM; break; } + if (o.len < sizeof(dn->sched)) { + err = EINVAL; + break; + } memcpy(&dn->sched, (char *)p + off, sizeof(dn->sched)); err = config_sched(&dn->sched, arg); @@ -2132,6 +2144,10 @@ do_config(void *p, size_t l) err = ENOMEM; break; } + if (o.len < sizeof(dn->fs)) { + err = EINVAL; + break; + } memcpy(&dn->fs, (char *)p + off, sizeof(dn->fs)); err = (NULL == config_fs(&dn->fs, arg, 0)); break; diff --git a/tests/sys/netpfil/common/Makefile b/tests/sys/netpfil/common/Makefile index 0938bd9d9c7e..721ec14a86d9 100644 --- a/tests/sys/netpfil/common/Makefile +++ b/tests/sys/netpfil/common/Makefile @@ -4,6 +4,8 @@ TESTSDIR= ${TESTSBASE}/sys/netpfil/common BINDIR= ${TESTSDIR} +ATF_TESTS_C+= dummynet_config_test + ATF_TESTS_SH+= \ dummynet \ pass_block \ diff --git a/tests/sys/netpfil/common/dummynet_config_test.c b/tests/sys/netpfil/common/dummynet_config_test.c new file mode 100644 index 000000000000..ecde680c5b8b --- /dev/null +++ b/tests/sys/netpfil/common/dummynet_config_test.c @@ -0,0 +1,119 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Osvaldo Janeri Filho + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/* + * do_config() validates that each command's declared length fits in the + * supplied buffer, but the DN_LINK, DN_PROFILE, DN_SCH and DN_FS cases + * copy a fixed sizeof(struct) that is larger than struct dn_id. A command + * whose oid.len is only sizeof(struct dn_id) must be rejected rather than + * read beyond the buffer. + */ +static void +check_short_object(uint8_t type) +{ + struct dn_id o; + int s, rv; + + s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + ATF_REQUIRE_MSG(s >= 0, "raw socket: %s", strerror(errno)); + + memset(&o, 0, sizeof(o)); + o.len = sizeof(o); + o.type = type; + o.id = DN_API_VERSION; + + rv = setsockopt(s, IPPROTO_IP, IP_DUMMYNET3, &o, sizeof(o)); + ATF_CHECK_MSG(rv == -1 && errno == EINVAL, + "type %u: expected EINVAL, got rv=%d errno=%d", type, rv, errno); + + close(s); +} + +static void +require_dummynet(atf_tc_t *tc) +{ + atf_tc_set_md_var(tc, "require.user", "root"); + atf_tc_set_md_var(tc, "require.kmods", "dummynet"); +} + +ATF_TC(dn_link_short); +ATF_TC_HEAD(dn_link_short, tc) +{ + require_dummynet(tc); +} +ATF_TC_BODY(dn_link_short, tc) +{ + check_short_object(DN_LINK); +} + +ATF_TC(dn_profile_short); +ATF_TC_HEAD(dn_profile_short, tc) +{ + require_dummynet(tc); +} +ATF_TC_BODY(dn_profile_short, tc) +{ + check_short_object(DN_PROFILE); +} + +ATF_TC(dn_sch_short); +ATF_TC_HEAD(dn_sch_short, tc) +{ + require_dummynet(tc); +} +ATF_TC_BODY(dn_sch_short, tc) +{ + check_short_object(DN_SCH); +} + +ATF_TC(dn_fs_short); +ATF_TC_HEAD(dn_fs_short, tc) +{ + require_dummynet(tc); +} +ATF_TC_BODY(dn_fs_short, tc) +{ + check_short_object(DN_FS); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, dn_link_short); + ATF_TP_ADD_TC(tp, dn_profile_short); + ATF_TP_ADD_TC(tp, dn_sch_short); + ATF_TP_ADD_TC(tp, dn_fs_short); + + return (atf_no_error()); +}