Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4011227rwb; Tue, 6 Sep 2022 00:42:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR5XhjUslV4mC/qvRXP1GTjQs3R4rLI1Xb+G89fmODcbtVyIVQAPjqNpSp2CkYgWoAp4nnC4 X-Received: by 2002:a17:902:f68d:b0:172:a34c:ff96 with SMTP id l13-20020a170902f68d00b00172a34cff96mr53015015plg.26.1662450124087; Tue, 06 Sep 2022 00:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662450124; cv=none; d=google.com; s=arc-20160816; b=EPOK+E+1nrNb+vif0Vi1aEXNm8vF9SueYDN9pJ+BbHoU25IxHA0EESNzQlwbZUNxEN CobhgIDznbigHiUyjmD4e4BjmWidKzVjpklNUmt47W7ougONzdQA9ahanibwSIH2RIMk 2rFvaB54PtG7DaKN+qPbfOE1SDEANfVIfiGQT90x0fycvOjSY1ojjNfcgrI56ZSmpHoy n9GN0+v5r+Bncg50N9OevPOBIRCdzm3CKOj5EKQH7Qx+qjzuU7iA2EXPsjLAJ3c8XR6C t/7I+haocxSLiV3++18WF8RvWtmTyM2x0MYkjvUbg1qWDRJ7gcP5cS8jLaxUKoMlHLFZ tkYA== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=caiMWj7kissLoLR8KbqAK5Ap+BIXDNFbPV4Fgn7cTvo=; b=W39ukFTKoFjjV9yOfSQEogcdYv1v3nzk2vpVBM7wAs/R+r6ffcTk1R8kOqsWVXxt0S VeueoRqaRBmrlW5bctCePhH8+JHP0d80x2RH8HJC7AgKSRxx2UYNUplitAqSpwGHKHTE TJ2kK9ha/7aogRckKCxCxVLgRtRBenUq1RogoNVEhgsThSyi5KubO4DZbXrcJZ2qY+Lh fslo0xFhRUxde1553e7F8DkOx44kb9mCR/HDXEbIcRRQN+Ew72HcvbS9liFZLsMB20UA KxdRkl3/HamMeGfZxgUpNq+MfrlUQb6JWNIeZtHvW43Ey7DHrRRQPR730/yhf52PwY6d 3Ylg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zj0zo5SR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a170902ef4600b0017680ae3a9csi10913687plx.534.2022.09.06.00.41.49; Tue, 06 Sep 2022 00:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zj0zo5SR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238740AbiIFHDA (ORCPT + 99 others); Tue, 6 Sep 2022 03:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232690AbiIFHC5 (ORCPT ); Tue, 6 Sep 2022 03:02:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B0DD65669 for ; Tue, 6 Sep 2022 00:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662447775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=caiMWj7kissLoLR8KbqAK5Ap+BIXDNFbPV4Fgn7cTvo=; b=Zj0zo5SR3LtzUEHdnemLL2fL/9gEhWJaHUA/Orb4xfbKR1Ri0LIs5fU75jTodDFfNsaKTH mvdlTIBv2tZaG94wb3RgCzvAm9NKc1nZPIFpSvLY+EpfQ+UID2K5A1her03TU05D7OESuV YjKE29t4O34NuK301z7VzL8FrkNx/hQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-372-iHKhmMJ9OfaLNO7lWH2TFA-1; Tue, 06 Sep 2022 03:02:54 -0400 X-MC-Unique: iHKhmMJ9OfaLNO7lWH2TFA-1 Received: by mail-wm1-f71.google.com with SMTP id a17-20020a05600c349100b003a545125f6eso8386837wmq.4 for ; Tue, 06 Sep 2022 00:02:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date; bh=caiMWj7kissLoLR8KbqAK5Ap+BIXDNFbPV4Fgn7cTvo=; b=PDfWsVbzMlnVVZRpklfIjoROpmWMrZbALoZ2d6O3qGbyko28NkizIzb7yGgtnhgwLJ yU6OM94XOK3MlNhxMxl1tbi5Mk91RWbD8UnFP2yY+6fNVQRwsls3LwD0QdgJeBm9hxpe e94V3n/yDd23y318xusLKHzJ7mQUKxAs6xSxYQqvBz0/XEPIZcvRIYcdjYjgtia1cuMW ens601QSlte6Jnqb+RWRn9nHdA6lCDK3QbfCjlGMZWN1VbtZshXScNXnndk39CsdxmTl 4D1TH+GYwVTwgN7xmreVoY2xcsK65ZZpXgNTSkUemn6W73uvwpmFVyQZ1KzeVZFcPyiH XAlA== X-Gm-Message-State: ACgBeo1vvxIekQsKrg02u67kVRnaoKAgjJJ4QZ/Or2U3TWlO7OSOJL51 EaH75QBWz5fQS1/pPFwWiTURyO6Tysz7gJIXvn/jhQIU0l2sMtV/Hl29Dpo7XKu+vupK0npsAoQ 7374192BdJiFtlhLeo3dvS03H X-Received: by 2002:a05:6000:2c8:b0:221:7aea:c87f with SMTP id o8-20020a05600002c800b002217aeac87fmr24730977wry.242.1662447773198; Tue, 06 Sep 2022 00:02:53 -0700 (PDT) X-Received: by 2002:a05:6000:2c8:b0:221:7aea:c87f with SMTP id o8-20020a05600002c800b002217aeac87fmr24730955wry.242.1662447772809; Tue, 06 Sep 2022 00:02:52 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-112-72.dyn.eolo.it. [146.241.112.72]) by smtp.gmail.com with ESMTPSA id k4-20020a7bc404000000b003a601a1c2f7sm19388512wmi.19.2022.09.06.00.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 00:02:52 -0700 (PDT) Message-ID: <1bfe80691f6d7c1cf427e5fb979d5dd6f841a4f0.camel@redhat.com> Subject: Re: [PATCH net] net: mptcp: fix unreleased socket in accept queue From: Paolo Abeni To: Menglong Dong Cc: mathew.j.martineau@linux.intel.com, matthieu.baerts@tessares.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-kernel@vger.kernel.org, Menglong Dong Date: Tue, 06 Sep 2022 09:02:50 +0200 In-Reply-To: References: <20220905050400.1136241-1-imagedong@tencent.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2022-09-05 at 17:03 +0800, Menglong Dong wrote: > On Mon, Sep 5, 2022 at 4:26 PM Paolo Abeni wrote: > > > > Hello, > > > > On Mon, 2022-09-05 at 13:04 +0800, menglong8.dong@gmail.com wrote: > > > From: Menglong Dong > > > > > > The mptcp socket and its subflow sockets in accept queue can't be > > > released after the process exit. > > > > > > While the release of a mptcp socket in listening state, the > > > corresponding tcp socket will be released too. Meanwhile, the tcp > > > socket in the unaccept queue will be released too. However, only init > > > subflow is in the unaccept queue, and the joined subflow is not in the > > > unaccept queue, which makes the joined subflow won't be released, and > > > therefore the corresponding unaccepted mptcp socket will not be released > > > to. > > > > > > This can be reproduced easily with following steps: > > > > > > 1. create 2 namespace and veth: > > > $ ip netns add mptcp-client > > > $ ip netns add mptcp-server > > > $ sysctl -w net.ipv4.conf.all.rp_filter=0 > > > $ ip netns exec mptcp-client sysctl -w net.mptcp.enabled=1 > > > $ ip netns exec mptcp-server sysctl -w net.mptcp.enabled=1 > > > $ ip link add red-client netns mptcp-client type veth peer red-server \ > > > netns mptcp-server > > > $ ip -n mptcp-server address add 10.0.0.1/24 dev red-server > > > $ ip -n mptcp-server address add 192.168.0.1/24 dev red-server > > > $ ip -n mptcp-client address add 10.0.0.2/24 dev red-client > > > $ ip -n mptcp-client address add 192.168.0.2/24 dev red-client > > > $ ip -n mptcp-server link set red-server up > > > $ ip -n mptcp-client link set red-client up > > > > > > 2. configure the endpoint and limit for client and server: > > > $ ip -n mptcp-server mptcp endpoint flush > > > $ ip -n mptcp-server mptcp limits set subflow 2 add_addr_accepted 2 > > > $ ip -n mptcp-client mptcp endpoint flush > > > $ ip -n mptcp-client mptcp limits set subflow 2 add_addr_accepted 2 > > > $ ip -n mptcp-client mptcp endpoint add 192.168.0.2 dev red-client id \ > > > 1 subflow > > > > > > 3. listen and accept on a port, such as 9999. The nc command we used > > > here is modified, which makes it uses mptcp protocol by default. > > > And the default backlog is 1: > > > ip netns exec mptcp-server nc -l -k -p 9999 > > > > > > 4. open another *two* terminal and connect to the server with the > > > following command: > > > $ ip netns exec mptcp-client nc 10.0.0.1 9999 > > > input something after connect, to triger the connection of the second > > > subflow > > > > > > 5. exit all the nc command, and check the tcp socket in server namespace. > > > And you will find that there is one tcp socket in CLOSE_WAIT state > > > and can't release forever. > > > > Thank you for the report! > > > > I have a doubt WRT the above scenario: AFAICS 'nc' will accept the > > incoming sockets ASAP, so the unaccepted queue should be empty at > > shutdown, but that does not fit with your description?!? > > > > By default, as far as in my case, nc won't accept the new connection > until the first connection closes with the '-k' set. Therefor, the second > connection will stay in the unaccepted queue. I missed the fact you opened 2 connections. I guess that is point 4 above. Please rephrase that sentence with something alike: --- 4. open another *two* terminal and use each of them to connect to the server with the following command: ... So that there are two established mptcp connections, with the second one still unaccepted. --- > > > > There are some solutions that I thought: > > > > > > 1. release all unaccepted mptcp socket with mptcp_close() while the > > > listening tcp socket release in mptcp_subflow_queue_clean(). This is > > > what we do in this commit. > > > 2. release the mptcp socket with mptcp_close() in subflow_ulp_release(). > > > 3. etc > > > > > > > Can you please point to a commit introducing the issue? > > > > In fact, I'm not sure. In my case, I found this issue in kernel 5.10. > And I wanted to find the solution in the upstream, but find that > upstream has this issue too. > > Hmm...I am curious if this issue exists in the beginning? I > can't find the opportunity that the joined subflow which are > unaccepted can be released. It looks like the problem is there since MPJ support, commit f296234c98a8fcec94eec80304a873f635d350ea > > > > Signed-off-by: Menglong Dong > > > --- > > > net/mptcp/subflow.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c > > > index c7d49fb6e7bd..e39dff5d5d84 100644 > > > --- a/net/mptcp/subflow.c > > > +++ b/net/mptcp/subflow.c > > > @@ -1770,6 +1770,10 @@ void mptcp_subflow_queue_clean(struct sock *listener_ssk) > > > msk->first = NULL; > > > msk->dl_next = NULL; > > > unlock_sock_fast(sk, slow); > > > + > > > + /* */ > > > + sock_hold(sk); > > > + sk->sk_prot->close(sk); > > > > You can call mptcp_close() directly here. > > > > Perhaps we could as well drop the mptcp_sock_destruct() hack? > > Do you mean to call mptcp_sock_destruct() directly here? I suspect that with this change setting msk->sk_destruct to mptcp_sock_destruct in subflow_syn_recv_sock() is not needed anymore, and the relevant intialization (and callback definition) could be removed. > Cheers, Paolo