Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1046243iob; Fri, 13 May 2022 20:58:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyW/4BXNhE1EfTDiNReB9n5/x7V6+r9WapYgdr53I6E6gRwGqr1zLa+Mif4FwWxPBa5sr6 X-Received: by 2002:adf:ec92:0:b0:20a:d261:2cf2 with SMTP id z18-20020adfec92000000b0020ad2612cf2mr6127833wrn.296.1652500681550; Fri, 13 May 2022 20:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500681; cv=none; d=google.com; s=arc-20160816; b=hmlvXmKdiJ+AfxBMA/JL+gUE+A8Fc0orkLNi4/qhhjacxnFEm3sLrEXPh8+N4OgnUs meZY3Kk2Dri3h5ei13ZcxhF3TEdr6pTCDoEdmURIW0Y4gzZrIKezq6KHlr7R0yyDCpKn 1SFBqDiWBwvurC+Ic4Dtt/kuhU0Xb+ge0YpWTeMWPFl/hWzT+JA6ET8wrd42AbUwfIyS zaGuJLd3PocEpOeSpj1d/gSxF8zPsKkC+t72DFtDchp9Nzx+61f8ttedDtdbKWUwdZQv Ih1+LhPtMlznBWII9D1mqF1xvEqJSfn01yc4tpbUlYySyqsqa+CjX6j8nKHxx7FiOxnU 6zcQ== 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=+RvotmzlXXJLUjxfnHqDPaXa716Ci6O256j8ra0+f68=; b=dzMbm6TapkQ0LoUdNFyoc3kZrW2RF/HLOeGovu4Byk1u/V6n9LUbXIO8W5jvukclrk usMkiZhGwvOGuJky5w/QvyzAQfWrcFCnV7jK1gOrEIzXZAi8lCKCECqYzsauLc7T+eyN kFy3jEbQjMRyeNMKjjhj/pb9I6mEgQkdM4tPag1T8MLvbgw5yOoKmr9mgC/ybHglLsse XsIEIohYu1Q3s7vRMQRukwRq0Z4XHcHEEJ5k1o9eHkeBASpYTvaXSRYG/EEMxVYMQ1XN +aJaQek45MvT6UyV19Gr+wSpSGJE3xqeQMBNm4yyTfEaUz/3R/BcJc4nkId/0qbhvD9x FsAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=g0GsQlOv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o1-20020a5d47c1000000b0020cf50ad95esi3011719wrc.1058.2022.05.13.20.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:58:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=g0GsQlOv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7ECA497825; Fri, 13 May 2022 17:29:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358302AbiELUJj (ORCPT + 99 others); Thu, 12 May 2022 16:09:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354491AbiELUJh (ORCPT ); Thu, 12 May 2022 16:09:37 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2EB2670AA for ; Thu, 12 May 2022 13:09:36 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-2f7ca2ce255so69283987b3.7 for ; Thu, 12 May 2022 13:09:36 -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=+RvotmzlXXJLUjxfnHqDPaXa716Ci6O256j8ra0+f68=; b=g0GsQlOvnxr8GQ9ath+D+MdVdAHaXyLhTt/CfZs6l7Ar6F5uYBhvWa/XylZxrFWxcQ 1zhc0mGLTwT/0Gn4apeojjEtse3mcuj2qV12KNPqhgeW8H4kvbEaeAEmZYV+3CBBvbbD 0a0AxJRm/bKaYOrnj19ALFto28G04rrbhQHNnrDGJJAAHE4ublazO9V9zqlX6PYJqXBk V5sixDdKEnFlkmi5J3oOHMhQauKmGdn5wIgz2y4L1g1cH7P0rdoOKpiN0dH2W5UDJx5K PVnQKhYAKKkZDtE9JtOKWryEJqgiXLqnChGzmoY4VI1E5YBSF4P5bNDO3EZ8kLu2sv0o iWWw== 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=+RvotmzlXXJLUjxfnHqDPaXa716Ci6O256j8ra0+f68=; b=1WkyPluMUv/BM/9mpM+euNzxEgbWh8NkYHlNORWPxJ1U40FnqTzsu6Tt6vCijSPZk2 9TIRl8wORXSltHn4NH9+dydf8UlkT8ocTwFEWoco5BVlLGENQ3vQtPRroOY8Q1jd/MDE QBNYRpXpFSyxHZo3FEKRNHSmhohk+Xc7QsXgohU8ojRrF04PAlt6uW+l1sNcemJPSqpY N7qKcUirMsX3evOJY/HV4grZ69YHR15yDkXXyYNFV7Nqrz+tl4DLcFFA7HWsyb+UDS3G eaK9wgm7PCsOyyUkFxAp5OU7kfkXWzRvYgdtYvx2UC6PH7/tQHFkh06xTdcvQhbpbjHO GOAg== X-Gm-Message-State: AOAM53084XWdhdLxk2BGbvF87I7XpSTVX07Lk8Hps9ovRRwXMvY7hpAP 2qwwD8EnGP4Ssb0CZk48gTEorUfVNHp6Ru3ZAEn5zE3aN8VH7A== X-Received: by 2002:a81:5603:0:b0:2f8:3187:f37a with SMTP id k3-20020a815603000000b002f83187f37amr1872082ywb.255.1652386175023; Thu, 12 May 2022 13:09:35 -0700 (PDT) MIME-Version: 1.0 References: <93323bba-476e-f821-045c-9fe942143da9@gmail.com> In-Reply-To: From: Eric Dumazet Date: Thu, 12 May 2022 13:09:23 -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:13 AM Eric Dumazet wrote: > > 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. Oh well, too many changes would be needed. I will send a revert, thanks.