Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp693912ybg; Mon, 1 Jun 2020 11:52:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOMRMsE78Gb6jyEC6eDzaQ6XKwPUYZXnaFmVdP02/XHv4dQrO/fsSS93H/xGD7e7c0VYP+ X-Received: by 2002:a17:906:b293:: with SMTP id q19mr21378891ejz.412.1591037547111; Mon, 01 Jun 2020 11:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591037547; cv=none; d=google.com; s=arc-20160816; b=n8ZEMIzUy27DOOz6dzN40ZTnMXM0xM47U2V9V2OhHUKaE0JYOlkk8G9WtdRakv5X/G MBCSFfbnUoSMNieApwneksGljL0iKUOm4d41ojvQn2DSca7n1am2MVWrlS/YQF8ODTkA I9jobWdmJkIjUY0fD8iUj8umIeudvRdRqthoWqRfrHiGW8dfSBuwdC80BoiHb4njqw0N BbqvWYJKZepZWyfstrBTgXhFgWgMrEPULOfnQ9B05dJK4I4LDB5WAHmRMJpZp/jSYVD2 FSOnDPbhqefcRzWXC6wYxTo4I/9vROkRH3iduJkJUAKfgSQVdlR+nhg9EZ1Sxl72yl/W y+oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FOdEgDHyxxvkei82gp3m2YQaBvl1VVVBVmFdTyXePGc=; b=WWnOL9hnNPX4M/j/wbKOqT6BIG+gu9mSm+ZMD0Ps63OXYWwgBTWBKxh+iTidwJNRCU LfQbv5/VbZ1Jf96qGRriuXuo3Y3YTQABLWldCM7uEjDCI1XajZe9H4JRpVcTVHnLCqwV eP8jCOswZFRgYn2heOgBe1Ixdit1Yw8srmTdKhzmhTjKppgPTUbbKwJiu0TguTBYyhCh 2a8hS2RldRziY7yJsAmR+7SkFw2oeQrKOqb7rkhaNC5Wk3LzpfX36qc3W22+uyHPPQ1W H1gQpZ78hxRt3DdQS5fmz0st2wERtJxvDyjblElDhFV9wjJao45qOFH+vJNOTYr3FR5X qEuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kk2ZnYXA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do11si236976ejc.450.2020.06.01.11.52.03; Mon, 01 Jun 2020 11:52:27 -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=@kernel.org header.s=default header.b=kk2ZnYXA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728553AbgFASsU (ORCPT + 99 others); Mon, 1 Jun 2020 14:48:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:53698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730044AbgFASHo (ORCPT ); Mon, 1 Jun 2020 14:07:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6D7B2077D; Mon, 1 Jun 2020 18:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034863; bh=eb70qoh+OfrO/rHwsvzv7fHkdcQRk9oZcbVN3cI3xLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kk2ZnYXAHiUJY0aEBuWnLKKHv0uC7jP1cYbsWlpUO7ISnuzSfLDMKuL05+9zOwk9v 9+3aiwNLdemTiCJNACQ56lwVVuNYDjyeXvYu5UwAxIToqXsQ7YyWBs7Ea+elBslszB GhouesKBgNhE28JtcJSpsbQoFWNsSbVY6rgkz74Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jere=20Lepp=C3=A4nen?= , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 5.4 019/142] sctp: Start shutdown on association restart if in SHUTDOWN-SENT state and socket is closed Date: Mon, 1 Jun 2020 19:52:57 +0200 Message-Id: <20200601174039.861486968@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Jere Lepp?nen" [ Upstream commit d3e8e4c11870413789f029a71e72ae6e971fe678 ] Commit bdf6fa52f01b ("sctp: handle association restarts when the socket is closed.") starts shutdown when an association is restarted, if in SHUTDOWN-PENDING state and the socket is closed. However, the rationale stated in that commit applies also when in SHUTDOWN-SENT state - we don't want to move an association to ESTABLISHED state when the socket has been closed, because that results in an association that is unreachable from user space. The problem scenario: 1. Client crashes and/or restarts. 2. Server (using one-to-one socket) calls close(). SHUTDOWN is lost. 3. Client reconnects using the same addresses and ports. 4. Server's association is restarted. The association and the socket move to ESTABLISHED state, even though the server process has closed its descriptor. Also, after step 4 when the server process exits, some resources are leaked in an attempt to release the underlying inet sock structure in ESTABLISHED state: IPv4: Attempt to release TCP socket in state 1 00000000377288c7 Fix by acting the same way as in SHUTDOWN-PENDING state. That is, if an association is restarted in SHUTDOWN-SENT state and the socket is closed, then start shutdown and don't move the association or the socket to ESTABLISHED state. Fixes: bdf6fa52f01b ("sctp: handle association restarts when the socket is closed.") Signed-off-by: Jere Leppänen Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/sm_statefuns.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1856,12 +1856,13 @@ static enum sctp_disposition sctp_sf_do_ /* Update the content of current association. */ sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); - if (sctp_state(asoc, SHUTDOWN_PENDING) && + if ((sctp_state(asoc, SHUTDOWN_PENDING) || + sctp_state(asoc, SHUTDOWN_SENT)) && (sctp_sstate(asoc->base.sk, CLOSING) || sock_flag(asoc->base.sk, SOCK_DEAD))) { - /* if were currently in SHUTDOWN_PENDING, but the socket - * has been closed by user, don't transition to ESTABLISHED. - * Instead trigger SHUTDOWN bundled with COOKIE_ACK. + /* If the socket has been closed by user, don't + * transition to ESTABLISHED. Instead trigger SHUTDOWN + * bundled with COOKIE_ACK. */ sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,