From: Al Viro <viro@zeniv.linux.org.uk>
To: Chen Linxuan <chenlinxuan@uniontech.com>
Cc: WangYuli <wangyuli@uniontech.com>,
brauner@kernel.org, jack@suse.cz, akpm@linux-foundation.org,
tglx@linutronix.de, jlayton@kernel.org, frederic@kernel.org,
xu.xin16@zte.com.cn, adrian.ratiu@collabora.com,
lorenzo.stoakes@oracle.com, mingo@kernel.org,
felix.moessbauer@siemens.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, zhanjun@uniontech.com,
niecheng1@uniontech.com, guanwentao@uniontech.com
Subject: Re: [PATCH] proc: Show the mountid associated with exe
Date: Sun, 11 May 2025 18:41:53 +0100 [thread overview]
Message-ID: <20250511174153.GB2023217@ZenIV> (raw)
In-Reply-To: <CAC1kPDP4MCfUFkrQu0-Fg3Du7bz25QAY1Wyqdi_HGVbw326U1w@mail.gmail.com>
On Mon, May 12, 2025 at 12:19:01AM +0800, Chen Linxuan wrote:
> On Sun, May 11, 2025 at 10:22 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> > Excuse me, just what is that path_get/path_put for? If you have
> > an opened file, you do have its ->f_path pinned and unchanging.
> > Otherwise this call of path_get() would've itself been unsafe...
>
> I am not very familiar with how these functions should be used.
> I just copied similar logic from proc_exe_link and added a path_put.
> Maybe I made a stupid mistake...
path_get() grabs an extra reference to mount and dentry; that is enough
to guarantee that their refcount will not drop to zero at least until
we drop the references.
To use it safely you need to be sure that currently refcounts are non-zero
and won't be dropped to zero right under you - for rather obvious reasons.
Your code also clearly relies upon ->f_path being unchanging - otherwise
you would've risked to drop the references not to the objects you've
grabbed earlier.
If both conditions are satisfied, what's the point of grabbing and dropping
these references in the first place?
*IF* there was a chance of mount going away under you, what would prevent
that happening right before that path_get()?
IOW, these dances with path_get()/path_put() are either nowhere near enough
or not needed at all. As it is, ->f_path of an open file *IS* stable and
mount and dentry references in it do contribute towards mount and dentry
refcounts. But my point is, that code does not pass the basic "how could
that possibly be right?" test.
PS: since you've mentioned proc_exe_link()... the difference there is that
we want the reference to be used by the caller. If the file happens to
be closed just as we return (that can't happen until proc_exe_link() drops
the reference to struct file it got from get_task_exe_file(), but as soon
as fput() had been called, there's nothing to guarantee the safety),
file's contributions to refcounts are dropped, so we can't count upon them
to stay for as long as we need. So in that case we fetch the references
out of ->f_path and pin them before we drop the file reference with fput().
PPS: I'm still not convinced regarding the usefulness of having that
information; "just because we can display it" isn't a strong argument
on its own...
next prev parent reply other threads:[~2025-05-11 17:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 11:42 [PATCH] proc: Show the mountid associated with exe WangYuli
2025-05-11 14:22 ` Al Viro
2025-05-11 16:19 ` Chen Linxuan
2025-05-11 17:41 ` Al Viro [this message]
2025-05-12 9:11 ` Christian Brauner
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=20250511174153.GB2023217@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=adrian.ratiu@collabora.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=chenlinxuan@uniontech.com \
--cc=felix.moessbauer@siemens.com \
--cc=frederic@kernel.org \
--cc=guanwentao@uniontech.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mingo@kernel.org \
--cc=niecheng1@uniontech.com \
--cc=tglx@linutronix.de \
--cc=wangyuli@uniontech.com \
--cc=xu.xin16@zte.com.cn \
--cc=zhanjun@uniontech.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