Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp607116pxj; Thu, 20 May 2021 17:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMAdy5tABI87NIQy858j3x7lL6vNv+N2BaPaCcB8D4M0RU8SCz2VoIyAQrXBvFQsiuV3oc X-Received: by 2002:a17:906:22c6:: with SMTP id q6mr7251795eja.275.1621557705743; Thu, 20 May 2021 17:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621557705; cv=none; d=google.com; s=arc-20160816; b=NYu1qdyhCPzG3EhnhA5QqQ33koIjQG+j9kEQCbKjLRaD75ZFHiEMUJ8KmaD8Eb17EH ADTGzspmgrpo7y84x7VlRmCeGLezZHiUX7+hTJTXGZvCpVYABVemnFQDe2b3UIfM8XKW qHREfXjRo31YnzcQU4F+6KBesHx04nJBm1j6kE7nMpm5NNlYcYh2FRdoV59Vs7ediUtN VuwGncNS6dN2MpNCm978IH/oJgO0EyxiENiPV2zKZy64DgRM9FYfCuwNoTc5qtQGaaJU vYK3Ua1YU0f1Y66qWVLn58a0V+/cnDrL5Rc0Qlikf51Gknzsotb9W6Z1FFSiz9I4xjXo gF1Q== 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=BhawnXjkrqLQ5ACzJcDjT3kUMhgJv2OEyyGTrsLvZ1Q=; b=EhmL/67+gzYNpVAWg+DyDRpVvqzUTYjRHMuOpunOciBUf7DOdLxcLwBAvkhmzxzp0y RRQcW74VrWB67cgKhaG/j6gzuhQwxfYCWI5tVF1FBrHVGduKa71yVZr2Hg1NOObS7ycb 8C48XFNJffwTs0HoE3ZPUMUjWN8iZX4iscVgeauaTKnFZsK+ER5OnI4WxjwsJx7iapLz vBzLvC4l+e8e5ZeYyUmW6bdmZDBDuDcZlGwAq2CcwCKSoAZxpjFQzwgBYtNrBkVLvWKC ycP7Qkd5s6Y6SNlD7uhEkADg8ZuG7jCqu7+pmn8uu3546ox9ZGeMZFx761ujq92NwWUw 7o9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iSCKPOgd; 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 dh5si3418383edb.241.2021.05.20.17.41.21; Thu, 20 May 2021 17:41:45 -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=iSCKPOgd; 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 S241073AbhETLXk (ORCPT + 99 others); Thu, 20 May 2021 07:23:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:57500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239244AbhETLCd (ORCPT ); Thu, 20 May 2021 07:02:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D011761923; Thu, 20 May 2021 10:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505049; bh=jfsRrB9tjlkcG7EqrW5XFjZ3xhqhWdzLrvSFZlS54vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iSCKPOgdgXfYkq4MVzCcidhHZqcHCE+nRdwagPD3SAzUCegKSqhncwjduJeb6SjbL YaQHboYCcrFwb5sk4OfCxk+Lf0C0Y7wkLFtD9+2YoyAv1PsSUaOEwdIU27kYwGCObk uT2eWRdDE66RC0QPMu3E4SrGfbVdj7ft7fJ1A5UE= 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.9 199/240] sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b Date: Thu, 20 May 2021 11:23:11 +0200 Message-Id: <20210520092115.335834355@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 146b568962e0..9045f6bcb34c 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