Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp697044pxv; Thu, 22 Jul 2021 09:57:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMVcWoCm/3/E67Z9Jc0v8CQ+I0wTNCitMi7llomSWaL8rR0t4HVecMEZqPQYRHa4fGspR6 X-Received: by 2002:a17:907:75d2:: with SMTP id jl18mr808417ejc.238.1626973075852; Thu, 22 Jul 2021 09:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626973075; cv=none; d=google.com; s=arc-20160816; b=ackgfyeSFhxT/88GUAOsc2I+dMvd+3a6BGaeJZPTII1Tytpk4667CQ8XUfZYNlUJI7 2tqgDvbz7BkhOxUEZIe7EZYNzR2U0y4BE4KfBr02VMWZX6/tnt0Sg/enM5Y0BomPcTOP oQBsemFAVc9kn4NGNzq+6WeSFXWXSQkaMV2SmukslXJYCRuDS+9qnORNSo8YAu99ibUo eXr+y7cq3GeF1vytdvxJnt/jM3SRivmhSWZ1ad+ct4oW3L/zidmoV+eSqAr4G3QqCi0V Ip6pYj7lJF8wPFOabv3IUcg3k0hwGVmHKOUlXlLObLB9NGJYTL/VNSmTOKTcwn5ppA4F sbXg== 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=HRdNpWM/0PvMobtqpQ1Zfmk1ZZGUNcwttpNGhKlIlp4=; b=tboUg61a5QKPaMUELVJaTTi28X7zuUR/5/SNEdqbUgnwdo0n/SNLDBbhb8GqmLwbG3 QOT98FCv4juVpIpU3mcnEX61O66eOO8Wz4cxMeHik0na/VPm40UabBL4iVTJJqQEf7fb fpHWiJ37rE/J9ht79PbDERM442HVeWgwKkBOgnUId2dy/newwuTpmhjwp+EhcK21oMvE 3HnDoNMv2/u6hDzassS3G/XsaCAMGAPhtK+F52UHNZUvqNM/CzexLcPFHq5I2bi3lBgJ QiSw3SzVRdEmq7vF0aeyfCGDDkHI12dnJ1BWNdabEO9rYHNLCIKCO9XDU0sKw+Wly3Gk iFZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q54FP6wf; 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 mc17si31227805ejb.622.2021.07.22.09.57.32; Thu, 22 Jul 2021 09:57:55 -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=Q54FP6wf; 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 S234537AbhGVQNx (ORCPT + 99 others); Thu, 22 Jul 2021 12:13:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:52698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234391AbhGVQI7 (ORCPT ); Thu, 22 Jul 2021 12:08:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1415461DBC; Thu, 22 Jul 2021 16:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626972527; bh=1RXP6ytD/3HAIj0p51H6rCUz/Ox5S93oB+0iFOunChU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q54FP6wfOTAbYs/mNGiNm9L3SRR+VMzAEtRzX7qEKJPv8RLXD9T3PyFaaUswiI8bc vvRuGr9FX7PeV86eSOy+7bEd7gh8nTh7dpR7WQMgQyBBWrBSrBpmtyOwc5+uoxIr/K beptDkojmbG1Wzd+2YW8r4W7jkW3nQLq5l+wg3Es= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f1e24a0594d4e3a895d3@syzkaller.appspotmail.com, Nguyen Dinh Phi , Neal Cardwell , "David S. Miller" Subject: [PATCH 5.13 145/156] tcp: fix tcp_init_transfer() to not reset icsk_ca_initialized Date: Thu, 22 Jul 2021 18:32:00 +0200 Message-Id: <20210722155633.030761592@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210722155628.371356843@linuxfoundation.org> References: <20210722155628.371356843@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: Nguyen Dinh Phi commit be5d1b61a2ad28c7e57fe8bfa277373e8ecffcdc upstream. This commit fixes a bug (found by syzkaller) that could cause spurious double-initializations for congestion control modules, which could cause memory leaks or other problems for congestion control modules (like CDG) that allocate memory in their init functions. The buggy scenario constructed by syzkaller was something like: (1) create a TCP socket (2) initiate a TFO connect via sendto() (3) while socket is in TCP_SYN_SENT, call setsockopt(TCP_CONGESTION), which calls: tcp_set_congestion_control() -> tcp_reinit_congestion_control() -> tcp_init_congestion_control() (4) receive ACK, connection is established, call tcp_init_transfer(), set icsk_ca_initialized=0 (without first calling cc->release()), call tcp_init_congestion_control() again. Note that in this sequence tcp_init_congestion_control() is called twice without a cc->release() call in between. Thus, for CC modules that allocate memory in their init() function, e.g, CDG, a memory leak may occur. The syzkaller tool managed to find a reproducer that triggered such a leak in CDG. The bug was introduced when that commit 8919a9b31eb4 ("tcp: Only init congestion control if not initialized already") introduced icsk_ca_initialized and set icsk_ca_initialized to 0 in tcp_init_transfer(), missing the possibility for a sequence like the one above, where a process could call setsockopt(TCP_CONGESTION) in state TCP_SYN_SENT (i.e. after the connect() or TFO open sendmsg()), which would call tcp_init_congestion_control(). It did not intend to reset any initialization that the user had already explicitly made; it just missed the possibility of that particular sequence (which syzkaller managed to find). Fixes: 8919a9b31eb4 ("tcp: Only init congestion control if not initialized already") Reported-by: syzbot+f1e24a0594d4e3a895d3@syzkaller.appspotmail.com Signed-off-by: Nguyen Dinh Phi Acked-by: Neal Cardwell Tested-by: Neal Cardwell Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5921,8 +5921,8 @@ void tcp_init_transfer(struct sock *sk, tp->snd_cwnd = tcp_init_cwnd(tp, __sk_dst_get(sk)); tp->snd_cwnd_stamp = tcp_jiffies32; - icsk->icsk_ca_initialized = 0; bpf_skops_established(sk, bpf_op, skb); + /* Initialize congestion control unless BPF initialized it already: */ if (!icsk->icsk_ca_initialized) tcp_init_congestion_control(sk); tcp_init_buffer_space(sk);