`set_port` in netlink.c races with `open` in device.c. This can cause the following code flow:
* thread 1: set_port: device is not up * thread 2: device is opened * thread 2: open: called and calls socket_init with the original port * thread 1: set_port: sets incoming_port to the new port and returns incoming_port is then inconsistent. While this is not particularly critical, it will become more critial when ste_port also sets the transit namespace. --- src/device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 72b93c7..49f9634 100644 --- a/src/device.c +++ b/src/device.c @@ -53,17 +53,18 @@ static int open(struct net_device *dev) #endif #endif + mutex_lock(&wg->device_update_lock); ret = wg_socket_init(wg, wg->incoming_port); if (ret < 0) - return ret; - mutex_lock(&wg->device_update_lock); + goto out; list_for_each_entry (peer, &wg->peer_list, peer_list) { wg_packet_send_staged_packets(peer); if (peer->persistent_keepalive_interval) wg_packet_send_keepalive(peer); } +out: mutex_unlock(&wg->device_update_lock); - return 0; + return ret; } #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_ANDROID) -- 2.19.0 _______________________________________________ WireGuard mailing list WireGuard@lists.zx2c4.com https://lists.zx2c4.com/mailman/listinfo/wireguard