summaryrefslogtreecommitdiff
path: root/security/openssh-portable/files/patch-serverloop.c
blob: 94a4609d712fa1f6bdeeae7bb0ee1df5a882a803 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
------------------------------------------------------------------------
r181918 | des | 2008-08-20 05:40:07 -0500 (Wed, 20 Aug 2008) | 6 lines
Changed paths:
   M /head/crypto/openssh/readconf.c

Use net.inet.ip.portrange.reservedhigh instead of IPPORT_RESERVED.
Submitted upstream, no reaction.

Submitted by:   delphij
[rewritten for 7.4 by bdrewery]
[base removed this in 7.8 but it is still useful - bdrewery]

--- serverloop.c.orig	2020-09-27 00:25:01.000000000 -0700
+++ serverloop.c	2020-11-16 12:58:44.823775000 -0800
@@ -56,6 +56,8 @@
 #include <unistd.h>
 #include <stdarg.h>
 
+#include <sys/sysctl.h>
+
 #include "openbsd-compat/sys-queue.h"
 #include "xmalloc.h"
 #include "packet.h"
@@ -104,13 +106,27 @@ static void server_init_dispatch(struct ssh *);
 /* requested tunnel forwarding interface(s), shared with session.c */
 char *tun_fwd_ifnames = NULL;
 
+static int
+ipport_reserved(void)
+{
+#ifdef __FreeBSD__
+	int old;
+	size_t len = sizeof(old);
+
+	if (sysctlbyname("net.inet.ip.portrange.reservedhigh",
+	    &old, &len, NULL, 0) == 0)
+		return (old + 1);
+#endif
+	return (IPPORT_RESERVED);
+}
+
 /* returns 1 if bind to specified port by specified user is permitted */
 static int
 bind_permitted(int port, uid_t uid)
 {
 	if (use_privsep)
 		return 1; /* allow system to decide */
-	if (port < IPPORT_RESERVED && uid != 0)
+	if (port < ipport_reserved() && uid != 0)
 		return 0;
 	return 1;
 }