Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp543132pxv; Wed, 30 Jun 2021 11:26:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR+eTg0yf0DE0IaSZClviBVpsxTnTpi5mxs/jJtRKu05ucepat9gzDZg86tVJZyepheWCi X-Received: by 2002:a92:b50d:: with SMTP id f13mr26973397ile.253.1625077578359; Wed, 30 Jun 2021 11:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625077578; cv=none; d=google.com; s=arc-20160816; b=nUivkG9+w0e68fuf/ONnt0uWTzgivqb5C/aCYRIT9TGF0xMU5rLSWMOv91U3+i261Q 7sMsMP9qu9GGLZBqguQrjM4yxfRlKlVY0CPyhMaQPe8xV5PaVke+e+PKRoyR3p3sLyS1 Ma0NrquBnxRV9Km3RlK8WycPgE4G7sAN7ggly4QBL70fPWKTXpBqDmxaNORvzKvrtdUw q7UpaGMclggSlenGL9yc9q+9zWT7l95e9DzO0zua5nWnK+fom/mo/3cVvdLxHDF2fKsh bfVHiGWMODohI7y/pv8hLCl+9N6Ug4vKHbMN5ZRlzV8dQJrC1EivJzlO80HRFOHu4VLT filg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=RvDcmONdyX10LsCogZh526Ob3MOiNIiyAoMdUbjNYVY=; b=qPPmEA7VOPKg0N8fFNrcyhe0eHL28xe4jr1qvSA10L8Qiu2ceGMfdECcG9+REorSwt ndPzYRoDH62Q+PD2UdfYTmH08jvI2/46q1Im35xKDmAfKqJ3pnD3E8PmZRrJ+flMtwTw iyggncrIAQeOoZKpQwxzpVq2LCb4dWCT4gvoQCmxMWumlqOAyEqwo4iF7oKlPYMndaHu 9Gf+utsFFQz+nV7aHdFY7UZCscgAaBOGzLRl2ax5JWUUJCpW//d8Ij/gj4rzWGC6YR0l dMDIgtZj3+zfCrG48+nUZQh7SQopiADXWtLTi9lE/+FkfmBxFEXFYx8MVz5WtRv9M3E2 Iz+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IhbSgoSq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si15663913jat.31.2021.06.30.11.26.06; Wed, 30 Jun 2021 11:26:18 -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=@gmail.com header.s=20161025 header.b=IhbSgoSq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233030AbhF3S2E (ORCPT + 99 others); Wed, 30 Jun 2021 14:28:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232694AbhF3S2E (ORCPT ); Wed, 30 Jun 2021 14:28:04 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FA2C061756; Wed, 30 Jun 2021 11:25:33 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id b5so1985656plg.2; Wed, 30 Jun 2021 11:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=RvDcmONdyX10LsCogZh526Ob3MOiNIiyAoMdUbjNYVY=; b=IhbSgoSqRJnLgBW0+P9Yus/OfADtejJOvJioaPlYT8TnMYVhk6wKXe0dviexFIDz2h 3SL1aYsFBV3h4QiJ/oV2RbIQEnScB7ta/T4Agx85ImkxggVv7u/rLnHbEpUFH4usl1R0 D8tEgceKFC1b+hFoD6roduWWlKQX0JEfEflfQ/vvOqZhxvD9mg9c7ZTNq+fNg6/vw9gU ll0k9nWkbHckQFPWm9tV0cD+qzn1TDfJdp3RrdqU8mZw6Otv3fckMn/7irfUOVZvGRlV 1r65NAenCEvmS1A94qFcKBIPBpNqD6WioQSyKJTJtsmZi/BqxuT4T16UZ8y6O12j6vUz s40A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RvDcmONdyX10LsCogZh526Ob3MOiNIiyAoMdUbjNYVY=; b=TVBT+APJDKHYQurzxvhoC4AYvjwy4QyNvfTUUI3uuItUZBvYbhYevjBFXwYHx4oyL2 Fd7udTThbtcqlYHVn+xuzZgv79sz7CxppdvMkojDzWijoL84B8oaIVJMKTbTaAn9nsP6 m5+wWALA/97DHmQab4FJK6J5bgHpEPr0ZTzn2d6/NyoYpsaDp8VFdMYPfjIvPF6f6XuQ oSoKu/s5c0z9bA2SDpti/L348493uU8bN1FfbitOoYhRnPIxthnTPCbMhgv33pzLZ1gX ETaur86n/QvVKyk3raWLuF28WpQIzBM+/ly+zuGgeXAso/ZQjnfFrVGAOEkkt113ztZw 1Omg== X-Gm-Message-State: AOAM531Oe+Qz1D89r0HF7uHpfLQcf3H0PbTp7fAqrkSGM4iVOy4MebqB 7PiVwiU75o3brhhkXuHj6TY= X-Received: by 2002:a17:90a:8403:: with SMTP id j3mr41618840pjn.212.1625077533070; Wed, 30 Jun 2021 11:25:33 -0700 (PDT) Received: from [192.168.93.106] (bb42-60-144-185.singnet.com.sg. [42.60.144.185]) by smtp.gmail.com with ESMTPSA id c24sm20423489pfn.86.2021.06.30.11.25.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Jun 2021 11:25:32 -0700 (PDT) Subject: Re: [PATCH] tcp: Do not reset the icsk_ca_initialized in tcp_init_transfer. To: Neal Cardwell , Eric Dumazet Cc: David Miller , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , kpsingh@kernel.org, netdev , LKML , bpf , linux-kernel-mentees@lists.linuxfoundation.org, syzbot+f1e24a0594d4e3a895d3@syzkaller.appspotmail.com, Yuchung Cheng References: <20210628144908.881499-1-phind.uet@gmail.com> <79490158-e6d1-aabf-64aa-154b71205c74@gmail.com> <205F52AB-4A5B-4953-B97E-17E7CACBBCD8@gmail.com> <1786BBEE-9C7B-45B2-B451-F535ABB804EF@gmail.com> From: Phi Nguyen Message-ID: <30527e25-dd66-da7a-7344-494b4539abf7@gmail.com> Date: Thu, 1 Jul 2021 02:25:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/29/2021 11:59 PM, Neal Cardwell wrote: > On Tue, Jun 29, 2021 at 8:58 AM Eric Dumazet wrote: > From my perspective, the bug was introduced when that 8919a9b31eb4 > commit introduced icsk_ca_initialized and set icsk_ca_initialized to 0 > in tcp_init_transfer(), missing the possibility that 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(). The 8919a9b31eb4 commit 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!). > >> Although I am not sure what happens at accept() time when the listener >> socket is cloned. > > It seems that for listener sockets, they cannot initialize their CC > module state, because there is no way for them to reach > tcp_init_congestion_control(), since: > > (a) tcp_set_congestion_control() -> tcp_reinit_congestion_control() > will not call tcp_init_congestion_control() on a socket in CLOSE or > LISTEN > > (b) tcp_init_transfer() -> tcp_init_congestion_control() can only > happen for established sockets and successful TFO SYN_RECV sockets Is this what was mentioned in this commit ce69e563b325(tcp: make sure listeners don't initialize congestion-control state) > -- > [PATCH] tcp: fix tcp_init_transfer() to not reset icsk_ca_initialized > > This commit fixes a bug (found by syzkaller) that could cause spurious > double-initializations for congestion control modules, which could cause memory > leaks orother 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 8919a9b31eb4 commit 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(). The 8919a9b31eb4 commit 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). Could I use your commit message when I resubmit patch? Thank you.