Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp581758iog; Mon, 13 Jun 2022 08:32:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLfTZs1Y4MlU/MUcYonuq+vC5VkGxxVbbY1+RFqrdYtca5HowgH8hnn99r2kv8Ypa2+OgZ X-Received: by 2002:a17:902:f688:b0:163:ee37:91c5 with SMTP id l8-20020a170902f68800b00163ee3791c5mr261055plg.86.1655134378548; Mon, 13 Jun 2022 08:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134378; cv=none; d=google.com; s=arc-20160816; b=rvYtWQOkbTaqH+aHglicc6B+H4//hhBbR2dE7C7poN/c+z5Wrjm/OMCrM5zaPp4yot GljV7t+dwLLRH2UMcZ6XKaR52Oqh6JVBNmbwnxqcPt+T9dVuP5fVzutuI5FtN8/il9pt tjymS0rHJ+nKAr9yTVXTJR1R/oxIC5h4Rz7bpeUOIIYqwNkJl/WR1Bab4AarR5us3dvu TCplei9g7wPtYe/RAqcCUYF0lWJ9gd3kvjn0oNe1wiIbC/Y/8oQWzB5M9opSSNpjMzyr spWxAtCGwDTk/SfLEyNEjMn+CBm9mj9OG8/Lp9H/o9CTU5SJD1OWuDMfpMc3tsb382PH f8UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z/g9J3zm+T0XftPg322PMMMIl3ff3ImAi4WIkMjiUro=; b=CV6WLCJyy5ObvDup/jLxz2DGcY76I09nPw8eDNjl0bfw4mBs9DB3QFSwGR2ethf45K SEhVktu3iYbXDTyEx5ATLhRv8FVEXupvjJmrVk/HHNY4MCGA/q7S3VUoGacO6QXRMSa4 pMRY1/Ft7N69RWShz9S1OVFctBZb4BJfD71wRqvZ+vImJ0hCJT8FJu3rtsnV9N23k5Sm fnX+skV3vIX6RiKLDnwRq9n3gqtNW3VnAVOfIWP6vf0gOGsdrzWux7gQadWmWg3p++9F eNe91yfISWAf2iEYwVYe5AY5hRDiSU2ASz6KT4WmlqikLdKK0Pfeoqqk4SSrF5IThsyy Wj0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D66+P4rg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i62-20020a626d41000000b0051c3dcbe8ffsi9035515pfc.373.2022.06.13.08.32.46; Mon, 13 Jun 2022 08:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D66+P4rg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376538AbiFMNY5 (ORCPT + 99 others); Mon, 13 Jun 2022 09:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377429AbiFMNUZ (ORCPT ); Mon, 13 Jun 2022 09:20:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EADA26AA73; Mon, 13 Jun 2022 04:23:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3279661127; Mon, 13 Jun 2022 11:23:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45A62C34114; Mon, 13 Jun 2022 11:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119391; bh=gsknnm1TEWssjyLcGyQFf5l/MRxpU5FvJ25DZvX++9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D66+P4rgzG3lMkXJGHU1ZdLs0cn26TL8WACXIjSvPLI8zqdAZgBsYY08fnVAAzTU+ 9qXLqJFNW+mJY4YIXyYeAO2iZ6G0/kdahX07jVT6+XGDr6AyU2+lgz/F2M/4NYM2NC bnRcAqSMexAyjq6EPoKqtcMnNXTtwjBtHKC7rjbc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Davide Caratti , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 5.15 245/247] net/sched: act_police: more accurate MTU policing Date: Mon, 13 Jun 2022 12:12:27 +0200 Message-Id: <20220613094930.376357741@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davide Caratti commit 4ddc844eb81da59bfb816d8d52089aba4e59e269 upstream. in current Linux, MTU policing does not take into account that packets at the TC ingress have the L2 header pulled. Thus, the same TC police action (with the same value of tcfp_mtu) behaves differently for ingress/egress. In addition, the full GSO size is compared to tcfp_mtu: as a consequence, the policer drops GSO packets even when individual segments have the L2 + L3 + L4 + payload length below the configured valued of tcfp_mtu. Improve the accuracy of MTU policing as follows: - account for mac_len for non-GSO packets at TC ingress. - compare MTU threshold with the segmented size for GSO packets. Also, add a kselftest that verifies the correct behavior. Signed-off-by: Davide Caratti Reviewed-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/act_police.c | 16 +++++- tools/testing/selftests/net/forwarding/tc_police.sh | 52 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) --- a/net/sched/act_police.c +++ b/net/sched/act_police.c @@ -239,6 +239,20 @@ release_idr: return err; } +static bool tcf_police_mtu_check(struct sk_buff *skb, u32 limit) +{ + u32 len; + + if (skb_is_gso(skb)) + return skb_gso_validate_mac_len(skb, limit); + + len = qdisc_pkt_len(skb); + if (skb_at_tc_ingress(skb)) + len += skb->mac_len; + + return len <= limit; +} + static int tcf_police_act(struct sk_buff *skb, const struct tc_action *a, struct tcf_result *res) { @@ -261,7 +275,7 @@ static int tcf_police_act(struct sk_buff goto inc_overlimits; } - if (qdisc_pkt_len(skb) <= p->tcfp_mtu) { + if (tcf_police_mtu_check(skb, p->tcfp_mtu)) { if (!p->rate_present && !p->pps_present) { ret = p->tcfp_result; goto end; --- a/tools/testing/selftests/net/forwarding/tc_police.sh +++ b/tools/testing/selftests/net/forwarding/tc_police.sh @@ -37,6 +37,8 @@ ALL_TESTS=" police_tx_mirror_test police_pps_rx_test police_pps_tx_test + police_mtu_rx_test + police_mtu_tx_test " NUM_NETIFS=6 source tc_common.sh @@ -346,6 +348,56 @@ police_pps_tx_test() tc filter del dev $rp2 egress protocol ip pref 1 handle 101 flower } +police_mtu_common_test() { + RET=0 + + local test_name=$1; shift + local dev=$1; shift + local direction=$1; shift + + tc filter add dev $dev $direction protocol ip pref 1 handle 101 flower \ + dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \ + action police mtu 1042 conform-exceed drop/ok + + # to count "conform" packets + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ + dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \ + action drop + + mausezahn $h1 -a own -b $(mac_get $rp1) -A 192.0.2.1 -B 198.51.100.1 \ + -t udp sp=12345,dp=54321 -p 1001 -c 10 -q + + mausezahn $h1 -a own -b $(mac_get $rp1) -A 192.0.2.1 -B 198.51.100.1 \ + -t udp sp=12345,dp=54321 -p 1000 -c 3 -q + + tc_check_packets "dev $dev $direction" 101 13 + check_err $? "wrong packet counter" + + # "exceed" packets + local overlimits_t0=$(tc_rule_stats_get ${dev} 1 ${direction} .overlimits) + test ${overlimits_t0} = 10 + check_err $? "wrong overlimits, expected 10 got ${overlimits_t0}" + + # "conform" packets + tc_check_packets "dev $h2 ingress" 101 3 + check_err $? "forwarding error" + + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower + tc filter del dev $dev $direction protocol ip pref 1 handle 101 flower + + log_test "$test_name" +} + +police_mtu_rx_test() +{ + police_mtu_common_test "police mtu (rx)" $rp1 ingress +} + +police_mtu_tx_test() +{ + police_mtu_common_test "police mtu (tx)" $rp2 egress +} + setup_prepare() { h1=${NETIFS[p1]}