[openssh-commits] [openssh] 13/18: upstream: Schedule client/server alive checked based on the time
git+noreply at mindrot.org
git+noreply at mindrot.org
Wed Nov 25 19:56:08 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 7af9e6eeca49088e168a345881df8132aa983725
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Wed Nov 25 08:26:59 2026 +0000
upstream: Schedule client/server alive checked based on the time
the last packet was received rather than then the last data was recevied.
Avoids an attack where an attacker sends a corrupt packet length
that (probably) gets interpreted as a large packet, then dribbles
in data slowly and one byte at a time to prevent the alive timer
for killing the connection as unresponsible. Unlikely, yeah - I know.
Anthropic ANT-2026-HQ3U6925
OpenBSD-Commit-ID: 7d6fc1a0769660b3ab5271c53471260bdae4ec83
---
clientloop.c | 18 +++++++++++++++---
serverloop.c | 38 +++++++++++++++++++++++---------------
2 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/clientloop.c b/clientloop.c
index 74a4751a1..54d7a6cf6 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.429 2026/10/30 09:00:39 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.430 2026/11/25 08:26:59 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -689,6 +689,8 @@ client_wait_until_can_do_something(struct ssh *ssh, struct pollfd **pfdp,
struct timespec timeout;
int ret, oready;
u_int p;
+ uint64_t ibytes;
+ static uint64_t last_ibytes;
*conn_in_readyp = *conn_out_readyp = 0;
@@ -724,8 +726,19 @@ client_wait_until_can_do_something(struct ssh *ssh, struct pollfd **pfdp,
set_control_persist_exit_time(ssh);
if (control_persist_exit_time > 0)
ptimeout_deadline_monotime(&timeout, control_persist_exit_time);
- if (options.server_alive_interval > 0)
+ if (options.server_alive_interval > 0) {
+ /*
+ * Only count complete packets that passed their MAC check
+ * as having heard from the server; raw data on the socket
+ * is unauthenticated and could have come from anyone.
+ */
+ ssh_packet_get_bytes(ssh, &ibytes, NULL);
+ if (ibytes != last_ibytes) {
+ schedule_server_alive_check();
+ last_ibytes = ibytes;
+ }
ptimeout_deadline_monotime(&timeout, server_alive_time);
+ }
if (options.rekey_interval > 0 && !ssh_packet_is_rekeying(ssh)) {
ptimeout_deadline_sec(&timeout,
ssh_packet_get_rekey_timeout(ssh));
@@ -797,7 +810,6 @@ client_process_net_input(struct ssh *ssh)
* Read input from the server, and add any such data to the buffer of
* the packet subsystem.
*/
- schedule_server_alive_check();
if ((r = ssh_packet_process_read(ssh, connection_in)) == 0)
return; /* success */
if (r == SSH_ERR_SYSTEM_ERROR) {
diff --git a/serverloop.c b/serverloop.c
index dfaaf57f0..ca38cbfc6 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: serverloop.c,v 1.250 2026/10/30 05:16:48 djm Exp $ */
+/* $OpenBSD: serverloop.c,v 1.251 2026/11/25 08:26:59 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -158,6 +158,8 @@ wait_until_can_do_something(struct ssh *ssh,
int client_alive_scheduled = 0;
u_int p;
time_t now;
+ uint64_t ibytes;
+ static uint64_t last_ibytes;
static time_t last_client_time, unused_connection_expiry;
*conn_in_readyp = *conn_out_readyp = 0;
@@ -197,11 +199,19 @@ wait_until_can_do_something(struct ssh *ssh,
* analysis more difficult, but we're not doing it yet.
*/
if (options.client_alive_interval) {
- /* Time we last heard from the client OR sent a keepalive */
- if (last_client_time == 0)
+ /*
+ * Time we last heard from the client OR sent a keepalive.
+ * Only count complete packets that passed their MAC check
+ * as having heard from the client; raw data on the socket
+ * is unauthenticated and could have come from anyone.
+ */
+ ssh_packet_get_bytes(ssh, &ibytes, NULL);
+ if (last_client_time == 0 || ibytes != last_ibytes) {
last_client_time = now;
- ptimeout_deadline_sec(&timeout, options.client_alive_interval);
- /* XXX ? deadline_monotime(last_client_time + alive_interval) */
+ last_ibytes = ibytes;
+ }
+ ptimeout_deadline_monotime(&timeout,
+ last_client_time + options.client_alive_interval);
client_alive_scheduled = 1;
}
@@ -238,16 +248,14 @@ wait_until_can_do_something(struct ssh *ssh,
now = monotime(); /* need to reset after ppoll() */
/* ClientAliveInterval probing */
- if (client_alive_scheduled) {
- if (ret == 0 &&
- now >= last_client_time + options.client_alive_interval) {
- /* ppoll timed out and we're due to probe */
- client_alive_check(ssh);
- last_client_time = now;
- } else if (ret != 0 && *conn_in_readyp) {
- /* Data from peer; reset probe timer. */
- last_client_time = now;
- }
+ if (client_alive_scheduled && !*conn_in_readyp &&
+ now >= last_client_time + options.client_alive_interval) {
+ /*
+ * We're due to probe. We can't rely on the ppoll timing out
+ * since activity on channels can keep waking it up.
+ */
+ client_alive_check(ssh);
+ last_client_time = now;
}
/* UnusedConnectionTimeout handling */
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list