Skip to content

Commit e0cd06f

Browse files
idoschdavem330
authored andcommitted
rtnetlink: bridge: Use a different policy for MDB bulk delete
For MDB bulk delete we will need to validate 'MDBA_SET_ENTRY' differently compared to regular delete. Specifically, allow the ifindex to be zero (in case not filtering on bridge port) and force the address to be zero as bulk delete based on address is not supported. Do that by introducing a new policy and choosing the correct policy based on the presence of the 'NLM_F_BULK' flag in the netlink message header. Use nlmsg_parse() for strict validation. Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Petr Machata <petrm@nvidia.com> Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e37a11f commit e0cd06f

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

net/core/rtnetlink.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,17 +6410,64 @@ static int rtnl_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
64106410
return dev->netdev_ops->ndo_mdb_add(dev, tb, nlh->nlmsg_flags, extack);
64116411
}
64126412

6413+
static int rtnl_validate_mdb_entry_del_bulk(const struct nlattr *attr,
6414+
struct netlink_ext_ack *extack)
6415+
{
6416+
struct br_mdb_entry *entry = nla_data(attr);
6417+
struct br_mdb_entry zero_entry = {};
6418+
6419+
if (nla_len(attr) != sizeof(struct br_mdb_entry)) {
6420+
NL_SET_ERR_MSG_ATTR(extack, attr, "Invalid attribute length");
6421+
return -EINVAL;
6422+
}
6423+
6424+
if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY) {
6425+
NL_SET_ERR_MSG(extack, "Unknown entry state");
6426+
return -EINVAL;
6427+
}
6428+
6429+
if (entry->flags) {
6430+
NL_SET_ERR_MSG(extack, "Entry flags cannot be set");
6431+
return -EINVAL;
6432+
}
6433+
6434+
if (entry->vid >= VLAN_N_VID - 1) {
6435+
NL_SET_ERR_MSG(extack, "Invalid entry VLAN id");
6436+
return -EINVAL;
6437+
}
6438+
6439+
if (memcmp(&entry->addr, &zero_entry.addr, sizeof(entry->addr))) {
6440+
NL_SET_ERR_MSG(extack, "Entry address cannot be set");
6441+
return -EINVAL;
6442+
}
6443+
6444+
return 0;
6445+
}
6446+
6447+
static const struct nla_policy mdba_del_bulk_policy[MDBA_SET_ENTRY_MAX + 1] = {
6448+
[MDBA_SET_ENTRY] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
6449+
rtnl_validate_mdb_entry_del_bulk,
6450+
sizeof(struct br_mdb_entry)),
6451+
[MDBA_SET_ENTRY_ATTRS] = { .type = NLA_NESTED },
6452+
};
6453+
64136454
static int rtnl_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
64146455
struct netlink_ext_ack *extack)
64156456
{
6457+
bool del_bulk = !!(nlh->nlmsg_flags & NLM_F_BULK);
64166458
struct nlattr *tb[MDBA_SET_ENTRY_MAX + 1];
64176459
struct net *net = sock_net(skb->sk);
64186460
struct br_port_msg *bpm;
64196461
struct net_device *dev;
64206462
int err;
64216463

6422-
err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb,
6423-
MDBA_SET_ENTRY_MAX, mdba_policy, extack);
6464+
if (!del_bulk)
6465+
err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb,
6466+
MDBA_SET_ENTRY_MAX, mdba_policy,
6467+
extack);
6468+
else
6469+
err = nlmsg_parse(nlh, sizeof(*bpm), tb, MDBA_SET_ENTRY_MAX,
6470+
mdba_del_bulk_policy, extack);
64246471
if (err)
64256472
return err;
64266473

0 commit comments

Comments
 (0)