netdev_get_vports() previously counted the number of ports outside the
mutex, allocated enough memory for that number, then grabbed the mutex
to iterate through them and filled the array with the pointers.

This is logically wrong; in theory the number of ports could change
between allocating the memory and grabbing the mutex. In practice, only
the main thread manages these so there is no chance for a segfault. Fix
it up anyway.

Signed-off-by: Joe Stringer <[email protected]>
---
 lib/netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/netdev.c b/lib/netdev.c
index 6c4c6571e295..b817ef1d4a4d 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1766,8 +1766,8 @@ netdev_get_vports(size_t *size)
     }
 
     /* Explicitly allocates big enough chunk of memory. */
-    vports = xmalloc(shash_count(&netdev_shash) * sizeof *vports);
     ovs_mutex_lock(&netdev_mutex);
+    vports = xmalloc(shash_count(&netdev_shash) * sizeof *vports);
     SHASH_FOR_EACH (node, &netdev_shash) {
         struct netdev *dev = node->data;
 
-- 
2.9.3

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to