nwtgck / handy-sshd

Portable SSH Server
MIT License
10 stars 7 forks source link

SIGSEGV when opening /dev/ptmx failed #27

Closed eunsikNota closed 2 months ago

eunsikNota commented 4 months ago
direct-tcpip --allow-execute
1970/01/03 20:34:00 INFO listening on :2222...
1970/01/03 20:34:00 INFO allowed: "direct-tcpip", "execute"
1970/01/03 20:34:00 INFO NOT allowed: "tcpip-forward", "sftp", "streamlocal-forward", "direct-streamlocal"
^[[A1970/01/03 20:34:01 INFO new SSH connection remote_address=10.169.4.1:57980 client_version=SSH-2.0-OpenSSH_9.6
1970/01/03 20:34:02 INFO unsupported request req_type=x11-req
1970/01/03 20:34:02 INFO creating pty...
1970/01/03 20:34:02 INFO failed to start pty err="open /dev/ptmx: no such file or directory"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xfc964]

goroutine 3 [running]:
os.(*Process).wait(0x0)
        /opt/hostedtoolcache/go/1.20.14/x64/src/os/exec_unix.go:17 +0x14
os.(*Process).Wait(...)
        /opt/hostedtoolcache/go/1.20.14/x64/src/os/exec.go:132
github.com/nwtgck/handy-sshd.(*Server).createPty.func1()
        /home/runner/work/handy-sshd/handy-sshd/pty_related_unix.go:34 +0xf4
github.com/nwtgck/handy-sshd.(*Server).createPty(0x8946a0, {0x0, 0x0}, {0x3da76c, 0x856080})
        /home/runner/work/handy-sshd/handy-sshd/pty_related_unix.go:46 +0x208
github.com/nwtgck/handy-sshd.(*Server).handleSession(0x8946a0, {0x0, 0x0}, {0x3da364, 0x856080})
        /home/runner/work/handy-sshd/handy-sshd/server.go:111 +0x4dc
github.com/nwtgck/handy-sshd.(*Server).handleChannel(0x8946a0, {0x0, 0x0}, {0x3da364, 0x856080})
        /home/runner/work/handy-sshd/handy-sshd/server.go:59 +0x234
created by github.com/nwtgck/handy-sshd.(*Server).HandleChannels
        /home/runner/work/handy-sshd/handy-sshd/server.go:52 +0x2c
nwtgck commented 4 months ago

Thanks for the report. I fixed in https://github.com/nwtgck/handy-sshd/commit/f6d96d1a78877168b9b02e2b6de530b9dce66fe5. Could you upgrade to 0.4.3?

eunsikNota commented 4 months ago

10.169.4.77/241970/01/01 00:05:46 INFO new SSH connection remote_address=10.169.4.1:52928 client_version=SSH-2.0-OpenSSH_for_Windows_8.6 1970/01/01 00:05:46 INFO creating pty... 1970/01/01 00:05:46 INFO failed to start pty err="open /dev/ptmx: no such file or directory" 1970/01/01 00:05:46 INFO session closed

ls /dev/ptmx
/dev/ptmx
nwtgck commented 4 months ago

/dev/ptmx exists but the error says "no such file or directory"... I'm not sure why.

handy-sshd relies on https://github.com/creack/pty for pty. Resovling this issue may improve creack/pty. The environment information, like OS may help to solve this issue.

Running the other tools using pty may provide better error:

python3 -c 'import pty; pty.spawn("bash")' 

OR

socat EXEC:'bash -li',pty,stderr,setsid,sigint,sane,rawer -