From nobody Wed May 22 07:41:24 2024 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 4Vkjsw5jsnz5L7bq; Wed, 22 May 2024 07:41:24 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vkjsw4VrDz4b9f; Wed, 22 May 2024 07:41:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716363684; 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=rk4+f8/ahlGsC6GYzdLW82W1iGLhRL4iR67iOpihzao=; b=SIYGaVZ4ob03pDkTYP0Q0Yq1R8nG11z6SyuLG5vn4a9Qnvg7WzuuzjNY+Eth9LrqoHS02R o9mP8Pl9i7pybnVZ2g99Ujt0tNVnG/9zNU2o3YHheaYxgaQiC1lKNdmzXarIqwu9nRNLer d4FIKP9l9zc8XljpgaJ7swXyWldrXXZtVheZRhcjEe0LLF3ySg8IqkAORp7XnHmy+dqU2t vzcFrb062dncOPdTO2qXcF8x8HCgrOXkpiD5bLnP1EJfBJ6vILlVeb5uVsQuAlR3VSxuQh J6FIPfoPnAotSxIAYeLHk7AumZz1GxoAJW/bW23TJ4NVXK9HMMQ+oMzqI8wCcg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716363684; a=rsa-sha256; cv=none; b=JJ2brLEehdMiLLY7OcLg+8peOSCnU/C5dCTOia0WQIqDAB4cTOTBiWIO7qnOPN+c0cinyC Jj3eFSfyHpWVQnlMFMDUSh692PpRhNUXZ1qazPmLbM0labXsST2L6osVblB00QNP75x6ZS A4PWVL6WZ2VfJOPeRmnphF97lYeGKZYasU58S4URMGfL+iuSthz+BtBgG/fBQPYsnWDhT8 bcSX7LMqUbYDxCgfXw9eh/9ehERQ7DiX+ubKT5w3pxhLxbU95PozPRfbfhBDV+QNwAs2e9 F2dAu6+T6DE9tbSwE+45Z8G9iL65+Qg+fiMGizF3udoTktKdpkGxMQJ+SfNZRQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716363684; 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=rk4+f8/ahlGsC6GYzdLW82W1iGLhRL4iR67iOpihzao=; b=Kws2J9ASOHQbPCtQeRiI1QYwpwCDHjCKeyss6Om9Wrw45csefnPvTk1jq+52YKdVCsywZs UBUK/nAooi1u5KJBZZlAUxyLVBlG5EwkcheuW0SyVSimdtj7TJvbEdlJ47LTzGe97zcIKX kMXdBo4oO/YbP6n9jCIqxeN9Vqx4SrgyUQYJ1vjQX2cLsFSL92L06tEbEJ/i4Xk2+YptvL XpU3TWUEz98egDCHtX8zp6y6oqi5UrfkOnMmoqBHv4ykBP3Gj+SJoBxJ9blLgEhKC1DwIl V++nA25xCORFRJIK/T2RyjpiYUnsMYLt0ByARoEyKvvcPpTjmv2OvSSuLJT4bw== 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 4Vkjsw3qFczwl4; Wed, 22 May 2024 07:41:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44M7fOEe019905; Wed, 22 May 2024 07:41:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44M7fOne019902; Wed, 22 May 2024 07:41:24 GMT (envelope-from git) Date: Wed, 22 May 2024 07:41:24 GMT Message-Id: <202405220741.44M7fOne019902@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: bdd12889eaa6 - main - if_vlan: handle VID conflicts 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bdd12889eaa64032b3d09ef47e9a6f7081863378 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=bdd12889eaa64032b3d09ef47e9a6f7081863378 commit bdd12889eaa64032b3d09ef47e9a6f7081863378 Author: Kristof Provost AuthorDate: 2024-05-21 11:31:13 +0000 Commit: Kristof Provost CommitDate: 2024-05-22 07:08:02 +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 --- 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 b69d8107e30d..788fdf787249 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1715,10 +1715,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" }