Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3677467pxv; Mon, 26 Jul 2021 09:12:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4slVWejIX5Dyh/c8a5lIrFrZdKU+QFDUf0/Bj38ye++0AU2SM30v2tMHZIgYGODfXT2pJ X-Received: by 2002:aa7:ca10:: with SMTP id y16mr13256833eds.308.1627315976932; Mon, 26 Jul 2021 09:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315976; cv=none; d=google.com; s=arc-20160816; b=U4CI3ODoRWekgqYQKwC3Kpn8A+sFxyT84UG8sTixt3JGV+Fh8+Fb1muQEY52SZzbi8 3cC5BkQRdTmGJ1JYniH8wvQSVTTnZ2jz8Y7SAfcCYuO6xUoQAURGNqKqWrxdis8jVCXh sqKHwK+x9yI5A1AW5Ll14knmENdiSiS1gYzhWeB+8R4wP/TQxrsFavQwvHg0wTf2BeRh HT71o7y1qBxXPX9h56A0q4gUr+XEd4v2Ubh23JVfFscIOQ9ELkczxQo07SRLIBrbCnnQ YqjpxyFO4SUJRDb9+NI0LRvOVlRk7cnD6YG4S/KUsT1pXyUsyFo2uZq0BaGB8NjjbNw9 uEsA== 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=P7tRN0nw7J9CnkqEbPU7yh2YjAhNjUf+eVLeVxCtYiE=; b=KqIZ5Re0pcRS68ETj9F8v8F4PsjNUrcj/uzoPJjXc7fGVlAR5RIwUTPFf3mU77lXnw CkzK/wPq7W627KZKG/DZWRAFPBINDOZ0TgwHIc2HjrDiU12N3/PsVtEwFAdw4jS51l2t G7n6eawwoGHRqzhs1vK13j0nKPmEWwMfwXl13sXb+itVQU9XBZoM4+Lzzw2TTyTI3w3R 07B7h7ZC01+TykgXaY0o/IED20ig0SzQW5gUAGjScj8xkz3iLRmalhHT0d6Na731jcnR NobrI+Iom6O8RcNo6u85YP2qnPYVwHuUti+qBIBfCrjSVLLwjaqrmjJuE6EmJ4qkrMI4 AC8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uBAj4fIh; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si294770edr.39.2021.07.26.09.12.33; Mon, 26 Jul 2021 09:12:56 -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=@linuxfoundation.org header.s=korg header.b=uBAj4fIh; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236906AbhGZP3M (ORCPT + 99 others); Mon, 26 Jul 2021 11:29:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:56526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbhGZPQm (ORCPT ); Mon, 26 Jul 2021 11:16:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3606A6056C; Mon, 26 Jul 2021 15:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315030; bh=0LxOJyZSpsLGI1DR7GX002GYLPjIyD8a1JgymydXNfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uBAj4fIhWI1z9dj0i7RQ5tPKzviQU50PqMQqwWuLJC7bEnPkpVUVGI/VNbrmPs3ce tJY7soufhWJkfPUldIxi9oAN2ledrq1r9gFB+6IUy3Xaxj+JeBlnA0T3k3XBQfqypo HagVIXhPAW5t6V50lEoGk5oNWGx04EMyir2f42+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cong Wang , Peilin Ye , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 058/108] net/sched: act_skbmod: Skip non-Ethernet packets Date: Mon, 26 Jul 2021 17:38:59 +0200 Message-Id: <20210726153833.545265115@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye [ Upstream commit 727d6a8b7ef3d25080fad228b2c4a1d4da5999c6 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 e858a0a9c045..f60d349542b1 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.30.2