Commit ffa934f1 authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

rtnetlink: fix link attribute validation with IFLA_GROUP

rtnl_group_changelink() is invoked by rtnl_newlink() before the link
attributes have been validated. Additionally the group changes are
performed even if NLM_F_CREATE is specified and a new link is
created, while more reasonable semantics would be to set the group
value on the newly created link.

Fix both problems by moving the rtnl_group_changelink() invocation
down to the handling of non-existant links without NLM_F_CREATE()
and add a dev_set_group() call to rtnl_create_link().
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Acked-by: default avatarVlad Dogaru <ddvlad@rosedu.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d52344a7
...@@ -1548,6 +1548,8 @@ struct net_device *rtnl_create_link(struct net *src_net, struct net *net, ...@@ -1548,6 +1548,8 @@ struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
if (tb[IFLA_LINKMODE]) if (tb[IFLA_LINKMODE])
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
if (tb[IFLA_GROUP])
dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
return dev; return dev;
...@@ -1606,10 +1608,6 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1606,10 +1608,6 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
else { else {
if (ifname[0]) if (ifname[0])
dev = __dev_get_by_name(net, ifname); dev = __dev_get_by_name(net, ifname);
else if (tb[IFLA_GROUP])
return rtnl_group_changelink(net,
nla_get_u32(tb[IFLA_GROUP]),
ifm, tb);
else else
dev = NULL; dev = NULL;
} }
...@@ -1676,8 +1674,13 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1676,8 +1674,13 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
return do_setlink(dev, ifm, tb, ifname, modified); return do_setlink(dev, ifm, tb, ifname, modified);
} }
if (!(nlh->nlmsg_flags & NLM_F_CREATE)) if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
if (ifm->ifi_index == 0 && tb[IFLA_GROUP])
return rtnl_group_changelink(net,
nla_get_u32(tb[IFLA_GROUP]),
ifm, tb);
return -ENODEV; return -ENODEV;
}
if (ifm->ifi_index) if (ifm->ifi_index)
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment