Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp480129pxj; Tue, 18 May 2021 07:39:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz527TRkVKBmvZ3aBvrKaBAbBQ0PgnFOYooWFHA4URkZS6UhSefPy+g7sZMy9abPkdfXi+6 X-Received: by 2002:a17:906:f211:: with SMTP id gt17mr36075ejb.360.1621348790361; Tue, 18 May 2021 07:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621348790; cv=none; d=google.com; s=arc-20160816; b=WVE+5kcyRvVpVujUcY4aZZZhbBJYHErfeSmiYUgdlDaCKhF6d/SJ2uhnBqMZLgCeCt a0QlxTaApmHQZED/s/uUuLLnDCF7gDOh7g/+ktctKMv8AP7zRoFTU/GtyDdauLjGHm7e EEdQ6mksCoeCnXhdacrRRhMGbxuWzgqGnOQf7+hQTiEND6BExJhU67LZEaUCI24iZF4p NfcPA6Gsukp/z0rQvHkZl68J3n32ecv4Gr/Gs7zB2f2cmHa4r4cVpy4IrybMWuP2GL2F NDgZ4FGAsz04ty0efZzmBSZTANVSkdMAo9fR10MTCy3skKX5aAOz/TtTmojCFt1Pc/zV NQGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gRaE+b59wx49vLfaSK25el1lFk9ObivKLvdDWQ4dWcw=; b=Ble8T7wlob9LdmeOYbb3Q7NyhPMoEQmcwJjQ5dh4ni+gGfgcPD7f0ZjeKChwUgoL2z gaFxb5tuRaegkD4ul5GU/03g7HIjDoywQB+TNRNnIvq9D0jFkWxGfm8W7PrgcDhF9aRI xR0roAUr/nx9K+eFRuJQ7KpTOf3hvPhrM5SqX7R16G/U8j7dD7RRucJpUTm0/5za8/Od DkuJ39OSqi0WzCMdLMuo1Mcty0b88Ist0nmDzEMAOIbNuMsObFwX25/BaUa3WJ3SeyUA 5zAuWQCYsjKbQKHixZ0H0zD4e/xraSToCpFd34oC/pjlgy9GzA7IRwiaajwCkDun7Y2B mTCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iPbsCp6a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lv19si4356039ejb.257.2021.05.18.07.39.25; Tue, 18 May 2021 07:39:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iPbsCp6a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238385AbhEQPsI (ORCPT + 99 others); Mon, 17 May 2021 11:48:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:54174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244021AbhEQPcG (ORCPT ); Mon, 17 May 2021 11:32:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E22D61CBF; Mon, 17 May 2021 14:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262308; bh=gOrwnBjMCh3rK/KlU0FplSlsr9Pyamyy1G0DCXz18Nk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iPbsCp6azrVoNZmdBCtl6iEY46Hv+oqo+dEO7JLhrxfbECd62sx60NDxGbafxGfXN QSPiqcpXGMlqP0yIT4YLn7gj0TapqsSDdesAbxAMesfLI/JWtQDIFlf1XP5ZCa5Og0 s4vDq02k/wo4ZciiATSLbQW5eby1p93IfVrfVJAU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcelo Ricardo Leitner , Xin Long , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 158/289] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Mon, 17 May 2021 16:01:23 +0200 Message-Id: <20210517140310.448544602@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit f282df0391267fb2b263da1cc3233aa6fb81defc ] Normally SCTP_MIB_CURRESTAB is always incremented once asoc enter into ESTABLISHED from the state < ESTABLISHED and decremented when the asoc is being deleted. However, in sctp_sf_do_dupcook_b(), the asoc's state can be changed to ESTABLISHED from the state >= ESTABLISHED where it shouldn't increment SCTP_MIB_CURRESTAB. Otherwise, one asoc may increment MIB_CURRESTAB multiple times but only decrement once at the end. I was able to reproduce it by using scapy to do the 4-way shakehands, after that I replayed the COOKIE-ECHO chunk with 'peer_vtag' field changed to different values, and SCTP_MIB_CURRESTAB was incremented multiple times and never went back to 0 even when the asoc was freed. This patch is to fix it by only incrementing SCTP_MIB_CURRESTAB when the state < ESTABLISHED in sctp_sf_do_dupcook_b(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Marcelo Ricardo Leitner Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/sm_statefuns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index d4d268b8b8aa..b65bdaa84228 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1933,7 +1933,8 @@ static enum sctp_disposition sctp_sf_do_dupcook_b( sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, SCTP_STATE(SCTP_STATE_ESTABLISHED)); - SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); + if (asoc->state < SCTP_STATE_ESTABLISHED) + SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); repl = sctp_make_cookie_ack(new_asoc, chunk); -- 2.30.2