Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4182814pxv; Mon, 19 Jul 2021 19:35:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzExHfKSNeJ0dqcH+bnQfuWTePa8IJDW2dwlGaGlUl6srcWOIjGiIxrw6mV5OeBG98PAGPh X-Received: by 2002:aa7:d857:: with SMTP id f23mr24741128eds.249.1626748523364; Mon, 19 Jul 2021 19:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626748523; cv=none; d=google.com; s=arc-20160816; b=i/9snRdfliKt91yQPNQrmIcvDc06BGX43GBZBOBqcIZcxkwKYQ5fPIC1YdU0qHZFvE OxyfEloZp+n6VwlnndzuLiV/tUFelGPTSVV0DgkOAIGPCJeoKXH6fpiJ2+rT61R46wt+ fSdOOt+R6e35FioNIFnTVduSMr8q4P18bS+K/rlt3ICZetcWL1jL9b1i3lmN5niTwQ4m IU8mcZ8D8lL1saHzArltmoyGQ8NmZGACuXcUPH55xYQDnl0jvbumUkjVsleMqX4+O80Y lRMvN46o8RpfojZTwq6TfqM596/EgLv5UuzyYNXgNypyIh5iv/mxrnvuYv1vPNsG5yOg 15sQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=tG3VNaXw5GOzMIsu0CiI5SvtjI+jDKkdFfqR2rMpbXQ=; b=jR8DVEbwPFhdvo91pzEKMN1b+s69rOsin4w5Mwb/rooWlTYz7MOh1F5A6kUF+rElMx 5mQrehDcLy+sY2zGoqYCGnm7EE5C4Y4Ed2UngEICjzun9zup3jmDFlnEFPbCnMmWaa2K GTaPGrAGUwFuiY2TKX0bp8VTryawh+FxToUZalyVqDNn+QvW84Glqtbg0oKdtW0Rs1Tz gabBwuy5tDD/Gc2MSvijyFy5nDdmJ9wEyZLxQ3ylknSYxA0uRZUMtG5N/NO0l5JO5WLR 2gasOCOzszqxVPCxy5cx9GoDLlZ4cKGPJ6f8WKay9WJc3hjdgGFpm+yLCcyC6IR9kBUw VSnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukHLi4nk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd35si25022841ejc.274.2021.07.19.19.34.48; Mon, 19 Jul 2021 19:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukHLi4nk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344595AbhGTBlP (ORCPT + 99 others); Mon, 19 Jul 2021 21:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443887AbhGSXFV (ORCPT ); Mon, 19 Jul 2021 19:05:21 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 477A8C061767; Mon, 19 Jul 2021 16:41:35 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id gh6so9276408qvb.3; Mon, 19 Jul 2021 16:41:35 -0700 (PDT) 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=tG3VNaXw5GOzMIsu0CiI5SvtjI+jDKkdFfqR2rMpbXQ=; b=ukHLi4nkEFU5WxlAaCJhPm4GSHtNNmHN+xODDOgQkICkx9CLlFvbvBhNIBonKE0fJg Ggl0q7FrCfw5psKcZbOcA1Awg1OodHbECGTMvBJ7ILivSLjEWJvHqh6YJxhmstdJEhyJ B4ks3IjMvc5pGWlvmIEkZMk/OKQdj4yc1TYIau+JiZAe9CTXepZkAipq5jd9aaKaBbmw EPg5FeoAzgE8ZJlfbZ5EiU8ZFn+f0cy/hUf7volywoSX8XeHfWFNcxo9Kd7/ApocefMa BG2l0zy0o5Qm3AeaxilP2Qw8mesVRimXoojBWYpoYids/odf3d+QBQYpPqA3o5PuLXiD yS1A== 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=tG3VNaXw5GOzMIsu0CiI5SvtjI+jDKkdFfqR2rMpbXQ=; b=YX0JcxbUNLxbtfIYXs/0H8uwTVoLvniVrj+MA5ILhL5lhGX16pLcNqkSlVuN2pdHBa QTiqWF+aaMADsk3caC811tCFjm5I1NXPjcr/rOcK9HABc7kI2uUpPlExR6UIAWCxM95h tuUA0lGL71UpEJ3U65uB+7cvTiPfb4qaAht9Q43A9xWmmozyW6X3xINf6UaH2G28PluH rOb0mcPk7PVen/CoqXuLZw8ZasAhX42PJKeGBBUOvjbYeY/TpkH9wyvle2Au0zXzPTY2 z4ZEBs/NTVaGByJn0Cd6Lvmwik421iRScCHoaJXIXdHD+f7o7G3rtq6xLCahakDS+XXE f3pA== X-Gm-Message-State: AOAM533XkjxPHidiI3UMvVcX4Qjdk86khjie3bBzH9G4oGonLRCPO05v kccTtxXXr4ext2VIfxm+2w== X-Received: by 2002:a05:6214:1882:: with SMTP id cx2mr27485724qvb.2.1626738094460; Mon, 19 Jul 2021 16:41:34 -0700 (PDT) Received: from bytedance.attlocal.net (ec2-52-52-7-82.us-west-1.compute.amazonaws.com. [52.52.7.82]) by smtp.gmail.com with ESMTPSA id l12sm124689qtx.45.2021.07.19.16.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 16:41:33 -0700 (PDT) From: Peilin Ye To: Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , "David S. Miller" , Jakub Kicinski , Cong Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye Subject: [PATCH net] net/sched: act_skbmod: Skip non-Ethernet packets Date: Mon, 19 Jul 2021 16:41:24 -0700 Message-Id: <20210719234124.18383-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye Currently tcf_skbmod_act() assumes that packets use Ethernet as their L2 protocol, which is not always the case. As an example, for CAN devices: $ ip link add dev vcan0 type vcan $ ip link set up vcan0 $ tc qdisc add dev vcan0 root handle 1: htb $ tc filter add dev vcan0 parent 1: protocol ip prio 10 \ matchall action skbmod swap mac Doing the above silently corrupts all the packets. Do not perform skbmod actions for non-Ethernet packets. Fixes: 86da71b57383 ("net_sched: Introduce skbmod action") Reviewed-by: Cong Wang Signed-off-by: Peilin Ye --- net/sched/act_skbmod.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c index 81a1c67335be..8d17a543cc9f 100644 --- a/net/sched/act_skbmod.c +++ b/net/sched/act_skbmod.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -33,6 +34,13 @@ static int tcf_skbmod_act(struct sk_buff *skb, const struct tc_action *a, tcf_lastuse_update(&d->tcf_tm); bstats_cpu_update(this_cpu_ptr(d->common.cpu_bstats), skb); + action = READ_ONCE(d->tcf_action); + if (unlikely(action == TC_ACT_SHOT)) + goto drop; + + if (!skb->dev || skb->dev->type != ARPHRD_ETHER) + return action; + /* XXX: if you are going to edit more fields beyond ethernet header * (example when you add IP header replacement or vlan swap) * then MAX_EDIT_LEN needs to change appropriately @@ -41,10 +49,6 @@ static int tcf_skbmod_act(struct sk_buff *skb, const struct tc_action *a, if (unlikely(err)) /* best policy is to drop on the floor */ goto drop; - action = READ_ONCE(d->tcf_action); - if (unlikely(action == TC_ACT_SHOT)) - goto drop; - p = rcu_dereference_bh(d->skbmod_p); flags = p->flags; if (flags & SKBMOD_F_DMAC) -- 2.20.1