ofproto-dpif: Discard any flow_miss_batches before destroy a ofproto
authorAndy Zhou <azhou@nicira.com>
Fri, 28 Feb 2014 01:15:07 +0000 (17:15 -0800)
committerAndy Zhou <azhou@nicira.com>
Fri, 28 Feb 2014 20:42:58 +0000 (12:42 -0800)
Commit dd2e44f835fac8 fixed a similar race conditions w.r.t.
removal of 'ofproto', but reintroduced this bug. While 'ofproto'
is being removed, the existing flow_miss_batches may still contain
references to the to be removed 'ofproto', causing access to freed
memory.

Bug #1202234

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ofproto/ofproto-dpif-upcall.c
ofproto/ofproto-dpif.c

index 7ec7e8d..6adc78e 100644 (file)
@@ -224,8 +224,8 @@ void
 udpif_synchronize(struct udpif *udpif)
 {
     /* This is stronger than necessary.  It would be sufficient to ensure
-     * (somehow) that each handler and revalidator thread had passed through
-     * its main loop once. */
+     * (somehow) that each handler thread had passed through its main
+     * loop once. */
     size_t n_handlers = udpif->n_handlers;
     if (n_handlers) {
         udpif_recv_set(udpif, 0, false);
index cf421ae..ede7533 100644 (file)
@@ -1411,6 +1411,10 @@ destruct(struct ofproto *ofproto_)
      * to the ofproto or anything in it. */
     udpif_synchronize(ofproto->backer->udpif);
 
+    /* Discard any flow_miss_batches queued up for 'ofproto', avoiding a
+     * use-after-free error. */
+    udpif_revalidate(ofproto->backer->udpif);
+
     hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node);
 
     OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {