mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andrei Vagin <avagin@google.com>
Cc: linux-kernel@vger.kernel.org, Amir Goldstein <amir73il@gmail.com>,
	Alexander Mikhalitsyn <alexander@mihalicyn.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 1/2] fs/proc: show correct device and inode numbers in /proc/pid/maps
Date: Mon, 11 Dec 2023 11:43:06 -0800	[thread overview]
Message-ID: <20231211114306.08211860253a77c69bab2a87@linux-foundation.org> (raw)
In-Reply-To: <20231211193048.580691-1-avagin@google.com>

On Mon, 11 Dec 2023 11:30:47 -0800 Andrei Vagin <avagin@google.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.

Al, could you please comment on this?

Thanks.

> --- 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

  parent reply	other threads:[~2023-12-11 19:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 19:30 Andrei Vagin
2023-12-11 19:30 ` [PATCH 2/2] selftests/overlayfs: verify " Andrei Vagin
2023-12-11 20:00   ` Alexander Mikhalitsyn
2023-12-12  5:17   ` Amir Goldstein
2023-12-12 19:45   ` Andrei Vagin
2023-12-11 19:43 ` Andrew Morton [this message]
2023-12-11 19:57 ` [PATCH 1/2] fs/proc: show correct " Alexander Mikhalitsyn
2023-12-12  5:51 ` Amir Goldstein
2023-12-12  9:27   ` Christian Brauner
2023-12-12 19:19     ` Andrei Vagin
2023-12-12 19:08   ` Andrei Vagin
2023-12-13 17:05     ` Amir Goldstein

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=20231211114306.08211860253a77c69bab2a87@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adobriyan@gmail.com \
    --cc=alexander@mihalicyn.com \
    --cc=amir73il@gmail.com \
    --cc=avagin@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®