public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RFC: /dev/stdin, symlinks & permissions
@ 2008-03-17 23:26 Michael Tokarev
  2008-03-17 23:54 ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Tokarev @ 2008-03-17 23:26 UTC (permalink / raw)
  To: Linux-kernel

I just come across an.. interesting (to me anyway) issue.

There are files - /dev/stdin, /dev/stdout & /dev/stderr -
which are handy sometimes and are available on several
*nix variants (including at least Solaris).

On Linux they're usually "implemented" as symlinks pointed
to /proc/self/fd/{0,1,2}, respectively.  Which, in turn,
are symlinks pointing to the actual files.

For example, in a root ssh session, /dev/stdin may look
like (omitting details):

   # ls -l /dev/stdin
   /dev/stdin -> /proc/self/fd/0
   # ls -l /proc/self/fd/0
   /proc/self/fd/0 -> /dev/pts/0
   # ls -l /dev/pts/0
   crw--w---- 1 root tty 136, 0 Mar 18 02:19 /dev/pts/0

So far so good.  Now, I change uid to something else, --
doing su(8) to "mjt".  /proc/self changed obviously,
but stdin &Co is still here, and points to the same
/dev/pts/0.  But *its* permissions/ownership did not
change!  So now I can't, for example,

  $ echo x > /dev/stdout
  bash: /dev/stdout: Permission denied

which is quite unexpected - I for one expect /dev/stdout
to work the way very similar to /dev/tty, to mean "current
standard output regardless of any permissions etc".

For example in Solaris the whole /proc/self/fd (equivalent)
is in /dev/, and all the files in there has permissions
similar to /dev/tty:

  # ls -l /dev/stdout
  /dev/stdin -> ./fd/0
  #ls -l /dev/fd/0
  crw-rw-rw-   1 root     root     306,  0 Mar 17 18:03 /dev/fd/0

To summarize.  I understand where the whole thing comes from.
I understand kernel does not provide /dev/stdin &Co, this
interface is provided by distributions.

But the current way is half-broken, and it can't be corrected
from userspace.

Should kernel support something similar to other systems, less
broken than current /dev/stdin&Co symlinks?

Thanks!

/mjt

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

end of thread, other threads:[~2008-03-23 16:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-17 23:26 RFC: /dev/stdin, symlinks & permissions Michael Tokarev
2008-03-17 23:54 ` Andreas Schwab
2008-03-18  7:24   ` Michael Tokarev
2008-03-18 12:54     ` Theodore Tso
2008-03-18 14:32       ` Al Viro
2008-03-18 15:04         ` Theodore Tso
2008-03-23 16:50           ` H. Peter Anvin
2008-03-23  4:35         ` Denys Vlasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox