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:11:50 +0000 (10:11 -0800)
commit9dd23c41ae4f273e57ad5621c5a8e947c5e56ae0
tree8a12e8bf90a9ba08796f8d52468dd716f45ff227
parented0a43ab99ae3ca8bbf0c12bcd0487a6715b6aa6
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