Skip to content

Commit 4798cfa

Browse files
committed
net: don't try to ops lock uninitialized devs
We need to be careful when operating on dev while in rtnl_create_link(). Some devices (vxlan) initialize netdev_ops in ->newlink, so later on. Avoid using netdev_lock_ops(), the device isn't registered so we cannot legally call its ops or generate any notifications for it. netdev_ops_assert_locked_or_invisible() is safe to use, it checks registration status first. Reported-by: [email protected] Fixes: 04efcee ("net: hold instance lock during NETDEV_CHANGE") Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2a5970d commit 4798cfa

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

net/core/dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,8 @@ EXPORT_SYMBOL(netdev_features_change);
15201520

15211521
void netif_state_change(struct net_device *dev)
15221522
{
1523+
netdev_ops_assert_locked_or_invisible(dev);
1524+
15231525
if (dev->flags & IFF_UP) {
15241526
struct netdev_notifier_change_info change_info = {
15251527
.info.dev = dev,

net/core/rtnetlink.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,11 +3676,8 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
36763676
nla_len(tb[IFLA_BROADCAST]));
36773677
if (tb[IFLA_TXQLEN])
36783678
dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
3679-
if (tb[IFLA_OPERSTATE]) {
3680-
netdev_lock_ops(dev);
3679+
if (tb[IFLA_OPERSTATE])
36813680
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
3682-
netdev_unlock_ops(dev);
3683-
}
36843681
if (tb[IFLA_LINKMODE])
36853682
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
36863683
if (tb[IFLA_GROUP])

0 commit comments

Comments
 (0)