Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3713769pxv; Mon, 26 Jul 2021 10:03:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMUcwO6oTP5QZ2DoIfRIX9LaJhJ3pTaKeAmBSbKrpMAXOkPd5Ig1+nOeW7t0YAdI3cb71u X-Received: by 2002:a05:6102:5c5:: with SMTP id v5mr13627911vsf.51.1627318997306; Mon, 26 Jul 2021 10:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318997; cv=none; d=google.com; s=arc-20160816; b=DDJZ882AmHrNz2QUNm9Os/MeOser7PX/aFTfWd4uuBNC82xiDEH1TfXh+OcZJb4+rb dSIO8zrlNDzHofFofcrMQb/SahZB2OzB7F+Kfog0PMmTKQ5J9Am3VbjI0VlPAdkrf75m cwIgznP1wz0KzvUD+sBuE/tLouNKWwYAuuyLJwvm4m8h1TdwNh9nH5HXZqZIH3jWGurn N5bXeiRZSnYs48AFbf/mFiqn8F8cXh4rWTTVYDCPH5c/qLOxHCfauytwkWgG/bZ+fW+y BixVbG/oD/gcdtN7O9r6D6Ho5FGi6YEvAQ6Z8NMx9Ar3HMyMr2zqDUi2qj3wM2tPgBl2 5qUQ== 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=uyLkTSZcwxmK+kzM9ww5SpwOLtS4MPzcItTCmImrqh4=; b=O5FgEbwd9CooR7pg7nO2b6cPj85XWfEFpHqFnVOF1osQbWFUsk2LdcvEwYKnIMTuRo zYY13PJZH6nTlkUcWQ+ZlXTA5ZzdjIJ+ONdsB7Cjg2CUwD/nQDGScgJ4ZGqaQjzPEKEj pd0DeZ7jNyCm8UHtKIf72OC1UK5c6nvqoeikHkDmQwSNjVc6yAQBMHGc+HwUgE4RKIZt WUkqyetDrG+NZN4K1f6/ocL6MyYJyvhqP/HWOJLccUAtkyWPqpeswjmOovvaMmCtRWP9 7NriXP6ulNr9oYBz7Tle7IXEFYEHLjJR2BbELeJLU3bzO8cgayfTyoiCCLcQhEoqzCpr ntLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bbixW6Lm; 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 y1si297123vsi.249.2021.07.26.10.02.43; Mon, 26 Jul 2021 10:03:17 -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=bbixW6Lm; 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 S238189AbhGZPks (ORCPT + 99 others); Mon, 26 Jul 2021 11:40:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:38278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237513AbhGZPXO (ORCPT ); Mon, 26 Jul 2021 11:23:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 17E9B60240; Mon, 26 Jul 2021 16:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315422; bh=BFNhlEZO6+UPnX1sDeZdmiBIyaFaT4PvZeZa4mtd29M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbixW6LmuT+ZRbzMxPZ3VzfVh63itoKLU9pU1YomIBPlMTWWWpxeOmWvYGGQoH0oo C2Obp0elFPys6kt9XCbgJ9sDoQeoAw1W+RfxRTYt2y1NlAB5IjvxtEgdh7Zr2ZEYgF C4MREqc1KnGcJ0WxabxqQ7kVzfwktUUKB7OViN94= 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.10 090/167] net/sched: act_skbmod: Skip non-Ethernet packets Date: Mon, 26 Jul 2021 17:38:43 +0200 Message-Id: <20210726153842.418731889@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@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 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.30.2