All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] procfs: Add file path and size to /proc/<pid>/fdinfo
@ 2022-06-23 22:06 ` Kalesh Singh
  0 siblings, 0 replies; 20+ messages in thread
From: Kalesh Singh @ 2022-06-23 22:06 UTC (permalink / raw)
  To: ckoenig.leichtzumerken, christian.koenig, viro, hch,
	stephen.s.brennan, David.Laight
  Cc: Randy Dunlap, linux-doc, Jonathan Corbet,
	Christoph Anton Mitterer, kernel-team, Johannes Weiner, ilkos,
	linux-kernel, Colin Cross, Sumit Semwal, linaro-mm-sig,
	Paul Gortmaker, dri-devel, Kalesh Singh, linux-fsdevel,
	Andrew Morton, surenb, tjmercier, Mike Rapoport, linux-media

Hi all,

This is v2 of the fdinfo patches. The main update is adding path
field only for files with anon inodes. Rebased on 5.19-rc3.

The previous cover letter is copied below for convenience.

Thanks,
Kalesh

-----------

Processes can pin shared memory by keeping a handle to it through a
file descriptor; for instance dmabufs, memfd, and ashmem (in Android).

In the case of a memory leak, to identify the process pinning the
memory, userspace needs to:
  - Iterate the /proc/<pid>/fd/* for each process
  - Do a readlink on each entry to identify the type of memory from
    the file path.
  - stat() each entry to get the size of the memory.

The file permissions on /proc/<pid>/fd/* only allows for the owner
or root to perform the operations above; and so is not suitable for
capturing the system-wide state in a production environment.

This issue was addressed for dmabufs by making /proc/*/fdinfo/*
accessible to a process with PTRACE_MODE_READ_FSCREDS credentials[1]
To allow the same kind of tracking for other types of shared memory,
add the following fields to /proc/<pid>/fdinfo/<fd>:

path - This allows identifying the type of memory based on common
       prefixes: e.g. "/memfd...", "/dmabuf...", "/dev/ashmem..."

       This was not an issued when dmabuf tracking was introduced
       because the exp_name field of dmabuf fdinfo could be used
       to distinguish dmabuf fds from other types.

size - To track the amount of memory that is being pinned.

       dmabufs expose size as an additional field in fdinfo. Remove
       this and make it a common field for all fds.

Access to /proc/<pid>/fdinfo is governed by PTRACE_MODE_READ_FSCREDS
-- the same as for /proc/<pid>/maps which also exposes the path and
size for mapped memory regions.

This allows for a system process with PTRACE_MODE_READ_FSCREDS to
account the pinned per-process memory via fdinfo.


Kalesh Singh (2):
  procfs: Add 'size' to /proc/<pid>/fdinfo/
  procfs: Add 'path' to /proc/<pid>/fdinfo/

 Documentation/filesystems/proc.rst | 22 ++++++++++++++++++++--
 drivers/dma-buf/dma-buf.c          |  1 -
 fs/libfs.c                         |  9 +++++++++
 fs/proc/fd.c                       | 18 ++++++++++++++----
 include/linux/fs.h                 |  1 +
 5 files changed, 44 insertions(+), 7 deletions(-)


base-commit: a111daf0c53ae91e71fd2bfe7497862d14132e3e
-- 
2.37.0.rc0.161.g10f37bed90-goog


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-06-30 21:30 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 22:06 [PATCH v2 0/2] procfs: Add file path and size to /proc/<pid>/fdinfo Kalesh Singh
2022-06-23 22:06 ` Kalesh Singh
2022-06-23 22:06 ` [PATCH v2 1/2] procfs: Add 'size' to /proc/<pid>/fdinfo/ Kalesh Singh
2022-06-23 22:06   ` Kalesh Singh
2022-06-28 11:53   ` Brian Foster
2022-06-28 11:53     ` Brian Foster
2022-06-28 22:38     ` Kalesh Singh
2022-06-28 22:38       ` Kalesh Singh
2022-06-29 12:23       ` Brian Foster
2022-06-29 12:23         ` Brian Foster
2022-06-29 20:43         ` Kalesh Singh
2022-06-29 20:43           ` Kalesh Singh
2022-06-30 11:48           ` Brian Foster
2022-06-30 11:48             ` Brian Foster
2022-06-30 12:03             ` Brian Foster
2022-06-30 12:03               ` Brian Foster
2022-06-30 21:30               ` Kalesh Singh
2022-06-30 21:30                 ` Kalesh Singh
2022-06-23 22:06 ` [PATCH v2 2/2] procfs: Add 'path' " Kalesh Singh
2022-06-23 22:06   ` Kalesh Singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.