Question: How to prefix "../root" to output of readlink in /proc/<pid>/fd/ ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi linux-fsdevel,

When you go into /proc/<pid>/fd and type 'ls -l', you see the numbered file descriptors as symlinks to the real files, devices, etc. Opening the file descriptors allows you to access the contents, even if the object has already been deleted.

In several virtualized environments (e.g. kubernetes/docker, chroot, etc), you can still access the contents, but the target of the symlink (output of readlink) is shown as an absolute path from the *virtual* root directory. This may not be the same environment the caller is in, resulting in (apparently) broken links.

One solution would be to show the path relative to /proc/<pid>/root instead, turning
  "6 -> /some/directory/foo" (broken link)
into
"6 -> ../root/some/directory/foo" (relative link using process' actual root directory),
or possibly
"6 -> /proc/1234/root/some/directory/foo" (absolute link using actual root directory).

Pros:
-----

+ This fixes some (maybe all?) of the erroneously broken links in /proc/<pid>/fd
+ This would work for all processes, virtualized or not.
+ It can't break existing code (any further), unless existing code depends on erroneously broken links.
+ It's short.

Cons:
-----

- Maybe there is existing code that assumes absolute links instead of relative links?

Implementation details:
-----------------------
It looks like adding some code to do_proc_readlink (https://github.com/torvalds/linux/blob/690e2aba7beb1ef06352803bea41a68a3c695015/fs/proc/base.c ) might do the trick; d_path() already appends ' (deleted)' to the link if necessary, prepending '../root' to paths that start with '/' should work the same way.

Question:
---------
I'd like to write a patch for this, but after reading some of the patches in linux-fsdevel, it looks like there are lots of implementation details I could get wrong through ignorance of kernel internals. What would you recommend for a good example to copy?

Conversely, if this is a 5-minute job for someone here, would anyone like to take it on?

Thanks!

--
Charles Howes <vger.kernel.org@xxxxxxxxxx>



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux