Skip to content

Commit b064d0d

Browse files
strssndktndavem330
authored andcommitted
ovs: limit ovs recursions in ovs_execute_actions to not corrupt stack
It was seen that defective configurations of openvswitch could overwrite the STACK_END_MAGIC and cause a hard crash of the kernel because of too many recursions within ovs. This problem arises due to the high stack usage of openvswitch. The rest of the kernel is fine with the current limit of 10 (RECURSION_LIMIT). We use the already existing recursion counter in ovs_execute_actions to implement an upper bound of 5 recursions. Cc: Pravin Shelar <pshelar@ovn.org> Cc: Simon Horman <simon.horman@netronome.com> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Simon Horman <simon.horman@netronome.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 60a6531 commit b064d0d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

net/openvswitch/actions.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,26 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
11601160
const struct sw_flow_actions *acts,
11611161
struct sw_flow_key *key)
11621162
{
1163-
int level = this_cpu_read(exec_actions_level);
1164-
int err;
1163+
static const int ovs_recursion_limit = 5;
1164+
int err, level;
1165+
1166+
level = __this_cpu_inc_return(exec_actions_level);
1167+
if (unlikely(level > ovs_recursion_limit)) {
1168+
net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n",
1169+
ovs_dp_name(dp));
1170+
kfree_skb(skb);
1171+
err = -ENETDOWN;
1172+
goto out;
1173+
}
11651174

1166-
this_cpu_inc(exec_actions_level);
11671175
err = do_execute_actions(dp, skb, key,
11681176
acts->actions, acts->actions_len);
11691177

1170-
if (!level)
1178+
if (level == 1)
11711179
process_deferred_actions(dp);
11721180

1173-
this_cpu_dec(exec_actions_level);
1181+
out:
1182+
__this_cpu_dec(exec_actions_level);
11741183
return err;
11751184
}
11761185

0 commit comments

Comments
 (0)