Skip to content

Commit f83a112

Browse files
Nikolay Aleksandrovkuba-moo
authored andcommitted
net: bridge: mcast: add and enforce startup query interval minimum
As reported[1] if startup query interval is set too low in combination with large number of startup queries and we have multiple bridges or even a single bridge with multiple querier vlans configured we can crash the machine. Add a 1 second minimum which must be enforced by overwriting the value if set lower (i.e. without returning an error) to avoid breaking user-space. If that happens a log message is emitted to let the admin know that the startup interval has been set to the minimum. It doesn't make sense to make the startup interval lower than the normal query interval so use the same value of 1 second. The issue has been present since these intervals could be user-controlled. [1] https://lore.kernel.org/netdev/[email protected]/ Fixes: d902eee ("bridge: Add multicast count/interval sysfs entries") Reported-by: Eric Dumazet <[email protected]> Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 99b4061 commit f83a112

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

net/bridge/br_multicast.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,6 +4538,22 @@ void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx,
45384538
brmctx->multicast_query_interval = intvl_jiffies;
45394539
}
45404540

4541+
void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx,
4542+
unsigned long val)
4543+
{
4544+
unsigned long intvl_jiffies = clock_t_to_jiffies(val);
4545+
4546+
if (intvl_jiffies < BR_MULTICAST_STARTUP_QUERY_INTVL_MIN) {
4547+
br_info(brmctx->br,
4548+
"trying to set multicast startup query interval below minimum, setting to %lu (%ums)\n",
4549+
jiffies_to_clock_t(BR_MULTICAST_STARTUP_QUERY_INTVL_MIN),
4550+
jiffies_to_msecs(BR_MULTICAST_STARTUP_QUERY_INTVL_MIN));
4551+
intvl_jiffies = BR_MULTICAST_STARTUP_QUERY_INTVL_MIN;
4552+
}
4553+
4554+
brmctx->multicast_startup_query_interval = intvl_jiffies;
4555+
}
4556+
45414557
/**
45424558
* br_multicast_list_adjacent - Returns snooped multicast addresses
45434559
* @dev: The bridge port adjacent to which to retrieve addresses

net/bridge/br_netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
13691369
if (data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]) {
13701370
u64 val = nla_get_u64(data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]);
13711371

1372-
br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
1372+
br_multicast_set_startup_query_intvl(&br->multicast_ctx, val);
13731373
}
13741374

13751375
if (data[IFLA_BR_MCAST_STATS_ENABLED]) {

net/bridge/br_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#define BR_MULTICAST_DEFAULT_HASH_MAX 4096
3131
#define BR_MULTICAST_QUERY_INTVL_MIN msecs_to_jiffies(1000)
32+
#define BR_MULTICAST_STARTUP_QUERY_INTVL_MIN BR_MULTICAST_QUERY_INTVL_MIN
3233

3334
#define BR_HWDOM_MAX BITS_PER_LONG
3435

@@ -966,6 +967,8 @@ size_t br_multicast_querier_state_size(void);
966967
size_t br_rports_size(const struct net_bridge_mcast *brmctx);
967968
void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx,
968969
unsigned long val);
970+
void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx,
971+
unsigned long val);
969972

970973
static inline bool br_group_is_l2(const struct br_ip *group)
971974
{

net/bridge/br_sysfs_br.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static ssize_t multicast_startup_query_interval_show(
706706
static int set_startup_query_interval(struct net_bridge *br, unsigned long val,
707707
struct netlink_ext_ack *extack)
708708
{
709-
br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
709+
br_multicast_set_startup_query_intvl(&br->multicast_ctx, val);
710710
return 0;
711711
}
712712

net/bridge/br_vlan_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static int br_vlan_process_global_one_opts(const struct net_bridge *br,
535535
u64 val;
536536

537537
val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL]);
538-
v->br_mcast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
538+
br_multicast_set_startup_query_intvl(&v->br_mcast_ctx, val);
539539
*changed = true;
540540
}
541541
if (tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER]) {

0 commit comments

Comments
 (0)