Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp126167pxu; Wed, 6 Jan 2021 23:56:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaTw/GBzu3aVhLsUiX3lLzaCu+VF8UWnsc/9t9Qz0MnLn3VV9a0KDNLPsF+4MD8cgMSqmo X-Received: by 2002:a05:6402:2377:: with SMTP id a23mr753633eda.34.1610006159831; Wed, 06 Jan 2021 23:55:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610006159; cv=none; d=google.com; s=arc-20160816; b=a9v8fQhgDEj5OFrUpJMGJvZqwUkR/wcftSR1UkK8EcazPfB8DSCDXDFnk93XTr9h22 Qpxk8OaHwN+gSmklmC69YC73T/sN/LSz2lgCBbhTgfbqJHmzLDLLUpiCwEhnX5XhvSqb vZqXdF7fnfiYLu3Qig5A95eJpeMsTiltnTMYm2MKfpjru/cOPUEgafTMOK3u95AcETqN rkW5vZXZ8fSYjvwUx0fjCCGohqmEjwlglVeXZAbt3w4+DKDRA8jFVSJI3JQxaiLVGiT/ PmcMGt/x5XdsmXAJjH36aUIheN4LJL9dd1Fs+ExI45c4kS1EWYiLukjqu8F5pdJCW7u4 axuw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EHUBgQklU7YV9OwP+gz7V0Tzt46kbKJX+ce0YFn05F8=; b=O3TWA1gCVDAMUdEPqFrSgYRxmk6KRZff15qq4cw3RBJRJ/egsnSUIX3o4P4C90HOhd kxBdIfdXGjOqXnXctYt+/1sF8kXqPNKS6CEqWwFHx5u6znfeip1Vsrz+8fQlLhjZC+4W tabVuBzFiMh8k0HZue4+/qK9jEwsnjxcTLFia8ZwdjOt/Fn//kogUcpNV7EhjYTiDX/9 TJpRQcddPoCaCpDYNDSvJAmaNae2T2IrtcvLh//HANMsidhOEzYlEUqr7V4ArpGZ5NXc GPgFzVpDyREm7SGkKf9Q1kVs9l54kh603P4567y6yT7vdFaVv5sLGw5SkVbH6ApZI9AR 51Mw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e25si2008220edq.489.2021.01.06.23.55.36; Wed, 06 Jan 2021 23:55:59 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbhAGHx0 (ORCPT + 99 others); Thu, 7 Jan 2021 02:53:26 -0500 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:49532 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727169AbhAGHxZ (ORCPT ); Thu, 7 Jan 2021 02:53:25 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UKyrqoJ_1610005960; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0UKyrqoJ_1610005960) by smtp.aliyun-inc.com(127.0.0.1); Thu, 07 Jan 2021 15:52:40 +0800 From: Wen Yang To: Greg Kroah-Hartman , Sasha Levin Cc: Xunlei Pang , linux-kernel@vger.kernel.org, "Eric W. Biederman" , stable@vger.kernel.org, Wen Yang Subject: [PATCH v2 4.9 09/10] proc: Use d_invalidate in proc_prune_siblings_dcache Date: Thu, 7 Jan 2021 15:52:21 +0800 Message-Id: <20210107075222.62623-10-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210107075222.62623-1-wenyang@linux.alibaba.com> References: <20210107075222.62623-1-wenyang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Eric W. Biederman" [ Upstream commit f90f3cafe8d56d593fc509a4185da1d5800efea4 ] The function d_prune_aliases has the problem that it will only prune aliases thare are completely unused. It will not remove aliases for the dcache or even think of removing mounts from the dcache. For that behavior d_invalidate is needed. To use d_invalidate replace d_prune_aliases with d_find_alias followed by d_invalidate and dput. For completeness the directory and the non-directory cases are separated because in theory (although not in currently in practice for proc) directories can only ever have a single dentry while non-directories can have hardlinks and thus multiple dentries. As part of this separation use d_find_any_alias for directories to spare d_find_alias the extra work of doing that. Plus the differences between d_find_any_alias and d_find_alias makes it clear why the directory and non-directory code and not share code. To make it clear these routines now invalidate dentries rename proc_prune_siblings_dache to proc_invalidate_siblings_dcache, and rename proc_sys_prune_dcache proc_sys_invalidate_dcache. V2: Split the directory and non-directory cases. To make this code robust to future changes in proc. Signed-off-by: "Eric W. Biederman" Cc: # 4.9.x (proc: fix up cherry-pick conflicts for f90f3cafe8d5) Signed-off-by: Wen Yang --- fs/proc/inode.c | 16 ++++++++++++++-- fs/proc/internal.h | 2 +- fs/proc/proc_sysctl.c | 8 ++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 739fb9c..2af9f4f 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -107,7 +107,7 @@ void __init proc_init_inodecache(void) init_once); } -void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock) +void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock) { struct inode *inode; struct proc_inode *ei; @@ -136,7 +136,19 @@ void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock) continue; } - d_prune_aliases(inode); + if (S_ISDIR(inode->i_mode)) { + struct dentry *dir = d_find_any_alias(inode); + if (dir) { + d_invalidate(dir); + dput(dir); + } + } else { + struct dentry *dentry; + while ((dentry = d_find_alias(inode))) { + d_invalidate(dentry); + dput(dentry); + } + } iput(inode); deactivate_super(sb); diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 9bc44a1..6a1d679 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -200,7 +200,7 @@ struct pde_opener { extern const struct inode_operations proc_pid_link_inode_operations; extern void proc_init_inodecache(void); -void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock); +void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock); extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *); extern int proc_fill_super(struct super_block *, void *data, int flags); extern void proc_entry_rundown(struct proc_dir_entry *); diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index f19063b..b6668a5 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -260,9 +260,9 @@ static void unuse_table(struct ctl_table_header *p) complete(p->unregistering); } -static void proc_sys_prune_dcache(struct ctl_table_header *head) +static void proc_sys_invalidate_dcache(struct ctl_table_header *head) { - proc_prune_siblings_dcache(&head->inodes, &sysctl_lock); + proc_invalidate_siblings_dcache(&head->inodes, &sysctl_lock); } /* called under sysctl_lock, will reacquire if has to wait */ @@ -284,10 +284,10 @@ static void start_unregistering(struct ctl_table_header *p) spin_unlock(&sysctl_lock); } /* - * Prune dentries for unregistered sysctls: namespaced sysctls + * Invalidate dentries for unregistered sysctls: namespaced sysctls * can have duplicate names and contaminate dcache very badly. */ - proc_sys_prune_dcache(p); + proc_sys_invalidate_dcache(p); /* * do not remove from the list until nobody holds it; walking the * list in do_sysctl() relies on that. -- 1.8.3.1