Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2068841pxp; Mon, 21 Mar 2022 10:34:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxZi2nHEixgwEx7dhyhysS7kRgGNxJUlsP7/+SqQYEoMjiQRNkjPgkFqiNQbi3i6wjhKsj X-Received: by 2002:a17:902:a982:b0:14f:f55:a09a with SMTP id bh2-20020a170902a98200b0014f0f55a09amr13719584plb.33.1647884070782; Mon, 21 Mar 2022 10:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647884070; cv=none; d=google.com; s=arc-20160816; b=nlON7j3TKoDnJKH2uTPaDv3k2y8EdG6zzbouA/kIeRlIDnEg/Nc6D+4OZ9nmVESzl7 os8Pe5f5H2pFuWHId8ZdEB1VrEJWwNRa7xxPTLxU58F6lSLAuLl584oFOSfiO7dH2XsX QzCE1tvxUQXgDsyl5VM2/PiL7vIboAPbKmh28vmeh97e/G2mA4L7WqqSQtZ99sWpbaRU LuIy2n94TMe4Xp/JfxGvQAMzv7/LPPMiymk/BZonpgoK0SnY/hnhCastNHJxy8JBhKU2 JjveofV8TsEnUt/rUOgb4VUWY3ZlgkvLc7sbBTpKc3fNHL0NWfRhNAzzDXSPwGltiqhT tlbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1bHq03jNRnCRtDNxwCXciuil1CSKlUgULr0uZ0a2LW8=; b=kK7l0OveinBnqnWPCS8ILeGMBrMCGzXJrF925Lut3KAgPIgu+HEzOHc2nz02L8AgSk +DK0es7y8yXalbiYKnD7JmQktcUxcEJHWcsZKB5gm2vBXwTkcdl3aqI0HhRSls61ihA9 xjFDKHYZKtGuw/gkFGgXlVILwMgu+QR0FP3P2PpV8ySRiPwH+gju5Q1u+EOEWxmaTkPp sRsduw7OcNPYhb2gvZpA6BSGmhrqv9dHukmYKT+uJXudsHkurVizEbgXLluWbkSHlPTi n6/cj1JBCwpOUxZKJcSl7fb7VLGsNdCe9h0s4PKw5qUQbAizW5lqDNw/AW9uh5/DL+pG jyXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iygiQUIq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a637555000000b003816043f050si15004281pgn.581.2022.03.21.10.34.07; Mon, 21 Mar 2022 10:34:30 -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=@gmail.com header.s=20210112 header.b=iygiQUIq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346856AbiCULwf (ORCPT + 99 others); Mon, 21 Mar 2022 07:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344272AbiCULwd (ORCPT ); Mon, 21 Mar 2022 07:52:33 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5845522A; Mon, 21 Mar 2022 04:51:05 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id i4so11618209qti.7; Mon, 21 Mar 2022 04:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1bHq03jNRnCRtDNxwCXciuil1CSKlUgULr0uZ0a2LW8=; b=iygiQUIqr3rmsvG7usVOfDxILLl7YQM4495zPlxxtygKNQZtBkT8HREnO9oTXDXaBA iNWGOMtsZnUrqmzvXimmq3ckXyyqoUfzfQBlnCUVVIaweLE9yorNOIks+VYYH5SNqK9X 0R0QXJfESbVqxW6R/zsn0yRxpC/40snDVUUGQIt0heeTDqJRporPNBw/AOJSAouboovh lVfPKdSZmFiF/Q5sVeA4NuA5recitstmMyq1VFzW/OH0Y5Rl8Vd1pa5oyS7EkuS6f04R 1szbJU57ACnt6pu7HkYxqRMDPiAuZjRsHH47DEtnaOdXt9UQ3n7Q9pq/piR4XJntd5RX 1+iQ== 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:content-transfer-encoding; bh=1bHq03jNRnCRtDNxwCXciuil1CSKlUgULr0uZ0a2LW8=; b=MMdeXF0jIQfoEVvTkd/Rn95MFCHQvQMJemYt7PaPMdK2IQ2pOl1Y8mEGZX8F3XFjhY dcE0WRkhkmxH6EwmCf8ABaos2NyQ5MrkA3n3du2rZJ8W2geBSh8zC1YJLdt7MyI3PlTo MMmgZX7D8/ilFqf1PoV+TO0+5ezkIHLaYNuXe+Cz22N/rCAmyq/ZgB7sTByfti84/2Cz CcrkaV9OgGi0DA7NCOLDoITM0K64h4YPK0G8KCfWon2Hs4TPA8pCx9h/6C+oEJ8Tdrr3 mDUzjJP8sehkWics1zX8ENJN/apqRWhYLmhrrn4uY+I64EewzlEOx000+XsisdKN2dJ+ mtzQ== X-Gm-Message-State: AOAM530A0FCEDF1WFQwn3FGOnu8Hm89Amh7Vp/cftIuNNVg1BihPqGyi fdOkR0/DhtmCkBPrHNWlSgEoJ0EPqWEjCym5DTm10io0 X-Received: by 2002:a05:622a:1996:b0:2e0:ffd3:a2d5 with SMTP id u22-20020a05622a199600b002e0ffd3a2d5mr15757989qtc.390.1647863464594; Mon, 21 Mar 2022 04:51:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: cael Date: Mon, 21 Mar 2022 19:50:53 +0800 Message-ID: Subject: Re: [PATCH] proc: fix dentry/inode overinstantiating under /proc/${pid}/net To: Alexey Dobriyan Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 I see, I will test on my system. Alexey Dobriyan =E4=BA=8E2022=E5=B9=B43=E6=9C=8821=E6= =97=A5=E5=91=A8=E4=B8=80 18:40=E5=86=99=E9=81=93=EF=BC=9A > > On Mon, Mar 21, 2022 at 05:15:02PM +0800, hui li wrote: > > Alexey Dobriyan =E4=BA=8E2022=E5=B9=B43=E6=9C=882= 1=E6=97=A5=E5=91=A8=E4=B8=80 00:24=E5=86=99=E9=81=93=EF=BC=9A > > > > > > When a process exits, /proc/${pid}, and /proc/${pid}/net dentries are= flushed. > > > However some leaf dentries like /proc/${pid}/net/arp_cache aren't. > > > That's because respective PDEs have proc_misc_d_revalidate() hook whi= ch > > > returns 1 and leaves dentries/inodes in the LRU. > > > > > > Force revalidation/lookup on everything under /proc/${pid}/net by inh= eriting > > > proc_net_dentry_ops. > > > > > > Fixes: c6c75deda813 ("proc: fix lookup in /proc/net subdirectories af= ter setns(2)") > > > Reported-by: hui li > > > Signed-off-by: Alexey Dobriyan > > > --- > > > > > > fs/proc/generic.c | 4 ++++ > > > fs/proc/proc_net.c | 3 +++ > > > 2 files changed, 7 insertions(+) > > > > > > --- a/fs/proc/generic.c > > > +++ b/fs/proc/generic.c > > > @@ -448,6 +448,10 @@ static struct proc_dir_entry *__proc_create(stru= ct proc_dir_entry **parent, > > > proc_set_user(ent, (*parent)->uid, (*parent)->gid); > > > > > > ent->proc_dops =3D &proc_misc_dentry_ops; > > > + /* Revalidate everything under /proc/${pid}/net */ > > > + if ((*parent)->proc_dops =3D=3D &proc_net_dentry_ops) { > > > + pde_force_lookup(ent); > > > + } > > > > > > out: > > > return ent; > > > --- a/fs/proc/proc_net.c > > > +++ b/fs/proc/proc_net.c > > > @@ -376,6 +376,9 @@ static __net_init int proc_net_ns_init(struct net= *net) > > > > > > proc_set_user(netd, uid, gid); > > > > > > + /* Seed dentry revalidation for /proc/${pid}/net */ > > > + pde_force_lookup(netd); > > > + > > > err =3D -EEXIST; > > > net_statd =3D proc_net_mkdir(net, "stat", netd); > > > if (!net_statd) > > > proc_misc_dentry_ops is a general ops for dentry under /proc, except > > for "/proc/${pid}/net"=EF=BC=8Cother dentries may also use there own op= s too, > > so I think change proc_misc_d_delete may be better? > > see patch under: https://lkml.org/lkml/2022/3/17/319 > > I don't think so. > > proc_misc_d_delete covers "everything else" part under /proc/ and > /proc/net which are 2 separate trees. Now /proc/net/ requires > revalidation because of > > commit c6c75deda81344c3a95d1d1f606d5cee109e5d54 > proc: fix lookup in /proc/net subdirectories after setns(2) > > so the bug is that the above commit was applied only partially. > In particular, /proc/*/net/stat/arp_cache was created with > proc_create_seq_data(), avoiding proc_net_* APIs. > > And there is probably the same "lookup after setns find wrong file" > if you search hard enough in /proc/*/net/ > > This is the logic. Please test on your systems.