From patchwork Wed Jul 16 07:32:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pravin B Shelar X-Patchwork-Id: 370619 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 17BC014011B for ; Wed, 16 Jul 2014 17:32:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934111AbaGPHca (ORCPT ); Wed, 16 Jul 2014 03:32:30 -0400 Received: from na3sys009aog101.obsmtp.com ([74.125.149.67]:52045 "HELO na3sys009aog101.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S934044AbaGPHc2 (ORCPT ); Wed, 16 Jul 2014 03:32:28 -0400 Received: from mail-pd0-f171.google.com ([209.85.192.171]) (using TLSv1) by na3sys009aob101.postini.com ([74.125.148.12]) with SMTP ID DSNKU8YqjGqapyzd7D8hv9nQy5mMRoOUzt3s@postini.com; Wed, 16 Jul 2014 00:32:28 PDT Received: by mail-pd0-f171.google.com with SMTP id z10so772278pdj.2 for ; Wed, 16 Jul 2014 00:32:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bBK77u0m9+q6h8/BnoX2L0O+bna1ImcNuubK+Yzacgs=; b=UK2s/QRfWwT4JZvcx1iHe26y+08ibwCqgrsekJpRoRZmAUPdih74PMB8VpB4VWWlmG 5+86M+ISK40IiMRfv+ahdHl9wRzwifCAWeFiqhuhDoBZkqhkQJyyNx+PZTNGkg5tJ3eK KNY2jpuwjQISRCefKL5tzIXxOsMEgkUgCxx8S9kq6lEdNhdZkvz+1q0nx8ZIC8mY5vyR FU3WZxdnV8goqKSZjX72mk5Vrnxd9Z4NR5dMB1mBsWpIleoY77ZMfF1VI5R3ennUkRQh Jy9gsh+eW6mKbAE7mgUQt10K0Im0IbShOsYhzaQoJmgQ51VRtr1PJ7IlsZZpjxB0aqmT o5zA== X-Gm-Message-State: ALoCoQkwtVpzzHaub7D9g4IepTbQUkR3EyDOIULt6jsM0FEIMF0/uwlhmUXkrPnSW6AcGlVxASvlrkanrx9gitHU2pJ+Rf8GPd9bXyverQjULJom7cwyIa4jhGo7M+0fQ1z5ZxmpaSib X-Received: by 10.67.15.40 with SMTP id fl8mr28215506pad.69.1405495948485; Wed, 16 Jul 2014 00:32:28 -0700 (PDT) X-Received: by 10.67.15.40 with SMTP id fl8mr28215501pad.69.1405495948429; Wed, 16 Jul 2014 00:32:28 -0700 (PDT) Received: from localhost (c-50-185-1-43.hsd1.ca.comcast.net. [50.185.1.43]) by mx.google.com with ESMTPSA id fv2sm16085039pbd.11.2014.07.16.00.32.27 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Wed, 16 Jul 2014 00:32:27 -0700 (PDT) From: Pravin B Shelar To: davem@davemloft.net Cc: netdev@vger.kernel.org, Simon Horman , Jesse Gross , Pravin B Shelar Subject: [PATCH net-next v3 08/11] openvswitch: Free skb(s) on recirculation error Date: Wed, 16 Jul 2014 00:32:28 -0700 Message-Id: <1405495948-2163-1-git-send-email-pshelar@nicira.com> X-Mailer: git-send-email 1.7.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Simon Horman This patch attempts to ensure that skb(s) are always freed (once) if an error occurs in execute_recirc(). It does so in two ways: 1. Ensure that execute_recirc() always consimes skb passed to it. Specifically, free the skb if the call to ovs_flow_extract() fails. 2. Return from the recirc case in execute_recirc() whenever the skb has not been cloned immediately above. This is only the case if the action is both the last action and the keep_skb parameter of execute_recirc is not true. As it is the last action and the skb is consumed one way or another by execute_recirc() it is correct to return here. In particular this avoids the possibility of the skb, which has been consumed by execute_recirc() from being freed. Conversely if this is not the case then the skb has been cloned and the clone has been consumed by execute_recirc(). This leads to three sub-cases: * If execute_recirc() returned an error code then the original skb will be freed by the error handling code below the case statement in do_execute_actions(). * If this is not the last action then action processing will continue, using the original skb. * If this is the last action then it must also be the case that keep_skb is true (otherwise the skb would not have been cloned). Thus do_execute_actions() will return without freeing the original skb. Signed-off-by: Simon Horman Signed-off-by: Jesse Gross Signed-off-by: Pravin B Shelar --- net/openvswitch/actions.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 8875697..f131d69 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -529,8 +529,10 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb, int err; err = ovs_flow_extract(skb, p->port_no, &recirc_key); - if (err) + if (err) { + kfree_skb(skb); return err; + } recirc_key.ovs_flow_hash = hash; recirc_key.recirc_id = nla_get_u32(a); @@ -602,7 +604,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, err = execute_recirc(dp, recirc_skb, a); __this_cpu_dec(net_xmit_recursion); - if (last_action || err) + if (recirc_skb == skb) return err; break;