Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3300069ybb; Tue, 31 Mar 2020 02:24:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuCA05slJrOSs+QffSWFJzthMSofuZkiYsX64NIXHBCR45dN4+mg2hibSHl4CfTZYR6oceC X-Received: by 2002:a9d:bf7:: with SMTP id 110mr12891624oth.259.1585646680044; Tue, 31 Mar 2020 02:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585646680; cv=none; d=google.com; s=arc-20160816; b=jBNKr7y+M/nnQG+sGW+IaRvtOGDZDhEqmGbRhyLqfqZC8RJAVyIeqh0gCV1eTlULXJ M3s8Aae7MjUYjBG/SizFWZL9TquNYCFX4/ipDv9Dnyol93fR3ZsvGMquEKJnh3m0NIsa CFywzQ1hUs0u3v6PxwFBoME04YFh4f0SNzN0vhvQolN8tlVY20HKxLymG7Z/1NiPIZg7 yRe0D7WsExfFenmLaMG4Eu5zdV6eOINEj5vNiyfwkyRv5COCmLSdW7xKYT3hotLZrIZ6 r8cdBCzKmODfZoGTnAwzMUwUh9wx70DR3X7itBOzVj7QGPX2e2fkuXaoJe5spich0Ozk khRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZK1sPFCB0tQnY5BV11/a6AaqhgraLsdp566CFmqfv9M=; b=1GYykqvUAps8wI6iZU8Zm7qLg6+KIIeHkEIwhk18BeHfhWDl+MKiJvNXR2nUFNf97y ct7GAc+Wyhj7V3D4xbOty8w9cxEuOav75iJbi6AworT521azr1qLWIWZs7Ie1+GR+PPl elXGd4bbwLKCWdxCMgZhEn/FBpgcB0uFU/KcIulUmZV4YJpkywyTvMe5ckxyBTTctzIj 6827McG6R2j3+K0qYgZI+BIUTb6cC7pK9qGmIpkG38XMwZLIJHZNJ8NSffhzI1h2Js6I pHZ8itMmnO6+6vx4W/RlSgW95ST7egUa1GEay+3BsQcb3PlYnvzunk3BJKFQk4F4jKe8 TFFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XgEJA1+n; 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 b22si9406139ots.245.2020.03.31.02.24.28; Tue, 31 Mar 2020 02:24:40 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=XgEJA1+n; 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 S1730607AbgCaJEE (ORCPT + 99 others); Tue, 31 Mar 2020 05:04:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:43852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730691AbgCaJEB (ORCPT ); Tue, 31 Mar 2020 05:04:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D93F20848; Tue, 31 Mar 2020 09:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645441; bh=Oz0qI06ehZL1R8FnE8z2ekkD37JMOBJNah1EdjcNgbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgEJA1+n/Tg5P0P4yiTOCw/TEl7iaktdGZ/1YL/5U1cWF+S0I5ILmghP86VcNDpcn lwMXBY5sgzeqrrWf/aosnL85CpZdZdzdyg2qH8Tnb78YrxJv02EkyVFPkZ6sO9fpY1 FPQn+AoUBfYa+T51EhYP2opn+YtSJSQzSvN9oP3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , "David S. Miller" Subject: [PATCH 5.5 054/170] hsr: add restart routine into hsr_get_node_list() Date: Tue, 31 Mar 2020 10:57:48 +0200 Message-Id: <20200331085430.189432340@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taehee Yoo [ Upstream commit ca19c70f5225771c05bcdcb832b4eb84d7271c5e ] The hsr_get_node_list() is to send node addresses to the userspace. If there are so many nodes, it could fail because of buffer size. In order to avoid this failure, the restart routine is added. Fixes: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)") Signed-off-by: Taehee Yoo Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/hsr/hsr_netlink.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -360,16 +360,14 @@ fail: */ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) { - /* For receiving */ - struct nlattr *na; + unsigned char addr[ETH_ALEN]; struct net_device *hsr_dev; - - /* For sending */ struct sk_buff *skb_out; - void *msg_head; struct hsr_priv *hsr; - void *pos; - unsigned char addr[ETH_ALEN]; + bool restart = false; + struct nlattr *na; + void *pos = NULL; + void *msg_head; int res; if (!info) @@ -387,8 +385,9 @@ static int hsr_get_node_list(struct sk_b if (!is_hsr_master(hsr_dev)) goto rcu_unlock; +restart: /* Send reply */ - skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); + skb_out = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); if (!skb_out) { res = -ENOMEM; goto fail; @@ -402,17 +401,28 @@ static int hsr_get_node_list(struct sk_b goto nla_put_failure; } - res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex); - if (res < 0) - goto nla_put_failure; + if (!restart) { + res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex); + if (res < 0) + goto nla_put_failure; + } hsr = netdev_priv(hsr_dev); - pos = hsr_get_next_node(hsr, NULL, addr); + if (!pos) + pos = hsr_get_next_node(hsr, NULL, addr); while (pos) { res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr); - if (res < 0) + if (res < 0) { + if (res == -EMSGSIZE) { + genlmsg_end(skb_out, msg_head); + genlmsg_unicast(genl_info_net(info), skb_out, + info->snd_portid); + restart = true; + goto restart; + } goto nla_put_failure; + } pos = hsr_get_next_node(hsr, pos, addr); } rcu_read_unlock(); @@ -429,7 +439,7 @@ invalid: return 0; nla_put_failure: - kfree_skb(skb_out); + nlmsg_free(skb_out); /* Fall through */ fail: