From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Abeni Subject: Re: [PATCH net-next 4/4] act_mirred: use ACT_REDIRECT when possible Date: Fri, 20 Jul 2018 12:16:36 +0200 Message-ID: References: <95034fe41fa132b2216686eeb41deaefd997e85b.1531473946.git.pabeni@redhat.com> <7f151d07041f0c0d3ecebad1629bf5803ed4133d.camel@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Linux Kernel Network Developers , Jamal Hadi Salim , Jiri Pirko , Alexei Starovoitov , Daniel Borkmann , Marcelo Ricardo Leitner , Eyal Birger To: Cong Wang Return-path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36872 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727179AbeGTLEL (ORCPT ); Fri, 20 Jul 2018 07:04:11 -0400 In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 2018-07-19 at 10:56 -0700, Cong Wang wrote: > On Wed, Jul 18, 2018 at 3:05 AM Paolo Abeni wrote: > > > > Hi, > > > > On Tue, 2018-07-17 at 10:24 -0700, Cong Wang wrote: > > > If you goal is to get rid of skb_clone(), why not just do the following? > > > > > > if (tcf_mirred_is_act_redirect(m_eaction)) { > > > skb2 = skb; > > > } else { > > > skb2 = skb_clone(skb, GFP_ATOMIC); > > > if (!skb2) > > > goto out; > > > } > > > > > > For redirect, we return TC_ACT_SHOT, so upper layer should not > > > touch the skb after that. > > > > > > What am I missing here? > > > > With ACT_SHOT caller/upper layer will free the skb, too. We will have > > an use after free (from either the upper layer and the xmit device). > > Similar issues with STOLEN, TRAP, etc. > > > > In the past, Changli Gao attempted to avoid the clone incrementing the > > skb usage count: > > > > commit 210d6de78c5d7c785fc532556cea340e517955e1 > > Author: Changli Gao > > Date: Thu Jun 24 16:25:12 2010 +0000 > > > > act_mirred: don't clone skb when skb isn't shared > > > > but some/many device drivers expect an skb usage count of 1, and that > > caused ooops and was revered. > > Interesting, I wasn't aware of the above commit and its revert. > > First, I didn't use skb_get() above. > > Second, I think the caller of dev_queue_xmit() should not > touch the skb after it, the skb is either freed by dev_queue_xmit() > or successfully transmitted, in either case, the ownership belongs > to dev_queue_xmit(). So, I think we should skip the qdisc_drop() > for this case. > > Not sure about netif_receive_skb() case, given veth calls in its > xmit too, I speculate the rule is probably same. > > Not sure about other ACT_SHOT case than act_mirred... I think any tc filter can be configured from user space to return ACT_SHOT, so changing the ACT_SHOT handling would be quite invasive and error prone, as all the tc filters (to free the skb on ACT_SHOT) and tc schedulers (to avoid touching the skb) must be modified. If there are no strong objection vs a new action value, I would opt for such option. Thanks, Paolo