6a55631
diff --git a/policy/modules/apps/mozilla.te b/policy/modules/apps/mozilla.te
6a55631
index 68929b9..3370160 100644
6a55631
--- a/policy/modules/apps/mozilla.te
6a55631
+++ b/policy/modules/apps/mozilla.te
6a55631
@@ -116,6 +116,7 @@ corenet_tcp_sendrecv_http_cache_port(mozilla_t)
6a55631
 corenet_tcp_sendrecv_squid_port(mozilla_t)
6a55631
 corenet_tcp_connect_flash_port(mozilla_t)
6a55631
 corenet_tcp_sendrecv_ftp_port(mozilla_t)
37ce30c
+corenet_tcp_connect_all_ephemeral_ports(mozilla_t)
6a55631
 corenet_tcp_sendrecv_ipp_port(mozilla_t)
6a55631
 corenet_tcp_connect_http_port(mozilla_t)
6a55631
 corenet_tcp_connect_http_cache_port(mozilla_t)
6a55631
diff --git a/policy/modules/apps/sandbox.te b/policy/modules/apps/sandbox.te
6a55631
index 31c02d2..f61ee10 100644
6a55631
--- a/policy/modules/apps/sandbox.te
6a55631
+++ b/policy/modules/apps/sandbox.te
6a55631
@@ -382,6 +382,7 @@ corenet_tcp_connect_http_cache_port(sandbox_web_type)
6a55631
 corenet_tcp_connect_squid_port(sandbox_web_type)
6a55631
 corenet_tcp_connect_flash_port(sandbox_web_type)
6a55631
 corenet_tcp_connect_ftp_port(sandbox_web_type)
37ce30c
+corenet_tcp_connect_all_ephemeral_ports(sandbox_web_type)
6a55631
 corenet_tcp_connect_ipp_port(sandbox_web_type)
6a55631
 corenet_tcp_connect_streaming_port(sandbox_web_type)
6a55631
 corenet_tcp_connect_pulseaudio_port(sandbox_web_type)
6a55631
diff --git a/policy/modules/kernel/corenetwork.if.in b/policy/modules/kernel/corenetwork.if.in
6a55631
index 5a41e58..54e4c81 100644
6a55631
--- a/policy/modules/kernel/corenetwork.if.in
6a55631
+++ b/policy/modules/kernel/corenetwork.if.in
6a55631
@@ -2269,6 +2269,42 @@ interface(`corenet_udp_bind_all_unreserved_ports',`
6a55631
 
6a55631
 ########################################
6a55631
 ## <summary>
6a55631
+##	Bind TCP sockets to all ports > 32768.
6a55631
+## </summary>
6a55631
+## <param name="domain">
6a55631
+##	<summary>
6a55631
+##	Domain allowed access.
6a55631
+##	</summary>
6a55631
+## </param>
6a55631
+#
6a55631
+interface(`corenet_tcp_bind_all_ephemeral_ports',`
6a55631
+	gen_require(`
6a55631
+		attribute ephemeral_port_type;
6a55631
+	')
6a55631
+
6a55631
+	allow $1 ephemeral_port_type:tcp_socket name_bind;
6a55631
+')
6a55631
+
6a55631
+########################################
6a55631
+## <summary>
6a55631
+##	Bind UDP sockets to all ports > 32768.
6a55631
+## </summary>
6a55631
+## <param name="domain">
6a55631
+##	<summary>
6a55631
+##	Domain allowed access.
6a55631
+##	</summary>
6a55631
+## </param>
6a55631
+#
6a55631
+interface(`corenet_udp_bind_all_ephemeral_ports',`
6a55631
+	gen_require(`
6a55631
+		attribute ephemeral_port_type;
6a55631
+	')
6a55631
+
6a55631
+	allow $1 ephemeral_port_type:udp_socket name_bind;
6a55631
+')
6a55631
+
6a55631
+########################################
6a55631
+## <summary>
6a55631
 ##	Connect DCCP sockets to reserved ports.
6a55631
 ## </summary>
6a55631
 ## <param name="domain">
6a55631
@@ -2341,6 +2377,24 @@ interface(`corenet_tcp_connect_all_unreserved_ports',`
6a55631
 
6a55631
 ########################################
6a55631
 ## <summary>
6a55631
+##	Connect TCP sockets to all ports > 32768.
6a55631
+## </summary>
6a55631
+## <param name="domain">
6a55631
+##	<summary>
6a55631
+##	Domain allowed access.
6a55631
+##	</summary>
6a55631
+## </param>
6a55631
+#
6a55631
+interface(`corenet_tcp_connect_all_ephemeral_ports',`
6a55631
+	gen_require(`
6a55631
+		attribute ephemeral_port_type;
6a55631
+	')
6a55631
+
6a55631
+	allow $1 ephemeral_port_type:tcp_socket name_connect;
6a55631
+')
6a55631
+
6a55631
+########################################
6a55631
+## <summary>
6a55631
 ##	Do not audit attempts to connect DCCP sockets
6a55631
 ##	all reserved ports.
6a55631
 ## </summary>
24b80bf
diff --git a/policy/modules/kernel/corenetwork.te.in b/policy/modules/kernel/corenetwork.te.in
6a55631
index 5287f7a..f65fb75 100644
24b80bf
--- a/policy/modules/kernel/corenetwork.te.in
24b80bf
+++ b/policy/modules/kernel/corenetwork.te.in
6a55631
@@ -14,6 +14,7 @@ attribute port_type;
6a55631
 attribute defined_port_type;
6a55631
 attribute reserved_port_type;
6a55631
 attribute unreserved_port_type;
6a55631
+attribute ephemeral_port_type;
6a55631
 attribute rpc_port_type;
6a55631
 attribute server_packet_type;
6a55631
 
6a55631
@@ -66,11 +67,17 @@ type port_t, port_type;
24b80bf
 sid port gen_context(system_u:object_r:port_t,s0)
24b80bf
 
24b80bf
 #
24b80bf
-# port_t is the default type of INET port numbers.
24b80bf
+# unreserved_port_t is the default type of port numbers > 1024 and non ephemeral
24b80bf
 #
24b80bf
 type unreserved_port_t, port_type, unreserved_port_type;
24b80bf
 
24b80bf
 #
24b80bf
+# ephemeral_port_t is the default type of ephemeral port numbers.
24b80bf
+# cat /proc/sys/net/ipv4/ip_local_port_range 
24b80bf
+#
6a55631
+type ephemeral_port_t, port_type, ephemeral_port_type;
24b80bf
+
24b80bf
+#
24b80bf
 # reserved_port_t is the type of INET port numbers below 1024.
24b80bf
 #
24b80bf
 type reserved_port_t, port_type, reserved_port_type;
6a55631
@@ -293,9 +300,12 @@ portcon tcp 512-1023 gen_context(system_u:object_r:hi_reserved_port_t, s0)
24b80bf
 portcon udp 512-1023 gen_context(system_u:object_r:hi_reserved_port_t, s0)
24b80bf
 portcon tcp 1-511 gen_context(system_u:object_r:reserved_port_t, s0)
24b80bf
 portcon udp 1-511 gen_context(system_u:object_r:reserved_port_t, s0)
24b80bf
-portcon udp 1024-65535 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
-portcon tcp 1024-65535 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
-
24b80bf
+portcon tcp 1024-32767 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
+portcon tcp 32768-61000 gen_context(system_u:object_r:ephemeral_port_t, s0)
24b80bf
+portcon tcp 61001-65535 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
+portcon udp 1024-32767 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
+portcon udp 32768-61000 gen_context(system_u:object_r:ephemeral_port_t, s0)
988daeb
+portcon udp 61001-65535 gen_context(system_u:object_r:unreserved_port_t, s0)
24b80bf
 ########################################
24b80bf
 #
24b80bf
 # Network nodes
6a55631
diff --git a/policy/modules/kernel/corenetwork.te.m4 b/policy/modules/kernel/corenetwork.te.m4
6a55631
index 49f27ca..e8acd10 100644
6a55631
--- a/policy/modules/kernel/corenetwork.te.m4
6a55631
+++ b/policy/modules/kernel/corenetwork.te.m4
6a55631
@@ -81,7 +81,13 @@ declare_nodes($1_node_t,shift($*))
6a55631
 define(`declare_ports',`dnl
6a55631
 ifelse(eval(range_start($3) < 1024),1,`typeattribute $1 reserved_port_type;
6a55631
 ifelse(eval(range_start($3) >= 512),1,`typeattribute $1 rpc_port_type;',`dnl')
6a55631
-',`typeattribute $1 unreserved_port_type;')
6a55631
+',`
6a55631
+ifelse(eval(range_start($3) < 32768),1,`typeattribute $1 unreserved_port_type;',`
6a55631
+      ifelse(eval(range_start($3) > 61001),1,`typeattribute $1 unreserved_port_type;',`
6a55631
+         typeattribute $1 ephemeral_port_type;
6a55631
+      ')
6a55631
+   ')
6a55631
+')
6a55631
 portcon $2 $3 gen_context(system_u:object_r:$1,$4)
6a55631
 ifelse(`$5',`',`',`declare_ports($1,shiftn(4,$*))')dnl
6a55631
 ')
6a55631
diff --git a/policy/modules/services/apache.te b/policy/modules/services/apache.te
6a55631
index 8596b90..9f37c11 100644
6a55631
--- a/policy/modules/services/apache.te
6a55631
+++ b/policy/modules/services/apache.te
6a55631
@@ -137,6 +137,14 @@ gen_tunable(httpd_enable_ftp_server, false)
6a55631
 
6a55631
 ## <desc>
6a55631
 ##	

6a55631
+##	Allow httpd to act as a FTP client
6a55631
+##	connecting to the ftp port and ephemeral ports
6a55631
+##	

6a55631
+## </desc>
6a55631
+gen_tunable(httpd_can_connect_ftp, false)
6a55631
+
6a55631
+## <desc>
6a55631
+##	

6a55631
 ##	Allow httpd to read home directories
6a55631
 ##	

6a55631
 ## </desc>
6a55631
@@ -583,6 +591,7 @@ tunable_policy(`httpd_can_network_relay',`
6a55631
 	corenet_sendrecv_http_client_packets(httpd_t)
6a55631
 	corenet_sendrecv_http_cache_client_packets(httpd_t)
6a55631
 	corenet_sendrecv_squid_client_packets(httpd_t)
37ce30c
+	corenet_tcp_connect_all_ephemeral_ports(httpd_t)
6a55631
 ')
6a55631
 
6a55631
 tunable_policy(`httpd_execmem',`
6a55631
@@ -621,8 +630,14 @@ tunable_policy(`httpd_enable_cgi && httpd_unified && httpd_builtin_scripting',`
6a55631
 	manage_lnk_files_pattern(httpd_t, httpdcontent, httpdcontent)
6a55631
 ')
6a55631
 
b8a4bfc
+tunable_policy(`httpd_can_connect_ftp',`
6a55631
+	corenet_tcp_connect_ftp_port(httpd_t)
37ce30c
+	corenet_tcp_connect_all_ephemeral_ports(httpd_t)
6a55631
+')
6a55631
+
6a55631
 tunable_policy(`httpd_enable_ftp_server',`
6a55631
 	corenet_tcp_bind_ftp_port(httpd_t)
99d7cca
+	corenet_tcp_bind_all_ephemeral_ports(httpd_t)
6a55631
 ')
6a55631
 
6a55631
 tunable_policy(`httpd_tmp_exec && httpd_builtin_scripting',`
6a55631
diff --git a/policy/modules/services/cobbler.te b/policy/modules/services/cobbler.te
6a55631
index 2607914..cb33e76 100644
6a55631
--- a/policy/modules/services/cobbler.te
6a55631
+++ b/policy/modules/services/cobbler.te
6a55631
@@ -110,6 +110,7 @@ corenet_tcp_sendrecv_generic_port(cobblerd_t)
6a55631
 corenet_tcp_sendrecv_cobbler_port(cobblerd_t)
6a55631
 # sync and rsync to ftp and http are permitted by default, for any other media use cobbler_can_network_connect.
6a55631
 corenet_tcp_connect_ftp_port(cobblerd_t)
69cf5b5
+corenet_tcp_connect_all_ephemeral_ports(cobblerd_t)
6a55631
 corenet_tcp_sendrecv_ftp_port(cobblerd_t)
6a55631
 corenet_sendrecv_ftp_client_packets(cobblerd_t)
6a55631
 corenet_tcp_connect_http_port(cobblerd_t)
6a55631
diff --git a/policy/modules/services/ftp.te b/policy/modules/services/ftp.te
6a55631
index 9a1355e..f807210 100644
6a55631
--- a/policy/modules/services/ftp.te
6a55631
+++ b/policy/modules/services/ftp.te
6a55631
@@ -218,9 +218,8 @@ corenet_tcp_bind_generic_node(ftpd_t)
6a55631
 corenet_tcp_bind_ftp_port(ftpd_t)
6a55631
 corenet_tcp_bind_ftp_data_port(ftpd_t)
6a55631
 corenet_tcp_bind_generic_port(ftpd_t)
6a55631
-corenet_tcp_bind_all_unreserved_ports(ftpd_t)
6a55631
-corenet_dontaudit_tcp_bind_all_ports(ftpd_t)
6a55631
-corenet_tcp_connect_all_ports(ftpd_t)
6a55631
+corenet_tcp_bind_all_ephemeral_ports(ftpd_t)
6a55631
+corenet_tcp_connect_all_ephemeral_ports(ftpd_t)
6a55631
 corenet_sendrecv_ftp_server_packets(ftpd_t)
6a55631
 
6a55631
 domain_use_interactive_fds(ftpd_t)
6a55631
diff --git a/policy/modules/services/mock.te b/policy/modules/services/mock.te
6a55631
index 1b9893a..a8eaa4d 100644
6a55631
--- a/policy/modules/services/mock.te
6a55631
+++ b/policy/modules/services/mock.te
6a55631
@@ -87,7 +87,7 @@ corecmd_dontaudit_exec_all_executables(mock_t)
6a55631
 
6a55631
 corenet_tcp_connect_http_port(mock_t)
6a55631
 corenet_tcp_connect_ftp_port(mock_t)
6a55631
-corenet_tcp_connect_all_unreserved_ports(mock_t)
37ce30c
+corenet_tcp_connect_all_ephemeral_ports(mock_t)
6a55631
 
6a55631
 dev_read_urand(mock_t)
6a55631
 dev_read_sysfs(mock_t)