From nobody Fri Oct 11 13:40:48 2024 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 4XQ7744tHQz5Ytvt; Fri, 11 Oct 2024 13:40:48 +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 4XQ77447fMz4bf6; Fri, 11 Oct 2024 13:40:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728654048; 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=qLG/baVGT0hYD/7ETrZKPWWkjaaCCskDvVqvxFN3Am8=; b=gElIYFebeoqJqU4stJyM04mx1KqZi18Ko28x1AHzL/XGE8adT0bpWxtNMHjTIT+ZpPm3Qz FAZukUXcjvx14m+3ZPFbezMY1HTi0+0PbByFra4zUvCHCcQByVjNQ1K0bXq63TRdZt/ODA UfC7ca3rFfZjqADEgTOVT0Dce7iL4AFPr8eQX4BgnXOPEQ1Rt9vnZKO2vbMt4rPhraiXom yWQ/AexqLyjgqLfEwqErYhHjamAyXlEgstnPkn9oW2YxFusI7U1R9Q/ZpYoeBhabZUV2yu UOUER7U9Dbnt/xmrqgM2N6DyEeP/9/lys3ILJciCTfCp6uJxjO19W/Oh079wNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728654048; 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=qLG/baVGT0hYD/7ETrZKPWWkjaaCCskDvVqvxFN3Am8=; b=uiyEtfjDQlq2M7n/oE1qDa+3+uE7P0DzVhUe4SObGsTkNqBoyOvBwjMDxqtDP1BS1WEs56 SyiMYR0zbTBCs07dFoSPVL53Gy1tKoh+VPmX4fyj/1o1XBS0rTEfHIElKQHdkPmiWI6qmb e41TJRNNhsKHgLuthjMdSUFA1AJdZjfwful+1y97dLUjXGsJSOqAYg2+DZDJCBR7zM/b3a FJKG+pDUh980I6TgrEL2matbidtW1vpUe0Ixtj/oGSBsQSThmpLUgwfIr+8bnJgspKUF1r YVE0wy/h5PpPHrJdSEJtf/cy1ZoRe1kDMEU7l4vqxklVXC9HsJOjnLLTwiB3eA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728654048; a=rsa-sha256; cv=none; b=ZD6Q+dhypbzq+S2UkWbmPYNRvHuOvIPbku1YvNbVUZlt5dS2+MYR6nWpFNixZLeOwRhS0n 3Tg2o/2wHkLh9E57KXKJ3B92gRSvFuZSfrG7r3mAvvVRBDxL2d9l6lkH6iXP8l61st7uY6 1wwl40Bj38lwjeGZYX1yb06WveXgfTF1misT/aVx43uRYxIVXv2ugcaqQfYtqBlvM2SB01 wKVu9vkjKSBIkxacXAGosxhRGC2Jk68OLULm42tuxJw+T4ua0YidyknNMQZdmgzMmfSAPh I5nCtUfm5zmatB8FsSNUM2uH9f0kPi35JLqQBUwWjIl4O80albRgLY3KrEpHRw== 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 4XQ7743KqpzkTN; Fri, 11 Oct 2024 13:40:48 +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 49BDemDr062194; Fri, 11 Oct 2024 13:40:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49BDemxM062191; Fri, 11 Oct 2024 13:40:48 GMT (envelope-from git) Date: Fri, 11 Oct 2024 13:40:48 GMT Message-Id: <202410111340.49BDemxM062191@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: ff5a685270a3 - stable/14 - if_vlan: handle VID conflicts List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org 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/stable/14 X-Git-Reftype: branch X-Git-Commit: ff5a685270a3946bf7941e82bb77528670b3aba3 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=ff5a685270a3946bf7941e82bb77528670b3aba3 commit ff5a685270a3946bf7941e82bb77528670b3aba3 Author: Kristof Provost AuthorDate: 2024-05-21 11:31:13 +0000 Commit: Kristof Provost CommitDate: 2024-10-11 10:04:09 +0000 if_vlan: handle VID conflicts If we fail to change the vlan id we have to undo the removal (and vlan id change) in the error path. Otherwise we'll have removed the vlan object from the hash table, and have the wrong vlan id as well. Subsequent modification attempts will then try to remove an entry which doesn't exist, and panic. Undo the vlan id modification if the insertion in the hash table fails, and re-insert it under the original vlan id. PR: 279195 Reviewed by: zlei MFC atfer: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D45285 (cherry picked from commit bdd12889eaa64032b3d09ef47e9a6f7081863378) --- sys/net/if_vlan.c | 10 ++++++++++ tests/sys/net/if_vlan.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 206d46e7f9be..c586b513e008 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1702,10 +1702,20 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t vid, ifv->ifv_proto = proto; if (ifv->ifv_vid != vid) { + int oldvid = ifv->ifv_vid; + /* Re-hash */ vlan_remhash(trunk, ifv); ifv->ifv_vid = vid; error = vlan_inshash(trunk, ifv); + if (error) { + int ret __diagused; + + ifv->ifv_vid = oldvid; + /* Re-insert back where we found it. */ + ret = vlan_inshash(trunk, ifv); + MPASS(ret == 0); + } } /* Will unlock */ goto done; diff --git a/tests/sys/net/if_vlan.sh b/tests/sys/net/if_vlan.sh index 458e3cc36bc6..41dac6222cbb 100755 --- a/tests/sys/net/if_vlan.sh +++ b/tests/sys/net/if_vlan.sh @@ -297,6 +297,42 @@ bpf_pcp_cleanup() vnet_cleanup } +atf_test_case "conflict_id" "cleanup" +conflict_id_head() +{ + atf_set descr 'Test conflicting VLAN IDs, PR #279195' + atf_set require.user root +} + +conflict_id_body() +{ + vnet_init + + epair=$(vnet_mkepair) + + vnet_mkjail alcatraz ${epair}b + vlan_a=$(jexec alcatraz ifconfig vlan create) + vlan_b=$(jexec alcatraz ifconfig vlan create) + + jexec alcatraz ifconfig ${vlan_a} vlan 100 vlandev ${epair}b + jexec alcatraz ifconfig ${vlan_b} vlan 101 vlandev ${epair}b + + atf_check -s exit:1 -o ignore -e ignore \ + jexec alcatraz ifconfig ${vlan_a} vlan 101 + + atf_check -s exit:0 -o match:"vlan: 100" \ + jexec alcatraz ifconfig ${vlan_a} + + atf_check -s exit:0 -o ignore -e ignore \ + jexec alcatraz ifconfig ${vlan_a} vlan 100 +} + +conflict_id_cleanup() +{ + vnet_cleanup + +} + atf_init_test_cases() { atf_add_test_case "basic" @@ -306,4 +342,5 @@ atf_init_test_cases() atf_add_test_case "qinq_dot" atf_add_test_case "qinq_setflags" atf_add_test_case "bpf_pcp" + atf_add_test_case "conflict_id" }