tipc: Fix unsafe device list search when enabling bearer
authorAllan Stephens <allan.stephens@windriver.com>
Fri, 27 May 2011 17:59:17 +0000 (13:59 -0400)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Sun, 18 Sep 2011 02:55:05 +0000 (22:55 -0400)
Ensures that the device list lock is held while trying to locate
the Ethernet device used by a newly enabled bearer, so that the
addition or removal of a device does not cause problems.

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
net/tipc/eth_media.c

index b69092eb95d8af2681e5f1475da5954971396a2b..69bedd8a297b966c33a2ff989aa504055df79f03 100644 (file)
@@ -2,7 +2,7 @@
  * net/tipc/eth_media.c: Ethernet bearer support for TIPC
  *
  * Copyright (c) 2001-2007, Ericsson AB
- * Copyright (c) 2005-2007, Wind River Systems
+ * Copyright (c) 2005-2008, 2011, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -144,12 +144,15 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
 
        /* Find device with specified name */
 
+       read_lock(&dev_base_lock);
        for_each_netdev(&init_net, pdev) {
                if (!strncmp(pdev->name, driver_name, IFNAMSIZ)) {
                        dev = pdev;
+                       dev_hold(dev);
                        break;
                }
        }
+       read_unlock(&dev_base_lock);
        if (!dev)
                return -ENODEV;
 
@@ -166,7 +169,6 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
                eb_ptr->tipc_packet_type.func = recv_msg;
                eb_ptr->tipc_packet_type.af_packet_priv = eb_ptr;
                INIT_LIST_HEAD(&(eb_ptr->tipc_packet_type.list));
-               dev_hold(dev);
                dev_add_pack(&eb_ptr->tipc_packet_type);
        }