Skip to content

Commit b0ad3c1

Browse files
lxinkuba-moo
authored andcommitted
rtnetlink: call validate_linkmsg in rtnl_create_link
validate_linkmsg() was introduced by commit 1840bb1 ("[RTNL]: Validate hardware and broadcast address attribute for RTM_NEWLINK") to validate tb[IFLA_ADDRESS/BROADCAST] for existing links. The same check should also be done for newly created links. This patch adds validate_linkmsg() call in rtnl_create_link(), to avoid the invalid address set when creating some devices like: # ip link add dummy0 type dummy # ip link add link dummy0 name mac0 address 01:02 type macsec Fixes: 0e06877 ("[RTNETLINK]: rtnl_link: allow specifying initial device address") Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent abaf8d5 commit b0ad3c1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

net/core/rtnetlink.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,7 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
32853285
struct net_device *dev;
32863286
unsigned int num_tx_queues = 1;
32873287
unsigned int num_rx_queues = 1;
3288+
int err;
32883289

32893290
if (tb[IFLA_NUM_TX_QUEUES])
32903291
num_tx_queues = nla_get_u32(tb[IFLA_NUM_TX_QUEUES]);
@@ -3320,13 +3321,18 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
33203321
if (!dev)
33213322
return ERR_PTR(-ENOMEM);
33223323

3324+
err = validate_linkmsg(dev, tb, extack);
3325+
if (err < 0) {
3326+
free_netdev(dev);
3327+
return ERR_PTR(err);
3328+
}
3329+
33233330
dev_net_set(dev, net);
33243331
dev->rtnl_link_ops = ops;
33253332
dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
33263333

33273334
if (tb[IFLA_MTU]) {
33283335
u32 mtu = nla_get_u32(tb[IFLA_MTU]);
3329-
int err;
33303336

33313337
err = dev_validate_mtu(dev, mtu, extack);
33323338
if (err) {

0 commit comments

Comments
 (0)