Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp941434iob; Fri, 13 May 2022 17:12:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT2i/5uDy/xLqUCFeVZGeoz9b4PRSbtytbNgZFvToqbws2BYgSpLffyfkdk2CGpXTjOKhr X-Received: by 2002:a05:600c:3595:b0:394:8343:a66d with SMTP id p21-20020a05600c359500b003948343a66dmr17211653wmq.49.1652487154772; Fri, 13 May 2022 17:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652487154; cv=none; d=google.com; s=arc-20160816; b=vBuyidOlFd4mBDUzEha6XtYyPRxFwjjg11xkKSikYESgMf1QIUqILhS5MwMPjhexJS iUoVy19JgB5ti2Cc6hvKXiKP5+ih8T/UF7RKxkG7xMVOvxOuOlML3jnPU5UkJ1o7bev7 nnbfD0VNCMClbFkTTrJpxqO1j0/3w5huJqGN/Y0t/WNaM15DMaMfV7fAr3V1/rzJmFiF KHC8tTOe+g33UbkszscRGWAQJOQELMvQO1obHBFRI9OQ/ESGz89Kf6+Q1cY7QVFz3tCg TjT6B0e4xywPiMvBw3wVbMbJgX8eKOuPmTD7WUvthcwbE4e6hD4A11gi1USqIUr5/TOd V34A== 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=cfuve+c5Cwa7UJ0vQNcacC+/40JGpfLbjA8g3t9eIqQ=; b=qtH/ceFl0BO4GTJkKxSi+s6I9ZpleZf22gq2M44UK450kWDyNnf4RsLhSZgQAFaClk iUopGNo3/s3hs442oYQShRU3rSo7VCdcHb1NTRLJZsTfECvJJmW/fzAkCI+xvQ5vMTYJ mvig4yvGEtMnXhCv1obApifCRgcsUzt+rqRc6IXel/X7csmKG1sepETG9tU24HVCEyiJ LWyT4k/KVd/Gi92l9swgpiqeVARCFMPh5HTfub5aP2FuU/p1YFNcSaTCTbHkpNepYf9A yWDm1N6w4zO8PyUExIr7DWfovAWva3gi/py2dl3830pT0QMfqxzajDKdXgIrqbb1IBKh Y6xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NZHWcKJj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q63-20020a1c4342000000b0039403a4fe89si3615947wma.54.2022.05.13.17.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:12:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NZHWcKJj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24FAE31C358; Fri, 13 May 2022 16:13:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357343AbiELSOA (ORCPT + 99 others); Thu, 12 May 2022 14:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241392AbiELSN7 (ORCPT ); Thu, 12 May 2022 14:13:59 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 343BE20D577 for ; Thu, 12 May 2022 11:13:58 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id g28so11239365ybj.10 for ; Thu, 12 May 2022 11:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cfuve+c5Cwa7UJ0vQNcacC+/40JGpfLbjA8g3t9eIqQ=; b=NZHWcKJjdxGhGeikxnkOyvDffaXBl4vKuicdYIsXaTBG2teHtca2Fd1CjL4dr0p4r/ SvpxexJECOuPNbkgeXDSwdkXpodxbGttPU3Kaci3pcsdLf2jEwK61kGImtNXRXYPgqU3 WNUD+ic2R0CXvMB+k4ApzwMxZsPVGQ+uaEWtCAsgw40To+8srzWnDv3luZ+MYVEXJiAS VtQrPHcUd0rrtZgelUdW8hafe8DlNNz9fEy1aKh5rJWDNceP9RwH/LBq2pLButUTjICb WupTbkYqQRJdPAfNOjruetejDsm8NzIcHVZcPBy+3V7amKui0xMwNj4JxDG8TqcegZvp Igiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cfuve+c5Cwa7UJ0vQNcacC+/40JGpfLbjA8g3t9eIqQ=; b=ZqBC5KLUaMQ2ObGte7w/w75mADNT51KzPd2IeEF9ZuXpY+nGNyiVltAIudoLq+HzpY DkPzPQdnhfjA29zb3yLi3JRgoBQ+ZclZhaN3gAJpdHnFVR1F/ECUH0ttGVagiHuCozye Q/LLuakCvp4tTw5weuzdO1gLPb+Ez9y01ii7TxFtI6OWT4soTuoOD9MW/1wrzRdXe2Ni H5XSuUYlcUYq06UNCs1Ns4Gveiwt39kdfV7/mGEwwQUnKDdqz+vb2lB8PYJwS+z6a86+ bKlunS9Auh2wV+rg/obbKadZEyXCvkFEhRCqWo3713JhbHyA6auPBoUB8d5MQwuVniOJ LoHA== X-Gm-Message-State: AOAM53112dpT6WsUVwvIkjYoeetDybPaTL9kLudpq6nNEn+LDAabZ2pf rkxU00GDjK6ucJpNC+LaktDgBiN6G304kM0H76NTVQ== X-Received: by 2002:a25:3157:0:b0:649:b216:bb4e with SMTP id x84-20020a253157000000b00649b216bb4emr1062269ybx.387.1652379237164; Thu, 12 May 2022 11:13:57 -0700 (PDT) MIME-Version: 1.0 References: <93323bba-476e-f821-045c-9fe942143da9@gmail.com> In-Reply-To: <93323bba-476e-f821-045c-9fe942143da9@gmail.com> From: Eric Dumazet Date: Thu, 12 May 2022 11:13:46 -0700 Message-ID: Subject: Re: BUG: TCP timewait sockets survive across namespace creation in net-next To: Leonard Crestez Cc: "David S. Miller" , David Ahern , netdev , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Thu, May 12, 2022 at 11:01 AM Leonard Crestez wrote: > > Hello, > > It appears that in recent net-next versions it is possible for sockets > in the timewait state to survive across namespace add/del. Timewait > sockets are inserted into a global hash and only the sock_net value is > compared when they are enumerated from interfaces like /proc/net/tcp and > inet_diag. Old TW sockets are not cleared after namespace delete and > namespaces are allocated from a slab and thus their pointers get reused > a lot, when that happens timewait sockets from an old namespace will > show up in the new one. > > This can be reproduced by establishing a TCP connection over a veth pair > between two namespaces, closing and then recreating those namespaces. > Old timewait sockets will be visible and it happens quite reliably, > often on the first iteration. I can try to provide a script for this. > > I can't point to specific bugs outside of tests that explicitly > enumerate timewait sockets but letting sk_net be a dangling pointer > seems very dangerous. It also violates the idea of network namespaces > being independent and isolated. > > This does not happen in 5.17, I bisected this behavior to commit > 0dad4087a86a ("tcp/dccp: get rid of inet_twsk_purge()") > Thanks for the report. I guess we will need to store the (struct net)->net_cookie to disambiguate the case where a new 'struct net' is reusing the same storage than an old one.