From: Oleg Nesterov <oleg@redhat.com>
To: Wen Yang <wenyang@linux.alibaba.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
Christian Brauner <christian@brauner.io>,
ebiederm@xmission.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] proc: add locking checks in proc_inode_is_dead
Date: Sat, 28 Nov 2020 20:01:06 +0100 [thread overview]
Message-ID: <20201128190105.GC19372@redhat.com> (raw)
In-Reply-To: <20201128175850.19484-1-wenyang@linux.alibaba.com>
On 11/29, Wen Yang wrote:
>
> The proc_inode_is_dead function might race with __unhash_process.
> This will result in a whole bunch of stale proc entries being cached.
> To prevent that, add the required locking.
I leave this to Eric but I don't understand how can this patch help,
__unhash_process() can be called right after proc_inode_is_dead().
And in any case, we certainly do not want to take tasklist_lock in
proc_inode_is_dead().
>
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: "Eric W. Biederman" <ebiederm@xmission.com>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: Christian Brauner <christian@brauner.io>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-fsdevel@vger.kernel.org
> ---
> fs/proc/base.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 1bc9bcd..59720bc 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1994,7 +1994,13 @@ static int pid_revalidate(struct dentry *dentry, unsigned int flags)
>
> static inline bool proc_inode_is_dead(struct inode *inode)
> {
> - return !proc_pid(inode)->tasks[PIDTYPE_PID].first;
> + bool has_task;
> +
> + read_lock(&tasklist_lock);
> + has_task = pid_has_task(proc_pid(inode), PIDTYPE_PID);
> + read_unlock(&tasklist_lock);
> +
> + return !has_task;
> }
>
> int pid_delete_dentry(const struct dentry *dentry)
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2020-11-28 22:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-28 17:58 [PATCH] proc: add locking checks in proc_inode_is_dead Wen Yang
2020-11-28 19:01 ` Oleg Nesterov [this message]
2020-11-30 18:41 ` Eric W. Biederman
2020-12-01 12:35 ` Oleg Nesterov
2020-12-01 15:06 ` Eric W. Biederman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201128190105.GC19372@redhat.com \
--to=oleg@redhat.com \
--cc=adobriyan@gmail.com \
--cc=christian@brauner.io \
--cc=ebiederm@xmission.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wenyang@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).