net: bridge: mcast: Do not allow users to set IGMP counter/timer to zero
Subsystems (2)
PATCH 1/1 net: bridge: mcast: Do not allow users to set IGMP counter/timer to zero
There is no meaning to set an IGMP counter/timer to 0. Or it will cause unexpected behavior. E.g. if set multicast_membership_interval to 0, bridge will remove the mdb immediately after adding.
--- net/bridge/br_netlink.c | 73 +++++++++++++++++++++++++++++--------- net/bridge/br_sysfs_br.c | 75 +++++++++++++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 32 deletions(-)
net/bridge/br_netlink.c +57 -16
@@ -1168,6 +1168,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct net_bridge *br =netdev_priv (brdev); +struct net_bridge_mcast *brmctx = &br->multicast_ctx;int err;if (!data)
@@ -1287,8 +1288,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],if (data[IFLA_BR_MCAST_ROUTER ]) {u8 multicast_router =nla_get_u8 (data[IFLA_BR_MCAST_ROUTER ]); - err =br_multicast_set_router (&br->multicast_ctx, - multicast_router); + err =br_multicast_set_router (brmctx, multicast_router);if (err)return err; }
@@ -1311,8 +1311,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],if (data[IFLA_BR_MCAST_QUERIER ]) {u8 mcast_querier =nla_get_u8 (data[IFLA_BR_MCAST_QUERIER ]); - err =br_multicast_set_querier (&br->multicast_ctx, - mcast_querier); + err =br_multicast_set_querier (brmctx, mcast_querier);if (err)return err; }
@@ -1327,49 +1326,93 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],if (data[IFLA_BR_MCAST_LAST_MEMBER_CNT ]) {u32 val =nla_get_u32 (data[IFLA_BR_MCAST_LAST_MEMBER_CNT ]); - br->multicast_ctx.multicast_last_member_count = val; +if (val) { + brmctx->multicast_last_member_count = val; + }else { +NL_SET_ERR_MSG (extack,"Invalid Last Member Count" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_STARTUP_QUERY_CNT ]) {u32 val =nla_get_u32 (data[IFLA_BR_MCAST_STARTUP_QUERY_CNT ]); - br->multicast_ctx.multicast_startup_query_count = val; +if (val) { + brmctx->multicast_startup_query_count = val; + }else { +NL_SET_ERR_MSG (extack,"Invalid Startup Query Count" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_LAST_MEMBER_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_LAST_MEMBER_INTVL ]); - br->multicast_ctx.multicast_last_member_interval =clock_t_to_jiffies (val); +if (val) { + brmctx->multicast_last_member_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Last Member Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_MEMBERSHIP_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_MEMBERSHIP_INTVL ]); - br->multicast_ctx.multicast_membership_interval =clock_t_to_jiffies (val); +if (val) { + brmctx->multicast_membership_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Membership Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_QUERIER_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_QUERIER_INTVL ]); - br->multicast_ctx.multicast_querier_interval =clock_t_to_jiffies (val); +if (val) { + brmctx->multicast_querier_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Querier Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_QUERY_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_QUERY_INTVL ]); - br->multicast_ctx.multicast_query_interval =clock_t_to_jiffies (val); +if (val &&clock_t_to_jiffies (val) > brmctx->multicast_query_response_interval) { + brmctx->multicast_query_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Query Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL ]); - br->multicast_ctx.multicast_query_response_interval =clock_t_to_jiffies (val); +/* RFC3376 8.3: The number of seconds represented by the +* [Query Response Interval] must be less than the [Query +* Interval]. +*/ +if (val &&clock_t_to_jiffies (val) < brmctx->multicast_query_interval) { + brmctx->multicast_query_response_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Query Response Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL ]) {u64 val =nla_get_u64 (data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL ]); - br->multicast_ctx.multicast_startup_query_interval =clock_t_to_jiffies (val); +if (val) { + brmctx->multicast_startup_query_interval =clock_t_to_jiffies (val); + }else { +NL_SET_ERR_MSG (extack,"Invalid Startup Query Interval" ); +return -EINVAL ; + } }if (data[IFLA_BR_MCAST_STATS_ENABLED ]) {
@@ -1383,8 +1426,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],__u8 igmp_version; igmp_version =nla_get_u8 (data[IFLA_BR_MCAST_IGMP_VERSION ]); - err =br_multicast_set_igmp_version (&br->multicast_ctx, - igmp_version); + err =br_multicast_set_igmp_version (brmctx, igmp_version);if (err)return err; }
@@ -1394,8 +1436,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],__u8 mld_version; mld_version =nla_get_u8 (data[IFLA_BR_MCAST_MLD_VERSION ]); - err =br_multicast_set_mld_version (&br->multicast_ctx, - mld_version); + err =br_multicast_set_mld_version (brmctx, mld_version);if (err)return err; }
net/bridge/br_sysfs_br.c +59 -16
123 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 4 lines · Hangbin Liu
There is no meaning to set an IGMP counter/timer to 0. Or it will cause unexpected behavior. E.g. if set
multicast_membership_intervalto 0, bridge will remove the mdb immediately after adding.
Quoted 9 lines
Fixes 79b859f573d6 ("bridge: netlink: add support for multicast_last_member_count")Fixes b89e6babad4b ("bridge: netlink: add support for multicast_startup_query_count")Fixes 7e4df51eb35d ("bridge: netlink: add support for igmp's intervals")Signed-off-by Hangbin Liu <[email protected]>--- net/bridge/br_netlink.c | 73 +++++++++++++++++++++++++++++--------- net/bridge/br_sysfs_br.c | 75 +++++++++++++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 32 deletions(-)
For a few reasons,
I'll start with the obvious that - yes, users are allowed to change the values to non-RFC compliant, but we cannot change that now as we'd risk breaking user-space which is probably doing that somewhere with some of the values below. We can fix any issues that might arise from doing it though, so it doesn't affect normal operation. If changing some of the options to 0 or to unreasonably high values lead to problems let's fix those and we could discuss adding constraints there if necessary.
The second issue is that you're mixing different checks below, you say do not allow zero but you're also checking for RFC compliance between different values.
The third issue is that you haven't done the same change for the same values for per-vlan multicast options (we have the same options per-vlan as well).
Your fixes tags are wrong, too. Most of these values could be set well before they were available through netlink.
Note on the style - generally I'd add helpers to set them and add the constraints in those helpers, so they can be used for both netlink and sysfs. It would definitely target net-next unless it's an actual bug fix.
Thanks,
Nik
Hi Nikolay,
Quoted 17 lines · Nikolay Aleksandrov
Quoted 4 lines · Hangbin Liu
There is no meaning to set an IGMP counter/timer to 0. Or it will cause unexpected behavior. E.g. if set
multicast_membership_intervalto 0, bridge will remove the mdb immediately after adding.Quoted 9 lines
Fixes 79b859f573d6 ("bridge: netlink: add support for multicast_last_member_count")Fixes b89e6babad4b ("bridge: netlink: add support for multicast_startup_query_count")Fixes 7e4df51eb35d ("bridge: netlink: add support for igmp's intervals")Signed-off-by Hangbin Liu <[email protected]>--- net/bridge/br_netlink.c | 73 +++++++++++++++++++++++++++++--------- net/bridge/br_sysfs_br.c | 75 +++++++++++++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 32 deletions(-)Nacked-by Nikolay Aleksandrov <[email protected]>
Quoted 7 lines
For a few reasons,
I'll start with the obvious that - yes, users are allowed to change the values to non-RFC compliant, but we cannot change that now as we'd risk breaking user-space which is probably doing that somewhere with some of the values below. We can fix any issues that might arise from doing it though, so it doesn't affect normal operation. If changing some of the options to 0 or to unreasonably high values lead to problems let's fix those and we could discuss adding constraints there if necessary.
I started this patch when I saw there is not limit for setting multicast_membership_interval to 0, which will cause bridge remove the mdb directly after adding. Do you think this is a problem.
And what about others? I don't think there is a meaning to set other intervals to 0.
Quoted 3 lines
The second issue is that you're mixing different checks below, you say do not allow zero but you're also checking for RFC compliance between different values.
Do you mean the RFC3376 8.3 rule? I can fix it in another patch.
Quoted 3 lines
The third issue is that you haven't done the same change for the same values for per-vlan multicast options (we have the same options per-vlan as well).
Ah, thanks, I could fix that.
Quoted 3 lines
Your fixes tags are wrong, too. Most of these values could be set well before they were available through netlink.
Oh... Then how should I set the fixes tag? Since I want fix both the netlink configs and sys configs. Add a new one d902eee43f19 ("bridge: Add multicast count/interval sysfs entries")
Quoted 4 lines
Note on the style - generally I'd add helpers to set them and add the constraints in those helpers, so they can be used for both netlink and sysfs. It would definitely target net-next unless it's an actual bug fix.
How about a helper like:
int br_multicast_set_interval(unsigned long *mcast_val, u64 val)
{
if (val) {
mcast_val = clock_t_to_jiffies(val);
return 0;
} else {
NL_SET_ERR_MSG(extack, "Invalid multicast interval, should not be 0");
return -EINVAL;
}
}Thanks
Hangbin
Quoted 28 lines · Hangbin Liu
Hi Nikolay,
Quoted 17 lines · Nikolay Aleksandrov
Quoted 4 lines · Hangbin Liu
There is no meaning to set an IGMP counter/timer to 0. Or it will cause unexpected behavior. E.g. if set
multicast_membership_intervalto 0, bridge will remove the mdb immediately after adding.Quoted 9 lines
Fixes 79b859f573d6 ("bridge: netlink: add support for multicast_last_member_count")Fixes b89e6babad4b ("bridge: netlink: add support for multicast_startup_query_count")Fixes 7e4df51eb35d ("bridge: netlink: add support for igmp's intervals")Signed-off-by Hangbin Liu <[email protected]>--- net/bridge/br_netlink.c | 73 +++++++++++++++++++++++++++++--------- net/bridge/br_sysfs_br.c | 75 +++++++++++++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 32 deletions(-)Nacked-by Nikolay Aleksandrov <[email protected]>Quoted 7 lines
For a few reasons,
I'll start with the obvious that - yes, users are allowed to change the values to non-RFC compliant, but we cannot change that now as we'd risk breaking user-space which is probably doing that somewhere with some of the values below. We can fix any issues that might arise from doing it though, so it doesn't affect normal operation. If changing some of the options to 0 or to unreasonably high values lead to problems let's fix those and we could discuss adding constraints there if necessary.
Quoted 7 lines
I started this patch when I saw there is not limit for setting
multicast_membership_intervalto 0, which will cause bridge remove the mdb directly after adding. Do you think this is a problem.And what about others? I don't think there is a meaning to set other intervals to 0.
The problem is not if there is meaning, we cannot start restricting option values now after they've become uapi (and have been for a very long time) because we can break user-space even though chances are pretty low. I don't think this patch is acceptable, I commented on the other patch issues but they don't matter because of this.
Thanks,
Nik
Quoted 4 lines · Nikolay Aleksandrov
Quoted 4 lines
I started this patch when I saw there is not limit for setting
multicast_membership_intervalto 0, which will cause bridge remove the mdb directly after adding. Do you think this is a problem.
Quoted 8 lines
Quoted 3 lines
And what about others? I don't think there is a meaning to set other intervals to 0.
The problem is not if there is meaning, we cannot start restricting option values now after they've become uapi (and have been for a very long time) because we can break user-space even though chances are pretty low. I don't think this patch is acceptable, I commented on the other patch issues but they don't matter because of this.
OK, I got your mean, we should not restrict the configurations based on whether there is a meaning.
Thanks
Hangbin
Quoted 14 lines · On Wed, 20 Oct 2021 09:02:01 +0800 Hangbin Liu <[email protected]> wrote:
Quoted 4 lines · Nikolay Aleksandrov
Quoted 4 lines
I started this patch when I saw there is not limit for setting
multicast_membership_intervalto 0, which will cause bridge remove the mdb directly after adding. Do you think this is a problem.Quoted 8 lines
Quoted 3 lines
And what about others? I don't think there is a meaning to set other intervals to 0.
The problem is not if there is meaning, we cannot start restricting option values now after they've become uapi (and have been for a very long time) because we can break user-space even though chances are pretty low. I don't think this patch is acceptable, I commented on the other patch issues but they don't matter because of this.
Quoted 5 lines
OK, I got your mean, we should not restrict the configurations based on whether there is a meaning.
Thanks
Hangbin
Maybe the bridge command could enforce that the value set are sane relative to the RFC? We already fixup some things in iproute2 utilities to workaround places where changing defaults in kernel would break userspace.
Quoted 17 lines · Stephen Hemminger
Quoted 17 lines · Nikolay Aleksandrov
Quoted 4 lines
Quoted 4 lines
I started this patch when I saw there is not limit for setting
multicast_membership_intervalto 0, which will cause bridge remove the mdb directly after adding. Do you think this is a problem.Quoted 8 lines
Quoted 3 lines
And what about others? I don't think there is a meaning to set other intervals to 0.
The problem is not if there is meaning, we cannot start restricting option values now after they've become uapi (and have been for a very long time) because we can break user-space even though chances are pretty low. I don't think this patch is acceptable, I commented on the other patch issues but they don't matter because of this.
OK, I got your mean, we should not restrict the configurations based on whether there is a meaning.
Quoted 6 lines
Quoted 2 lines
Thanks
HangbinMaybe the bridge command could enforce that the value set are sane relative to the RFC? We already fixup some things in iproute2 utilities to workaround places where changing defaults in kernel would break userspace.
I'm afraid this may make user more confused. As user could also echo the values via sys fs directly. e.g.
# ip link set br0 type bridge mcast_query_interval 0 Error: Invalid QI, must greater than 0. # echo 0 > /sys/devices/virtual/net/br0/bridge/multicast_query_interval
Then ip -d link show br0 would show the mcast_query_interval is 0.
Thanks
Hangbin