Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4510576pxv; Tue, 29 Jun 2021 08:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ5rPJHg+eXe7N4u8eIyq4lSlwTtUXABOAZ/E4HHbUC8MLX8raUdGsxlyzhTF5J3kXv61h X-Received: by 2002:a17:907:9c9:: with SMTP id bx9mr30583074ejc.144.1624981147356; Tue, 29 Jun 2021 08:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624981147; cv=none; d=google.com; s=arc-20160816; b=fNGAMaxrNoHS3+YYBMAv0i553z88dEtz38qWyIlMlTDflaPqDaHk08PjMMzE2YCGj3 wnBBBwiEdEOR4Nzy2/0eIdZpLJ246oY/TbuTLitAJourliA1rB9vHWqAdRQ/x64gPlQO 0hrZtw5HZ8hLZQXNAw8Hrgq0YfwD24tUDH8mcOIxN8wOci0epzPc1g4/xhZK+js7w7x3 ZtksSi72SDdnA20gCqegK6tHSC2LLVEaELPY2VJMNoV27LNyWnnyR2M+yvxJYT04X3kh hAPWqQo//WeVjJ64f33tVXDRS/FxxACc59vaqUX3zZyj49jiJ4nkTfnK6MDPIG0HG7IZ jy4A== 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=1Ixc1yg9az9B0t1cymNZSTN2Zbg+u86yZpoOKVTjo0E=; b=0rvcaBqhEwwrE4d3tpdC8hSQP6llyEQdcEK0N1fczDsx96FbJKR8kZb9mySFuPEPYy WPLT/uNCevHUptgUbWrRWPv/09DUvUXD6exgn8U0MSNfEiJzlz7PWkvIb20twzTv4fSF M+X+lrHyhhnvdwY24el4BcYRxJllxbWfcF+P7wJqdDKrIWtVoCKJ+HYXVAC6xW3VMcHA pC2gsY89lYk1s0TYVArq+N22AFlmDvoBgyQBnvGIS5Ji9v4OkBqlSo+PA8qFIbaps6a2 yq4T+VZYR5cW5JwmWa6WbTzawH6g3bJppEyPkT7fCl1sIISsS02mSNpMFKn6R+O+cBni hGiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Wicg5j6C; 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 ne2si461552ejc.639.2021.06.29.08.38.40; Tue, 29 Jun 2021 08:39:07 -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=Wicg5j6C; 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 S233610AbhF2NA4 (ORCPT + 99 others); Tue, 29 Jun 2021 09:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbhF2NA4 (ORCPT ); Tue, 29 Jun 2021 09:00:56 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34C3C061766 for ; Tue, 29 Jun 2021 05:58:28 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id m9so24243120ybp.8 for ; Tue, 29 Jun 2021 05:58:28 -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=1Ixc1yg9az9B0t1cymNZSTN2Zbg+u86yZpoOKVTjo0E=; b=Wicg5j6Czkzx0aBfwLjleCGbinRhL8+0w31l9FEZowcaMUpWvwBFPkRpcYqAIq9Uhn E/eMTTWZeI+EKOhf4H++Inrj3nLMtGcbPRthOpIWvPU9ZmoRh54CInF1TPBq8qaOcML3 tv+eMU6hdKk3RSimSdiuYz3fuVFIXc5LrHNGoNn0v5la4fA5NQIzcBmQhbFzSBmoQfcw Srg8l463/0H/NQh/0SnvrHEwFqijLF0lSv6Mgh99EyZCG2ATAywcksdxC5avjcBuwa/M 9ALnQkHDCcsr7Z8AZJsCIMqeB1MArs/LWT6uP+QARJjnyjCjwGkbEXFii77kkOS3lXtT h19A== 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=1Ixc1yg9az9B0t1cymNZSTN2Zbg+u86yZpoOKVTjo0E=; b=rXXu0p0dMnK2Cw3BHJbZM5hHOHeKo0DrHdvUNbwsyhLkFTfIZpAIXL3fJiyBenV54t xKWVye7UDF2yAxpMoB8LPDeXsvvIUvkXOZxYyDzoP4oJb82uA2f82poGgsI1SdjxD+No s4h7jztAygKta6AW3vrNWIitk0One8W/LxER/p4BKgU2lTei2Mf3bZVE8wyH4B4haFFP WD0cRQRRG/XK7x1y22Yn8C0M8Jn5RPFttT438ocpt1yGwZLqHZ5lsvehZHPDTyALi7pK Pf9vH+aGvIMbT5b75ZcYWm6rsAu/ZgzdmXUuEe6qmXqVvWZlIUfe/dIqVkYcfU3XjIxz UbnA== X-Gm-Message-State: AOAM532AQ4NweCmI8z7A6joiCNUE6U6T3aERaPCyF9V8XAstnTfMXGrS xeuc8NPJ7cMqZsdp3RgkoMcoAcRr/5Dq+GfPLVkSow== X-Received: by 2002:a05:6902:544:: with SMTP id z4mr39530633ybs.452.1624971507741; Tue, 29 Jun 2021 05:58:27 -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> In-Reply-To: <1786BBEE-9C7B-45B2-B451-F535ABB804EF@gmail.com> From: Eric Dumazet Date: Tue, 29 Jun 2021 14:58:16 +0200 Message-ID: Subject: Re: [PATCH] tcp: Do not reset the icsk_ca_initialized in tcp_init_transfer. To: Nguyen Dinh Phi Cc: Neal Cardwell , 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 Tue, Jun 29, 2021 at 2:28 PM Nguyen Dinh Phi wrote: > > On June 29, 2021 4:21:59 PM GMT+08:00, Eric Dumazet wrote: > >On Tue, Jun 29, 2021 at 9:17 AM Nguyen Dinh Phi > >wrote: > >> > >> On June 29, 2021 1:20:19 AM GMT+08:00, Neal Cardwell > > wrote: > >> >) > >> > > >> >On Mon, Jun 28, 2021 at 1:15 PM Phi Nguyen > >wrote: > >> >> > >> >> On 6/29/2021 12:24 AM, Neal Cardwell wrote: > >> >> > >> >> > Thanks. > >> >> > > >> >> > Can you also please provide a summary of the event sequence that > >> >> > triggers the bug? Based on your Reported-by tag, I guess this is > >> >based > >> >> > on the syzbot reproducer: > >> >> > > >> >> > > >> > >>https://groups.google.com/g/syzkaller-bugs/c/VbHoSsBz0hk/m/cOxOoTgPCAAJ > >> >> > > >> >> > but perhaps you can give a summary of the event sequence that > >> >causes > >> >> > the bug? Is it that the call: > >> >> > > >> >> > setsockopt$inet_tcp_TCP_CONGESTION(r0, 0x6, 0xd, > >> >> > &(0x7f0000000000)='cdg\x00', 0x4) > >> >> > > >> >> > initializes the CC and happens before the connection is > >> >established, > >> >> > and then when the connection is established, the line that sets: > >> >> > icsk->icsk_ca_initialized = 0; > >> >> > is incorrect, causing the CC to be initialized again without > >first > >> >> > calling the cleanup code that deallocates the CDG-allocated > >memory? > >> >> > > >> >> > thanks, > >> >> > neal > >> >> > > >> >> > >> >> Hi Neal, > >> >> > >> >> The gdb stack trace that lead to init_transfer_input() is as > >bellow, > >> >the > >> >> current sock state is TCP_SYN_RECV. > >> > > >> >Thanks. That makes sense as a snapshot of time for > >> >tcp_init_transfer(), but I think what would be more useful would be > >a > >> >description of the sequence of events, including when the CC was > >> >initialized previous to that point (as noted above, was it that the > >> >setsockopt(TCP_CONGESTION) completed before that point?). > >> > > >> >thanks, > >> >neal > >> > >> I resend my message because I accidently used html format in last > >one. I am very sorry for the inconvenience caused. > >> --- > >> Yes, the CC had been initialized by the setsockopt, after that, it > >was initialized again in function tcp_init_transfer() because of > >setting isck_ca_initialized to 0. > > > >"the setsockopt" is rather vague, sorry. > > > > > >The hard part is that all scenarios have to be considered. > > > >TCP flows can either be passive and active. > > > >CC can be set : > > > >1) Before the connect() or accept() > >2) After the connect() or accept() > >3) after the connect() but before 3WHS is completed. > > > >So we need to make sure all cases will still work with any combination > >of CDG CC (before/after) in the picture. > > > >Note that a memory leak for a restricted CC (CDG can only be used by > >CAP_NET_ADMIN privileged user) > > is a small problem compared to more serious bug that could be added > >by an incomplete fix. > > > >I also note that if icsk_ca_priv] was increased from 104 to 120 bytes, > >tcp_cdg would no longer need a dynamic memory allocation. > > > >Thank you. > > Hi, > I will try to see whether I am able to get the full sequence. I am also affraid of making a change that could affect big part of the kernel. > About CDG, how we can get rid of dynamic allocation by increasing icsk_priv_data to 120? because I see that the window size is a module parameter, so I guess it is not a fixed value. Given this module parameter is constant, I doubt anyone really uses a bigger window. If researchers want to experiment bigger window, they could adjust a macro and recompile (#define TCP_CDG_WINDOW 8 -> X) > Because the problem only happens with CDG, is adding check in its tcp_cdg_init() function Ok? And about icsk_ca_initialized, Could I expect it to be 0 in CC's init functions? I think icsk_ca_initialized lost its strong meaning when CDG was introduced (since this is the only CC allocating memory) The bug really is that before clearing icsk_ca_initialized we should call cc->release() Maybe we missed this cleanup in commit 8919a9b31eb4fb4c0a93e5fb350a626924302aa6 ("tcp: Only init congestion control if not initialized already") Although I am not sure what happens at accept() time when the listener socket is cloned. If we make any hypothesis, we need to check all CC modules to make sure they respect it. > > Thank you.