Received: by 10.223.185.111 with SMTP id b44csp901295wrg; Fri, 9 Mar 2018 16:24:06 -0800 (PST) X-Google-Smtp-Source: AG47ELsNXJ9z1+V252IYRSx9NolUougUM7gGyXrXvZS/LuDi7/frrEHph9ze6a5yHEo3PpuDZyyd X-Received: by 2002:a17:902:9a4a:: with SMTP id x10-v6mr341928plv.256.1520641446088; Fri, 09 Mar 2018 16:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641446; cv=none; d=google.com; s=arc-20160816; b=qcDI58J4If5cAu2JkXHUHpkSnIZOtXGaX99AVFG0DYZpTogb5j/ItwxKmZH++KEHzW 9Mr7r8aRgtnvCkRKRnrFgCnY7g8fJo3m0L/fG22I+s4fSaUTrvobU3G8Z2kiMd4Pe+K0 RV/7sIIwCsaqBivrUXslaz74Jbe/4uUlJrQgQQneXtggncGRh2cmsNATDMndmpPQeQB3 6rzpH1siECA5t/oIS1GGNbfKwkc5sB1/Sj4ZN3tN9he0b/QFFZVDrU2GUkCaghZvADpe 9E9dxb20auFJwFD9TUwrd8WupZOMIm3oD/XuFDTM5nJmLQJhu/Gg7127FXaF07dC+tmi lMFA== 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=Ws8Ofx0bASgqATAfFykxNu4OBpgujsaa9xXlgnnrI+I=; b=GxI3ef54kfJ9BEjA29Fb4fN2kRT90NkeEdbHohyNZ0HL2NmstqmcrZsoLLd98omeTJ aCry+cpMS9lcNw3Jzha77OgehcP/mpU1GW5mfAQ3VAxRBE19vxNrHCr2RGy6w2oSnKqk S+ZukGOnNVJuj5I1g3Ef2Clh/BUY7CvtdPvGSdUWZctY8jQJYE4XtV3Q/JCIhgRTUX+E dm8wzCALWKLoFYog1dZ/DJRZ+sCBgVAA2AVpw5VuFytCQ6EQ5AK8BP4CGEUCS9XrXf9L 1ks/65bwmJXYqaR12dnMpkHHauSchUVs/zBWxZZkzt/zKMEQTX6tLWDOiDhXjEmI4sUl k9GQ== 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 k131si1480964pgc.361.2018.03.09.16.23.51; Fri, 09 Mar 2018 16:24:06 -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 S933864AbeCJAW0 (ORCPT + 99 others); Fri, 9 Mar 2018 19:22:26 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39978 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeCJAWV (ORCPT ); Fri, 9 Mar 2018 19:22:21 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5264B1181; Sat, 10 Mar 2018 00:22:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kodanev , Neil Horman , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 4.9 48/65] sctp: fix dst refcnt leak in sctp_v6_get_dst() Date: Fri, 9 Mar 2018 16:18:48 -0800 Message-Id: <20180310001828.807994342@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Kodanev [ Upstream commit 957d761cf91cdbb175ad7d8f5472336a4d54dbf2 ] When going through the bind address list in sctp_v6_get_dst() and the previously found address is better ('matchlen > bmatchlen'), the code continues to the next iteration without releasing currently held destination. Fix it by releasing 'bdst' before continue to the next iteration, and instead of introducing one more '!IS_ERR(bdst)' check for dst_release(), move the already existed one right after ip6_dst_lookup_flow(), i.e. we shouldn't proceed further if we get an error for the route lookup. Fixes: dbc2b5e9a09e ("sctp: fix src address selection if using secondary addresses for ipv6") Signed-off-by: Alexey Kodanev Acked-by: Neil Horman Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/ipv6.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -324,8 +324,10 @@ static void sctp_v6_get_dst(struct sctp_ final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final); bdst = ip6_dst_lookup_flow(sk, fl6, final_p); - if (!IS_ERR(bdst) && - ipv6_chk_addr(dev_net(bdst->dev), + if (IS_ERR(bdst)) + continue; + + if (ipv6_chk_addr(dev_net(bdst->dev), &laddr->a.v6.sin6_addr, bdst->dev, 1)) { if (!IS_ERR_OR_NULL(dst)) dst_release(dst); @@ -334,8 +336,10 @@ static void sctp_v6_get_dst(struct sctp_ } bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a); - if (matchlen > bmatchlen) + if (matchlen > bmatchlen) { + dst_release(bdst); continue; + } if (!IS_ERR_OR_NULL(dst)) dst_release(dst);