Received: by 10.223.185.116 with SMTP id b49csp5461288wrg; Wed, 7 Mar 2018 12:09:18 -0800 (PST) X-Google-Smtp-Source: AG47ELv+lvhLqUTCEswS0rAL9tz1kOluOzBwj0Jh5m1d8COs96hTscHp863hBPOBttFPl+yJaj9N X-Received: by 10.167.131.135 with SMTP id u7mr17224652pfm.50.1520453358657; Wed, 07 Mar 2018 12:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520453358; cv=none; d=google.com; s=arc-20160816; b=BUNvdztPmhHiBz93w1UybhLNRkrdJJhx9Sljd4HKuhPBoIGGj2jCrlMHNUFhyGKNU1 /qJTplnHAIyPaXixlmHwfyibvdGBBcflYZ4F6DgR1dLDmk8oPp/8KFW+nZhsJ6oI9kDW w7IRwhulPKEzL7ejyw/rSqk7NHD7MoGbrnKLS0NlDRFK3ufotnHe2nbpWq/Mudc1LpWr jh4ggad3rSZFAdxYlDBUboC7Kf1Ryt0Oz0541liPpR54LBLBcmUWji1x9Jb02+I9KLh+ RkxSsPI95qh5I2C7h6nqMJyMYpmEFtzY9z+R0JIyd0kN6mBn/pieP6DbsX9NkFTSLTP3 XNfw== 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=RvYIcvU61ivm+3eFfEu/8nQVXqQaqIaw1jdVLaA4tHY=; b=gdYyfFjyI1cEKE6ttvGZ+QpNM64LmNYp4S7sbjt+fcvlBXBfhve+GtR2Vm2rUwm0FA V60D6yK5mydJRSu4ER1NdWFoEMaSw6yrPynFL3AT2f4ZBvNW1LB66XCUaXnFEMasAFEO 0j5RG66ZF0mzO/FsYtyiyk9oZNVzmBmRQ5EgcKS3CvWbwYpQDC+ERyBAM8cRVe8WWeXO ImuOzATRyqrDxg6koiQjIuxQrwZrX0yXb4zSN595zdyShlxfbp0Ap8oW7SZNnBGhtIJj Mko13wpFWgVH5z5mUfNKEmHrz/tbTDNcgzyyBf6K4mkJIAtkHo0w3j12Fkt4wqu07g27 qNsQ== 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 w24-v6si13110229plq.553.2018.03.07.12.09.03; Wed, 07 Mar 2018 12:09:18 -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 S965186AbeCGUGw (ORCPT + 99 others); Wed, 7 Mar 2018 15:06:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44422 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965440AbeCGTqB (ORCPT ); Wed, 7 Mar 2018 14:46:01 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 041A1FA2; Wed, 7 Mar 2018 19:46:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tommi Rantala , Marcelo Ricardo Leitner , Neil Horman , "David S. Miller" Subject: [PATCH 4.14 048/110] sctp: fix dst refcnt leak in sctp_v4_get_dst Date: Wed, 7 Mar 2018 11:38:31 -0800 Message-Id: <20180307191045.865516721@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tommi Rantala [ Upstream commit 4a31a6b19f9ddf498c81f5c9b089742b7472a6f8 ] Fix dst reference count leak in sctp_v4_get_dst() introduced in commit 410f03831 ("sctp: add routing output fallback"): When walking the address_list, successive ip_route_output_key() calls may return the same rt->dst with the reference incremented on each call. The code would not decrement the dst refcount when the dst pointer was identical from the previous iteration, causing the dst refcnt leak. Testcase: ip netns add TEST ip netns exec TEST ip link set lo up ip link add dummy0 type dummy ip link add dummy1 type dummy ip link add dummy2 type dummy ip link set dev dummy0 netns TEST ip link set dev dummy1 netns TEST ip link set dev dummy2 netns TEST ip netns exec TEST ip addr add 192.168.1.1/24 dev dummy0 ip netns exec TEST ip link set dummy0 up ip netns exec TEST ip addr add 192.168.1.2/24 dev dummy1 ip netns exec TEST ip link set dummy1 up ip netns exec TEST ip addr add 192.168.1.3/24 dev dummy2 ip netns exec TEST ip link set dummy2 up ip netns exec TEST sctp_test -H 192.168.1.2 -P 20002 -h 192.168.1.1 -p 20000 -s -B 192.168.1.3 ip netns del TEST In 4.4 and 4.9 kernels this results to: [ 354.179591] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 364.419674] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 374.663664] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 384.903717] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 395.143724] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 405.383645] unregister_netdevice: waiting for lo to become free. Usage count = 1 ... Fixes: 410f03831 ("sctp: add routing output fallback") Fixes: 0ca50d12f ("sctp: fix src address selection if using secondary addresses") Signed-off-by: Tommi Rantala Acked-by: Marcelo Ricardo Leitner Acked-by: Neil Horman Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/protocol.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -514,22 +514,20 @@ static void sctp_v4_get_dst(struct sctp_ if (IS_ERR(rt)) continue; - if (!dst) - dst = &rt->dst; - /* Ensure the src address belongs to the output * interface. */ odev = __ip_dev_find(sock_net(sk), laddr->a.v4.sin_addr.s_addr, false); if (!odev || odev->ifindex != fl4->flowi4_oif) { - if (&rt->dst != dst) + if (!dst) + dst = &rt->dst; + else dst_release(&rt->dst); continue; } - if (dst != &rt->dst) - dst_release(dst); + dst_release(dst); dst = &rt->dst; break; }