Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2735811pxj; Mon, 31 May 2021 09:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5B0EkFp6PtaytPHRoWRtgJRg6f/+1mFOIW4Xj5zRG90n1h7A2Hh7/27rWVcl/rSzt+cu6 X-Received: by 2002:a05:6602:2d8d:: with SMTP id k13mr17587014iow.121.1622478349990; Mon, 31 May 2021 09:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622478349; cv=none; d=google.com; s=arc-20160816; b=kSn7+4MRgp97w7csJ+8F+CGA3vBgMeUOIyL2CzemjFnVq2P5wkVlda/nj3raI9Ft0m lp7Ill0SR8n8SfsXZs6DUZN7nFoTfQS3eGLHswRkboqVzl9PIZt+cROl9R0uHatQrOI+ ZUtUwIgjIU+RNjb4CzU2BmTGKHhXUolk/EA7VxoQc6inZA4lCbict78Pus2nyGMn2RBS MwqNb46NRkl2sjX13iwUDnoAUnfEpstLrIze7Xs8VIAiSegn1q2u7d669MpYp2YeejRX 6b4g1hC20+6CgL2fc54F6cY9r/B6yDK/XgMcHdIDqX0qUi4oF69AG5Tno3tKZ9bmJHxx RZ5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qcQ2mQHjoHKhZ8OhdykXGdneSY5ymuLaGbV1BqcAmAY=; b=uAVJZFWQp5B2K8DQHHGjeAMioWgwu7HO/spvcmFsuuR6UaYL4Vr2pJBRMakfCi+bdM Z5bNtnJd1BxSfAKHRzPPKkAwBeNeJHL2L6liACrIOBzh/rB3L0iobLH6eVka7qT1v238 T4vFUWBMby3TuyZ9DErwSw9Tkv7AVmZxUuCV97idLOBUNjebqoZBGf+x6/J0LGwtg7Xs wxqz0Yjpc9vkDOjgysBkcmAFTRa6K/o6+H/IU1Qdu2U2iJfwa++SE8CXWSIPrxCmpNJG mPzAXM7bLAn1kw1Pp1Z4HXEN9ontf66CpBf6MH2N5G8KKd2cpxeLqUWaWsSyoukNjlQW D1Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jknpNU86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si7375589ils.9.2021.05.31.09.25.36; Mon, 31 May 2021 09:25:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jknpNU86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233854AbhEaQ0T (ORCPT + 99 others); Mon, 31 May 2021 12:26:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:40210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233962AbhEaOoL (ORCPT ); Mon, 31 May 2021 10:44:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 036FE61C7A; Mon, 31 May 2021 13:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469292; bh=ecVOHXG2H/p/BcQ8/ULU/fY1B/iSnZOBzF+lCQL9Ejk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jknpNU86m5uT3fXRE13tk7m9Ga9D0tL0cRodZuVQWGnpGAtMP9rX5yeeVTXbCznV5 vzP26Z5QaqTkCpzgkAQRvFRteMuPOf0xbdLo87uKbkq/nHTBsiE+BDESn7YtO1wlzO fFz/M59Nsm2tGvAjtAoBq7v7lKSFQ7iWoZyUdFps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , "David S. Miller" Subject: [PATCH 5.12 143/296] net: dsa: sja1105: update existing VLANs from the bridge VLAN list Date: Mon, 31 May 2021 15:13:18 +0200 Message-Id: <20210531130708.679794153@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean commit b38e659de966a122fe2cb178c1e39c9bea06bc62 upstream. When running this sequence of operations: ip link add br0 type bridge vlan_filtering 1 ip link set swp4 master br0 bridge vlan add dev swp4 vid 1 We observe the traffic sent on swp4 is still untagged, even though the bridge has overwritten the existing VLAN entry: port vlan ids swp4 1 PVID br0 1 PVID Egress Untagged This happens because we didn't consider that the 'bridge vlan add' command just overwrites VLANs like it's nothing. We treat the 'vid 1 pvid untagged' and the 'vid 1' as two separate VLANs, and the first still has precedence when calling sja1105_build_vlan_table. Obviously there is a disagreement regarding semantics, and we end up doing something unexpected from the PoV of the bridge. Let's actually consider an "existing VLAN" to be one which is on the same port, and has the same VLAN ID, as one we already have, and update it if it has different flags than we do. The first blamed commit is the one introducing the bug, the second one is the latest on top of which the bugfix still applies. Fixes: ec5ae61076d0 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Fixes: 5899ee367ab3 ("net: dsa: tag_8021q: add a context structure") Signed-off-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/dsa/sja1105/sja1105_main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2817,11 +2817,22 @@ static int sja1105_vlan_add_one(struct d bool pvid = flags & BRIDGE_VLAN_INFO_PVID; struct sja1105_bridge_vlan *v; - list_for_each_entry(v, vlan_list, list) - if (v->port == port && v->vid == vid && - v->untagged == untagged && v->pvid == pvid) + list_for_each_entry(v, vlan_list, list) { + if (v->port == port && v->vid == vid) { /* Already added */ - return 0; + if (v->untagged == untagged && v->pvid == pvid) + /* Nothing changed */ + return 0; + + /* It's the same VLAN, but some of the flags changed + * and the user did not bother to delete it first. + * Update it and trigger sja1105_build_vlan_table. + */ + v->untagged = untagged; + v->pvid = pvid; + return 1; + } + } v = kzalloc(sizeof(*v), GFP_KERNEL); if (!v) {