Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6122938ybv; Wed, 12 Feb 2020 06:27:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyuvMeN7PJHmNGYTS5j+YWfax/SO6zfSgqN3pL7nPLsb7GtvZg4+6vqSY5QCbm4R00DJd4N X-Received: by 2002:aca:cd46:: with SMTP id d67mr6444307oig.156.1581517633517; Wed, 12 Feb 2020 06:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581517633; cv=none; d=google.com; s=arc-20160816; b=rJUYqlUXmZc23VrUEM1yodZgLWJNjCgo6ULNguQYvzEvpfOBXve9euZkfwKIDiu3WB pmnFzqkmJu1xdWjXu3e1/k6Pk4xAKsBGiVayO0tjvEB0U92UswVzEeqmihNjXmrF2rDj yU6yYl+mDg5hQYUxW1ONWmjG48Uh1g/qJrtEywZA0SojVILNs8rv+V3S7NIha4Tu68Eh xAuqoC7mheveuu1SiRj3nj3JyfQ+OcdMy6pyjpxEc1ljm+DJ6xgyOhvhPdIbt3V5okMl 0Q9HDLHD2YSXzSwlpNlYOW61Dv0ixyodPrqjUyPCgSCHbhqFhmKSRufH9C39UpADmTEm jRIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date; bh=r9WKd1bT0TlxSPtHgWpN4hF6BNwGQRkADFPfP1qCJJo=; b=tZDcgEaAA8arZ9+qE+jcml+OiU4LLf/eQRPcAl1JpQdi1FvHtV3ZBqCbTWLJNTjPFG r9cmAWnYKiToubi2WQ6xEAtLHWvmjZOo07lVLgNQDkuxQpdcHFUONI+1viIpnOScYaRl U9405qFp2TeOGcmtmBFD3VB0orq7JylOdAa0u7oW3ypfORa5GG5pSNSjsA8PnLtEmk/E McM7jIab7ZgBtIPlzr399pk4oHDxHsi3sNVmw+/Oy2oLMnJNi7QAERKucY76drHIIfYw 3GKdPj+/InrNlZGgkjSigg5dc4sPo/uE4yVjPyq618AMCpPr8v0akgHZwk5wkh08QEI5 YuAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si279190otk.173.2020.02.12.06.27.01; Wed, 12 Feb 2020 06:27:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728402AbgBLO0p (ORCPT + 99 others); Wed, 12 Feb 2020 09:26:45 -0500 Received: from monster.unsafe.ru ([5.9.28.80]:53146 "EHLO mail.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727963AbgBLO0p (ORCPT ); Wed, 12 Feb 2020 09:26:45 -0500 Received: from comp-core-i7-2640m-0182e6 (nat-pool-brq-t.redhat.com [213.175.37.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.unsafe.ru (Postfix) with ESMTPSA id C3542C61AB0; Wed, 12 Feb 2020 14:26:39 +0000 (UTC) Date: Wed, 12 Feb 2020 15:26:38 +0100 From: Alexey Gladkov To: Al Viro Cc: LKML , Kernel Hardening , Linux API , Linux FS Devel , Linux Security Module , Akinobu Mita , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Daniel Micay , Djalal Harouni , "Dmitry V . Levin" , "Eric W . Biederman" , Greg Kroah-Hartman , Ingo Molnar , "J . Bruce Fields" , Jeff Layton , Jonathan Corbet , Kees Cook , Linus Torvalds , Oleg Nesterov , Solar Designer Subject: Re: [PATCH v8 07/11] proc: flush task dcache entries from all procfs instances Message-ID: <20200212142637.dhcrgy252qw6eg42@comp-core-i7-2640m-0182e6> Mail-Followup-To: Al Viro , LKML , Kernel Hardening , Linux API , Linux FS Devel , Linux Security Module , Akinobu Mita , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Daniel Micay , Djalal Harouni , "Dmitry V . Levin" , "Eric W . Biederman" , Greg Kroah-Hartman , Ingo Molnar , "J . Bruce Fields" , Jeff Layton , Jonathan Corbet , Kees Cook , Linus Torvalds , Oleg Nesterov , Solar Designer References: <20200210150519.538333-1-gladkov.alexey@gmail.com> <20200210150519.538333-8-gladkov.alexey@gmail.com> <20200211224553.GK23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200211224553.GK23230@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 10:45:53PM +0000, Al Viro wrote: > On Mon, Feb 10, 2020 at 04:05:15PM +0100, Alexey Gladkov wrote: > > This allows to flush dcache entries of a task on multiple procfs mounts > > per pid namespace. > > > > The RCU lock is used because the number of reads at the task exit time > > is much larger than the number of procfs mounts. > > > > Cc: Kees Cook > > Cc: Andy Lutomirski > > Signed-off-by: Djalal Harouni > > Suggested-by: Linus Torvalds > > Signed-off-by: Alexey Gladkov > > --- > > fs/proc/base.c | 20 +++++++++++++++----- > > fs/proc/root.c | 27 ++++++++++++++++++++++++++- > > include/linux/pid_namespace.h | 2 ++ > > include/linux/proc_fs.h | 2 ++ > > 4 files changed, 45 insertions(+), 6 deletions(-) > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > index 4ccb280a3e79..24b7c620ded3 100644 > > --- a/fs/proc/base.c > > +++ b/fs/proc/base.c > > @@ -3133,7 +3133,7 @@ static const struct inode_operations proc_tgid_base_inode_operations = { > > .permission = proc_pid_permission, > > }; > > > > -static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid) > > +static void proc_flush_task_mnt_root(struct dentry *mnt_root, pid_t pid, pid_t tgid) > > { > > struct dentry *dentry, *leader, *dir; > > char buf[10 + 1]; > > @@ -3142,7 +3142,7 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid) > > name.name = buf; > > name.len = snprintf(buf, sizeof(buf), "%u", pid); > > /* no ->d_hash() rejects on procfs */ > > - dentry = d_hash_and_lookup(mnt->mnt_root, &name); > > + dentry = d_hash_and_lookup(mnt_root, &name); > > if (dentry) { > > d_invalidate(dentry); > ... which can block > > dput(dentry); > ... and so can this > > > + rcu_read_lock(); > > + list_for_each_entry_rcu(fs_info, &upid->ns->proc_mounts, pidns_entry) { > > + mnt_root = fs_info->m_super->s_root; > > + proc_flush_task_mnt_root(mnt_root, upid->nr, tgid->numbers[i].nr); > > ... making that more than slightly unsafe. I see. So, I can't use rcu locks here as well as spinlocks. Thanks! -- Rgrds, legion