Michal Kubecek d564e3
From: wenxu <wenxu@ucloud.cn>
Michal Kubecek d564e3
Date: Wed, 25 Nov 2020 12:01:22 +0800
Michal Kubecek d564e3
Subject: net/sched: act_mirred: refactor the handle of xmit
Michal Kubecek d564e3
Patch-mainline: v5.11-rc1
Michal Kubecek d564e3
Git-commit: fa6d639930ee5cd3f932cc314f3407f07a06582d
Michal Kubecek d564e3
References: CVE-2022-4269 bsc#1206024
Michal Kubecek d564e3
Michal Kubecek d564e3
This one is prepare for the next patch.
Michal Kubecek d564e3
Michal Kubecek d564e3
Signed-off-by: wenxu <wenxu@ucloud.cn>
Michal Kubecek d564e3
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Michal Kubecek d564e3
Acked-by: Michal Kubecek <mkubecek@suse.cz>
Michal Kubecek d564e3
Michal Kubecek d564e3
---
Michal Kubecek d564e3
 include/net/sch_generic.h |  5 -----
Michal Kubecek d564e3
 net/sched/act_mirred.c    | 21 +++++++++++++++------
Michal Kubecek d564e3
 2 files changed, 15 insertions(+), 11 deletions(-)
Michal Kubecek d564e3
Michal Kubecek d564e3
--- a/include/net/sch_generic.h
Michal Kubecek d564e3
+++ b/include/net/sch_generic.h
Michal Kubecek d564e3
@@ -1296,9 +1296,4 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,
Michal Kubecek d564e3
 void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,
Michal Kubecek d564e3
 			  struct mini_Qdisc __rcu **p_miniq);
Michal Kubecek d564e3
 
Michal Kubecek d564e3
-static inline int skb_tc_reinsert(struct sk_buff *skb, struct tcf_result *res)
Michal Kubecek d564e3
-{
Michal Kubecek d564e3
-	return res->ingress ? netif_receive_skb(skb) : dev_queue_xmit(skb);
Michal Kubecek d564e3
-}
Michal Kubecek d564e3
-
Michal Kubecek d564e3
 #endif
Michal Kubecek d564e3
--- a/net/sched/act_mirred.c
Michal Kubecek d564e3
+++ b/net/sched/act_mirred.c
Michal Kubecek d564e3
@@ -207,6 +207,18 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
Michal Kubecek d564e3
 	return err;
Michal Kubecek d564e3
 }
Michal Kubecek d564e3
 
Michal Kubecek d564e3
+static int tcf_mirred_forward(bool want_ingress, struct sk_buff *skb)
Michal Kubecek d564e3
+{
Michal Kubecek d564e3
+	int err;
Michal Kubecek d564e3
+
Michal Kubecek d564e3
+	if (!want_ingress)
Michal Kubecek d564e3
+		err = dev_queue_xmit(skb);
Michal Kubecek d564e3
+	else
Michal Kubecek d564e3
+		err = netif_receive_skb(skb);
Michal Kubecek d564e3
+
Michal Kubecek d564e3
+	return err;
Michal Kubecek d564e3
+}
Michal Kubecek d564e3
+
Michal Kubecek d564e3
 static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
Michal Kubecek d564e3
 			  struct tcf_result *res)
Michal Kubecek d564e3
 {
Michal Kubecek d564e3
@@ -291,18 +303,15 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
Michal Kubecek d564e3
 		/* let's the caller reinsert the packet, if possible */
Michal Kubecek d564e3
 		if (use_reinsert) {
Michal Kubecek d564e3
 			res->ingress = want_ingress;
Michal Kubecek d564e3
-			if (skb_tc_reinsert(skb, res))
Michal Kubecek d564e3
+			err = tcf_mirred_forward(res->ingress, skb);
Michal Kubecek d564e3
+			if (err)
Michal Kubecek d564e3
 				tcf_action_inc_overlimit_qstats(&m->common);
Michal Kubecek d564e3
 			__this_cpu_dec(mirred_rec_level);
Michal Kubecek d564e3
 			return TC_ACT_CONSUMED;
Michal Kubecek d564e3
 		}
Michal Kubecek d564e3
 	}
Michal Kubecek d564e3
 
Michal Kubecek d564e3
-	if (!want_ingress)
Michal Kubecek d564e3
-		err = dev_queue_xmit(skb2);
Michal Kubecek d564e3
-	else
Michal Kubecek d564e3
-		err = netif_receive_skb(skb2);
Michal Kubecek d564e3
-
Michal Kubecek d564e3
+	err = tcf_mirred_forward(want_ingress, skb2);
Michal Kubecek d564e3
 	if (err) {
Michal Kubecek d564e3
 out:
Michal Kubecek d564e3
 		tcf_action_inc_overlimit_qstats(&m->common);