Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp67345pxj; Thu, 20 May 2021 04:44:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6U7wuOC/HE2GuCybyy/hsuWi4OIK0m3mW+MkzyCzTg3Uoh/pleTyXYXYeYQ7vTfIWBvLH X-Received: by 2002:a17:906:38cc:: with SMTP id r12mr4264428ejd.150.1621511066191; Thu, 20 May 2021 04:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621511066; cv=none; d=google.com; s=arc-20160816; b=h6bGcvkuefFEKjqDAUfP7eXMTh9S0o9BneeRBXuz6UiQyKXtaf6TTrr5KM60RQLi8s Ez/+tUt3GSQx6usIWOQW0RDjYdEbXdtKTH6Oyi/MpvOo9LGMqqxU8FTfOFWLb20VEMBi 9IxoI8aBghpEkRwiAwHBvTIwj8sqEHci+SkVfhT/S6tUVIYxr8Sm1qRiZscq4FAc8z2S jF530yBMCmJNUGscBibZPnuuzV7I/PGv9wnczhYhKnIQH9YlkEhvh0wFr8ciRYZqiy1a XOJFEeIbRIINcis1+VgH6ZExeTTCMm62NshyM7HsOdiH6n3MNwPfxNujt0pFbrXz4hTf 5Hbw== 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=X/h/loRDACMk8KruaXCyw42wuxjKYk5eYqD6EK4OZj4=; b=arNit8nwO8TQ2kwj6tXaFup152pZEi17F2h86d/g3AXH5ZsOqO3y0j9+xxGwQhVxq5 YdUeNLZnwyeJA3cktyJMuYW4tC787mavozwlZA3QTW4iEuClFreT+IKE7Ch70oVThj3x +zC5XYUg/4dTkJH4dI62Yux9+HuIyKvbMQBjjcFzIppkoTi0le2Sm33M1QA4rb+sN+R8 WoUFmSuZCVOYnO+aW62K5cfB5VZLriDvVs9Eqb8uvRr0Mx9wdS+8Njq6dKDfG/7ybl+a K288lrM/mm302YzGFrUM06s+6AOxlmKjBuZAtJts2THokz8mAHd/zm6+xDgZren1ezOn kscw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M7EhijdC; 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 a90si2080272edf.408.2021.05.20.04.43.59; Thu, 20 May 2021 04:44:26 -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=M7EhijdC; 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 S241406AbhETLmS (ORCPT + 99 others); Thu, 20 May 2021 07:42:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:44410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240968AbhETLVp (ORCPT ); Thu, 20 May 2021 07:21:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0B0FA61430; Thu, 20 May 2021 10:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505487; bh=rYCCULLztU7od0So7eMpCzb6sjaWePsMR0pnfPpPrNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M7EhijdC20hUMwa1vB2PScnSvYCiKyVdN3cOFaW5lvPK/jhsM2nUyj8fDmUfvVnbe tb5KeMTjwkvLAE0nn91wyjxQein6m16ckOzbMlZQLCHN4YrCH90y7YMZ/4BIMLze/b 6UqHpGx+itT+P5A7OyEvyuVuI0rwf2UyTfd4+iiY= 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.4 158/190] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Thu, 20 May 2021 11:23:42 +0200 Message-Id: <20210520092107.389871451@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 a9a72f7e0cd7..a9ba6f2bb8c8 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1851,7 +1851,8 @@ static sctp_disposition_t sctp_sf_do_dupcook_b(struct net *net, 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