[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231211205759.583ca1ff4ea510061068027f@canonical.com>
Date: Mon, 11 Dec 2023 20:57:59 +0100
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
To: Andrei Vagin <avagin@...gle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, Amir Goldstein <amir73il@...il.com>,
Alexander Mikhalitsyn <alexander@...alicyn.com>,
brauner@...nel.org
Subject: Re: [PATCH 1/2] fs/proc: show correct device and inode numbers in
/proc/pid/maps
On Mon, 11 Dec 2023 11:30:47 -0800
Andrei Vagin <avagin@...gle.com> wrote:
> Device and inode numbers in /proc/pid/maps have to match numbers returned by
> statx for the same files.
>
> /proc/pid/maps shows device and inode numbers of vma->vm_file-s. Here is
> an issue. If a mapped file is on a stackable file system (e.g.,
> overlayfs), vma->vm_file is a backing file whose f_inode is on the
> underlying filesystem. To show correct numbers, we need to get a user
> file and shows its numbers. The same trick is used to show file paths in
> /proc/pid/maps.
>
> But it isn't the end of this story. A file system can manipulate inode numbers
> within the getattr callback (e.g., ovl_getattr), so vfs_getattr must be used to
> get correct numbers.
>
> Cc: Amir Goldstein <amir73il@...il.com>
> Cc: Alexander Mikhalitsyn <alexander@...alicyn.com>
We have discussed this with Andrei offlist, so LGTM.
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
+cc Christian
> Signed-off-by: Andrei Vagin <avagin@...gle.com>
> ---
> fs/proc/task_mmu.c | 20 +++++++++++++++++---
> 1 file changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 435b61054b5b..abbf96c091ad 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -273,9 +273,23 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
> const char *name = NULL;
>
> if (file) {
> - struct inode *inode = file_inode(vma->vm_file);
> - dev = inode->i_sb->s_dev;
> - ino = inode->i_ino;
> + const struct path *path;
> + struct kstat stat;
> +
> + path = file_user_path(file);
> + /*
> + * A file system can manipulate inode numbers within the
> + * getattr callback (e.g. ovl_getattr).
> + */
> + if (!vfs_getattr_nosec(path, &stat, STATX_INO, AT_STATX_DONT_SYNC)) {
> + dev = stat.dev;
> + ino = stat.ino;
> + } else {
> + struct inode *inode = d_backing_inode(path->dentry);
> +
> + dev = inode->i_sb->s_dev;
> + ino = inode->i_ino;
> + }
> pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
> }
>
> --
> 2.43.0.472.g3155946c3a-goog
>
--
Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
Powered by blists - more mailing lists