Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp381705pxj; Thu, 20 May 2021 11:29:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy79BEBO+hJ1w08La3Snu785vAj47Wrt4PXlo2d/0WHvPE4od67acvMyuVqQyB9bLee/wl X-Received: by 2002:a17:906:3615:: with SMTP id q21mr6096784ejb.414.1621535368232; Thu, 20 May 2021 11:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535368; cv=none; d=google.com; s=arc-20160816; b=K7cNhn+6xOS1MCer962pQHgjjCt2hVov852i7MV8aacAuRNonHEXUJ2gHoUAsLMA4B Rjka0R1iHB1j2w3r79Clj1Uqv/Qe2zdTUIWHG3P9IBLXVf865qM6JStAhFtsAx/WHl6k BZApdHYMYCDBlCE82KgPr+XeAGPSBLDtmyD7BMkxuiHdWaEMSG6UTEV41D6FsKshKf7u vS0A2sm2sczDaR6q885bJj+U3jFZN3ADWMHZ5vFW859KsjScZXqqvlwlBp6NYTWgdocO aC08w4wvFDjlrtU3qSIKaGFKW4rtMigtQIC6D1LtaDwz3ykoKpicGVSfqGXti4n632Kg PSlA== 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=3C0Fl1yDxI3QGqgrXTas1GI4pK5qSwFPYilCiNeD4UA=; b=w96B4GcAlxxaU5twJ0foa1+jaVdcNdtsUSYFCVRbHS/kjzmVsjth1drNQ3b65quI5v efO/XLeNstOUfVk8uZxw/PnzYAscj5tBVDanlRQ8FswI6cZP2s//M6jz8540NSDt/Cx9 CxLzViwmQC3vd5+BZ3qMvs/qVtiFeockOM+WgMgqouS9xoanaWn/NAU3Mj0t8dGi5oEX sTuctn0yYjb+lSJKfHuBzJp7b0LK0JD1wKfp6W6i2feXmlhP1dSD+fLCqgjvjcZRybs+ 2D6W3Omu1Da4lni5ZWMP2SnsTrkdqGtyZ6bXS2xmo/t7dPjNqu8G0NL/+pna7ObjsY3g CdEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uVfDg/Rs"; 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 s18si3926091eji.59.2021.05.20.11.29.04; Thu, 20 May 2021 11:29:28 -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="uVfDg/Rs"; 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 S234552AbhETKPs (ORCPT + 99 others); Thu, 20 May 2021 06:15:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:42434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235707AbhETKHb (ORCPT ); Thu, 20 May 2021 06:07:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30BC561425; Thu, 20 May 2021 09:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503718; bh=/vRINm2inUXT1BBueNtSb1XjWGGJo/Mnn0HPG+2sUvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uVfDg/RsLtmV1Bw34ERGYlCR6VYTmRBY4+0eHG8IScjePvSYHMnhwieKdCzdFqg9b fdjUGflTKSYnQ3bNRcRa86kwIG8f3K6fS4GfcWvcS2O5E3x5sQH/Ssz9X00b+Vqx+u 7vvQqGI63rfatRerWjWgIXOg350Olht9zF2K6T5o= 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 4.19 348/425] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Thu, 20 May 2021 11:21:57 +0200 Message-Id: <20210520092142.843961400@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 882cd5f40a0a..be5ea5e8b19e 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1948,7 +1948,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