Skip to content

Commit d73ef2d

Browse files
f0rm2l1nkuba-moo
authored andcommitted
rtnetlink: let rtnl_bridge_setlink checks IFLA_BRIDGE_MODE length
There are totally 9 ndo_bridge_setlink handlers in the current kernel, which are 1) bnxt_bridge_setlink, 2) be_ndo_bridge_setlink 3) i40e_ndo_bridge_setlink 4) ice_bridge_setlink 5) ixgbe_ndo_bridge_setlink 6) mlx5e_bridge_setlink 7) nfp_net_bridge_setlink 8) qeth_l2_bridge_setlink 9) br_setlink. By investigating the code, we find that 1-7 parse and use nlattr IFLA_BRIDGE_MODE but 3 and 4 forget to do the nla_len check. This can lead to an out-of-attribute read and allow a malformed nlattr (e.g., length 0) to be viewed as a 2 byte integer. To avoid such issues, also for other ndo_bridge_setlink handlers in the future. This patch adds the nla_len check in rtnl_bridge_setlink and does an early error return if length mismatches. To make it works, the break is removed from the parsing for IFLA_BRIDGE_FLAGS to make sure this nla_for_each_nested iterates every attribute. Fixes: b1edc14 ("ice: Implement ice_bridge_getlink and ice_bridge_setlink") Fixes: 5161601 ("i40e: Add support for getlink, setlink ndo ops") Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Lin Ma <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Reviewed-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 57012c5 commit d73ef2d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/core/rtnetlink.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5140,13 +5140,17 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
51405140
br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
51415141
if (br_spec) {
51425142
nla_for_each_nested(attr, br_spec, rem) {
5143-
if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
5143+
if (nla_type(attr) == IFLA_BRIDGE_FLAGS && !have_flags) {
51445144
if (nla_len(attr) < sizeof(flags))
51455145
return -EINVAL;
51465146

51475147
have_flags = true;
51485148
flags = nla_get_u16(attr);
5149-
break;
5149+
}
5150+
5151+
if (nla_type(attr) == IFLA_BRIDGE_MODE) {
5152+
if (nla_len(attr) < sizeof(u16))
5153+
return -EINVAL;
51505154
}
51515155
}
51525156
}

0 commit comments

Comments
 (0)