Skip to content

Commit 6ecf189

Browse files
author
Herton R. Krzesinski
committed
Merge: net/sched: use the backlog for nested mirred ingress
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1937 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2150278 CVE: CVE-2022-4269 Upstream Status: All mainline in net-next.git. Tested: boot-tested only Conflicts: None Signed-off-by: Davide Caratti <dcaratti@redhat.com> Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com> Approved-by: Xin Long <lxin@redhat.com> Approved-by: Andrea Claudi <aclaudi@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 98f0fb1 + 567714b commit 6ecf189

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

net/sched/act_mirred.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
static LIST_HEAD(mirred_list);
2929
static DEFINE_SPINLOCK(mirred_list_lock);
3030

31-
#define MIRRED_RECURSION_LIMIT 4
32-
static DEFINE_PER_CPU(unsigned int, mirred_rec_level);
31+
#define MIRRED_NEST_LIMIT 4
32+
static DEFINE_PER_CPU(unsigned int, mirred_nest_level);
3333

3434
static bool tcf_mirred_is_act_redirect(int action)
3535
{
@@ -206,12 +206,19 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
206206
return err;
207207
}
208208

209+
static bool is_mirred_nested(void)
210+
{
211+
return unlikely(__this_cpu_read(mirred_nest_level) > 1);
212+
}
213+
209214
static int tcf_mirred_forward(bool want_ingress, struct sk_buff *skb)
210215
{
211216
int err;
212217

213218
if (!want_ingress)
214219
err = tcf_dev_queue_xmit(skb, dev_queue_xmit);
220+
else if (is_mirred_nested())
221+
err = netif_rx(skb);
215222
else
216223
err = netif_receive_skb(skb);
217224

@@ -225,7 +232,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
225232
struct sk_buff *skb2 = skb;
226233
bool m_mac_header_xmit;
227234
struct net_device *dev;
228-
unsigned int rec_level;
235+
unsigned int nest_level;
229236
int retval, err = 0;
230237
bool use_reinsert;
231238
bool want_ingress;
@@ -236,11 +243,11 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
236243
int mac_len;
237244
bool at_nh;
238245

239-
rec_level = __this_cpu_inc_return(mirred_rec_level);
240-
if (unlikely(rec_level > MIRRED_RECURSION_LIMIT)) {
246+
nest_level = __this_cpu_inc_return(mirred_nest_level);
247+
if (unlikely(nest_level > MIRRED_NEST_LIMIT)) {
241248
net_warn_ratelimited("Packet exceeded mirred recursion limit on dev %s\n",
242249
netdev_name(skb->dev));
243-
__this_cpu_dec(mirred_rec_level);
250+
__this_cpu_dec(mirred_nest_level);
244251
return TC_ACT_SHOT;
245252
}
246253

@@ -310,7 +317,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
310317
err = tcf_mirred_forward(res->ingress, skb);
311318
if (err)
312319
tcf_action_inc_overlimit_qstats(&m->common);
313-
__this_cpu_dec(mirred_rec_level);
320+
__this_cpu_dec(mirred_nest_level);
314321
return TC_ACT_CONSUMED;
315322
}
316323
}
@@ -322,7 +329,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
322329
if (tcf_mirred_is_act_redirect(m_eaction))
323330
retval = TC_ACT_SHOT;
324331
}
325-
__this_cpu_dec(mirred_rec_level);
332+
__this_cpu_dec(mirred_nest_level);
326333

327334
return retval;
328335
}

tools/testing/selftests/net/forwarding/tc_actions.sh

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
ALL_TESTS="gact_drop_and_ok_test mirred_egress_redirect_test \
55
mirred_egress_mirror_test matchall_mirred_egress_mirror_test \
6-
gact_trap_test mirred_egress_to_ingress_test"
6+
gact_trap_test mirred_egress_to_ingress_test \
7+
mirred_egress_to_ingress_tcp_test"
78
NUM_NETIFS=4
89
source tc_common.sh
910
source lib.sh
@@ -198,6 +199,52 @@ mirred_egress_to_ingress_test()
198199
log_test "mirred_egress_to_ingress ($tcflags)"
199200
}
200201

202+
mirred_egress_to_ingress_tcp_test()
203+
{
204+
local tmpfile=$(mktemp) tmpfile1=$(mktemp)
205+
206+
RET=0
207+
dd conv=sparse status=none if=/dev/zero bs=1M count=2 of=$tmpfile
208+
tc filter add dev $h1 protocol ip pref 100 handle 100 egress flower \
209+
$tcflags ip_proto tcp src_ip 192.0.2.1 dst_ip 192.0.2.2 \
210+
action ct commit nat src addr 192.0.2.2 pipe \
211+
action ct clear pipe \
212+
action ct commit nat dst addr 192.0.2.1 pipe \
213+
action ct clear pipe \
214+
action skbedit ptype host pipe \
215+
action mirred ingress redirect dev $h1
216+
tc filter add dev $h1 protocol ip pref 101 handle 101 egress flower \
217+
$tcflags ip_proto icmp \
218+
action mirred ingress redirect dev $h1
219+
tc filter add dev $h1 protocol ip pref 102 handle 102 ingress flower \
220+
ip_proto icmp \
221+
action drop
222+
223+
ip vrf exec v$h1 nc --recv-only -w10 -l -p 12345 -o $tmpfile1 &
224+
local rpid=$!
225+
ip vrf exec v$h1 nc -w1 --send-only 192.0.2.2 12345 <$tmpfile
226+
wait -n $rpid
227+
cmp -s $tmpfile $tmpfile1
228+
check_err $? "server output check failed"
229+
230+
$MZ $h1 -c 10 -p 64 -a $h1mac -b $h1mac -A 192.0.2.1 -B 192.0.2.1 \
231+
-t icmp "ping,id=42,seq=5" -q
232+
tc_check_packets "dev $h1 egress" 101 10
233+
check_err $? "didn't mirred redirect ICMP"
234+
tc_check_packets "dev $h1 ingress" 102 10
235+
check_err $? "didn't drop mirred ICMP"
236+
local overlimits=$(tc_rule_stats_get ${h1} 101 egress .overlimits)
237+
test ${overlimits} = 10
238+
check_err $? "wrong overlimits, expected 10 got ${overlimits}"
239+
240+
tc filter del dev $h1 egress protocol ip pref 100 handle 100 flower
241+
tc filter del dev $h1 egress protocol ip pref 101 handle 101 flower
242+
tc filter del dev $h1 ingress protocol ip pref 102 handle 102 flower
243+
244+
rm -f $tmpfile $tmpfile1
245+
log_test "mirred_egress_to_ingress_tcp ($tcflags)"
246+
}
247+
201248
setup_prepare()
202249
{
203250
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)