Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp270170img; Mon, 18 Mar 2019 02:45:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKDcejxA2OC/iOYdShqctl2kvuceQF5c95D87wAKAAKZIs8s+V82BmtEjHYdD7fxdhdIq3 X-Received: by 2002:a63:d209:: with SMTP id a9mr16775504pgg.341.1552902301086; Mon, 18 Mar 2019 02:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902301; cv=none; d=google.com; s=arc-20160816; b=ovEpRF6MWwjJdpPEFadrJwrzlqFDgxbQobekmC9hIucwsF6juA0noZUlYhYkL0H55k 9q6+llOO9ruedfs+0kzerz3k4vHRibHVcint8JQuHM2egRpaflXzrE6FiBuP0ZZhU5Qd QsFjjnkMJ6E35qXlBvLMCoJ2/CVMeaI4klm+QHw/JmBAWViD6vWD0fbEOQWVG4JOv4If gL73ZuJ6ecLMsw3qPD/CedfcEQQnz4vbudFWiwfC/7AeCIYlYBUz3chJvNR2nvxbskpM C5sthp83X709yxUvJmP650sLXviQqSqoFdkz1VWLpun7H6ccKGE0lcAlpw+9ca6oQ5ab inRA== 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=wvm6CYtXFTYxsFDlzYKr8MpFQH1zubuYcdDkab4I7Q4=; b=Oc89LAjCgByPO0tucNGtIQf00Pa9ql9dhXtsKMGQzAO8OcPG3RxEiEwcUem6x5v0Zv 4sbert2Faom1Uc3inbLD34GSDK2ksQYVYY7CyrSHylMxH4NVpbU2QHOTsG3ul0kWa7yy /+tVo75+NMdUIyUuUOlf9nypMCYU8oSkD6EnJ25GmeaagkQxBoeshBYHRohnk2Yhi7p1 lgvk3gUcKRvRdydqUfeFpsqd1jzHFD1+kUoZ8KsO/3lAyRp67EmpLZfzOcDXiPgw+LdL CQ8K/wfb2WUadfi16vYgWvjTM4W2LnP3aBPNqQtsmi321zKkAkG/uYMCGSfrWRtdjthp 3a8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IL7zZFuV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b39si9407589pla.381.2019.03.18.02.44.46; Mon, 18 Mar 2019 02:45:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IL7zZFuV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727844AbfCRJn0 (ORCPT + 99 others); Mon, 18 Mar 2019 05:43:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:39930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728294AbfCRJb7 (ORCPT ); Mon, 18 Mar 2019 05:31:59 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 93EDB21734; Mon, 18 Mar 2019 09:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901519; bh=6tLv82KEJ9OuMlFVTebC4chr8lYSCl3kFdZA+YiqpiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IL7zZFuVOQ5uQ/2jnRiiUgMdh4DX8vo1pUrz5aSEaJf/CNjHgl0h7pN3pjdrHvBKu 5K4TELJ0o7KPGxH6ce0ONBCjUvg2SO0lrFhT5mNK1pQNA3tuxSB+dWqBrd8JEwxPPu uDNN/5TOZ3c/ebE7pysEgEGUYrjbcGQsLS29AtsU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.19 19/52] tcp: handle inet_csk_reqsk_queue_add() failures Date: Mon, 18 Mar 2019 10:25:16 +0100 Message-Id: <20190318084015.824760648@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084013.532280682@linuxfoundation.org> References: <20190318084013.532280682@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guillaume Nault [ Upstream commit 9d3e1368bb45893a75a5dfb7cd21fdebfa6b47af ] Commit 7716682cc58e ("tcp/dccp: fix another race at listener dismantle") let inet_csk_reqsk_queue_add() fail, and adjusted {tcp,dccp}_check_req() accordingly. However, TFO and syncookies weren't modified, thus leaking allocated resources on error. Contrary to tcp_check_req(), in both syncookies and TFO cases, we need to drop the request socket. Also, since the child socket is created with inet_csk_clone_lock(), we have to unlock it and drop an extra reference (->sk_refcount is initially set to 2 and inet_csk_reqsk_queue_add() drops only one ref). For TFO, we also need to revert the work done by tcp_try_fastopen() (with reqsk_fastopen_remove()). Fixes: 7716682cc58e ("tcp/dccp: fix another race at listener dismantle") Signed-off-by: Guillaume Nault Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/syncookies.c | 7 ++++++- net/ipv4/tcp_input.c | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -216,7 +216,12 @@ struct sock *tcp_get_cookie_sock(struct refcount_set(&req->rsk_refcnt, 1); tcp_sk(child)->tsoffset = tsoff; sock_rps_save_rxhash(child, skb); - inet_csk_reqsk_queue_add(sk, req, child); + if (!inet_csk_reqsk_queue_add(sk, req, child)) { + bh_unlock_sock(child); + sock_put(child); + child = NULL; + reqsk_put(req); + } } else { reqsk_free(req); } --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6514,7 +6514,13 @@ int tcp_conn_request(struct request_sock af_ops->send_synack(fastopen_sk, dst, &fl, req, &foc, TCP_SYNACK_FASTOPEN); /* Add the child socket directly into the accept queue */ - inet_csk_reqsk_queue_add(sk, req, fastopen_sk); + if (!inet_csk_reqsk_queue_add(sk, req, fastopen_sk)) { + reqsk_fastopen_remove(fastopen_sk, req, false); + bh_unlock_sock(fastopen_sk); + sock_put(fastopen_sk); + reqsk_put(req); + goto drop; + } sk->sk_data_ready(sk); bh_unlock_sock(fastopen_sk); sock_put(fastopen_sk);