tun channel FDs changed to -1?

Fergal Meath fergalme at gmail.com
Tue Nov 11 00:46:53 EST 2014


Hi,

I eventually found the offender.

do_child sets up the environment and before executing the command
(ifconfig) it tries to close the "connection descriptors".
In my use case, the effect is that the ssh tun channel 0 file descriptors
are all set to -1.

The patch below prevents the problem and everything seems to work fine - my
tunnel now passes traffic. I have also tested that interactive login and
command execution works okay and tidies up FD's when finished.

I suspect that this is an issue with uClinux vfork and would be very
interested in any uClinux user/developer feedback.
Also I would like to do more testing before submitting the patch below.


diff --git a/SW/source/user/ssh/session.c b/SW/source/user/ssh/session.c
index e0e5555..62ecb7a 100755
--- a/SW/source/user/ssh/session.c
+++ b/SW/source/user/ssh/session.c
@@ -1725,7 +1725,9 @@ do_child(Session *s, const char *command)
         * closed before building the environment, as we call
         * get_remote_ipaddr there.
         */
+#ifndef __uClinux__
        child_close_fds();
+#endif

        /*
         * Must take new environment into use so that .ssh/rc,


Regards,

Fergal

On Wed, Oct 22, 2014 at 1:58 PM, Fergal Meath <fergalme at gmail.com> wrote:

> Hi,
>
> I have sshd (OpenSSH_5.8p1) running on uCLinux (Linux version 2.6.19-uc1)
> Interactive sessions are working okay.
> Tunnel device seems to be set up but is not passing any traffic to other
> end.
> Debug output shows that tun channel 0 file descriptors are changed from
> 8/8 to -1/-1.
> Does anyone know how or what could be causing this?
>
> Client command is…
> ssh –w0:0 root at 192.168.1.100 ifconfig tun0 10.0.0.1 pointopoint 10.0.0.2
> netmask 255.255.255.255
>
> My sshd debug output is shown below.
>
> Any help or tips would be appreciated,
> Regards,
>
> Fergal
>
> ---------- SSHD DEBUG OUTPUT
> ----------------------------------------------------
> Jan  1 01:50:09 (none) auth.info sshd[2344]: Accepted password for root
> from 192.168.1.200 port 55408 ssh2
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: Entering interactive
> session for SSH2.
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 6 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 7 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_init_dispatch_20
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_open: ctype tun at openssh.com rchan 0 win 2097152 max
> 32768
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: sys_tun_open: tun0
> mode 1 fd 8
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 8 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug3: fd 8 is O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: channel 0: new [tun]
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_open: confirm tun at openssh.com
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_open: ctype session rchan 2 win 2097152 max 32768
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: input_session_request
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: channel 1: new
> [server-session]
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: session_new:
> allocate (allocated 0 max 10)
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug3: session_unused:
> session id 0 unused
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: session_new: session
> 0
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: session_open:
> channel 1
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: session_open:
> session 0: link with channel 1
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_open: confirm session
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_req: channel 1 request env reply 0
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: session_by_channel:
> session 0 channel 1
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> session_input_channel_req: session 0 req env
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: Ignoring env request
> LANG: disallowed name
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> server_input_channel_req: channel 1 request exec reply 1
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1: session_by_channel:
> session 0 channel 1
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug1:
> session_input_channel_req: session 0 req exec
> Jan  1 01:50:09 (none) auth.debug sshd[2415]: debug1: permanently_set_uid:
> 0/0
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 4 setting
> TCP_NODELAY
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug3: packet_set_tos: set
> IP_TOS 0x08
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 11 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 10 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: fd 13 setting
> O_NONBLOCK
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: channel 1: rcvd eof
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: channel 1: output
> open -> drain
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: channel 1: obuf empty
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: channel 1:
> close_write
> Jan  1 01:50:09 (none) auth.debug sshd[2344]: debug2: channel 1: output
> drain -> closed
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1: Received SIGCHLD.
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1: session_by_pid: pid
> 2415
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1:
> session_exit_message: session 0 channel 1 pid 2415
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: request
> exit-status confirm 0
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1:
> session_exit_message: release channel 1
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: read<=0
> rfd 11 len 0
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: read
> failed
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: close_read
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: input
> open -> drain
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: read 0
> from efd 13
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: closing
> read-efd 13
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: ibuf empty
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: send eof
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: input
> drain -> closed
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: send close
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: notify_done: reading
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug3: channel 1: will not
> send data after close
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: rcvd close
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug3: channel 1: will not
> send data after close
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: is dead
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: gc:
> notify user
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1: session_by_channel:
> session 0 channel 1
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1:
> session_close_by_channel: channel 1 child 0
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1: session_close:
> session 0 pid 0
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug3: session_unused:
> session id 0 unused
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: gc: user
> detached
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: is dead
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug2: channel 1: garbage
> collecting
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug1: channel 1: free:
> server-session, nchannels 2
> Jan  1 01:50:10 (none) auth.debug sshd[2344]: debug3: channel 1: status:
> The following connections are open:\r\n  #0 tun (t4 r0 i0/0 o0/0 fd -1/-1
> cc -1)\r\n  #1 server-session (t4 r2 i3/0 o3/0 fd -1/-1 cc -1)\r\n
>
>


More information about the openssh-unix-dev mailing list