Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3080734pxj; Mon, 17 May 2021 17:16:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC+bLfYNUbzaHa1pbxYbjRe4qdq3yA2rYvh9vpWSY+7iPCpGlWe4+pPhHXjMjixO0Dw+gp X-Received: by 2002:a17:906:af70:: with SMTP id os16mr2704193ejb.201.1621296999700; Mon, 17 May 2021 17:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621296999; cv=none; d=google.com; s=arc-20160816; b=kR+PIbRriG6kkA2LiMbCdOgxLlhudCMN4Wvbirrj/3QaQ22S0oWHGX1RZv4hx+tfsr iYGyW1M1I0k22odogbU7kYCxAgvL1Jfqv8i91SFmV9q5d2odfqPzT/Rzvm4Yg5JUxsM3 hUB2xotXQDdkVk4ZOOcNViSfb3fEhvNIQJrEYLMYOh6NFfdOrBDuJWOkyt0RFtiuGlI+ z/aI9BNdPn6icJLVMeET90v6xQj2ZCAFn40cZTmKKcvChxermHek5svynfa7JDcTBJTY XPiFthGAja7aIMuNx6sfj4D86h7ovkl+sJDalP+37ZaPaDOCn2EXvB6SOkaaMsvR4o5y OpFA== 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=AMGZjxCGmbMrdGFyDHxLhsGDdhrE9vtiBIiPDRVEAwY=; b=JIkcOmGz9kt4O6yZQBcAy7LSS8BPHQrFbYOi8VWBprUARbCLR7qT4DHxF/60val28p zUjll4qT+f7Rcn3c1khXMSbBza9XY+F4uwaYipQPxbAAnRrR/qakhX5dLtB+aK/bUJ1m zOQCLdI0rgW1ikCi5dUeJ8WIsEqYItkb02cJLdhbxHdDEwtuCXt66TNuRUw01dho/gjQ n9kWbnsvGXn/tZMYYJTMcXqrMPrfoUlaJBjGr6r2zxYzrVl+ZHeYguuwuCc9kasLdy/E 8WIgfmGrGsDt8xfEdDWzDy8NtjC3glJJRRgkaCTeTdDqufI4meoFVoIY7M0Ko6UctFr1 morA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vBGXtG3p; 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 p10si16071694ejo.39.2021.05.17.17.16.00; Mon, 17 May 2021 17:16:39 -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=vBGXtG3p; 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 S239142AbhEQO0M (ORCPT + 99 others); Mon, 17 May 2021 10:26:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:36010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239225AbhEQOW1 (ORCPT ); Mon, 17 May 2021 10:22:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8E84613BE; Mon, 17 May 2021 14:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260719; bh=Gyz8a5InTYkZXWKi7pCFWIwgU7luEqB4PmUgOTWukFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vBGXtG3p8YJUwMMq7bFAKEOQZrgRyEW82K835pfIjBv9SoxipF44tS0FNwV8d9Jdk GjEOzhMkfoUEN9nE2XIbIG06ywvj7iO8yO+MZnPm1pbWtif6EiV/D6Qjkb+6L8OLOq rIDtfW0p+gehTIY7WTcj4wpo8CJ1tHGhKBSQq0eI= 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.12 208/363] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Mon, 17 May 2021 16:01:14 +0200 Message-Id: <20210517140309.617599358@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 c7138f85f18f..73bb4c6e9201 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1944,7 +1944,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