Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp460420pxj; Thu, 20 May 2021 13:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYRPIZFFROArePg0vOy1+xZwYzPfmb05DthD6sz945y5/LdsTG8iKkUvXT6C2GxSvd1k0c X-Received: by 2002:a5d:9644:: with SMTP id d4mr7321847ios.84.1621542548959; Thu, 20 May 2021 13:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621542548; cv=none; d=google.com; s=arc-20160816; b=ZvX/no9W10Rt6ev1utaUxXKv0sb75X3EUvNMz7kPv8FzMluYli08Mf2bhdmSZycA4F Bz+xnCW9vec3u8qrHmvnxFhCBZZCq4KpGqro0Q6oAJTlGWwNysxlbEYNZ6S+rJzGaXaT TNmloi9WygVenX09nR9Mx7mDh5bjXldF6ftZXvO02r0h7TVe7Loa13LKsHCNA9qBI8dy QEoLhasPrjFCDIpwqQMuV4tKISHdHzTMYK4UESgAUqj/Sq31sM4edbzPJyNrXpLIhAQV k7nU/esKbulzgrm08LOuCl0n8xtP06S2jNhzU9ZcRJLb6/j4bmaXJ2sgjbCA/rAx37dW dE7g== 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=vpsmdjOPhPAIPMOTF+nKyV9n5tneWentG9xUvM/2va8=; b=uN5fPxki7Mm/i6CCY2uhSJgZWQV/ryHSfmS13aUge0sh9D/H59yCus5RMmGwzkRdvj 8KZ1LzFI+p5JzQLk7nNsOVuqjMsDtANzL2qvNf3iRfEcjdIOhcHwTequK8USkc4nioeO T1xBetsG2G3oPdGf+NIfFtn0GqMthwJxECaMzRpOpETpw4gP2BzJA1IX3MgWCGCfrva0 u9M9kpmaLJii2ixQZ7WvXzZkz1y3UCquO6wd5SQ79LWss+dg5q40PJ0jE73onIwnzo/p LO0c57hBWJ9e9OGV115Qwrwci47zF1C1RPaUeyUsBA5uFNvzklTdjkpaHwuGzzN4TNqC 29Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="dPL/xUoE"; 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 w12si3218137jad.49.2021.05.20.13.28.56; Thu, 20 May 2021 13:29:08 -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="dPL/xUoE"; 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 S238605AbhETKxq (ORCPT + 99 others); Thu, 20 May 2021 06:53:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:40080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237274AbhETKiT (ORCPT ); Thu, 20 May 2021 06:38:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 42E2D613C0; Thu, 20 May 2021 09:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504490; bh=DGmIQn6oImeSiXY5vbZ7+UpRlO6h6eSIf8xyQ6tvbd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dPL/xUoEKqQOYgXlWcm93pp6kLQdK7pLomyPAHDPmkwSfVnJfWYoXctUeXtNk7iVk 80JltfrfczUKwhHqxfgipJEyNYdNv/IUbhlRpSx8NMV10sYjBZRBb7cYYw53zB0VVr v5PZFEY7gh/3W1Eow/i3DO5dssbpZbDy4VfZJcN4= 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.14 268/323] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Thu, 20 May 2021 11:22:40 +0200 Message-Id: <20210520092129.399604815@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 80b9f7f097fa..e943fb28f581 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1888,7 +1888,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