Received: by 10.223.176.5 with SMTP id f5csp1052834wra; Fri, 2 Feb 2018 10:20:49 -0800 (PST) X-Google-Smtp-Source: AH8x225rAm4URijvMtkLw+tLI50mGk7fuOcwIn7Z299d+POlS0fCLIIJd2AdcUtYbP5GWP1j2/dn X-Received: by 10.99.123.92 with SMTP id k28mr97092pgn.71.1517595649233; Fri, 02 Feb 2018 10:20:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517595649; cv=none; d=google.com; s=arc-20160816; b=gVl7RfO/ptVaKsA0H4SMS66RwcWKFOtew9HriOOMnfTLYFylawQPTgdZyTagz68dN1 yEV3KDcBXdHJvXFuVY+DbiId07JrLgJdU8slCxr9Sq3QMh0YH8ZjrJ8BiI7U1XEj+YdI H+ycN8XEtvsP5BTyere9PmlR5AnHKiTAF2rXdk2I8L4HFocG+m8oiO35VEN0iWH293Rq 9KiRlGkSju8aWoCMvjN0PJYK2mHNXxBFlLRKkiCNOF0HcdGhe6jhjOpwByWe57WPpNxf 3BfMj12vbP6ym5d5TgX2UH75k6ODUYJ67YxysbYW/dBNdWP9xn3FJZIk4kJzSn3LQDxJ LqKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Nt3ApN0cms1XUMu8ZvkbpE8scof0HY8wwZISr0T5TJI=; b=mGbxOq/PPQLqb7ukctyWBTYrCM3lbNApOO/Nu5v6BWbWqJLp2fnQCXIWApk1DwKTsu 5l/OiRshtXsfhA1obq6WXLK/nuWIO9fHc5LnTtZPymj0MpwA/+IvmZkdl5MLex+XxNKu 373gOmFNW7S04WczmWY3rm4zxmAy3JuCZz/1d8aTJuRl94ZZfsH+pAh7Arm5Pgp8Bo4u vfFT4PikScGFqp1SpChvdToWahnI+FH2tpmkcFc90iezGCekFgvsnx4auBLR6MudNvjM 3S34VH2ACByVhtgssKq8vADK/b2VRXIfUTM4jSi09ChVwYgHZ1+4BbNOKLUTPdHr01aM s3dA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t69si170671pgd.620.2018.02.02.10.20.34; Fri, 02 Feb 2018 10:20:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754437AbeBBSTf (ORCPT + 99 others); Fri, 2 Feb 2018 13:19:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36090 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752723AbeBBREE (ORCPT ); Fri, 2 Feb 2018 12:04:04 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 842FE8E2; Fri, 2 Feb 2018 17:04:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, zhangliping , Pravin B Shelar , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 32/86] openvswitch: fix the incorrect flow action alloc size Date: Fri, 2 Feb 2018 17:57:52 +0100 Message-Id: <20180202140825.515335098@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhangliping [ Upstream commit 67c8d22a73128ff910e2287567132530abcf5b71 ] If we want to add a datapath flow, which has more than 500 vxlan outputs' action, we will get the following error reports: openvswitch: netlink: Flow action size 32832 bytes exceeds max openvswitch: netlink: Flow action size 32832 bytes exceeds max openvswitch: netlink: Actions may not be safe on all matching packets ... ... It seems that we can simply enlarge the MAX_ACTIONS_BUFSIZE to fix it, but this is not the root cause. For example, for a vxlan output action, we need about 60 bytes for the nlattr, but after it is converted to the flow action, it only occupies 24 bytes. This means that we can still support more than 1000 vxlan output actions for a single datapath flow under the the current 32k max limitation. So even if the nla_len(attr) is larger than MAX_ACTIONS_BUFSIZE, we shouldn't report EINVAL and keep it move on, as the judgement can be done by the reserve_sfa_size. Signed-off-by: zhangliping Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/openvswitch/flow_netlink.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -1789,14 +1789,11 @@ int ovs_nla_put_mask(const struct sw_flo #define MAX_ACTIONS_BUFSIZE (32 * 1024) -static struct sw_flow_actions *nla_alloc_flow_actions(int size, bool log) +static struct sw_flow_actions *nla_alloc_flow_actions(int size) { struct sw_flow_actions *sfa; - if (size > MAX_ACTIONS_BUFSIZE) { - OVS_NLERR(log, "Flow action size %u bytes exceeds max", size); - return ERR_PTR(-EINVAL); - } + WARN_ON_ONCE(size > MAX_ACTIONS_BUFSIZE); sfa = kmalloc(sizeof(*sfa) + size, GFP_KERNEL); if (!sfa) @@ -1869,12 +1866,15 @@ static struct nlattr *reserve_sfa_size(s new_acts_size = ksize(*sfa) * 2; if (new_acts_size > MAX_ACTIONS_BUFSIZE) { - if ((MAX_ACTIONS_BUFSIZE - next_offset) < req_size) + if ((MAX_ACTIONS_BUFSIZE - next_offset) < req_size) { + OVS_NLERR(log, "Flow action size exceeds max %u", + MAX_ACTIONS_BUFSIZE); return ERR_PTR(-EMSGSIZE); + } new_acts_size = MAX_ACTIONS_BUFSIZE; } - acts = nla_alloc_flow_actions(new_acts_size, log); + acts = nla_alloc_flow_actions(new_acts_size); if (IS_ERR(acts)) return (void *)acts; @@ -2500,7 +2500,7 @@ int ovs_nla_copy_actions(struct net *net { int err; - *sfa = nla_alloc_flow_actions(nla_len(attr), log); + *sfa = nla_alloc_flow_actions(min(nla_len(attr), MAX_ACTIONS_BUFSIZE)); if (IS_ERR(*sfa)) return PTR_ERR(*sfa);