All of lore.kernel.org
 help / color / mirror / Atom feed
* [ libsepol 2/6] Ports
@ 2005-07-21 17:40 Ivan Gyurdiev
  2005-07-21 18:04 ` Joshua Brindle
  0 siblings, 1 reply; 64+ messages in thread
From: Ivan Gyurdiev @ 2005-07-21 17:40 UTC (permalink / raw)
  To: selinux

[-- Attachment #1: Type: text/plain, Size: 401 bytes --]

The following patch pushes the port loading
code into libsepol. It adds a function to
load a port, and a function to get the context
for a port. No shadowing is allowed. It creates
a structure for high level representation of
a port (sepol_portinfo_t). Uses new debug system
and writes to policydb object. Comments welcome.

libsepol-1.2-ports.diff

This patch depends on:
libsepol-1.1-context.diff



[-- Attachment #2: libsepol-1.2-ports.diff --]
[-- Type: text/x-patch, Size: 5356 bytes --]

diff -aru libsepol.work/include/sepol/ports.h libsepol-1.2-ports/include/sepol/ports.h
--- libsepol.work/include/sepol/ports.h	2005-07-08 19:30:00.000000000 -0400
+++ libsepol-1.2-ports/include/sepol/ports.h	2005-07-21 08:48:52.000000000 -0400
@@ -0,0 +1,42 @@
+#ifndef _SEPOL_PORTS_H_
+#define _SEPOL_PORTS_H_
+
+#include <sepol/policydb.h>
+#include <sepol/context.h>
+
+#define SEPOL_TCP_PROTO 0
+#define SEPOL_UDP_PROTO 1
+
+/* High level representation of a port */
+typedef struct sepol_portinfo {
+
+	/* Port parameters */
+	int protocol;
+	int low, high;
+
+	/* Sufficient information to construct 
+	 * the port context */
+	sepol_ctxinfo_t con;
+} sepol_portinfo_t;
+
+/* Create a port structure from high level representation */
+extern int sepol_port_create(
+	policydb_t* policydb,
+	ocontext_t** port,
+	sepol_portinfo_t* data);
+
+/* Get the current context mapping
+ * for this port. Returns 1 if no match, -1 on error, 0 on
+ * success. The returned data is allocated on the heap */
+int sepol_port_get_context(
+	policydb_t* policydb,
+	sepol_portinfo_t* data,
+	char** con_str,
+	size_t* con_str_len);
+
+/* Load the given port into policy. No shadowing is allowed. */
+extern int sepol_port_load(
+	policydb_t* policydb, 
+	sepol_portinfo_t* port);
+
+#endif /* _SEPOL_PORTS_H_ */
diff -aru libsepol.work/src/ports.c libsepol-1.2-ports/src/ports.c
--- libsepol.work/src/ports.c	2005-07-08 19:30:04.000000000 -0400
+++ libsepol-1.2-ports/src/ports.c	2005-07-21 12:19:19.000000000 -0400
@@ -0,0 +1,167 @@
+#include <netinet/in.h>
+#include <stdlib.h>
+
+#include "debug.h"
+#include <sepol/sepol.h>
+#include <sepol/policydb.h>
+#include <sepol/context.h>
+#include <sepol/sidtab.h>
+#include <sepol/services.h>
+#include <sepol/ports.h>
+
+static const char* proto_to_str(int proto) {
+	switch(proto) {
+		case SEPOL_TCP_PROTO:
+			return "TCP";
+		case SEPOL_UDP_PROTO:
+			return "UDP";
+		default:
+			return "???";
+	}
+}
+
+static int sepol2ipproto(int proto) {
+	switch(proto) {
+		case SEPOL_TCP_PROTO:
+			return IPPROTO_TCP;
+		case SEPOL_UDP_PROTO:
+			return IPPROTO_UDP;
+		default:
+			DEBUG(__FUNCTION__, "unsupported protocol %d\n",
+                                proto);
+			return -1;
+	}
+}
+
+/* Create a low level port structure from
+ * a high level representation */
+int sepol_port_create(
+	policydb_t* policydb,
+	ocontext_t** port,
+	sepol_portinfo_t* data) {
+
+	ocontext_t* tmp_port = NULL;
+	context_struct_t* tmp_con = NULL;
+	int tmp_proto;
+
+	tmp_port = (ocontext_t *) calloc(1, sizeof(ocontext_t));
+	if (!tmp_port) {
+		DEBUG(__FUNCTION__, "out of memory\n");
+		goto err;
+	}
+	
+	/* Process protocol */
+	tmp_proto = sepol2ipproto(data->protocol);
+	if (tmp_proto < 0)
+		goto err;
+	tmp_port->u.port.protocol = tmp_proto;
+
+	/* Port range */
+	tmp_port->u.port.low_port = data->low;
+	tmp_port->u.port.high_port = data->high;
+	if (data->low > data->high) {
+		DEBUG(__FUNCTION__, "low port %d exceeds high port %d\n",
+			data->low, data->high);
+		goto err;
+	}
+
+	/* Context */
+	if (sepol_context_create(policydb, &tmp_con, &data->con) < 0)
+		goto err;
+	context_cpy(&tmp_port->context[0], tmp_con);
+	free(tmp_con);
+
+	*port = tmp_port;
+	return STATUS_SUCCESS;
+
+	err:
+	free(tmp_port);
+	DEBUG(__FUNCTION__, "error creating port structure\n");
+	return STATUS_ERR;
+}
+
+/* Get the current context mapping for this port */
+int sepol_port_get_context(
+	policydb_t* policydb,
+	sepol_portinfo_t* data,
+	char** con_str,	
+	size_t* con_str_len) {
+
+	int low = data->low;	
+	int high = data->high;
+
+	int proto = sepol2ipproto(data->protocol);
+	if (proto < 0)
+		goto err;
+
+	ocontext_t *c, *l, *head;
+
+	head = policydb->ocontexts[OCON_PORT];
+	for (l = NULL, c = head; c; l = c, c = c->next) {
+		int proto2 = c->u.port.protocol;
+		int low2 = c->u.port.low_port;
+		int high2 = c->u.port.high_port;
+		context_struct_t* con2 = &c->context[0];
+
+		if (proto != proto2)
+			continue;
+
+		if ((low == low2 && high == high2) ||
+		    (low2 <= low && high2 >= high)) {
+			if (sepol_context_to_string(policydb, con2, 
+				con_str, con_str_len) < 0)
+				goto err;		
+	
+			return STATUS_SUCCESS;
+		}
+	}
+
+	return STATUS_NODATA;
+
+	err: 
+	DEBUG(__FUNCTION__, "could not retrieve context string for "
+		"port entry %s %d-%d\n", proto_to_str(data->protocol), 
+			low, high);
+	return STATUS_ERR;
+
+}
+
+/* Load a port into policy */
+int sepol_port_load(
+	policydb_t* policydb, 
+	sepol_portinfo_t* data) {
+
+	ocontext_t* port = NULL;
+	char* dup_match;
+	size_t dup_size; 
+	int rc;
+
+	if (sepol_port_create(policydb, &port, data) < 0)
+		goto err;
+
+	rc = sepol_port_get_context(policydb, data, &dup_match, &dup_size);
+	if (rc < 0) 
+		goto err;
+
+#warning Is dup_match null terminated ??
+#warning if so, what's the purpose of dup_size
+	else if (rc != STATUS_NODATA) {
+		DEBUG(__FUNCTION__, "port entry for %s %d-%d "
+			"is already mapped to context %s\n",
+			proto_to_str(data->protocol), 
+			data->low, data->high, dup_match);
+		goto err;
+	}
+	
+	/* Attach to context list */
+	port->next = policydb->ocontexts[OCON_PORT];
+	policydb->ocontexts[OCON_PORT] = port;
+
+	return STATUS_SUCCESS;
+
+	err:
+	DEBUG(__FUNCTION__, "error while loading port %s %d-%d\n",
+		proto_to_str(data->protocol), data->low, data->high);
+	free(port);
+	return STATUS_ERR;
+}

^ permalink raw reply	[flat|nested] 64+ messages in thread
* RE: Iptables discussion
@ 2005-07-22 14:54 Chad Hanson
  2005-07-24  5:08 ` James Morris
  0 siblings, 1 reply; 64+ messages in thread
From: Chad Hanson @ 2005-07-22 14:54 UTC (permalink / raw)
  To: 'Karl MacMillan ', ''Daniel J Walsh' ',
	'gyurdiev@redhat.com '
  Cc: ''Joshua Brindle' ',
	'selinux@tycho.nsa.gov '


>> 
>> MLS System, wants to have two Apache systems,  One listening at port 80
>> for Top Secret communications, another at port 81 for secret.  How do
>> you do this?
>> 
>
>I know that this is just a motivating example, but I feel compelled to
>point out that 1) this problem is not really related to MLS in the real
>world and 2) separation based on ports is _very_ unlikely to meet the
>requirements of a system that will be processing data at different
>sensitivities.
>

Common MLS networking uses are having at least 2 interfaces, these
interfaces have different MLS labels. Also nodes/networks are given MLS
labels to tie together their usage on an interface.  

A simple web server example for say label unclass and confidential  would
want to make sure that those servers no matter which port they listen, only
communicate to nodes or the same label across an interface of the same label
as well. 

A client example of a web browser is the same. If you are unclass, the
browser should only communicate to unclass nodes and interfaces.  

iptables is complimentary and essential to solutions as it does the needed
filtering. 

-Chad

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 64+ messages in thread
* RE: Iptables discussion
@ 2005-07-25 21:00 Chad Hanson
  0 siblings, 0 replies; 64+ messages in thread
From: Chad Hanson @ 2005-07-25 21:00 UTC (permalink / raw)
  To: gyurdiev, Joshua Brindle
  Cc: Daniel J Walsh, Christopher J. PeBenito, James Morris,
	Casey Schaufler, Karl MacMillan, selinux



> > The interfaces to do this work should be exported through libsemanage to

> > do it seamlessly regardless of policy backend. The labels will have to 
> > (unfortunatly) be part of some configutation file, which is policy 
> > specific. 
> 
> The labels can be inferred from the card name, if necessary.
> 

contexts for interfaces and nodes need to managed and shouldn't be just
inferred.

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 64+ messages in thread
* RE: Iptables discussion
@ 2005-07-25 21:04 Chad Hanson
  0 siblings, 0 replies; 64+ messages in thread
From: Chad Hanson @ 2005-07-25 21:04 UTC (permalink / raw)
  To: Christopher J. PeBenito, Daniel J Walsh
  Cc: James Morris, Casey Schaufler, gyurdiev, Joshua Brindle,
	Karl MacMillan, selinux


> 
> I think the better way would be to change the way the policy works,
> rather then conditionally applying the attribute.  The default should
> probably be to not have any netifcon statements except for interfaces we
> want different behavior.  The above macro would be changed to use
> netif_t as the target, rather then netif_type.  Then all interface types
> still keep the netif_type attribute, so the privilege of using all
> interfaces still exists, if needed, but since there are no netifcons,
> all interfaces fall back to the initial sid type (netif_t).  When the
> user wants different behaviors for a specific interface, then the tool
> would add the netifcon to the policy, and add the appropriate rules to
> the policy.
> 
> To make this work better, then the can_network*() macros could be
> modified to have an additional optional parameter to specify which
> interface(s) to use.  Then if the interface is supplied, the specified
> interface type is used; otherwise, the generic interface (netif_t) is
> used.
> 
> So you could have:
> 
> can_network(apache_t)
> 
> and then to change it to only use eth0,
> 
> can_network(apache_t,eth0_netif_t)
> 
> and label the external interface in net_contexts:
> 
> netifcon eth0 system_u:object_r:eth0_netif_t 
> system_u:object_r:unlabeled_t
> 
> or perhaps the type could just be shortened to just eth0, and the type
> name inferred.  This would then just result in a one line 
> policy change,
> and a netifcon for each specified interface.

There is a problem with virtual interfaces here as they contain colons I
believe.

> 
> The reference policy does not have the can_network() style macros, but
> rather specifies ports, nodes, and netifs interfaces 
> separately, so this
> would also be fairly simple.  So the apache policy might 
> start out with
> this:
> 
> corenet_tcp_sendrecv_generic_if(apache_t)
> 
> to use generic (netif_t) interfaces, and to make it use the "external"
> interfaces eth1 and eth2, we just change it to
> 
> corenet_tcp_sendrecv_external_if(apache_t)
> 
> and label the external interfaces by adding this in corenetwork:
> 
> network_interface(external, eth1,s0, eth2,s0)
> 
> (sensitivity would be dropped on non MLS policies)
> 

I like the ideas above and think they sound reasonable.  

-Chad

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2005-07-26  0:18 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-21 17:40 [ libsepol 2/6] Ports Ivan Gyurdiev
2005-07-21 18:04 ` Joshua Brindle
2005-07-21 18:06   ` Ivan Gyurdiev
2005-07-21 18:27   ` Ivan Gyurdiev
2005-07-21 19:35     ` Karl MacMillan
2005-07-21 19:38       ` Ivan Gyurdiev
2005-07-21 20:30         ` Karl MacMillan
2005-07-21 20:47           ` Ivan Gyurdiev
2005-07-21 21:06             ` Joshua Brindle
2005-07-21 21:06               ` Ivan Gyurdiev
2005-07-21 21:15                 ` Joshua Brindle
2005-07-21 21:25                   ` Ivan Gyurdiev
2005-07-21 23:34                     ` Joshua Brindle
2005-07-22 11:53                       ` Iptables discussion Ivan Gyurdiev
2005-07-22 12:31                         ` Daniel J Walsh
2005-07-22 12:46                           ` Karl MacMillan
2005-07-22 13:44                             ` Ivan Gyurdiev
2005-07-22 14:19                               ` Karl MacMillan
2005-07-22 14:24                                 ` Ivan Gyurdiev
2005-07-22 15:28                                   ` Karl MacMillan
2005-07-22 18:18                                     ` Ivan Gyurdiev
2005-07-22 18:40                                       ` Karl MacMillan
2005-07-22 19:01                                         ` Ivan Gyurdiev
2005-07-22 14:42                                 ` Daniel J Walsh
2005-07-22 15:28                                   ` Karl MacMillan
2005-07-22 14:51                                 ` Joshua Brindle
2005-07-22 14:51                               ` Joshua Brindle
2005-07-22 15:39                                 ` Ivan Gyurdiev
2005-07-22 15:57                                   ` Karl MacMillan
2005-07-22 16:14                                     ` Ivan Gyurdiev
2005-07-22 16:31                                       ` Karl MacMillan
2005-07-22 17:59                                         ` Ivan Gyurdiev
2005-07-22 16:28                                     ` Ivan Gyurdiev
2005-07-22 17:28                                   ` Jason Tang
2005-07-22 17:54                                     ` Ivan Gyurdiev
2005-07-22 18:28                                       ` Jason Tang
2005-07-22 18:32                                         ` Ivan Gyurdiev
2005-07-22 19:19                                   ` Joshua Brindle
2005-07-22 19:44                                     ` Ivan Gyurdiev
2005-07-22 19:56                                       ` Joshua Brindle
2005-07-22 20:18                                         ` Ivan Gyurdiev
2005-07-22 20:56                                           ` Ivan Gyurdiev
2005-07-22 15:46                             ` Casey Schaufler
2005-07-22 15:54                               ` Joshua Brindle
2005-07-22 16:11                               ` Frank Mayer
2005-07-22 18:56                                 ` Casey Schaufler
2005-07-24  5:25                           ` James Morris
2005-07-24 15:28                             ` Casey Schaufler
2005-07-25  4:24                               ` James Morris
2005-07-25 15:37                                 ` Daniel J Walsh
2005-07-25 18:24                                   ` Christopher J. PeBenito
2005-07-25 18:28                                     ` Ivan Gyurdiev
2005-07-25 18:43                                       ` Ivan Gyurdiev
2005-07-25 18:55                                         ` Daniel J Walsh
2005-07-25 19:01                                           ` Joshua Brindle
2005-07-25 19:53                                             ` Ivan Gyurdiev
2005-07-25 22:42                                               ` Joshua Brindle
2005-07-26  0:07                                                 ` Ivan Gyurdiev
2005-07-26  0:13                                                   ` Joshua Brindle
2005-07-22 12:37                         ` Karl MacMillan
  -- strict thread matches above, loose matches on Subject: below --
2005-07-22 14:54 Chad Hanson
2005-07-24  5:08 ` James Morris
2005-07-25 21:00 Chad Hanson
2005-07-25 21:04 Chad Hanson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.