From nobody Wed May 21 05:48:34 2025 X-Original-To: dev-commits-src-main@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 4b2L7k2kxWz5wsl9; Wed, 21 May 2025 05:48:34 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b2L7k21Nrz4JJP; Wed, 21 May 2025 05:48:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747806514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hv6Sq6O6sbcJS8h8rle/JCwnf6UJ5z0b69JJVR+OArQ=; b=Dx/mzNg6sQXqIXUrfbagw9xUFGOSRpKJK3yovwO9Z00f562vAwKYGV4fN8VYHay13UtksA eKyv8hGjVJmEgnSP8LI3yT4KLeZLb37DHXT9Ve2q5ot1jPSCfL0uRLeLLkDWDhUJ6PPFFN J1rzBG//oQF64d571+zHn2UkOZFkFDa6zaUJTkWlHVV15+ttL3c6go1/39YXZjR7RFfU8E EqIFObwjomECYGFCkaGjcQH2SLYTRgtADrSR97W09ot3Rr0joaGHQ7dYLncAsKxbM07VMk wO4wYAsLE3/8b2CK4vopIzj5CruIyiyTo18lzVyJXfIzYfOQToFQLKxCmxL9nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747806514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hv6Sq6O6sbcJS8h8rle/JCwnf6UJ5z0b69JJVR+OArQ=; b=Nv7AlkeplpbWGYEcZhl+wcWk4VYFG3qLI66/mPcqMY1ruy8tgn8btTQBJE6lLYqZL75cv5 7zLBFkL1I4+p8Sph/9byTf3+/XffWxVFybeoOklZBzynFHu4BXfKF1x2Z2tmkRFJKXTo95 GRPV+Sm8mOXLFY87GJhwMdo/uRXoe5NiQSI8jgri3CdrWBp716npqifwPts9XVskhAuuAH UIQlj6tF7EW2NtWHxWL9yJnG7H/3gpInrfhYNGmUMAgHc/fbpKaJi0EGlk3BunCWhUI+48 RBgEIPHOVtg+R61U/AvPpVzykZpYo3W45mEPSVwX6vTE5+MXo0L/CYn85LvTQQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747806514; a=rsa-sha256; cv=none; b=Zat6k5LHrf+y5+YG7CVVzFqcF6qYwOVAcSDMqqnKh+Zn6+eCRsrESyv0NXY3e0izBa+RH5 P/x4gr4flu9Sor09EshietN3V/ikl48q63OCzBSwfOJnu+dhv5kHSa2kUpZlPNz1OlU9XH F65l9hoAmwTqAJlk+Hhv6r8Nqj/+nVR8bqwNKuzNVU2DiPZ7LiWTD0S5u6wTYmTmt4qrQk 5XaIfyRveNqlnJYKBAwqPMmhi0FfE9AnSy5jRWJ4mv3OgjbgpF/yNTN5m0UGOgrPWISbGQ xxKroQvi8d5WD3arVhJ/+GBB2uLC/0CO/KYsP/8dae8AF5jtHjy8hPALMpTa3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4b2L7k1cScz6hF; Wed, 21 May 2025 05:48:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54L5mYTA022944; Wed, 21 May 2025 05:48:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54L5mYMs022941; Wed, 21 May 2025 05:48:34 GMT (envelope-from git) Date: Wed, 21 May 2025 05:48:34 GMT Message-Id: <202505210548.54L5mYMs022941@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Lexi Winter Subject: git: 59ee9260e6bb - main - ifconfig: reject netmask and broadcast for inet6 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ivy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 59ee9260e6bbcc3b5654126eed6e9490315c81f1 Auto-Submitted: auto-generated The branch main has been updated by ivy: URL: https://cgit.FreeBSD.org/src/commit/?id=59ee9260e6bbcc3b5654126eed6e9490315c81f1 commit 59ee9260e6bbcc3b5654126eed6e9490315c81f1 Author: Lexi Winter AuthorDate: 2025-05-21 03:59:59 +0000 Commit: Lexi Winter CommitDate: 2025-05-21 05:46:17 +0000 ifconfig: reject netmask and broadcast for inet6 We don't support setting netmask or broadcast address for INET6 addresses, and trying to do crashes ifconfig. Handle this the same way as af_link, by rejecting attempts to configure these parameters. PR: 286910 Reported by: Hayzam Sherif MFC after: 3 days Reviewed by: zlei, kevans, des, cy Approved by: kevans (mentor) Differential Revision: https://reviews.freebsd.org/D50413 --- sbin/ifconfig/af_inet6.c | 5 +++ sbin/ifconfig/tests/Makefile | 7 ++-- sbin/ifconfig/tests/inet6.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index fcd04139a8c1..17dc068ee875 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -428,6 +428,11 @@ in6_getaddr(const char *addr_str, int which) { struct in6_px *px = sin6tab_nl[which]; + if (which == MASK) + errx(1, "netmask: invalid option for inet6"); + if (which == BRDADDR) + errx(1, "broadcast: invalid option for inet6"); + px->set = true; px->plen = 128; if (which == ADDR) { diff --git a/sbin/ifconfig/tests/Makefile b/sbin/ifconfig/tests/Makefile index ff545f603085..e902f262552a 100644 --- a/sbin/ifconfig/tests/Makefile +++ b/sbin/ifconfig/tests/Makefile @@ -1,5 +1,8 @@ -NETBSD_ATF_TESTS_SH= nonexistent_test +NETBSD_ATF_TESTS_SH= nonexistent_test +ATF_TESTS_SH+= inet6 -.include +TEST_METADATA+= execenv="jail" +TEST_METADATA+= execenv_jail_params="vnet allow.raw_sockets" +.include .include diff --git a/sbin/ifconfig/tests/inet6.sh b/sbin/ifconfig/tests/inet6.sh new file mode 100644 index 000000000000..cf7f97e01d79 --- /dev/null +++ b/sbin/ifconfig/tests/inet6.sh @@ -0,0 +1,84 @@ +#! /bin/sh +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2025 Lexi Winter + +. $(atf_get_srcdir)/../../sys/common/vnet.subr + +# Bug 286910: adding 'netmask' or 'broadcast' to an IPv6 address crashed +# ifconfig. + +atf_test_case "netmask" "cleanup" +netmask_head() +{ + atf_set descr "Test invalid 'netmask' option" + atf_set require.user root +} + +netmask_body() +{ + vnet_init + + ep=$(vnet_mkepair) + vnet_mkjail ifcjail ${ep}a + + # Add the address the wrong way + atf_check -s exit:1 \ + -e match:"ifconfig: netmask: invalid option for inet6" \ + jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1 netmask 64 + + # Add the address the correct way + atf_check -s exit:0 \ + jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1/64 + atf_check -s exit:0 -o match:"2001:db8:1::1 prefixlen 64" \ + jexec ifcjail ifconfig ${ep}a + + # Remove the address the wrong way + atf_check -s exit:1 \ + -e match:"ifconfig: netmask: invalid option for inet6" \ + jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1 netmask 64 -alias +} + +netmask_cleanup() +{ + vnet_cleanup +} + +atf_test_case "broadcast" "cleanup" +broadcast_head() +{ + atf_set descr "Test invalid 'broadcast' option" + atf_set require.user root +} + +broadcast_body() +{ + vnet_init + + ep=$(vnet_mkepair) + vnet_mkjail ifcjail ${ep}a + + atf_check -s exit:1 \ + -e match:"ifconfig: broadcast: invalid option for inet6" \ + jexec ifcjail ifconfig ${ep}a \ + inet6 2001:db8:1::1 broadcast 2001:db8:1::ffff + + atf_check -s exit:0 \ + jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1/64 + + atf_check -s exit:1 \ + -e match:"ifconfig: broadcast: invalid option for inet6" \ + jexec ifcjail ifconfig ${ep}a \ + inet6 2001:db8:1::1 broadcast 2001:db:1::ffff -alias +} + +broadcast_cleanup() +{ + vnet_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case netmask + atf_add_test_case broadcast +}