Bug 1424 - Cannot signal a process over a channel (rfc 4254, section 6.9)
Summary: Cannot signal a process over a channel (rfc 4254, section 6.9)
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 4.7p1
Hardware: ix86 Linux
: P2 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_7_8
  Show dependency treegraph
 
Reported: 2008-01-01 06:47 AEDT by Daniel Azuma
Modified: 2019-10-09 15:11 AEDT (History)
15 users (show)

See Also:


Attachments
Implement "signal" channel request type, server and client. (5.60 KB, patch)
2008-01-01 10:31 AEDT, Darren Tucker
no flags Details | Diff
Move signo2name functions to channels.c (5.94 KB, patch)
2008-01-08 13:16 AEDT, Darren Tucker
no flags Details | Diff
update, improve the client UI a bit, remove client pass-through of signal (4.29 KB, patch)
2009-10-18 10:56 AEDT, Darren Tucker
no flags Details | Diff
extend the signals patch to accept them over the mux socket (11.85 KB, patch)
2009-10-20 06:16 AEDT, Salvador Fandiño
no flags Details | Diff
control command for sending signals (3.36 KB, patch)
2009-10-26 17:47 AEDT, Salvador Fandiño
no flags Details | Diff
Update of #1699 versus 6.7p1 (3.97 KB, patch)
2014-10-30 10:19 AEDT, Iain Morgan
no flags Details | Diff
Add server support for signal channel (subset of previous patches) (2.10 KB, patch)
2018-02-16 05:29 AEDT, Jay Weisskopf
jay: ok?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Azuma 2008-01-01 06:47:43 AEDT
It does not appear that sshd in OpenSSH implements section 6.9 of rfc 4254. That is, sending SSH_MSG_CHANNEL_REQUEST with type "signal" for a channel, has no effect.

This is being reproduced with a custom client, connecting to OpenSSH 4.7p1 sshd running on Linux (Fedora 8 package openssh-4.7p1-4.fc8). I opened a channel, started a simple long-running remote process (e.g. sleep) with an "exec", and then attempted to send the "TERM" signal as described in the rfc, with want_reply set to TRUE. The server sent back SSH_MSG_CHANNEL_FAILURE, and the process was unaffected.

However, I do not believe this is platform-specific or usage-specific. Looking at the code for session.c in cvs, it appears that the function session_input_channel_req does not recognize an rtype of "signal".
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/session.c?rev=1.224

This appears to have been reported before on the mailing list, but there were no replies, and I could not find a bug open for it.
http://marc.info/?l=openssh-unix-dev&m=115992994907390&w=2

Also see this thread from some years ago, which includes a patch against an older version of OpenSSH:
http://marc.info/?l=openssh-unix-dev&m=104300802407848&w=2
Comment 1 Darren Tucker 2008-01-01 10:31:47 AEDT
Created attachment 1432 [details]
Implement "signal" channel request type, server and client.

Please try this patch, which is based on the one posted by Markus.

The client interace is not documented, but it's an escape sequence command line:

[CR]~C (should give you the "ssh> " prompt, then
-SHUP
Comment 2 Daniel Azuma 2008-01-08 08:40:43 AEDT
(In reply to comment #1)
> Created an attachment (id=1432) [details]
> Implement "signal" channel request type, server and client.
> 
> Please try this patch, which is based on the one posted by Markus.
> 
> The client interace is not documented, but it's an escape sequence
> command line:
> 
> [CR]~C (should give you the "ssh> " prompt, then
> -SHUP

I haven't tested the client, but the server side of your patch appears to work. I applied it to the CVS head (as of about noon -0800 on 07 Jan 2008), and compiled and ran sshd on a Fedora 8 i386 box. Sending the TERM signal from my custom client (based on ruby Net::SSH) now appears to work as expected.

To get it to compile, I did have to modify your patch to add the following line to misc.c:

#include <signal.h>

Thanks! Looking forward to seeing this in the release version.
Comment 3 Daniel Azuma 2008-01-08 09:19:35 AEDT
(In reply to comment #2)
> I haven't tested the client, but the server side of your patch appears
> to work. I applied it to the CVS head (as of about noon -0800 on 07 Jan
> 2008), and compiled and ran sshd on a Fedora 8 i386 box. Sending the
> TERM signal from my custom client (based on ruby Net::SSH) now appears
> to work as expected.

Sorry, a little (probably unnecessary) clarification... my "applied to cvs head" != "checked in". I'm not a maintainer. Just mentioning that the patch seems to work against my test case. I'd still like to see it get into cvs and an official release, though, since I'd rather wait for it to trickle into the package management of our linux distribution before installing onto our production servers.
Comment 4 Darren Tucker 2008-01-08 13:16:30 AEDT
Created attachment 1438 [details]
Move signo2name functions to channels.c

Minor tweak to the patch: move the signal no -> name functions to channels.c.  This saves ~120 bytes in some of the other programs the link in misc.o via libssh.a but don't actually need those channel name functions.
Comment 5 Damien Miller 2008-01-20 06:42:12 AEDT
Comment on attachment 1438 [details]
Move signo2name functions to channels.c

>+} no2name[] = {
>+	{ SIGABRT,	"ABRT" },
>+	{ SIGALRM,	"ALRM" },
>+	{ SIGFPE,	"FPE" },
>+	{ SIGHUP,	"HUP" },
>+	{ SIGILL,	"ILL" },
>+	{ SIGINT,	"INT" },
>+	{ SIGKILL,	"KILL" },
>+	{ SIGPIPE,	"PIPE" },
>+	{ SIGQUIT,	"QUIT" },
>+	{ SIGSEGV,	"SEGV" },
>+	{ SIGTERM,	"TERM" },
>+	{ SIGUSR1,	"USR1" },
>+	{ SIGUSR2,	"USR2" },

I don't think it makes sense to automatically pass some of these from the client to the server. E.g. SIGSEGV, SIGFPE, SIGILL, SIGBUS, SIGPIPE, SIGALRM and SIGABRT should be considered "internal" and never passed (or acted upon by the server).
Comment 6 Darren Tucker 2008-01-20 09:50:33 AEDT
(In reply to comment #5)
> I don't think it makes sense to automatically pass some of these from
> the client to the server. E.g. SIGSEGV, SIGFPE, SIGILL, SIGBUS,
> SIGPIPE, SIGALRM and SIGABRT should be considered "internal" and never
> passed (or acted upon by the server).

The list of signals is specified in the RFC, but while we can generate (and process) all of these, only the ones for which the client has a signal handler will be automatically passed on.

I'm not entirely happy with the client interface, but it worked for testing.  (Should also interop test with at least one other implementation, I think PuTTY has it these days.)
Comment 7 Martin Oberhuber 2008-09-30 21:38:09 AEST
This may be interesting for us. Is there any plan to get this patch released?
Comment 8 Andrew Hayden 2008-11-21 03:11:18 AEDT
I'm voting for this one.  I sent an email to openssh-unix-dev and Darren Tucker was kind enough to point me here.

I'm building an app based on JSch, a Java implementation of SSH2, and I strongly desire the ability to send SIGINT and SIGKILL to the remote processes that will be spawned via my program.  Currently I have no clean way to do this, but this patch should allow it.

I concur with Damien Miller (though I am not a contributor) that some of these signals make little or no sense to send through to clients.  I would imagine that HUP, INT and KILL are probably the most frequent use cases for remote clients trying to talk to something they've spawned on the other side of the channel.  USR1 and USR2 probably make sense as well for custom magic.

Would people be more comfortable committing this if the signals that Damien lists as inappropriate (SIGSEGV, SIGFPE, SIGILL, SIGBUS,
SIGPIPE, SIGALRM and SIGABRT) are suppressed?

As a gentle nudge, the patch mentioned by the original poster, Daniel Azuma, was proposed over 5 years ago.  I'm *not* complaining about the timeline, as I'm not a committer and don't have any OpenSSH domain knowledge whatsoever, but it would be *fantastic* if this could actually make it into a release soon, especially since there's another independent path here along with confirmation that it, too, works.

I'll be eternally grateful :)

Thanks, regardless.

-Andrew Hayden
Comment 9 Darren Tucker 2009-07-31 11:44:14 AEST
look at this for 5.4
Comment 10 Adrian 2009-10-05 08:34:27 AEDT
Getting signal support would be awesome.
I'm curious if there are any reasons why it wasn't added yet (almost 2 years after the patch was submitted).
Comment 11 Darren Tucker 2009-10-18 10:56:25 AEDT
Created attachment 1699 [details]
update, improve the client UI a bit, remove client pass-through of signal
Comment 12 Salvador Fandiño 2009-10-20 06:16:51 AEDT
Created attachment 1700 [details]
extend the signals patch to accept them over the mux socket

Note, Darren Tucker patch 1699 has to be applied first!

This patch adds support for two new -O commands: ps and kill

- ps will list the PIDs of slave ssh processes
- kill allows to send signals

It also adds support to sshd to accept signals by number.

Sample session:
===============
 $ ./ssh -S /tmp/mux -M localhost -f perl ~/g/my-ssh/tellsignal.pl 
 $ ./ssh -S /tmp/mux localhost -O ps      
 24140
 $ ./ssh -S /tmp/mux localhost -O kill HUP 24140
 Signal request sent.
 signal HUP received
 $ ./ssh -S /tmp/mux localhost -O kill 15 24140
 Signal request sent.
 signal TERM received
 $ ./ssh -S /tmp/mux localhost -O kill KILL 24140
 Signal request sent.
 $ 

Some notes:
===========
* A new field "tag" is added to Channel, it is used as the session logical name. The current client implementation (muxclient) uses the process PID as the tag.

* muxclient() now gets the arguments remaining in argv after getopt processing so it can use them for the -O commands (currently, just "kill"). I am not completely sure about this because it can be a bit counterintuitive when the "-O cmd" part is used before the hostname:

  $ ssh -S /tmp/mux -O kill localhost TERM 24140


Bye,

 - Salva
Comment 13 Salvador Fandiño 2009-10-20 06:19:15 AEDT
The silly perl script that tells about the received signals...

$ cat tellsignal.pl 
#!/usr/bin/perl

for my $name (grep /^[A-Z]+$/, keys %SIG) {
    $SIG{$name} = sub { warn "signal $name received\n" };
}

while (1) {
    sleep 1;
}
Comment 14 Damien Miller 2009-10-21 21:45:14 AEDT
(In reply to comment #12)
> Created an attachment (id=1700) [details]
> extend the signals patch to accept them over the mux socket

Nice idea, and I think I like the concept of "friendly names" for subsessions but this is really a separate enhancement. Could you please file it under a new bug of its own?
Comment 15 Salvador Fandiño 2009-10-25 22:07:53 AEDT
> Nice idea, and I think I like the concept of "friendly names" for
> subsessions but this is really a separate enhancement. Could you please
> file it under a new bug of its own?

done, see ticket 1664
Comment 16 Salvador Fandiño 2009-10-26 17:47:34 AEDT
Created attachment 1709 [details]
control command for sending signals

This patch contains the implementation of the kill command that allows to send signals to remote processes.

The patches attached to 1664 must be applied first.
Comment 17 Damien Miller 2010-08-03 15:40:47 AEST
We are freezing for the OpenSSH 5.6 release. Retargetting these bugs to the next release.
Comment 18 Damien Miller 2010-08-03 15:42:22 AEST
Targetting OpenSSH 5.7
Comment 19 Christian Kandeler 2011-07-27 18:39:05 AEST
In 5.8, there is still no support for the "signal" request. What's holding it back?
Comment 20 Damien Miller 2011-09-06 10:34:12 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 21 Damien Miller 2011-09-06 10:36:25 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 22 Damien Miller 2011-09-06 10:39:00 AEST
Retarget unresolved bugs/features to 6.0 release

(try again - bugzilla's "change several" isn't)
Comment 23 Damien Miller 2012-02-24 10:34:20 AEDT
Retarget from 6.0 to 6.1
Comment 24 Damien Miller 2012-02-24 10:37:58 AEDT
Retarget 6.0 => 6.1
Comment 25 Damien Miller 2012-09-07 11:37:45 AEST
Retarget uncompleted bugs from 6.1 => 6.2
Comment 26 Damien Miller 2012-09-07 11:40:14 AEST
Retarget bugs from 6.1 => 6.2
Comment 27 Damien Miller 2013-03-08 10:23:23 AEDT
retarget to openssh-6.3
Comment 28 Damien Miller 2013-07-25 12:17:27 AEST
Retarget to openssh-6.4
Comment 29 Damien Miller 2013-07-25 12:20:25 AEST
Retarget 6.3 -> 6.4
Comment 30 Damien Miller 2014-02-06 10:17:39 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 31 Damien Miller 2014-02-06 10:19:28 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 32 Damien Miller 2014-04-12 14:48:34 AEST
Retarget to 6.7 release, since 6.6 was mostly bugfixing.
Comment 33 Damien Miller 2014-04-12 14:55:04 AEST
Remove from 6.6 tracking bug
Comment 34 Damien Miller 2014-08-30 04:37:54 AEST
Retarget incomplete bugs to 6.8 release.
Comment 35 Damien Miller 2014-08-30 04:39:34 AEST
These bugs are no longer targeted at the imminent 6.7 release
Comment 36 Iain Morgan 2014-10-30 10:19:42 AEDT
Created attachment 2500 [details]
Update of #1699 versus 6.7p1

Updated Darren's patch. Testing limited to compiling and basic client
functionality; no server testing.

It looks to me like the ability to have signals "automatically passed
on" is no lnnger present. That functionality is what I am really looking
for: We have some users that require the ability to pass SIGINT,
SIGQUIT, and SIGTERM to remote porcesses in a manner similar to what rsh
supports.

I like the idea of adding -O support for sending the signal. That might
be more useful than the ~S mechanism. I think I would lean towards
something like: -O signal INT rather than imitating kill(1)'s syntax.
Comment 37 Damien Miller 2015-03-03 07:59:44 AEDT
OpenSSH 6.8 is approaching release and closed for major work. Retarget these bugs for the next release.
Comment 38 Damien Miller 2015-03-03 08:01:01 AEDT
Retarget to 6.9
Comment 39 Damien Miller 2015-08-11 22:59:16 AEST
Retarget pending bugs to openssh-7.1
Comment 40 mikeh 2016-12-20 03:51:34 AEDT
The OpenSSH 7.4 release notes state "OpenSSH is a 100% complete SSH protocol 2.0 implementation and includes sftp client and server support." which made me think of this bug, and how great it would be to have this RFC documented protocol feature in OpenSSH.
Comment 41 Ron Frederick 2017-11-11 11:53:52 AEDT
Lack of support for this channel message has been raised as an issue a couple of times in the last month from AsyncSSH users. AsyncSSH is capable of sending "signal" channel requests, but it's usually OpenSSH on the other end, and so these messages end up getting ignored, with no indication on the client why they didn't work.

I'd like to second the request for this support to be added! There are definitely users out there who are trying to use it.
Comment 42 Thomas Kluyver 2018-01-30 04:28:57 AEDT
Is there anything we can do to move this forwards? I've also just run into the lack of support for signalling processes started through SSH.

Would it help to separate out the client part from the server part? It seems that most of the discussion that has held it up is about the user interface. If the server part went in, other clients could start using it to send signals while OpenSSH worked out how to expose it in the client.

At present, other implementations are stuck waiting for OpenSSH to support this, because they're usually used against an OpenSSH server.

E.g. for Python: https://github.com/paramiko/paramiko/issues/785
and for Go: https://github.com/golang/go/issues/16597

(Also, a slightly belated happy 10th birthday to this bug ;-)
Comment 43 Jay Weisskopf 2018-02-13 08:48:02 AEDT
+1 for adding signal support to the daemon and punting on the client, if necessary.
Comment 44 Jay Weisskopf 2018-02-16 05:29:35 AEDT
Created attachment 3120 [details]
Add server support for signal channel (subset of previous patches)

This is a subset of previous patches that adds signal channel support to just the server. I lightly tested it using Go's SSH package as a client. The patch was generated from the tip of master (currently affa6ba) of the openssh-portable Git repo.
Comment 45 Thierry Parmentelat 2018-04-11 19:43:10 AEST
I'd like to second the request about adding this feature to the openssh server in priority, as an AsyncSSH user myself, and on behalf of my own users who run consequently into this issue as well.
Comment 46 Damien Miller 2018-10-02 22:45:39 AEST
I've committed a slightly revised version of the sshd changes. Signalling will only be supported to login and command sessions (i.e. not subsystems like sftp) and only for sessions without a forced command.
Comment 47 Andrew Hayden 2018-10-02 23:51:35 AEST
Thanks, Damien. Glad to see this. And thanks for the long-term commitment here, it's pretty awesome to see this issue still progressing and tracked after 10 years. I really appreciate that it never got closed as "will not implement" or working as intended.

Also thanks to Darren for the patch and to the other folks here who have built on top of it over the years.
Comment 48 Thomas Kluyver 2018-10-03 00:57:08 AEST
Thanks Damien!

For reference, I'll link what looks like the main change implementing this: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/session.c.diff?r1=1.305&r2=1.306&f=h

Should this issue be marked resolved? Or will it be kept for tracking the implementation of signalling in the client side?
Comment 49 Daniel Azuma 2018-10-03 01:57:12 AEST
I was the original reporter. This issue has long since ceased to be relevant to me, but in my original report, I was looking only for a server-side implementation, as I was using a custom client. In my opinion, this issue can be closed, as solving the server side will unblock a lot of users on other clients. And it would be good, as has been suggested previously, to separate out a discussion of the client interface since it raises a whole different set of questions.
Comment 50 Ron Frederick 2018-11-07 15:58:02 AEDT
I just tested OpenSSH 7.9p1 against AsyncSSH and can confirm that the server support for handling signals seems to be working nicely. I second that this bug can probably be closed, and a new bug should be opened if anyone wants to re-visit client-side support.
Comment 51 Damien Miller 2019-05-31 14:25:43 AEST
I'll close this - please open a separate bug if anyone wants the ability to send signals from the client.
Comment 52 Damien Miller 2019-10-09 15:11:45 AEDT
Close bugs fixed in openssh-8.1 release cycle