Skip to contentSkip to conversation

bridge: mcast: Fail MDB get request on empty entry

PATCH Applied Ido Schimmel 3 participants 3 messages Sep 29, 2024 – Oct 3, 2024

Subsystems (3)
lore
Share & tools
lore

Ido Schimmel

author maintainer
#0 lore raw

PATCH 1/1 bridge: mcast: Fail MDB get request on empty entry

When user space deletes a port from an MDB entry, the port is removed synchronously. If this was the last port in the entry and the entry is not joined by the host itself, then the entry is scheduled for deletion via a timer.

The above means that it is possible for the MDB get netlink request to retrieve an empty entry which is scheduled for deletion. This is problematic as after deleting the last port in an entry, user space cannot rely on a non-zero return code from the MDB get request as an indication that the port was successfully removed.

Fix by returning an error when the entry's port list is empty and the entry is not joined by the host.

---
 net/bridge/br_mdb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_mdb.c +1 -1
index bc37e47ad829..1a52a0bca086 100644
@@ -1674,7 +1674,7 @@ int br_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, u32 seq,
 	spin_lock_bh(&br->multicast_lock);
 
 	mp = br_mdb_ip_get(br, &group);
-	if (!mp) {
+	if (!mp || (!mp->ports && !mp->host_joined)) {
 		NL_SET_ERR_MSG_MOD(extack, "MDB entry not found");
 		err = -ENOENT;
 		goto unlock;
Signature · 1 line
2.46.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Ido Schimmel

When user space deletes a port from an MDB entry, the port is removed synchronously. If this was the last port in the entry and the entry is not joined by the host itself, then the entry is scheduled for deletion via a timer.

The above means that it is possible for the MDB get netlink request to retrieve an empty entry which is scheduled for deletion. This is problematic as after deleting the last port in an entry, user space cannot rely on a non-zero return code from the MDB get request as an indication that the port was successfully removed.

Fix by returning an error when the entry's port list is empty and the entry is not joined by the host.

---
 net/bridge/br_mdb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_mdb.c +0 -0
index bc37e47ad829..1a52a0bca086 100644

net/bridge/br_mdb.c int br_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, u32 seq, · line 1680

Quoted 8 lines
net/bridge/br_mdb.c +1 -1
@@ -1674,7 +1674,7 @@ int br_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, u32 seq,
 	spin_lock_bh(&br->multicast_lock);
 
 	mp = br_mdb_ip_get(br, &group);
-	if (!mp) {
+	if (!mp || (!mp->ports && !mp->host_joined)) {
 		NL_SET_ERR_MSG_MOD(extack, "MDB entry not found");
 		err = -ENOENT;
 		goto unlock;
#2 lore raw
In reply to Ido Schimmel
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Sun, 29 Sep 2024 15:36:40 +0300 you wrote:

When user space deletes a port from an MDB entry, the port is removed synchronously. If this was the last port in the entry and the entry is not joined by the host itself, then the entry is scheduled for deletion via a timer.

Quoted 7 lines

The above means that it is possible for the MDB get netlink request to retrieve an empty entry which is scheduled for deletion. This is problematic as after deleting the last port in an entry, user space cannot rely on a non-zero return code from the MDB get request as an indication that the port was successfully removed.

[...]

Here is the summary with links:
- [net] bridge: mcast: Fail MDB get request on empty entry

    https://git.kernel.org/netdev/net/c/555f45d24ba7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html