ofproto-dpif: Fix use-after-free for OFPP_CONTROLLER flows.
authorBen Pfaff <blp@nicira.com>
Fri, 16 Dec 2011 18:09:30 +0000 (10:09 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 16 Dec 2011 18:22:30 +0000 (10:22 -0800)
commit918769dda1ede0c88d6cce287b4d7e7cac5cd390
tree58899795f251bcf21b7fe0cbfa242b4496998bcc
parent6e8da577277b1ad352a7d7fe9ad83d06443d24bc
ofproto-dpif: Fix use-after-free for OFPP_CONTROLLER flows.

When a flow consists solely of an output to OFPP_CONTROLLER, we avoid a
round trip to the kernel and back by calling execute_controller_action()
from handle_flow_miss().  However, execute_controller_action() frees the
packet passed in.  This is dangerous, because the packet and the upcall
key are in the same block of malloc()'d memory, as the comment on struct
dpif_upcall says:

/* A packet passed up from the datapath to userspace.
 *
 * If 'key' or 'actions' is nonnull, then it points into data owned by
 * 'packet', so their memory cannot be freed separately.  (This is hardly a
 * great way to do things but it works out OK for the dpif providers and
 * clients that exist so far.)
 */

Thus, we get a use-after-free later on in handle_flow_miss() and eventually
a double free.

This fixes the problem by making execute_controller_action() clone the
packet in this case.

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