Re: [Bridge] [PATCH net-next v3 00/16] bridge: Limit number of MDB entries per port, port-vlan

2023-02-06 Thread patchwork-bot+netdevbpf
Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller :

On Thu, 2 Feb 2023 18:59:18 +0100 you wrote:
> The MDB maintained by the bridge is limited. When the bridge is configured
> for IGMP / MLD snooping, a buggy or malicious client can easily exhaust its
> capacity. In SW datapath, the capacity is configurable through the
> IFLA_BR_MCAST_HASH_MAX parameter, but ultimately is finite. Obviously a
> similar limit exists in the HW datapath for purposes of offloading.
> 
> In order to prevent the issue of unilateral exhaustion of MDB resources,
> introduce two parameters in each of two contexts:
> 
> [...]

Here is the summary with links:
  - [net-next,v3,01/16] net: bridge: Set strict_start_type at two policies
https://git.kernel.org/netdev/net-next/c/c00041cf1cb8
  - [net-next,v3,02/16] net: bridge: Add extack to br_multicast_new_port_group()
https://git.kernel.org/netdev/net-next/c/60977a0c6337
  - [net-next,v3,03/16] net: bridge: Move extack-setting to 
br_multicast_new_port_group()
https://git.kernel.org/netdev/net-next/c/1c85b80b20a1
  - [net-next,v3,04/16] net: bridge: Add br_multicast_del_port_group()
https://git.kernel.org/netdev/net-next/c/976b3858dd14
  - [net-next,v3,05/16] net: bridge: Change a cleanup in 
br_multicast_new_port_group() to goto
https://git.kernel.org/netdev/net-next/c/eceb30854f6b
  - [net-next,v3,06/16] net: bridge: Add a tracepoint for MDB overflows
https://git.kernel.org/netdev/net-next/c/d47230a3480a
  - [net-next,v3,07/16] net: bridge: Maintain number of MDB entries in 
net_bridge_mcast_port
https://git.kernel.org/netdev/net-next/c/b57e8d870d52
  - [net-next,v3,08/16] net: bridge: Add netlink knobs for number / maximum MDB 
entries
https://git.kernel.org/netdev/net-next/c/a1aee20d5db2
  - [net-next,v3,09/16] selftests: forwarding: Move IGMP- and MLD-related 
functions to lib
https://git.kernel.org/netdev/net-next/c/344dd2c9e743
  - [net-next,v3,10/16] selftests: forwarding: bridge_mdb: Fix a typo
https://git.kernel.org/netdev/net-next/c/f7ccf60c4ada
  - [net-next,v3,11/16] selftests: forwarding: lib: Add helpers for IP address 
handling
https://git.kernel.org/netdev/net-next/c/fcf4927632ee
  - [net-next,v3,12/16] selftests: forwarding: lib: Add helpers for checksum 
handling
https://git.kernel.org/netdev/net-next/c/952e0ee38c72
  - [net-next,v3,13/16] selftests: forwarding: lib: Parameterize IGMPv3/MLDv2 
generation
https://git.kernel.org/netdev/net-next/c/506a1ac9d32b
  - [net-next,v3,14/16] selftests: forwarding: lib: Allow list of IPs for 
IGMPv3/MLDv2
https://git.kernel.org/netdev/net-next/c/705d4bc7b6b6
  - [net-next,v3,15/16] selftests: forwarding: lib: Add helpers to build 
IGMP/MLD leave packets
https://git.kernel.org/netdev/net-next/c/9ae854697317
  - [net-next,v3,16/16] selftests: forwarding: bridge_mdb_max: Add a new 
selftest
https://git.kernel.org/netdev/net-next/c/3446dcd7df05

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




[Bridge] [PATCH net-next v3 00/16] bridge: Limit number of MDB entries per port, port-vlan

2023-02-02 Thread Petr Machata via Bridge
The MDB maintained by the bridge is limited. When the bridge is configured
for IGMP / MLD snooping, a buggy or malicious client can easily exhaust its
capacity. In SW datapath, the capacity is configurable through the
IFLA_BR_MCAST_HASH_MAX parameter, but ultimately is finite. Obviously a
similar limit exists in the HW datapath for purposes of offloading.

In order to prevent the issue of unilateral exhaustion of MDB resources,
introduce two parameters in each of two contexts:

- Per-port and (when BROPT_MCAST_VLAN_SNOOPING_ENABLED is enabled)
  per-port-VLAN number of MDB entries that the port is member in.

- Per-port and (when BROPT_MCAST_VLAN_SNOOPING_ENABLED is enabled)
  per-port-VLAN maximum permitted number of MDB entries, or 0 for
  no limit.

Per-port number of entries keeps track of the total number of MDB entries
configured on a given port. The per-port-VLAN value then keeps track of the
subset of MDB entries configured specifically for the given VLAN, on that
port. The number is adjusted as port_groups are created and deleted, and
therefore under multicast lock.

A maximum value, if non-zero, then places a limit on the number of entries
that can be configured in a given context. Attempts to add entries above
the maximum are rejected.

Rejection reason of netlink-based requests to add MDB entries is
communicated through extack. This channel is unavailable for rejections
triggered from the control path. To address this lack of visibility, the
patchset adds a tracepoint, bridge:br_mdb_full:

# perf record -e bridge:br_mdb_full &
# [...]
# perf script | cut -d: -f4-
 dev v2 af 2 src :::0.0.0.0 grp 
:::239.1.1.112/00:00:00:00:00:00 vid 0
 dev v2 af 10 src :: grp ff0e::112/00:00:00:00:00:00 vid 0
 dev v2 af 2 src :::0.0.0.0 grp 
:::239.1.1.112/00:00:00:00:00:00 vid 10
 dev v2 af 10 src 2001:db8:1::1 grp ff0e::1/00:00:00:00:00:00 vid 10
 dev v2 af 2 src :::192.0.2.1 grp 
:::239.1.1.1/00:00:00:00:00:00 vid 10

Another option to consume the tracepoint is e.g. through the bpftrace tool:

# bpftrace -e ' tracepoint:bridge:br_mdb_full /args->af != 0/ {
printf("dev %s src %s grp %s vid %u\n",
   str(args->dev), ntop(args->src),
   ntop(args->grp), args->vid);
}
tracepoint:bridge:br_mdb_full /args->af == 0/ {
printf("dev %s grp %s vid %u\n",
   str(args->dev),
   macaddr(args->grpmac), args->vid);
}'

This tracepoint is triggered for mcast_hash_max exhaustions as well.

The following is an example of how the feature is used. A more extensive
example is available in patch #8:

# bridge vlan set dev v1 vid 1 mcast_max_groups 1
# bridge mdb add dev br port v1 grp 230.1.2.3 temp vid 1
# bridge mdb add dev br port v1 grp 230.1.2.4 temp vid 1
Error: bridge: Port-VLAN is already in 1 groups, and mcast_max_groups=1.

The patchset progresses as follows:

- In patch #1, set strict_start_type at two bridge-related policies. The
  reason is we are adding a new attribute to one of these, and want the new
  attribute to be parsed strictly. The other was adjusted for completeness'
  sake.

- In patches #2 to #5, br_mdb and br_multicast code is adjusted to make the
  following additions smoother.

- In patch #6, add the tracepoint.

- In patch #7, the code to maintain number of MDB entries is added as
  struct net_bridge_mcast_port::mdb_n_entries. The maximum is added, too,
  as struct net_bridge_mcast_port::mdb_max_entries, however at this point
  there is no way to set the value yet, and since 0 is treated as "no
  limit", the functionality doesn't change at this point. Note however,
  that mcast_hash_max violations already do trigger at this point.

- In patch #8, netlink plumbing is added: reading of number of entries, and
  reading and writing of maximum.

  The per-port values are passed through RTM_NEWLINK / RTM_GETLINK messages
  in IFLA_BRPORT_MCAST_N_GROUPS and _MAX_GROUPS, inside IFLA_PROTINFO nest.

  The per-port-vlan values are passed through RTM_GETVLAN / RTM_NEWVLAN
  messages in BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS, _MAX_GROUPS, inside
  BRIDGE_VLANDB_ENTRY.

The following patches deal with the selftest:

- Patches #9 and #10 clean up and move around some selftest code.

- Patches #11 to #14 add helpers and generalize the existing IGMP / MLD
  support to allow generating packets with configurable group addresses and
  varying source lists for (S,G) memberships.

- Patch #15 adds code to generate IGMP leave and MLD done packets.

- Patch #16 finally adds the selftest itself.

v3:
- Patch #7:
- Access mdb_max_/_n_entries through READ_/WRITE_ONCE
- Move extack setting to br_multicast_port_ngroups_inc_one().
  Since we use