Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2029040imm; Thu, 24 May 2018 04:47:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqOhYPY+WsxLFsMSbJ5W0kJw2EX/Nnub0rBjscyNb0G0cMNjd+TBt3M2l6W/MhMVT4czY5X X-Received: by 2002:a17:902:28ab:: with SMTP id f40-v6mr7113588plb.208.1527162461387; Thu, 24 May 2018 04:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527162461; cv=none; d=google.com; s=arc-20160816; b=rGDH4k9914tLAivvGfFw4jJgOm8UEWr7RvHmEyxar/k4ib0bp4mEqSf7kuP8MaQVNR aNgClJ34eF0ov3oWPeCoy8fRuXrSUF/SWEsuzsU/DdCici2iWvWH3Yzd2IWnqi3NNocP 5xgj3oSB9vW1k3RG6oX2PvlVH1olTHsO0KJS1/HE4/GGIAw9cKAFTtrtQAw2TG/hP3d/ VfBZVi42Ak7Ull45KnBH18q+6CEg3NJVQdnMzxPlc7/T7DPxGqUR9bZWu5DI10k7wZfO g3ZumzR28WkGXUBHryWy7SHHMte3WAD1dGLANyjsdPkkvO9XufeeexZn31eak9RhgXAj 0xeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Ofxb74EuWpbeGjXf3ZxDGbwF+WLGAW+wLYtUUgero4Y=; b=XhKp2boqJVEKrvtpH/atFWAiHEtHt10wGD1QxZVnHSD/nb0RohUCRODe4Gk+TxQayK 7Rk52BEIqvMSWayZV55uJf9DGGtwK82eh3n4A0TTLV0PBg2Q7RQlmENY021QZmL5oEvT rKaBU/n9ojQwbGJBfBYmwTdXu07OKuEMeoan/Jfc3CWpAUJYHElg8BrLt3GzMNgelJCh Nv+pNSgJckykW78FXfKyDaR5BPRlm86t3dy78q58mNCJfwgjU8gMrR9XXFOg27BBCMfz jljNcacZClfkXnRsql+GqmJJAUKuDEWUNtYef4qNZfZAqai9iT41YpowpnAlU4aCW/bf 6e7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M2xc4gRx; 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 e12-v6si2574105plt.209.2018.05.24.04.47.25; Thu, 24 May 2018 04:47:41 -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=M2xc4gRx; 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 S967150AbeEXJr6 (ORCPT + 99 others); Thu, 24 May 2018 05:47:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:60822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967125AbeEXJrw (ORCPT ); Thu, 24 May 2018 05:47:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 BF82E208BA; Thu, 24 May 2018 09:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155272; bh=S6EY4jFutUgkuy0nkpbhxzMIGvJQunzAnh/qR2btJ6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M2xc4gRx2m6znMXIZfGyaW1sOXhGFKsd01CwcKaBd79gvME7mqNXw4MWpH4KLZsOo ukQCUtdcgXS48zHVU8nH+2LsbvPloXy7wW0zvGhflVTK5RE7LpBARhcLwadw8hWNVD xVl6i8XeNM/f1eZDxQafO4xEkr8dK6a0zApaif+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Yuchung Cheng , Neal Cardwell , syzbot , "David S. Miller" Subject: [PATCH 4.9 05/96] tcp: purge write queue in tcp_connect_init() Date: Thu, 24 May 2018 11:37:48 +0200 Message-Id: <20180524093605.948487855@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 7f582b248d0a86bae5788c548d7bb5bca6f7691a ] syzkaller found a reliable way to crash the host, hitting a BUG() in __tcp_retransmit_skb() Malicous MSG_FASTOPEN is the root cause. We need to purge write queue in tcp_connect_init() at the point we init snd_una/write_seq. This patch also replaces the BUG() by a less intrusive WARN_ON_ONCE() kernel BUG at net/ipv4/tcp_output.c:2837! invalid opcode: 0000 [#1] SMP KASAN Dumping ftrace buffer: (ftrace buffer empty) Modules linked in: CPU: 0 PID: 5276 Comm: syz-executor0 Not tainted 4.17.0-rc3+ #51 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__tcp_retransmit_skb+0x2992/0x2eb0 net/ipv4/tcp_output.c:2837 RSP: 0000:ffff8801dae06ff8 EFLAGS: 00010206 RAX: ffff8801b9fe61c0 RBX: 00000000ffc18a16 RCX: ffffffff864e1a49 RDX: 0000000000000100 RSI: ffffffff864e2e12 RDI: 0000000000000005 RBP: ffff8801dae073a0 R08: ffff8801b9fe61c0 R09: ffffed0039c40dd2 R10: ffffed0039c40dd2 R11: ffff8801ce206e93 R12: 00000000421eeaad R13: ffff8801ce206d4e R14: ffff8801ce206cc0 R15: ffff8801cd4f4a80 FS: 0000000000000000(0000) GS:ffff8801dae00000(0063) knlGS:00000000096bc900 CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 CR2: 0000000020000000 CR3: 00000001c47b6000 CR4: 00000000001406f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: tcp_retransmit_skb+0x2e/0x250 net/ipv4/tcp_output.c:2923 tcp_retransmit_timer+0xc50/0x3060 net/ipv4/tcp_timer.c:488 tcp_write_timer_handler+0x339/0x960 net/ipv4/tcp_timer.c:573 tcp_write_timer+0x111/0x1d0 net/ipv4/tcp_timer.c:593 call_timer_fn+0x230/0x940 kernel/time/timer.c:1326 expire_timers kernel/time/timer.c:1363 [inline] __run_timers+0x79e/0xc50 kernel/time/timer.c:1666 run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692 __do_softirq+0x2e0/0xaf5 kernel/softirq.c:285 invoke_softirq kernel/softirq.c:365 [inline] irq_exit+0x1d1/0x200 kernel/softirq.c:405 exiting_irq arch/x86/include/asm/apic.h:525 [inline] smp_apic_timer_interrupt+0x17e/0x710 arch/x86/kernel/apic/apic.c:1052 apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:863 Fixes: cf60af03ca4e ("net-tcp: Fast Open client - sendmsg(MSG_FASTOPEN)") Signed-off-by: Eric Dumazet Cc: Yuchung Cheng Cc: Neal Cardwell Reported-by: syzbot Acked-by: Neal Cardwell Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_output.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2691,8 +2691,10 @@ int __tcp_retransmit_skb(struct sock *sk return -EBUSY; if (before(TCP_SKB_CB(skb)->seq, tp->snd_una)) { - if (before(TCP_SKB_CB(skb)->end_seq, tp->snd_una)) - BUG(); + if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) { + WARN_ON_ONCE(1); + return -EINVAL; + } if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq)) return -ENOMEM; } @@ -3236,6 +3238,7 @@ static void tcp_connect_init(struct sock sock_reset_flag(sk, SOCK_DONE); tp->snd_wnd = 0; tcp_init_wl(tp, 0); + tcp_write_queue_purge(sk); tp->snd_una = tp->write_seq; tp->snd_sml = tp->write_seq; tp->snd_up = tp->write_seq;