From patchwork Tue Jan 12 23:39:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Frederic Sowa X-Patchwork-Id: 566769 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 85B80140B97 for ; Wed, 13 Jan 2016 10:40:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=stressinduktion.org header.i=@stressinduktion.org header.b=SLquwHMO; dkim=pass (1024-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b=d4x4ZUqt; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753484AbcALXj7 (ORCPT ); Tue, 12 Jan 2016 18:39:59 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:46237 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752483AbcALXj6 (ORCPT ); Tue, 12 Jan 2016 18:39:58 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 810E820151 for ; Tue, 12 Jan 2016 18:39:57 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Tue, 12 Jan 2016 18:39:57 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= stressinduktion.org; h=cc:date:from:message-id:subject:to :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=TsF9RbY/FKvtBYmYx1hU8SL89CE =; b=SLquwHMOURohV/47O+IFkIPIYMOohV54aMq+Mjzc1XnPO0P8Y9n7hrTncGy f7huFjG/yxLzMUSzPQGma3xCbTpAfd9ndjOuZ05gbr4pZTuSG/Aztahb+l4mcrqj uWkcDjwUQXvKiAPqsN2OViZ/Rnn5wltO/volCKpSNkNtH3Pc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-sasl-enc:x-sasl-enc; s=smtpout; bh=TsF9RbY/FKvtBYmYx1hU8SL89C E=; b=d4x4ZUqtK7Qa6vfpGbaXR4EL0lF5tl2cquxWYY12DG0+XwZuCrHyAb5QLj C8tTYTAuAjZHf5vvIdOsabOjpYzdqQdiNt2XkemORiP8cOkFpfxZyyLthDXfo/MC DAMKEKJwLMcJd+ZRjKsiQYqawIsiRLZenVo8VbpP8HeHTv6oQ= X-Sasl-enc: 2ndFW7Nzu63HhDF30UpHuDfr5PlxvrVz9Yxvg8jx7guT 1452641996 Received: from z.localhost.localdomain (unknown [213.55.184.141]) by mail.messagingengine.com (Postfix) with ESMTPA id 4C86DC00017; Tue, 12 Jan 2016 18:39:56 -0500 (EST) From: Hannes Frederic Sowa To: netdev@vger.kernel.org Cc: dev@openvswitch.org, Pravin Shelar Subject: [PATCH net] ovs: add recursion limit to ovs_vport_receive Date: Wed, 13 Jan 2016 00:39:49 +0100 Message-Id: <1452641989-31293-1-git-send-email-hannes@stressinduktion.org> X-Mailer: git-send-email 2.5.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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). Thus add an extra recursion limit counter for ovs_vport_receive until parts of the stack usage is moved to percpu scratch space. Cc: Pravin Shelar Signed-off-by: Hannes Frederic Sowa --- net/openvswitch/vport.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 31cbc8c5c7db82..9fb0ee8e5a4dc3 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c @@ -426,6 +426,9 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, struct sk_buff *skb) return ids->ids[ids_index]; } +static DEFINE_PER_CPU(int, ovs_recursion); +static const int ovs_recursion_limit = 8; + /** * ovs_vport_receive - pass up received packet to the datapath for processing * @@ -442,6 +445,14 @@ int ovs_vport_receive(struct vport *vport, struct sk_buff *skb, struct sw_flow_key key; int error; + if (__this_cpu_inc_return(ovs_recursion) > ovs_recursion_limit) { + net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n", + ovs_dp_name(vport->dp)); + error = -ENETDOWN; + kfree_skb(skb); + goto out; + } + OVS_CB(skb)->input_vport = vport; OVS_CB(skb)->mru = 0; if (unlikely(dev_net(skb->dev) != ovs_dp_get_net(vport->dp))) { @@ -457,10 +468,13 @@ int ovs_vport_receive(struct vport *vport, struct sk_buff *skb, error = ovs_flow_key_extract(tun_info, skb, &key); if (unlikely(error)) { kfree_skb(skb); - return error; + goto out; } + ovs_dp_process_packet(skb, &key); - return 0; +out: + __this_cpu_dec(ovs_recursion); + return error; } EXPORT_SYMBOL_GPL(ovs_vport_receive);