strange behaviour with ssh / stdin

Darren Tucker dtucker at zip.com.au
Tue Oct 14 22:24:39 EST 2003


Damien Miller wrote:
> 
> On Mon, 2003-10-13 at 19:56, Laurent Bartholdi wrote:
> > hi,
> > i noted the following strange behaviour using ssh and linux. this is
> > probably a low-priority bug:
> >
> > # ssh -V
> > OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f
> > # uname -a
> > Linux funnyfarm 2.4.21-20.1.2024.2.1.nptl #1 Fri Jul 11 06:04:52 EDT 2003 i686 i686 i386 GNU/Linux
> >
> > # echo Hello | ssh frodo 'cat'
> > Hello
> > # echo Hello | ssh frodo 'cat /proc/self/fd/0'
> > cat: /proc/self/fd/0: No such device or address
> > # ssh frodo 'ls -l /proc/self/fd/0'
> > lrwx------    1 root     root           64 Oct 13 18:51 /proc/self/fd/0 -> socket:[27105]
> 
> This is probably some weird Linux race condition. I can't imagine
> anything that ssh could do that would cause this.
> 
> Does /dev/stdin or /dev/fd/0 work? These are often aliases for the same
> purpose.

On my RH8 box they're all symlinks to the controlling tty if it has one or
to some kind of socket descriptor if not (as you noted).  The problem
appears to be Linux-specific.

$  uname -sr; ls -l /dev/stdin /dev/fd/0 /proc/self/fd/0
Linux 2.4.20-20.8
lrwx------    1 dtucker  dtucker        64 Oct 14 22:06 /dev/fd/0 ->
/dev/pts/2
lrwxrwxrwx    1 root     root           17 Mar 31  2003 /dev/stdin ->
../proc/self/fd/0
lrwx------    1 dtucker  dtucker        64 Oct 14 22:06 /proc/self/fd/0 ->
/dev/pts/2

In contrast, on Solaris, /dev/fd/0 is a character special device, and your
example works as expected:
$ uname -sr; ls -l /dev/fd/0 /dev/stdin
SunOS 5.8
crw-rw-rw-   1 root     root     247,  0 Oct 14 22:09 /dev/fd/0
lrwxrwxrwx   1 root     root           6 Apr  2  2002 /dev/stdin -> ./fd/0
$ echo Hello | ssh localhost "cat /dev/fd/0"
Hello

I remember reading an explanation about this someplace but I don't
remember the details and I've been unable to locate it again.

-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.




More information about the openssh-unix-dev mailing list