Skip to content

Commit 5857d1d

Browse files
alexaringholtmann
authored andcommitted
Bluetooth: 6lowpan: Fix possible race
This patch fix a possible race after calling register_netdev. After calling netdev_register it could be possible that netdev_ops callbacks use the uninitialized private data of lowpan_dev. By moving the initialization of this data before netdev_register we can be sure that initialized private data is be used after netdev_register. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent c22ff7b commit 5857d1d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

net/bluetooth/6lowpan.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,22 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
859859
SET_NETDEV_DEV(netdev, &chan->conn->hcon->hdev->dev);
860860
SET_NETDEV_DEVTYPE(netdev, &bt_type);
861861

862+
*dev = netdev_priv(netdev);
863+
(*dev)->netdev = netdev;
864+
(*dev)->hdev = chan->conn->hcon->hdev;
865+
INIT_LIST_HEAD(&(*dev)->peers);
866+
867+
spin_lock(&devices_lock);
868+
INIT_LIST_HEAD(&(*dev)->list);
869+
list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
870+
spin_unlock(&devices_lock);
871+
862872
err = register_netdev(netdev);
863873
if (err < 0) {
864874
BT_INFO("register_netdev failed %d", err);
875+
spin_lock(&devices_lock);
876+
list_del_rcu(&(*dev)->list);
877+
spin_unlock(&devices_lock);
865878
free_netdev(netdev);
866879
goto out;
867880
}
@@ -871,16 +884,6 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
871884
&chan->src, chan->src_type);
872885
set_bit(__LINK_STATE_PRESENT, &netdev->state);
873886

874-
*dev = netdev_priv(netdev);
875-
(*dev)->netdev = netdev;
876-
(*dev)->hdev = chan->conn->hcon->hdev;
877-
INIT_LIST_HEAD(&(*dev)->peers);
878-
879-
spin_lock(&devices_lock);
880-
INIT_LIST_HEAD(&(*dev)->list);
881-
list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
882-
spin_unlock(&devices_lock);
883-
884887
return 0;
885888

886889
out:

0 commit comments

Comments
 (0)