vfs: Fix /proc/<tid>/fdinfo/<fd> file handling
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 4 Jun 2012 18:00:45 +0000 (11:00 -0700)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Sat, 16 Apr 2016 22:04:32 +0000 (22:04 +0000)
commit12f9ab0b5d27c7da3bcc6b6ab590eec1872b8515
tree77b21f4a0c517070036a4f1658f652b0edb57e36
parent77d9e4631b9ea711f7a4dcc75a522d303b54fcf5
vfs: Fix /proc/<tid>/fdinfo/<fd> file handling

Cyrill Gorcunov reports that I broke the fdinfo files with commit
30a08bf2d31d ("proc: move fd symlink i_mode calculations into
tid_fd_revalidate()"), and he's quite right.

The tid_fd_revalidate() function is not just used for the <tid>/fd
symlinks, it's also used for the <tid>/fdinfo/<fd> files, and the
permission model for those are different.

So do the dynamic symlink permission handling just for symlinks, making
the fdinfo files once more appear as the proper regular files they are.

Of course, Al Viro argued (probably correctly) that we shouldn't do the
symlink permission games at all, and make the symlinks always just be
the normal 'lrwxrwxrwx'.  That would have avoided this issue too, but
since somebody noticed that the permissions had changed (which was the
reason for that original commit 30a08bf2d31d in the first place), people
do apparently use this feature.

[ Basically, you can use the symlink permission data as a cheap "fdinfo"
  replacement, since you see whether the file is open for reading and/or
  writing by just looking at st_mode of the symlink.  So the feature
  does make sense, even if the pain it has caused means we probably
  shouldn't have done it to begin with. ]

Reported-and-tested-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/base.c