Skip to content

Commit 6d51fea

Browse files
committed
upstream: ssh-agent: record failed session-bind attempts
Record failed attempts to session-bind a connection and refuse signing operations on that connection henceforth. Prevents a future situation where we add a new hostkey type that is not recognised by an older ssh-agent, that consequently causes session-bind to fail (this situation is only likely to arise when people mix ssh(1) and ssh-agent(1) of different versions on the same host). Previously, after such a failure the agent socket would be considered unbound and not subject to restriction. Spotted by Jann Horn OpenBSD-Commit-ID: b0fdd023e920aa4831413f640de4c5307b53552e
1 parent 7ef3787 commit 6d51fea

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ssh-agent.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh-agent.c,v 1.302 2023/12/18 14:46:56 djm Exp $ */
1+
/* $OpenBSD: ssh-agent.c,v 1.303 2023/12/18 14:48:08 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <[email protected]>
44
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
@@ -130,6 +130,7 @@ typedef struct socket_entry {
130130
struct sshbuf *request;
131131
size_t nsession_ids;
132132
struct hostkey_sid *session_ids;
133+
int session_bind_attempted;
133134
} SocketEntry;
134135

135136
u_int sockets_alloc = 0;
@@ -477,6 +478,10 @@ identity_permitted(Identity *id, SocketEntry *e, char *user,
477478
e->nsession_ids, id->ndest_constraints);
478479
if (id->ndest_constraints == 0)
479480
return 0; /* unconstrained */
481+
if (e->session_bind_attempted && e->nsession_ids == 0) {
482+
error_f("previous session bind failed on socket");
483+
return -1;
484+
}
480485
if (e->nsession_ids == 0)
481486
return 0; /* local use */
482487
/*
@@ -556,6 +561,12 @@ identity_permitted(Identity *id, SocketEntry *e, char *user,
556561
return 0;
557562
}
558563

564+
static int
565+
socket_is_remote(SocketEntry *e)
566+
{
567+
return e->session_bind_attempted || (e->nsession_ids != 0);
568+
}
569+
559570
/* return matching private key for given public key */
560571
static Identity *
561572
lookup_identity(struct sshkey *key)
@@ -1367,7 +1378,7 @@ process_add_identity(SocketEntry *e)
13671378
if (strcasecmp(sk_provider, "internal") == 0) {
13681379
debug_f("internal provider");
13691380
} else {
1370-
if (e->nsession_ids != 0 && !remote_add_provider) {
1381+
if (socket_is_remote(e) && !remote_add_provider) {
13711382
verbose("failed add of SK provider \"%.100s\": "
13721383
"remote addition of providers is disabled",
13731384
sk_provider);
@@ -1565,7 +1576,7 @@ process_add_smartcard_key(SocketEntry *e)
15651576
goto send;
15661577
}
15671578
dump_dest_constraints(__func__, dest_constraints, ndest_constraints);
1568-
if (e->nsession_ids != 0 && !remote_add_provider) {
1579+
if (socket_is_remote(e) && !remote_add_provider) {
15691580
verbose("failed PKCS#11 add of \"%.100s\": remote addition of "
15701581
"providers is disabled", provider);
15711582
goto send;
@@ -1680,6 +1691,7 @@ process_ext_session_bind(SocketEntry *e)
16801691
u_char fwd = 0;
16811692

16821693
debug2_f("entering");
1694+
e->session_bind_attempted = 1;
16831695
if ((r = sshkey_froms(e->request, &key)) != 0 ||
16841696
(r = sshbuf_froms(e->request, &sid)) != 0 ||
16851697
(r = sshbuf_froms(e->request, &sig)) != 0 ||

0 commit comments

Comments
 (0)