upstream: Fix ChannelTimeout specificity

Previously a more specific channel type (e.g. "session:shell") could
clobber a user-specified ChannelTimeout if it was less specific
(e.g. "session").

Also, in some cases, the debug messages were printing 0 instead of the
effective timeout.

From Bhagavathiyappan Shanmugam <Bhagavathiyappan.Shanmugam@ibm.com>
via bz3994

OpenBSD-Commit-ID: ba88e80db4957b98dfc0cc3b93a8d6d34e18d32d
This commit is contained in:
djm@openbsd.org authored and Damien Miller committed 2026-09-15 16:09:45 +10:00
1 parent 78db1b7e9f
commit 02cf3c2bd6
1 file changed
+16 -7
+16 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: channels.c,v 1.464 2026/09/14 02:38:27 djm Exp $ */
/* $OpenBSD: channels.c,v 1.465 2026/09/15 06:05:47 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -378,6 +378,7 @@ channel_classify(struct ssh *ssh, Channel *c)
void
channel_set_xtype(struct ssh *ssh, int id, const char *xctype)
{
struct ssh_channels *sc = ssh->chanctxt;
Channel *c;
if ((c = channel_by_id(ssh, id)) == NULL)
@@ -385,11 +386,15 @@ channel_set_xtype(struct ssh *ssh, int id, const char *xctype)
if (c->xctype != NULL)
free(c->xctype);
c->xctype = xstrdup(xctype);
/* Type has changed, so look up inactivity deadline again */
c->inactive_deadline = lookup_timeout(ssh, c->xctype);
/* Only override deadline if xctype has a more specific match. */
int xtype_deadline = lookup_timeout(ssh, c->xctype);
if (xtype_deadline != 0)
c->inactive_deadline = xtype_deadline;
channel_classify(ssh, c);
/* report effective timeout: per-channel if set, else global */
debug2_f("labeled channel %d as %s (inactive timeout %u)", id, xctype,
c->inactive_deadline);
c->inactive_deadline != 0 ? c->inactive_deadline
: (u_int)sc->global_deadline);
}
/*
@@ -560,7 +565,9 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd,
TAILQ_INIT(&c->status_confirms);
channel_classify(ssh, c);
debug("channel %d: new %s [%s] (inactive timeout: %u)",
found, c->ctype, remote_name, c->inactive_deadline);
found, c->ctype, remote_name,
c->inactive_deadline != 0 ? c->inactive_deadline
: (u_int)sc->global_deadline);
return c;
}
@@ -2708,9 +2715,11 @@ channel_handler(struct ssh *ssh, int table, struct timespec *timeout)
channel_get_expiry(ssh, c) != 0 &&
now >= channel_get_expiry(ssh, c)) {
/* channel closed for inactivity */
u_int fired_deadline = c->inactive_deadline != 0
? c->inactive_deadline
: (u_int)sc->global_deadline;
verbose("channel %d: closing after %u seconds "
"of inactivity", c->self,
c->inactive_deadline);
"of inactivity", c->self, fired_deadline);
channel_force_close(ssh, c, 1);
} else if (c->notbefore <= now) {
/* Run handlers that are not paused. */