Skip to content

Commit 73e2a88

Browse files
committed
openssh-7.3p1-x11-max-displays
1 parent f878d7c commit 73e2a88

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

channels.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,7 +5067,7 @@ rdynamic_connect_finish(struct ssh *ssh, Channel *c)
50675067
*/
50685068
int
50695069
x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
5070-
int x11_use_localhost, int single_connection,
5070+
int x11_use_localhost, int x11_max_displays, int single_connection,
50715071
u_int *display_numberp, int **chanids)
50725072
{
50735073
Channel *nc = NULL;
@@ -5080,8 +5080,11 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
50805080
x11_display_offset > UINT16_MAX - X11_BASE_PORT - MAX_DISPLAYS)
50815081
return -1;
50825082

5083+
/* Try to bind ports starting at 6000+X11DisplayOffset */
5084+
x11_max_displays = x11_max_displays + x11_display_offset;
5085+
50835086
for (display_number = x11_display_offset;
5084-
display_number < x11_display_offset + MAX_DISPLAYS;
5087+
display_number < x11_max_displays;
50855088
display_number++) {
50865089
port = X11_BASE_PORT + display_number;
50875090
memset(&hints, 0, sizeof(hints));
@@ -5136,7 +5139,7 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
51365139
if (num_socks > 0)
51375140
break;
51385141
}
5139-
if (display_number >= x11_display_offset + MAX_DISPLAYS) {
5142+
if (display_number >= x11_max_displays || port < X11_BASE_PORT ) {
51405143
error("Failed to allocate internet-domain X11 display socket.");
51415144
return -1;
51425145
}

channels.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ int permitopen_port(const char *);
389389

390390
void channel_set_x11_refuse_time(struct ssh *, time_t);
391391
int x11_connect_display(struct ssh *);
392-
int x11_create_display_inet(struct ssh *, int, int, int, u_int *, int **);
392+
int x11_create_display_inet(struct ssh *, int, int, int, int, u_int *, int **);
393393
void x11_request_forwarding_with_spoofing(struct ssh *, int,
394394
const char *, const char *, const char *, int);
395395
int x11_channel_used_recently(struct ssh *ssh);

servconf.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ initialize_server_options(ServerOptions *options)
114114
options->print_lastlog = -1;
115115
options->x11_forwarding = -1;
116116
options->x11_display_offset = -1;
117+
options->x11_max_displays = -1;
117118
options->x11_use_localhost = -1;
118119
options->permit_tty = -1;
119120
options->permit_user_rc = -1;
@@ -342,6 +343,8 @@ fill_default_server_options(ServerOptions *options)
342343
options->x11_forwarding = 0;
343344
if (options->x11_display_offset == -1)
344345
options->x11_display_offset = 10;
346+
if (options->x11_max_displays == -1)
347+
options->x11_max_displays = DEFAULT_MAX_DISPLAYS;
345348
if (options->x11_use_localhost == -1)
346349
options->x11_use_localhost = 1;
347350
if (options->xauth_location == NULL)
@@ -555,7 +558,7 @@ typedef enum {
555558
sKerberosGetAFSToken, sPasswordAuthentication,
556559
sKbdInteractiveAuthentication, sListenAddress, sAddressFamily,
557560
sPrintMotd, sPrintLastLog, sIgnoreRhosts,
558-
sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
561+
sX11Forwarding, sX11DisplayOffset, sX11MaxDisplays, sX11UseLocalhost,
559562
sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
560563
sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
561564
sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
@@ -678,6 +681,7 @@ static struct {
678681
{ "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
679682
{ "x11forwarding", sX11Forwarding, SSHCFG_ALL },
680683
{ "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
684+
{ "x11maxdisplays", sX11MaxDisplays, SSHCFG_ALL },
681685
{ "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
682686
{ "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
683687
{ "strictmodes", sStrictModes, SSHCFG_GLOBAL },
@@ -1696,6 +1700,10 @@ process_server_config_line_depth(ServerOptions *options, char *line,
16961700
*intptr = value;
16971701
break;
16981702

1703+
case sX11MaxDisplays:
1704+
intptr = &options->x11_max_displays;
1705+
goto parse_int;
1706+
16991707
case sX11UseLocalhost:
17001708
intptr = &options->x11_use_localhost;
17011709
goto parse_flag;
@@ -2964,6 +2972,7 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
29642972
M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
29652973
M_CP_INTOPT(x11_display_offset);
29662974
M_CP_INTOPT(x11_forwarding);
2975+
M_CP_INTOPT(x11_max_displays);
29672976
M_CP_INTOPT(x11_use_localhost);
29682977
M_CP_INTOPT(permit_tty);
29692978
M_CP_INTOPT(permit_user_rc);
@@ -3257,6 +3266,7 @@ dump_config(ServerOptions *o)
32573266
#endif
32583267
dump_cfg_int(sLoginGraceTime, o->login_grace_time);
32593268
dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
3269+
dump_cfg_int(sX11MaxDisplays, o->x11_max_displays);
32603270
dump_cfg_int(sMaxAuthTries, o->max_authtries);
32613271
dump_cfg_int(sMaxSessions, o->max_sessions);
32623272
dump_cfg_int(sClientAliveInterval, o->client_alive_interval);

servconf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#define DEFAULT_AUTH_FAIL_MAX 6 /* Default for MaxAuthTries */
4040
#define DEFAULT_SESSIONS_MAX 10 /* Default for MaxSessions */
41+
#define DEFAULT_MAX_DISPLAYS 1000 /* Maximum number of fake X11 displays to try. */
4142

4243
/* Magic name for internal sftp-server */
4344
#define INTERNAL_SFTP_NAME "internal-sftp"
@@ -115,6 +116,7 @@ typedef struct {
115116
int x11_forwarding; /* If true, permit inet (spoofing) X11 fwd. */
116117
int x11_display_offset; /* What DISPLAY number to start
117118
* searching at */
119+
int x11_max_displays; /* Number of displays to search */
118120
int x11_use_localhost; /* If true, use localhost for fake X11 server. */
119121
char *xauth_location; /* Location of xauth program */
120122
int permit_tty; /* If false, deny pty allocation */

session.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,8 +2549,9 @@ session_setup_x11fwd(struct ssh *ssh, Session *s)
25492549
return 0;
25502550
}
25512551
if (x11_create_display_inet(ssh, options.x11_display_offset,
2552-
options.x11_use_localhost, s->single_connection,
2553-
&s->display_number, &s->x11_chanids) == -1) {
2552+
options.x11_use_localhost, options.x11_max_displays,
2553+
s->single_connection, &s->display_number,
2554+
&s->x11_chanids) == -1) {
25542555
debug("x11_create_display_inet failed.");
25552556
return 0;
25562557
}

sshd_config.5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ Available keywords are
13511351
.Cm TrustedUserCAKeys ,
13521352
.Cm UnusedConnectionTimeout ,
13531353
.Cm X11DisplayOffset ,
1354+
.Cm X11MaxDisplays ,
13541355
.Cm X11Forwarding
13551356
and
13561357
.Cm X11UseLocalhost .
@@ -2074,6 +2075,12 @@ Specifies the first display number available for
20742075
X11 forwarding.
20752076
This prevents sshd from interfering with real X11 servers.
20762077
The default is 10.
2078+
.It Cm X11MaxDisplays
2079+
Specifies the maximum number of displays available for
2080+
.Xr sshd 8 Ns 's
2081+
X11 forwarding.
2082+
This prevents sshd from exhausting local ports.
2083+
The default is 1000.
20772084
.It Cm X11Forwarding
20782085
Specifies whether X11 forwarding is permitted.
20792086
The argument must be

0 commit comments

Comments
 (0)