Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp698851pxv; Thu, 1 Jul 2021 07:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYM4GqMS5kp+D4lqEVGGQuPhE1xRWv2Q4OIgQJk1E1L+WFo/71p1N3trvr5TMvqQdEorss X-Received: by 2002:a05:6638:2706:: with SMTP id m6mr158647jav.100.1625149574264; Thu, 01 Jul 2021 07:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625149574; cv=none; d=google.com; s=arc-20160816; b=CZ1VJIylWUdq1Ma6RuUqMklmrNMnCmPzZL8ZXBMtthjLWbOOHRFfnKKoTf491xnu92 9ppFFiQtkKUx6iPpovqFEiBTHEZjqp//vLbUe2UaXkgOwCWBLlK7tmQOObegkq/NR/zE +DnQxMKmOM1BQCpEpNi26M2IwX5NB1bAL4EqoDpM3yYswyh+CkqWc4BuNP3zUzm9NWMh PL5/jtiZ0yxiqz0FOnB63Gf0SQLOYdWnbtlCB/4rb1kptVBvZUXRvjJZSLqanTiG5yuC 1zfzK74HcHgHdmEp8cyAnHZCV2uI0BjRrto6P/9642ntEkqPodAXNdw8LU+T25khMmsn u+lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8ZYZZPLtxm0D8wKCq6t4+Fy+RhxhZRnjK7G5sIibVAY=; b=WEEqUHf7aAOAeoHycsgyIcSnMs3Z7fOPaki7dhmJQ4ubgEFrOBT00AhqIPluTIWMSt ttB/qEQGITSxyYs2+oHdx5ho9IyhEki2gfonRtD+oM3jrni46OkWtYcBri5Y/14U3sdv 5mlUaFT8CAJUbjjJyAOUYZpOlUpEywOctmFl8yk2xtZ+A8MxD9Oo9Ik6Ghj5HLyEK8Xd /IjPttFsdCKBls0xbcuDR5XH+tljHkTxa0HPqBjauq4atMDQWHR5N4F48wEa9SVYwizY Rq7flqP7rLk+SVFxg3704uyvvKB9zp8rvgg5w3scvsf+qZfp/YR5wf+173OB2wfnFiqx exfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kBv9cdGr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si47932jan.5.2021.07.01.07.26.00; Thu, 01 Jul 2021 07:26:14 -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=@google.com header.s=20161025 header.b=kBv9cdGr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233353AbhGAO0D (ORCPT + 99 others); Thu, 1 Jul 2021 10:26:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233302AbhGAO0D (ORCPT ); Thu, 1 Jul 2021 10:26:03 -0400 Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4D8C061765 for ; Thu, 1 Jul 2021 07:23:31 -0700 (PDT) Received: by mail-ua1-x92f.google.com with SMTP id f34so2516242uae.4 for ; Thu, 01 Jul 2021 07:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8ZYZZPLtxm0D8wKCq6t4+Fy+RhxhZRnjK7G5sIibVAY=; b=kBv9cdGrIayWfMzZazwxNI9/duBTp2RkiZ5RCpTGoMmI4sxwPfmxtyqijgoC6eFaHP vuY6nQPmSg0rBx1F6AnU3iGjJXVrIv6hMPT5BDZnXtJ8kZ6ta2AKfwvSzsQiBoGDBLxe Dmi2eQ+66de1aSZjyItIFwNWh1cy7b6EjIO393RJPGKNXebp3P4Yx/mAegF28z7zxu3H LLjGSN1TkEEC2gynwHgOJdUg1KIDxVmNmxUfSOg+YNg1SDUVOYC9QVrLdvNk9oHHIut5 NEaw07sNcTuAQPUw2+IKV8UcC+TCiR2ZQmvtrZRt2mROer1FgbKX1f54BG6f/nPVo19B +X5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8ZYZZPLtxm0D8wKCq6t4+Fy+RhxhZRnjK7G5sIibVAY=; b=K2C5VGLtdhpRjgRcU1YwXpSQMC5Pf2Mk8D+cOmii5IdnjrExxQ0fEh7qD2Uv/GRPJi WfcOI8DMxj/5iqwHBJqd6v8s0IjuxrzaIIyX8nYTuPBHUYL6/BECCDcXUV7GEao8aBJ0 GcDslBcI5ii9rnd/fA+8wy7uAqYsgG2oO8HewnWBgSev5AOX9qmnI6YOvrSvDY8Syw1x GqcEarjQVeDXUQzVbCifmkFGy/5zCNbxpGW5tKuvpV/LoXNqrWtSKbvGJCzLKChe+IM9 0QTI8QKZRQjc2a6df2JdYMoPpUk9tYzdZt1masuLVI3yr85o+zYVziTfIcfBZogyXQsJ xXEw== X-Gm-Message-State: AOAM5315JdU+vUnOgt0anh1jHBp5RQtiPdJrE1L4Bv63pGBMvsNTv88z CXu3Aydq2CQYCFWzqeGvCZy8CuPerk/PjZujrPJLiQ== X-Received: by 2002:ab0:3ae:: with SMTP id 43mr211048uau.63.1625149409711; Thu, 01 Jul 2021 07:23:29 -0700 (PDT) MIME-Version: 1.0 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> <30527e25-dd66-da7a-7344-494b4539abf7@gmail.com> In-Reply-To: <30527e25-dd66-da7a-7344-494b4539abf7@gmail.com> From: Neal Cardwell Date: Thu, 1 Jul 2021 10:23:13 -0400 Message-ID: Subject: Re: [PATCH] tcp: Do not reset the icsk_ca_initialized in tcp_init_transfer. To: Phi Nguyen Cc: Eric Dumazet , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 30, 2021 at 2:25 PM Phi Nguyen wrote: > > 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) Yes, exactly. > > -- > > [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? Yes, feel free to use that commit message verbatim or modified. thanks, neal