ofproto: Fix use-after-free error when ports disappear. branch-1.3
authorBen Pfaff <blp@nicira.com>
Mon, 23 Apr 2012 16:16:18 +0000 (09:16 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 23 Apr 2012 21:02:57 +0000 (14:02 -0700)
commitf2504a72f096d6cbd96b63584626ef1bd79d1044
treee433edaff43ba779f18e268eb9a33fb378090a6c
parent393828f12596207eb4924fa83bc4e56a2611480b
ofproto: Fix use-after-free error when ports disappear.

update_port() can delete the port for which it is called, if the underlying
network device has been destroyed, so HMAP_FOR_EACH is unsafe in
ofproto_run().

Less obviously, update_port() can delete unrelated ports.  For example,
suppose that initially device A is port 1 and device B is port 2.  If
update_port("A") runs just after this, then it will ofport_remove() both
ports, then ofport_install() A as the new port 2.

So this commit first assembles a list of ports to update, then updates them
in a separate loop.

Without this commit, running "ovs-dpctl del-dp" while ovs-vswitchd is
running consistently causes a crash for me within a few seconds.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ofproto/ofproto.c