Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp586715img; Fri, 22 Mar 2019 04:36:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqynllLUmJCSc7PNeGZ3AgyEWiCPhqN7AZlkM9NyYcHli1FifbBlA/XkF8bR0AT7/m0ryruT X-Received: by 2002:aa7:92c1:: with SMTP id k1mr8706539pfa.246.1553254576056; Fri, 22 Mar 2019 04:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553254576; cv=none; d=google.com; s=arc-20160816; b=piPVN07t/F/FjOMnAvM45L0kn3aQfbs+xjiBfKsoXLZMxcW2Po6UTrs34FafHo9zBG yTZwy/2/jKgLhmwzqHk5Uh6kkNqM74wDWhUvu3B+t4h6vulWI7PBEtSmpCyRIT84uCoM UtZyC0fd51cq8pcVWySo9NfXKG19dE7wgAsjJdG4JwjS4xT5CXorVGsevp4HSHSIBtzW STxyxS+TFBd5OxVQL+WWlFUbRkvFZ/GvlDfQLNAXL6gEc5UhFbBaB3OhC8jS/iGZR35O FJFGAySEZ+x7KjjPMANPjar0+EJA5vbdDZyZEIvGwunfSCfH1Q/jazIfMLPX369cZHHH kfkg== 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=qBEslgfNtPRcS1oJ2l+yExGxxuZ0+Q6LBt0U2fsugJY=; b=r/g3+95BI5W9Mm04IUm0KYpXeqPERvBRYRjvI6+3z/L6RnzOVxkrJEGpTdVesBVgOP VmSgzty2U+jztQyYNO4yadlkFwCejL+sj8lUgLXCYuz4zr4cbO5vjbhOP5MxZYNeZkHU IKZOqNJIrjKE7ijENCYvCflcpqNM7ispWgCHEoNbIuQZCU/16o4pf679zL9qzLfxTs5Z qkZZDc1cwRROBzoIRmEElhlXZMbXG2BZiu4GAxsaOkJiuQeev4Uky2snXYDcrvNTR1am a07VSPWzsFX95avoIrws5OJpoSnSl2Q1DfmrWefSu7gFhl1V82qi4/Xq8Srd99zVtLKa 2VUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wp0FoZlo; 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 h10si6227917pgs.573.2019.03.22.04.36.01; Fri, 22 Mar 2019 04:36:16 -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=Wp0FoZlo; 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 S1730063AbfCVLeR (ORCPT + 99 others); Fri, 22 Mar 2019 07:34:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:34884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729680AbfCVLeP (ORCPT ); Fri, 22 Mar 2019 07:34:15 -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 396422192C; Fri, 22 Mar 2019 11:34:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254454; bh=JXSHeJ9YY4t8zr67PU0dgb4Ny2AIW3b5mPYbX2RaiTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wp0FoZloqTbzWJfVp20+HAg33oLscBim758C2nK01jgHl1bELKFS1UIZ8R5Kao/xg yuFU5XS2uil58WKbnz8rESUDHOLWQldagy7QCjvHU+UeRdI7u0Psqiu8vtsCd1wXYN b0py+3fofP+cIViPDf1GxuK1A5ndE9Jpk/cM341M= 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.4 133/230] tcp: handle inet_csk_reqsk_queue_add() failures Date: Fri, 22 Mar 2019 12:14:31 +0100 Message-Id: <20190322111246.021116010@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111236.796964179@linuxfoundation.org> References: <20190322111236.796964179@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.4-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 @@ -228,7 +228,12 @@ struct sock *tcp_get_cookie_sock(struct if (child) { atomic_set(&req->rsk_refcnt, 1); 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 @@ -6409,7 +6409,13 @@ int tcp_conn_request(struct request_sock af_ops->send_synack(fastopen_sk, dst, &fl, req, &foc, false); /* 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);