lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <900f28da-83db-4b17-b56b-21acde70e47f@huawei.com>
Date: Thu, 26 Jun 2025 11:41:45 +0800
From: "dongchenchen (A)" <dongchenchen2@...wei.com>
To: Jakub Kicinski <kuba@...nel.org>
CC: <davem@...emloft.net>, <edumazet@...gle.com>, <pabeni@...hat.com>,
	<horms@...nel.org>, <jiri@...nulli.us>, <oscmaes92@...il.com>,
	<linux@...blig.org>, <pedro.netdev@...devamos.com>, <netdev@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <yuehaibing@...wei.com>,
	<zhangchangzhong@...wei.com>
Subject: Re: [PATCH net] net: vlan: fix VLAN 0 refcount imbalance of toggling
 filtering during runtime


> On Mon, 23 Jun 2025 19:30:08 +0800 Dong Chenchen wrote:
>> $ ip link add bond0 type bond mode 0
>> $ ip link add link bond0 name vlan0 type vlan id 0 protocol 802.1q
>> $ ethtool -K bond0 rx-vlan-filter off
>> $ ifconfig bond0 up
>> $ ethtool -K bond0 rx-vlan-filter on
>> $ ifconfig bond0 down
>> $ ifconfig bond0 up
>> $ ip link del vlan0

Hi, Jakub
Thanks for your review!

> Please try to figure out the reasonable combinations in which we can
> change the flags and bring the device up and down. Create a selftest
> in bash and add it under tools/testing/selftests/net

selftest patch will be added in v2.

>> diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
>> index 06908e37c3d9..6e01ece0a95c 100644
>> --- a/net/8021q/vlan.c
>> +++ b/net/8021q/vlan.c
>> @@ -504,12 +504,21 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
>>   		break;
>>   
>>   	case NETDEV_CVLAN_FILTER_PUSH_INFO:
>> +		flgs = dev_get_flags(dev);
> Why call dev_get_flags()? You can test dev->flags & IFF_UP directly

Yes, there is no need to use this function, I will modify it in v2

>> +		if (flgs & IFF_UP) {
>> +			pr_info("adding VLAN 0 to HW filter on device %s\n",
>> +				dev->name);
>> +			vlan_vid_add(dev, htons(ETH_P_8021Q), 0);
> Not sure if this works always, because if we have no vlan at all when
> the device comes up vlan_info will be NULL and we won't even get here.
>
> IIUC adding vlan 0 has to be handled early, where UP is handled.

Yes, that's right.

the sequence as below can still trigger the issue:

$ ip link add bond0 type bond mode 0
$ ethtool -K bond0 rx-vlan-filter off
$ ifconfig bond0 up
$ ethtool -K bond0 rx-vlan-filter on
$ ip link add link bond0 name vlan0 type vlan id 0 protocol 802.1q
$ ifconfig bond0 down
$ ifconfig bond0 up
$ ip link del vlan0

maybe we can fix it by:

diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 6e01ece0a95c..262f8d3f06ef 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -378,14 +378,18 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
              return notifier_from_errno(err);
      }
  
-    if ((event == NETDEV_UP) &&
-        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) {
+    if (((event == NETDEV_UP) &&
+        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) ||
+        (event == NETDEV_CVLAN_FILTER_PUSH_INFO &&
+        (dev->flags & IFF_UP))) {
          pr_info("adding VLAN 0 to HW filter on device %s\n",
              dev->name);
          vlan_vid_add(dev, htons(ETH_P_8021Q), 0);
      }
-    if (event == NETDEV_DOWN &&
-        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
+    if ((event == NETDEV_DOWN &&
+        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) ||
+        (event == NETDEV_CVLAN_FILTER_DROP_INFO &&
+        (dev->flags & IFF_UP)))
          vlan_vid_del(dev, htons(ETH_P_8021Q), 0);
  
     vlan_info = rtnl_dereference(dev->vlan_info);

------
Best regards
Dong Chenchen

>> +		}
>>   		err = vlan_filter_push_vids(vlan_info, htons(ETH_P_8021Q));
>>   		if (err)
>>   			return notifier_from_errno(err);
>>   		break;
>>   
>>   	case NETDEV_CVLAN_FILTER_DROP_INFO:
>> +		flgs = dev_get_flags(dev);
>> +		if (flgs & IFF_UP)
>> +			vlan_vid_del(dev, htons(ETH_P_8021Q), 0);
>>   		vlan_filter_drop_vids(vlan_info, htons(ETH_P_8021Q));

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ