]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsfd: use /proc/$PID/map_files as the fallback information source
authorMasatake YAMATO <yamato@redhat.com>
Mon, 4 Apr 2022 12:05:31 +0000 (21:05 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sat, 9 Apr 2022 11:33:46 +0000 (20:33 +0900)
commite395a0388718b290662d87f32ebd5e2715aab3e6
tree8d6bfca45a7f74ec1ecff8cd348869a1ba67cb80
parent9c2ab4c16833ea215792358ad7c1509b7d06e574
lsfd: use /proc/$PID/map_files as the fallback information source

The original code scanning /proc/$PID/maps assumed two things; an entry
of the file contains a path started from '/' if a file is mapped, and
stat(2) works well with the path in the entry.

A mmap'ed socket breaks the former assumption.
tcpdump/lipcap does mmap an AF_PACKET socket to its address space!

A file is deleted after mapping breaks the latter assumption.

With this change, lsfd utilizes dentries under /proc/$PID/map_files
for gathering information of the mapped file in the case that the
assumptions are broken.

Private anonymous mappings are skipped to avoid wasting CPU time.

Example output:

  # ./lsfd -p 1541379 -Q '(ASSOC == "shm")'
  COMMAND     PID    USER ASSOC MODE TYPE SOURCE MNTID     INODE NAME
  tcpdump 1541379 tcpdump   shm  rw- SOCK sockfs     0 114535087 PACKET:[114535087]

  # ./lsfd -Q '(ASSOC == "shm") and DELETED' | head -2
  COMMAND             PID            USER ASSOC MODE TYPE SOURCE MNTID    INODE NAME
  systemd-resolve     870 systemd-resolve   shm  r--  REG   dm-0     0  1180413 /var/lib/sss/mc/passwd (deleted)

NOTE: CAP_SYS_ADMIN capability is required to access map_files.
See proc(5) for more details.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd.c