From nobody Wed Aug 23 09:56:59 2023 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 4RW1pM3k1Jz4rNj5; Wed, 23 Aug 2023 09:56:59 +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 4RW1pM38c9z3JVJ; Wed, 23 Aug 2023 09:56:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692784619; 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=UrcmxM6lHtWhLp8TDyUHACsJU1auheGkM0fA/TpaoB0=; b=rJPLCC7FjZWCDXfgEX2v2CB7aGbn+WMMEzFi7QEKB/AJALtfd6V8hYy6cf3s2AeZMU0Sd5 Cz2SougDOd5GCXm/UEAmKJfYi+tag7ROies8TDvhl62NU1gYwk9ny4I9FjYDfObIVdETFL 3osKnZiqGScNFN6OXSlMDngcMNOY+c4W0qqZ9o7GUOL4Gjv0jzJBQ72X0/bvBLZCkGS7/K wGKcf+SytxeTdhYk38qMo+033KIiIPSehrajf6y2Al5ft/acAqy/KzMOajmG4Hp+NezUNX WHjIcRMoO+74UL6lDJdCpekkpzSNzlZvEBwAE9ddCyjpLAiedMrJgoGqfJTjhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692784619; 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=UrcmxM6lHtWhLp8TDyUHACsJU1auheGkM0fA/TpaoB0=; b=LFeDQBcqzl0ausTlWjptQzIx7JvUQB5EL3Z49D8QP+P3KyLJU8DPRvBeOTUKgBL0NzAIvG 9ocUd/jJcUdCEY+LRJQ0sDfrBl85+aJsPFxyjNionD0axTdrFXsC/rPwrPWRxnjPmDhwcv I8aSW1owtd+dWr4D20Y+m/M/LwqjzkCN94mOlpWWfekpPWPriHSG+sZAakJ9UuBqEWSX68 QYbm7CReGL3AaxTMigomVAyNnK4jxpsT45pU3VqZYdcNZRXIWIyNN7VtAVyrjVpmf/zYi5 bbEKLWIrL6+qquPpqrc3l5ejYlI5qTJtnrBskFSujvtOXqWp6aAo8dDVi8UvPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692784619; a=rsa-sha256; cv=none; b=Pn3nmNjgsVts6PdkviWG6hCI6lAomDp7uwr3WOgQu7tXcQ4UYHuV9AuzwVYMklew+00gM2 3n/Xit7/l4uvmBYPwQKvQgyhLhsuHPuxZEajhFxXAGVXk6EMo6gqZ4kgRe5LdJeqAiEJqO qDV01KEP2e3l1KGjz6wcd5WBRHESfDYCUpSr7eMo6DrlTkK0gB5ZF6fw33NN605pGz9rV6 kMskGQ3+nMuC1IcVIk/GtUDANFMnQ77IC6phkQZmnFAXdw4oJl2My1Pgc4AGTwqnwmLN8o s3z+Lxm0v+HKXNy3Ss0dLdkOV1TlxIWmbfuqnQQ6JPNkv+MnKWTRfJUjPzAoYg== 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 4RW1pM2D1Pzh6x; Wed, 23 Aug 2023 09:56:59 +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 37N9uxdJ060341; Wed, 23 Aug 2023 09:56:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37N9uxk3060338; Wed, 23 Aug 2023 09:56:59 GMT (envelope-from git) Date: Wed, 23 Aug 2023 09:56:59 GMT Message-Id: <202308230956.37N9uxk3060338@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: 838c8c47860a - main - net: Do not overwrite if_vlan's PCP 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 838c8c47860a0203130bd558d507a0565a2eba8f Auto-Submitted: auto-generated The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=838c8c47860a0203130bd558d507a0565a2eba8f commit 838c8c47860a0203130bd558d507a0565a2eba8f Author: Zhenlei Huang AuthorDate: 2023-08-23 09:48:12 +0000 Commit: Zhenlei Huang CommitDate: 2023-08-23 09:53:48 +0000 net: Do not overwrite if_vlan's PCP In commit c7cffd65c5d8 the function ether_8021q_frame() was slightly refactored to use pointer of struct ether_8021q_tag as parameter qtag to include the new option proto. It is wrong to write to qtag->pcp as it will effectively change the memory that qtag points to. Unfortunately the transmit routine of if_vlan parses pointer of the member ifv_qtag of its softc which stores vlan interface's PCP internally, when transmitting mbufs that contains PCP the vlan interface's PCP will get overwritten. Fix by operating on a local copy of qtag->pcp. Also mark 'struct ether_8021q_tag' as const so that compilers can pick up such kind of bug. PR: 273304 Reviewed by: kp Fixes: c7cffd65c5d85 Add support for stacked VLANs (IEEE 802.1ad, AKA Q-in-Q) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D39505 --- sys/net/ethernet.h | 2 +- sys/net/if_ethersubr.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index 8a4b9336b9cc..fca6748a0da7 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -446,7 +446,7 @@ void ether_vlan_mtap(struct bpf_if *, struct mbuf *, void *, u_int); struct mbuf *ether_vlanencap_proto(struct mbuf *, uint16_t, uint16_t); bool ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, - struct ifnet *p, struct ether_8021q_tag *); + struct ifnet *p, const struct ether_8021q_tag *); void ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr); static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag) diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 25f4d151866e..63ea5e7591c2 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1400,11 +1400,12 @@ SYSCTL_INT(_net_link_vlan, OID_AUTO, mtag_pcp, CTLFLAG_RW | CTLFLAG_VNET, bool ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, - struct ether_8021q_tag *qtag) + const struct ether_8021q_tag *qtag) { struct m_tag *mtag; int n; uint16_t tag; + uint8_t pcp = qtag->pcp; static const char pad[8]; /* just zeros */ /* @@ -1437,7 +1438,7 @@ ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, * If PCP is set in mbuf, use it */ if ((*mp)->m_flags & M_VLANTAG) { - qtag->pcp = EVL_PRIOFTAG((*mp)->m_pkthdr.ether_vtag); + pcp = EVL_PRIOFTAG((*mp)->m_pkthdr.ether_vtag); } /* @@ -1451,7 +1452,7 @@ ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, MTAG_8021Q_PCP_OUT, NULL)) != NULL) tag = EVL_MAKETAG(qtag->vid, *(uint8_t *)(mtag + 1), 0); else - tag = EVL_MAKETAG(qtag->vid, qtag->pcp, 0); + tag = EVL_MAKETAG(qtag->vid, pcp, 0); if ((p->if_capenable & IFCAP_VLAN_HWTAGGING) && (qtag->proto == ETHERTYPE_VLAN)) { (*mp)->m_pkthdr.ether_vtag = tag;