From patchwork Sat Jan 12 02:55:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 1023841 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Iu1r8FdH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c49q6hCGz9s9h for ; Sat, 12 Jan 2019 13:55:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbfALCz6 (ORCPT ); Fri, 11 Jan 2019 21:55:58 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38082 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbfALCz6 (ORCPT ); Fri, 11 Jan 2019 21:55:58 -0500 Received: by mail-pf1-f195.google.com with SMTP id q1so7811661pfi.5 for ; Fri, 11 Jan 2019 18:55:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a5TKF9M+ALK2zH7aquEY+C21TU3Wj92bYesu1mhEu7Y=; b=Iu1r8FdHnSDX+6VjX99b6Sj3GvrU84wjJQ7wSKpODCm/wvi736wIvpKv8gIfUBEsvT xh77KL0P4Ilt5h71yfahB+8sRDp1EJJRqMbOcK/3zyl5KdrNRK+CT+qh23OF9Xt7sqd8 kArfsljyrbD56lzUaiMVzIzpKIbMrpGc9EkZkNTqq9tlpDX9dQqUuyq1gGSwlabYkl8x l+W1zHnB2QKU/YPP7OkGiigHGFZYGPqz31yg9Fu5pnT60lSFZjIEWTuHRLFBsmA3qaLb Uxe3z7794YkQw/JHvGPMA1FuOrWHUFgZLKpIhpuKBF706pNRMBuG0z3diT2nZweHYvSQ lUKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a5TKF9M+ALK2zH7aquEY+C21TU3Wj92bYesu1mhEu7Y=; b=rP7SiUlYeq6ynn/SxPV4U9yx0qMxI5qnmpCqLLNCGYCGCIqbEwC86M8y65AmzBTord gnRgPSJsQsrXaZqsDX/mi3ecRrqF9A7BrVwqpKx0TS7LpZw0fmWy4g5WjXr7aBctCWJ4 uDx2yR1DHtyspBKbMRiaZ7VYqDUMLCHqFwrLBq1DYUj3n97jCyJdke/r87p614N8/wfJ yjANgVdYRx4q6BkYfCs5hAo1vHiT1D9Ht4h9VWGCKZqeXTp2Nrv/Tr/XXoJqzWNzxqq1 Wg78ZRlabw59ORPjjZg7aEw/Lfz0tLmH0kggpFPjCpe6Ck0zY20zPpX4hBMx+JKpfXcI qzXg== X-Gm-Message-State: AJcUukefT/xdf0FNgTAUXgj2dzS1RU/jmc8BUkXwHzK8KdgDdc52q83l gRF7KhzmZPDn/9aB9f8EMPuuRhTu X-Google-Smtp-Source: ALg8bN52Px0/M/djklP+9Z+V+Yki8PrPkF4Qvg4gYPJMMqBcNeXRyeyAweB20ZOyAQOhFHV3UaStkQ== X-Received: by 2002:a62:190e:: with SMTP id 14mr16922798pfz.70.1547261756860; Fri, 11 Jan 2019 18:55:56 -0800 (PST) Received: from tw-172-25-17-123.office.twttr.net ([8.25.197.27]) by smtp.gmail.com with ESMTPSA id c23sm104373534pfi.83.2019.01.11.18.55.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jan 2019 18:55:56 -0800 (PST) From: Cong Wang To: netdev@vger.kernel.org Cc: Cong Wang , Martin Olsson , Jamal Hadi Salim , Jiri Pirko Subject: [Patch net] net_sched: refetch skb protocol for each filter Date: Fri, 11 Jan 2019 18:55:42 -0800 Message-Id: <20190112025542.397-1-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Martin reported a set of filters don't work after changing from reclassify to continue. Looking into the code, it looks like skb protocol is not always fetched for each iteration of the filters. But, as demonstrated by Martin, TC actions could modify skb->protocol, for example act_vlan, this means we have to refetch skb protocol in each iteration, rather than using the one we fetch in the beginning of the loop. This bug is _not_ introduced by commit 3b3ae880266d ("net: sched: consolidate tc_classify{,_compat}"), technically, if act_vlan is the only action that modifies skb protocol, then it is commit c7e2b9689ef8 ("sched: introduce vlan action") which introduced this bug. Reported-by: Martin Olsson Cc: Jamal Hadi Salim Cc: Jiri Pirko Signed-off-by: Cong Wang Acked-by: Jamal Hadi Salim --- net/sched/cls_api.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 8ce2a0507970..e2b5cb2eb34e 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -1277,7 +1277,6 @@ EXPORT_SYMBOL(tcf_block_cb_unregister); int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, struct tcf_result *res, bool compat_mode) { - __be16 protocol = tc_skb_protocol(skb); #ifdef CONFIG_NET_CLS_ACT const int max_reclassify_loop = 4; const struct tcf_proto *orig_tp = tp; @@ -1287,6 +1286,7 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, reclassify: #endif for (; tp; tp = rcu_dereference_bh(tp->next)) { + __be16 protocol = tc_skb_protocol(skb); int err; if (tp->protocol != protocol && @@ -1319,7 +1319,6 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, } tp = first_tp; - protocol = tc_skb_protocol(skb); goto reclassify; #endif }