Skip to contentSkip to conversation

Updated NetLabel patch

RFC In review [email protected] 8 participants 30 messages Jun 21, 2006 – Jun 27, 2006

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover Updated NetLabel patch

This is an updated version of the NetLabel patch I sent out on May 25th. It contains a variety of fixes and incorporates comments from James Morris, Stephen Smalley, and Steve Grubb. An intermediate version of this patch set has also been tested against Trusted Solaris and HP-UX CMW for CIPSO interoperability. I have tested this patch set on x86 and x86_64 architectures running both the targeted/enforcing and mls/permissive SELinux policies.

Just like before I am sending this patch out in an effort to solicit feedback from developers, any comments you can afford to send would be greatly appreciated. While the patch is still "unfinished" my current todo list is much shorter, the major tasks still remaining are:

* protect against setsockopt() calls
* address the remaining "PM" comments

For those wishing to try the patch for themselves you will need to download and install the NetLabel tools. The tools are used to configure the NetLabel subsystem, documentation (including a man page) is included in the tarball. The NetLabel tools, as well as more information, can be found here:

* http://free.linux.hp.com/~pmoore/projects/linux_cipso

Thanks.

--
paul moore
linux security @ hp

#1 lore raw

RFC 1/7 NetLabel: documentation

Documentation for the NetLabel system, this includes a basic overview of how NetLabel works and how LSM developers can integrate it into their favorite LSM. Also, due to the difficulty of finding expired IETF drafts, I am including the IETF CIPSO draft that is the basis of the NetLabel CIPSO implementation.

---
 CREDITS                                                   |    7 
 Documentation/00-INDEX                                    |    2 
 Documentation/netlabel/00-INDEX                           |   10 
 Documentation/netlabel/cipso_ipv4.txt                     |   48 
 Documentation/netlabel/draft-ietf-cipso-ipsecurity-01.txt |  791 ++++++++++++++
 Documentation/netlabel/introduction.txt                   |   52 
 Documentation/netlabel/lsm_interface.txt                  |   47 
 7 files changed, 957 insertions(+)
CREDITS +7 -0
Index: linux-2.6.17.i686-quilt/CREDITS
===================================================================
@@ -2383,6 +2383,13 @@ N: Thomas Molina
 E: [email protected]
 D: bug fixes, documentation, minor hackery
 
+N: Paul Moore
+E: [email protected]
+D: NetLabel author
+S: Hewlett-Packard
+S: 110 Spit Brook Road
+S: Nashua, NH 03062
+
 N: James Morris
 E: [email protected]
 W: http://namei.org/
Documentation/00-INDEX +2 -0
Index: linux-2.6.17.i686-quilt/Documentation/00-INDEX
===================================================================
@@ -184,6 +184,8 @@ mtrr.txt
 	- how to use PPro Memory Type Range Registers to increase performance.
 nbd.txt
 	- info on a TCP implementation of a network block device.
+netlabel/
+	- directory with information on the NetLabel subsystem.
 networking/
 	- directory with info on various aspects of networking with Linux.
 nfsroot.txt
Documentation/netlabel/00-INDEX new file +10 -0
Index: linux-2.6.17.i686-quilt/Documentation/netlabel/00-INDEX
===================================================================
@@ -0,0 +1,10 @@
+00-INDEX
+	- this file.
+cipso_ipv4.txt
+	- documentation on the IPv4 CIPSO protocol engine.
+draft-ietf-cipso-ipsecurity-01.txt
+	- IETF draft of the CIPSO protocol, dated 16 July 1992.
+introduction.txt
+	- NetLabel introduction, READ THIS FIRST.
+lsm_interface.txt
+	- documentation on the NetLabel kernel security module API.
Documentation/netlabel/cipso_ipv4.txt new file +48 -0

48 lines not on this page · raw message

Documentation/netlabel/draft-ietf-cipso-ipsecurity-01.txt new file +791 -0

791 lines not on this page · raw message

Documentation/netlabel/introduction.txt new file +52 -0

52 lines not on this page · raw message

Documentation/netlabel/lsm_interface.txt new file +47 -0

47 lines not on this page · raw message

--
paul moore
linux security @ hp

#2 lore raw

RFC 2/7 NetLabel: core network changes

In reply to [email protected]

Changes to the core network stack to support the NetLabel subsystem. This includes changes to support the NetLabel NETLINK communication mechanism, changes to the IPv4 option handling to support CIPSO labels, minor changes to the socket_post_create() LSM hook so that it can return error codes, and a new NetLabel hook in inet_accept() to handle NetLabel attributes across an accept().

---
 include/linux/ip.h       |    1 +
 include/linux/netlink.h  |    1 +
 include/linux/security.h |   16 ++++++++--------
 include/net/inet_sock.h  |    2 +-
 net/ipv4/Makefile        |    3 +++
 net/ipv4/af_inet.c       |    3 +++
 net/ipv4/ah4.c           |    2 +-
 net/ipv4/ip_options.c    |   19 +++++++++++++++++++
 net/socket.c             |   13 +++++++++++--
 security/dummy.c         |   12 ++++++------
 10 files changed, 54 insertions(+), 18 deletions(-)
include/linux/ip.h +1 -0
Index: linux-2.6.17.i686-quilt/include/linux/ip.h
===================================================================
@@ -57,6 +57,7 @@
 #define IPOPT_SEC	(2 |IPOPT_CONTROL|IPOPT_COPY)
 #define IPOPT_LSRR	(3 |IPOPT_CONTROL|IPOPT_COPY)
 #define IPOPT_TIMESTAMP	(4 |IPOPT_MEASUREMENT)
+#define IPOPT_CIPSO	(6 |IPOPT_CONTROL|IPOPT_COPY)
 #define IPOPT_RR	(7 |IPOPT_CONTROL)
 #define IPOPT_SID	(8 |IPOPT_CONTROL|IPOPT_COPY)
 #define IPOPT_SSRR	(9 |IPOPT_CONTROL|IPOPT_COPY)
include/linux/netlink.h +1 -0
Index: linux-2.6.17.i686-quilt/include/linux/netlink.h
===================================================================
@@ -21,6 +21,7 @@
 #define NETLINK_DNRTMSG		14	/* DECnet routing messages */
 #define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
 #define NETLINK_GENERIC		16
+#define NETLINK_NETLABEL	17	/* Network packet labeling */
 
 #define MAX_LINKS 32		
 
include/linux/security.h +8 -8
Index: linux-2.6.17.i686-quilt/include/linux/security.h
===================================================================
@@ -1267,8 +1267,8 @@ struct security_operations {
 	int (*unix_may_send) (struct socket * sock, struct socket * other);
 
 	int (*socket_create) (int family, int type, int protocol, int kern);
-	void (*socket_post_create) (struct socket * sock, int family,
-				    int type, int protocol, int kern);
+	int (*socket_post_create) (struct socket * sock, int family,
+				   int type, int protocol, int kern);
 	int (*socket_bind) (struct socket * sock,
 			    struct sockaddr * address, int addrlen);
 	int (*socket_connect) (struct socket * sock,
@@ -2677,13 +2677,13 @@ static inline int security_socket_create
 	return security_ops->socket_create(family, type, protocol, kern);
 }
 
-static inline void security_socket_post_create(struct socket * sock, 
-					       int family,
-					       int type, 
-					       int protocol, int kern)
+static inline int security_socket_post_create(struct socket * sock,
+					      int family,
+					      int type,
+					      int protocol, int kern)
 {
-	security_ops->socket_post_create(sock, family, type,
-					 protocol, kern);
+	return security_ops->socket_post_create(sock, family, type,
+						protocol, kern);
 }
 
 static inline int security_socket_bind(struct socket * sock, 
include/net/inet_sock.h +1 -1
Index: linux-2.6.17.i686-quilt/include/net/inet_sock.h
===================================================================
@@ -52,7 +52,7 @@ struct ip_options {
 			ts_needtime:1,
 			ts_needaddr:1;
 	unsigned char	router_alert;
-	unsigned char	__pad1;
+	unsigned char	cipso;
 	unsigned char	__pad2;
 	unsigned char	__data[0];
 };
net/ipv4/Makefile +3 -0
Index: linux-2.6.17.i686-quilt/net/ipv4/Makefile
===================================================================
@@ -42,6 +42,9 @@ obj-$(CONFIG_TCP_CONG_HYBLA) += tcp_hybl
 obj-$(CONFIG_TCP_CONG_HTCP) += tcp_htcp.o
 obj-$(CONFIG_TCP_CONG_VEGAS) += tcp_vegas.o
 obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
+ifeq ($(CONFIG_NETLABEL_CIPSOV4),y)
+obj-y += cipso_ipv4.o
+endif
 
 obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \
 		      xfrm4_output.o
net/ipv4/af_inet.c +3 -0
Index: linux-2.6.17.i686-quilt/net/ipv4/af_inet.c
===================================================================
@@ -114,6 +114,7 @@
 #ifdef CONFIG_IP_MROUTE
 #include <linux/mroute.h>
 #endif
+#include <net/netlabel.h>
 
 DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
 
@@ -616,6 +617,8 @@ int inet_accept(struct socket *sock, str
 
 	sock_graft(sk2, newsock);
 
+	netlbl_socket_inet_accept(sock, newsock);
+
 	newsock->state = SS_CONNECTED;
 	err = 0;
 	release_sock(sk2);
net/ipv4/ah4.c +1 -1
Index: linux-2.6.17.i686-quilt/net/ipv4/ah4.c
===================================================================
@@ -35,7 +35,7 @@ static int ip_clear_mutable_options(stru
 		switch (*optptr) {
 		case IPOPT_SEC:
 		case 0x85:	/* Some "Extended Security" crap. */
-		case 0x86:	/* Another "Commercial Security" crap. */
+		case IPOPT_CIPSO:
 		case IPOPT_RA:
 		case 0x80|21:	/* RFC1770 */
 			break;
net/ipv4/ip_options.c +19 -0
Index: linux-2.6.17.i686-quilt/net/ipv4/ip_options.c
===================================================================
@@ -24,6 +24,7 @@
 #include <net/ip.h>
 #include <net/icmp.h>
 #include <net/route.h>
+#include <net/cipso_ipv4.h>
 
 /* 
  * Write options to IP header, record destination address to
@@ -194,6 +195,13 @@ int ip_options_echo(struct ip_options * 
 			dopt->is_strictroute = sopt->is_strictroute;
 		}
 	}
+	if (sopt->cipso) {
+		optlen  = sptr[sopt->cipso+1];
+		dopt->cipso = dopt->optlen+sizeof(struct iphdr);
+		memcpy(dptr, sptr+sopt->cipso, optlen);
+		dptr += optlen;
+		dopt->optlen += optlen;
+	}
 	while (dopt->optlen & 3) {
 		*dptr++ = IPOPT_END;
 		dopt->optlen++;
@@ -435,6 +443,17 @@ int ip_options_compile(struct ip_options
 			if (optptr[2] == 0 && optptr[3] == 0)
 				opt->router_alert = optptr - iph;
 			break;
+		      case IPOPT_CIPSO:
+		        if (opt->cipso) {
+				pp_ptr = optptr;
+				goto error;
+			}
+			opt->cipso = optptr - iph;
+		        if (cipso_v4_validate(&optptr)) {
+				pp_ptr = optptr;
+				goto error;
+			}
+			break;
 		      case IPOPT_SEC:
 		      case IPOPT_SID:
 		      default:
net/socket.c +11 -2
Index: linux-2.6.17.i686-quilt/net/socket.c
===================================================================
@@ -976,11 +976,18 @@ int sock_create_lite(int family, int typ
 		goto out;
 	}
 
-	security_socket_post_create(sock, family, type, protocol, 1);
 	sock->type = type;
+	err = security_socket_post_create(sock, family, type, protocol, 1);
+	if (err)
+		goto out_release;
+
 out:
 	*res = sock;
 	return err;
+out_release:
+	sock_release(sock);
+	sock = NULL;
+	goto out;
 }
 
 /* No kernel lock held - perfect */
@@ -1218,7 +1225,9 @@ static int __sock_create(int family, int
 	 */
 	module_put(net_families[family]->owner);
 	*res = sock;
-	security_socket_post_create(sock, family, type, protocol, kern);
+	err = security_socket_post_create(sock, family, type, protocol, kern);
+	if (err)
+		goto out_release;
 
 out:
 	net_family_read_unlock();
security/dummy.c +6 -6
Index: linux-2.6.17.i686-quilt/security/dummy.c
===================================================================
@@ -692,10 +692,10 @@ static int dummy_socket_create (int fami
 	return 0;
 }
 
-static void dummy_socket_post_create (struct socket *sock, int family, int type,
-				      int protocol, int kern)
+static int dummy_socket_post_create (struct socket *sock, int family, int type,
+				     int protocol, int kern)
 {
-	return;
+	return 0;
 }
 
 static int dummy_socket_bind (struct socket *sock, struct sockaddr *address,
@@ -720,10 +720,10 @@ static int dummy_socket_accept (struct s
 	return 0;
 }
 
-static void dummy_socket_post_accept (struct socket *sock, 
-				      struct socket *newsock)
+static int dummy_socket_post_accept (struct socket *sock,
+				     struct socket *newsock)
 {
-	return;
+	return 0;
 }
 
 static int dummy_socket_sendmsg (struct socket *sock, struct msghdr *msg,

--
paul moore
linux security @ hp

maintainer
#3 lore raw

Re: [RFC 2/7] NetLabel: core network changes

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:37 -0400

include/linux/netlink.h line 26

Quoted 11 lines

Index: linux-2.6.17.i686-quilt/include/linux/netlink.h
===================================================================

include/linux/netlink.h +1 -0
@@ -21,6 +21,7 @@
 #define NETLINK_DNRTMSG		14	/* DECnet routing messages */
 #define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
 #define NETLINK_GENERIC		16
+#define NETLINK_NETLABEL	17	/* Network packet labeling */
 
 #define MAX_LINKS 32		

Please use generic netlink.

Jamal posted a very nice document recently on how to use it properly. You can read that thread here:

http://marc.theaimsgroup.com/?l=linux-netdev&m=115072450928755&w=2

Thanks.

#4 lore raw

Re: [RFC 2/7] NetLabel: core network changes

Quoted 6 lines · David Miller
Quoted 4 lines

 #define NETLINK_GENERIC              16
+#define NETLINK_NETLABEL     17      /* Network packet labeling */
 #define MAX_LINKS 32

Please use generic netlink.

Since this is a security interface, shouldn't it be its own protocol so that SE Linux can control commands being sent? Paul's patches do include a netlink table in security/selinux/nlmsgtab.c. But I do not see any hooks to control generic netlink messages. (There seems to be several protocols that SE Linux is not controlling.) I could see that someone in secadm role should be able to issue these commands, but someone at sysadm or auditadm would not.

If moving this over to generic is a must, then I think SE Linux will have to clip into generic to control its packet flow.

-Steve

maintainer
#5 lore raw

Re: [RFC 2/7] NetLabel: core network changes

Quoted 15 lines · Steve Grubb
Quoted 6 lines · David Miller
Quoted 4 lines

 #define NETLINK_GENERIC              16
+#define NETLINK_NETLABEL     17      /* Network packet labeling */
 #define MAX_LINKS 32

Please use generic netlink.

Since this is a security interface, shouldn't it be its own protocol so that SE Linux can control commands being sent? Paul's patches do include a netlink table in security/selinux/nlmsgtab.c. But I do not see any hooks to control generic netlink messages. (There seems to be several protocols that SE Linux is not controlling.) I could see that someone in secadm role should be able to issue these commands, but someone at sysadm or auditadm would not.

Quoted 2 lines

If moving this over to generic is a must, then I think SE Linux will have to clip into generic to control its packet flow.

SELinux will mediate them as 'generic' netlink.

Fine-grained SELinux support for generic netlink is todo.

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#6 lore raw

Re: [RFC 2/7] NetLabel: core network changes

In reply to Steve Grubb

From: Steve Grubb <[email protected]>
Date: Thu, 22 Jun 2006 11:05:00 -0400

Quoted 2 lines

If moving this over to generic is a must, then I think SE Linux will have to clip into generic to control its packet flow.

James Morris has already started discussions on this. It's great that there will be another reason why that work needs to be done :)

maintainer
#7 lore raw

Re: [RFC 2/7] NetLabel: core network changes

In reply to [email protected]

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:37 -0400

net/ipv4/Makefile obj-$(CONFIG_TCP_CONG_HYBLA) += tcp_hybl · line 47

Quoted 11 lines

Index: linux-2.6.17.i686-quilt/net/ipv4/Makefile
===================================================================

net/ipv4/Makefile +3 -0
@@ -42,6 +42,9 @@ obj-$(CONFIG_TCP_CONG_HYBLA) += tcp_hybl
 obj-$(CONFIG_TCP_CONG_HTCP) += tcp_htcp.o
 obj-$(CONFIG_TCP_CONG_VEGAS) += tcp_vegas.o
 obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
+ifeq ($(CONFIG_NETLABEL_CIPSOV4),y)
+obj-y += cipso_ipv4.o
+endif

Why not "obj-$CONFIG_NETLABEL_CIPSOV4 += cipso_ipv4.o"?

The whole idea behind the obj-$CONFIG_OPTION technique is to avoid conditionals all over the makefile.

Quoted 13 lines

Index: linux-2.6.17.i686-quilt/net/ipv4/af_inet.c
===================================================================

net/ipv4/af_inet.c +1 -0
@@ -114,6 +114,7 @@
 #ifdef CONFIG_IP_MROUTE
 #include <linux/mroute.h>
 #endif
+#include <net/netlabel.h>
 
 DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
 

net/ipv4/af_inet.c int inet_accept(struct socket *sock, str · line 624

Quoted 8 lines
net/ipv4/af_inet.c +2 -0
@@ -616,6 +617,8 @@ int inet_accept(struct socket *sock, str
 
 	sock_graft(sk2, newsock);
 
+	netlbl_socket_inet_accept(sock, newsock);
+
 	newsock->state = SS_CONNECTED;
 	err = 0;
 	release_sock(sk2);

Neither the netlabel.h header not the implementation of the netlbl_socket_inet_accept() function exist at this point in your patch set.

At each patch point, the tree must build and function properly.

This means you have to split up and order your changes correctly, gradually building up the infrastructure and then finally plugging it in and making use of it.

Nobody can test your work in an incremental fashion, and thus it's not possible to determine if a bug or behavior gets introduced at patch 2, 3 or 4, for example.

net/ipv4/af_inet.c

Quoted 5 lines
net/ipv4/af_inet.c +5 -0
+		        if (cipso_v4_validate(&optptr)) {
+				pp_ptr = optptr;
+				goto error;
+			}
+			break;

Same thing here, cipso_v4_validate() doesn't exist in the tree at this point in the patch set, so the tree doesn't build after applying this patch.

Please split up your submission properly.

I really can't sanely review the rest of this until you dice up your changes properly.

author
#8 lore raw

Re: [RFC 2/7] NetLabel: core network changes

Quoted 17 lines · David Miller

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:37 -0400

net/ipv4/Makefile obj-$(CONFIG_TCP_CONG_HYBLA) += tcp_hybl · line 47

Quoted 11 lines

Index: linux-2.6.17.i686-quilt/net/ipv4/Makefile
===================================================================

net/ipv4/Makefile +3 -0
@@ -42,6 +42,9 @@ obj-$(CONFIG_TCP_CONG_HYBLA) += tcp_hybl
 obj-$(CONFIG_TCP_CONG_HTCP) += tcp_htcp.o
 obj-$(CONFIG_TCP_CONG_VEGAS) += tcp_vegas.o
 obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
+ifeq ($(CONFIG_NETLABEL_CIPSOV4),y)
+obj-y += cipso_ipv4.o
+endif

Why not "obj-$CONFIG_NETLABEL_CIPSOV4 += cipso_ipv4.o"?

Quoted 2 lines

The whole idea behind the obj-$CONFIG_OPTION technique is to avoid conditionals all over the makefile.

Because it's not supported as a module and I thought I saw some similar examples in other Makefiles. No matter, I'll make the change.

Quoted 29 lines
Quoted 13 lines

Index: linux-2.6.17.i686-quilt/net/ipv4/af_inet.c
===================================================================

net/ipv4/af_inet.c +1 -0
@@ -114,6 +114,7 @@
 #ifdef CONFIG_IP_MROUTE
 #include <linux/mroute.h>
 #endif
+#include <net/netlabel.h>
 
 DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
 

net/ipv4/af_inet.c int inet_accept(struct socket *sock, str · line 624

Quoted 8 lines
net/ipv4/af_inet.c +2 -0
@@ -616,6 +617,8 @@ int inet_accept(struct socket *sock, str
 
 	sock_graft(sk2, newsock);
 
+	netlbl_socket_inet_accept(sock, newsock);
+
 	newsock->state = SS_CONNECTED;
 	err = 0;
 	release_sock(sk2);

Neither the netlabel.h header not the implementation of the netlbl_socket_inet_accept() function exist at this point in your patch set.

At each patch point, the tree must build and function properly.

Quoted 7 lines

This means you have to split up and order your changes correctly, gradually building up the infrastructure and then finally plugging it in and making use of it.

Nobody can test your work in an incremental fashion, and thus it's not possible to determine if a bug or behavior gets introduced at patch 2, 3 or 4, for example.

I intended the entire patch set to be digested as a whole, the only reason I split it up into several different patches was to get around size limitations in the mailing list. I'll go ahead and rearrange things so they build incrementally.

Thanks for your patience.

Signature · 2 lines
paul moore
linux security @ hp
#9 lore raw

RFC 3/7 NetLabel: CIPSOv4 engine

In reply to [email protected]

Add support for the Commercial IP Security Option (CIPSO) to the IPv4 network stack. CIPSO has become a de-facto standard for trusted/labeled networking amongst existing Trusted Operating Systems such as Trusted Solaris, HP-UX CMW, etc. This implementation is designed to be used with the NetLabel subsystem to provide explicit packet labeling to LSM developers.

The CIPSO/IPv4 packet labeling works by the LSM calling a NetLabel API function which attaches a CIPSO label (IPv4 option) to a given socket; this in turn attaches the CIPSO label to every packet leaving the socket without any extra processing on the outbound side. On the inbound side the individual packet's sk_buff is examined through a call to a NetLabel API function to determine if a CIPSO/IPv4 label is present and if so the security attributes of the CIPSO label are returned to the caller of the NetLabel API function.

---
 include/net/cipso_ipv4.h |  165 ++++
 net/ipv4/cipso_ipv4.c    | 1755 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1920 insertions(+)
include/net/cipso_ipv4.h new file +165 -0
Index: linux-2.6.17.i686-quilt/include/net/cipso_ipv4.h
===================================================================
@@ -0,0 +1,165 @@
+/*
+ * CIPSO - Commercial IP Security Option
+ *
+ * This is an implementation of the CIPSO 2.2 protocol as specified in
+ * draft-ietf-cipso-ipsecurity-01.txt with additional tag types as found in
+ * FIPS-188, copies of both documents can be found in the Documentation
+ * directory.  While CIPSO never became a full IETF RFC standard many vendors
+ * have chosen to adopt the protocol and over the years it has become a
+ * de-facto standard for labeled networking.
+ *
+ * Author: Paul Moore <[email protected]>
+ *
+ */
+
+/*
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
+ *
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _CIPSO_IPV4_H
+#define _CIPSO_IPV4_H
+
+#include <linux/types.h>
+#include <linux/rcupdate.h>
+#include <linux/list.h>
+#include <net/netlabel.h>
+
+/* known doi values */
+#define CIPSO_V4_DOI_UNKNOWN          0x00000000
+
+/* tag types */
+#define CIPSO_V4_TAG_INVALID          0
+#define CIPSO_V4_TAG_RBITMAP          1
+#define CIPSO_V4_TAG_ENUM             2
+#define CIPSO_V4_TAG_RANGE            5
+#define CIPSO_V4_TAG_PBITMAP          6
+#define CIPSO_V4_TAG_FREEFORM         7
+
+/* doi mapping types */
+#define CIPSO_V4_MAP_UNKNOWN          0
+#define CIPSO_V4_MAP_STD              1
+#define CIPSO_V4_MAP_PASS             2
+
+/* limits */
+#define CIPSO_V4_MAX_REM_LVLS         256
+#define CIPSO_V4_INV_LVL              0x80000000
+#define CIPSO_V4_MAX_LOC_LVLS         (CIPSO_V4_INV_LVL - 1)
+#define CIPSO_V4_MAX_REM_CATS         65536
+#define CIPSO_V4_INV_CAT              0x80000000
+#define CIPSO_V4_MAX_LOC_CATS         (CIPSO_V4_INV_CAT - 1)
+
+/*
+ * CIPSO DOI definitions
+ */
+
+/* DOI definition struct */
+#define CIPSO_V4_TAG_MAXCNT           5
+struct cipso_v4_doi {
+	u32 doi;
+	u32 type;
+	union {
+		struct cipso_v4_std_map_tbl *std;
+	} map;
+	u8 tags[CIPSO_V4_TAG_MAXCNT];
+
+	u32 valid;
+	struct list_head list;
+	struct rcu_head rcu;
+	struct list_head dom_list;
+};
+
+/* Standard CIPSO mapping table */
+/* NOTE: the highest order bit (i.e. 0x80000000) is an 'invalid' flag, if the
+ *       bit is set then consider that value as unspecified, meaning the
+ *       mapping for that particular level/category is invalid */
+struct cipso_v4_std_map_tbl {
+	struct {
+		u32 *cipso;
+		u32 *local;
+		u32 cipso_size;
+		u32 local_size;
+	} lvl;
+	struct {
+		u32 *cipso;
+		u32 *local;
+		u32 cipso_size;
+		u32 local_size;
+	} cat;
+};
+
+/*
+ * Helper Functions
+ */
+
+#define CIPSO_V4_OPTEXIST(x) (IPCB(x)->opt.cipso != 0)
+#define CIPSO_V4_OPTPTR(x) ((x)->nh.raw + IPCB(x)->opt.cipso)
+
+/*
+ * DOI List Functions
+ */
+
+int cipso_v4_doi_add(struct cipso_v4_doi *doi_def);
+int cipso_v4_doi_remove(const u32 doi,
+			void (*callback) (struct rcu_head * head));
+struct cipso_v4_doi *cipso_v4_doi_getdef(const u32 doi);
+
+struct sk_buff *cipso_v4_doi_dump(const u32 doi, const u32 headroom);
+
+int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def, const char *domain);
+int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
+			       const char *domain);
+
+/*
+ * Label Mapping Cache Functions
+ */
+
+void cipso_v4_cache_invalidate(void);
+int cipso_v4_cache_add(const struct sk_buff *skb,
+		       const struct netlbl_lsm_secattr *secattr);
+
+/*
+ * Protocol Handling Functions
+ */
+
+int cipso_v4_error(struct sk_buff *skb,
+		   const int error,
+		   const u32 gateway);
+int cipso_v4_socket_setopt(struct socket *sock,
+			   unsigned char *opt,
+			   u32 opt_len);
+int cipso_v4_socket_setattr(const struct socket *sock,
+			    const struct cipso_v4_doi *doi_def,
+			    const struct netlbl_lsm_secattr *secattr);
+int cipso_v4_socket_getopt(const struct socket *sock,
+			   unsigned char **opt,
+			   u32 *opt_len);
+int cipso_v4_socket_getattr(const struct socket *sock,
+			    struct netlbl_lsm_secattr *secattr);
+int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
+			    struct netlbl_lsm_secattr *secattr);
+
+#ifdef CONFIG_NETLABEL_CIPSOV4
+int cipso_v4_validate(unsigned char **option);
+#else
+static inline int cipso_v4_validate(unsigned char **option)
+{
+	return *option;
+}
+#endif /* CONFIG_NETLABEL_CIPSOV4 */
+
+#endif /* _CIPSO_IPV4_H */
net/ipv4/cipso_ipv4.c new file +1755 -0

1,755 lines not on this page · raw message

--
paul moore
linux security @ hp

maintainer
#10 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:38 -0400

Quoted 6 lines

Add support for the Commercial IP Security Option (CIPSO) to the IPv4 network stack. CIPSO has become a de-facto standard for trusted/labeled networking amongst existing Trusted Operating Systems such as Trusted Solaris, HP-UX CMW, etc. This implementation is designed to be used with the NetLabel subsystem to provide explicit packet labeling to LSM developers.

The thing that concerns me most about CIPSO is that even once users migrate to a more SELINUX native approach from this CIPSO stuff, the CIPSO code, it's bloat, and it's maintainence burdon will remain.

It's easy to put stuff it, it's impossible to take stuff out even once it's largely unused by even it's original target audience.

And that's what I see happening here.

This is why, to be perfectly honest with you, I'd much rather something like this stay out-of-tree and people are strongly encouraged to use the more native stuff under Linux.

author
#11 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 14 lines · David Miller

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:38 -0400

Quoted 6 lines

Add support for the Commercial IP Security Option (CIPSO) to the IPv4 network stack. CIPSO has become a de-facto standard for trusted/labeled networking amongst existing Trusted Operating Systems such as Trusted Solaris, HP-UX CMW, etc. This implementation is designed to be used with the NetLabel subsystem to provide explicit packet labeling to LSM developers.

The thing that concerns me most about CIPSO is that even once users migrate to a more SELINUX native approach from this CIPSO stuff, the CIPSO code, it's bloat, and it's maintainence burdon will remain.

Quoted 8 lines

It's easy to put stuff it, it's impossible to take stuff out even once it's largely unused by even it's original target audience.

And that's what I see happening here.

This is why, to be perfectly honest with you, I'd much rather something like this stay out-of-tree and people are strongly encouraged to use the more native stuff under Linux.

Well, not exactly the response I was hoping for, but let me plead my case one more time :)

Traditional MLS CIPSO is a niche "protocol", I won't try to argue that point, and I also won't try to argue that the NetLabel patch is late to the party, the IPsec/XFRM labeling approach has already been accepted as "the" SELinux packet labeling mechanism. However, the XFRM labeling mechanism in not currently supported by any OS other than Linux/SELinux. I have spoken with users that need CIPSO to interoperate with their other trusted systems, the XFRM approach is simply not a viable solution for them. I strongly believe that failure to support an interoperable packet labeling mechanism on Linux will seriously restrict Linux's deployment in trusted networks.

It's all about compatibility and enabling Linux to be used in places it can't be used now. True, other OS vendors might support the SELinux/IPsec packet labeling approach, but I see very little in the way of motivation for them to do the work.

If it makes you feel any better I do intend to support the Selopt approach (or at least something very similar) for CIPSO as envisioned by James Morris for the SELinux networking hooks of long ago. This will allow CIPSO to carry the full SELinux context making it a more "SELINUX native approach" than traditional MLS CIPSO. I just wanted to keep this initial patch set as small as possible (you can see how well that worked out) ... :)

Signature · 2 lines
paul moore
linux security @ hp
#12 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 23 lines · Paul Moore
Quoted 9 lines · David Miller

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:38 -0400

The thing that concerns me most about CIPSO is that even once users migrate to a more SELINUX native approach from this CIPSO stuff, the CIPSO code, it's bloat, and it's maintainence burdon will remain.

Quoted 10 lines

It's easy to put stuff it, it's impossible to take stuff out even once it's largely unused by even it's original target audience.

And that's what I see happening here.

This is why, to be perfectly honest with you, I'd much rather something like this stay out-of-tree and people are strongly encouraged to use the more native stuff under Linux.

Quoted 4 lines

Well, not exactly the response I was hoping for, but let me plead my case one more time :)

Traditional MLS CIPSO is a niche "protocol", I won't try to argue that point, and I also won't try to argue that the NetLabel patch is late to the party, the IPsec/XFRM labeling approach has already been accepted as "the" SELinux packet labeling mechanism. However, the XFRM labeling mechanism in not currently supported by any OS other than Linux/SELinux. I have spoken with users that need CIPSO to interoperate with their other trusted systems, the XFRM approach is simply not a viable solution for them. I strongly believe that failure to support an interoperable packet labeling mechanism on Linux will seriously restrict Linux's deployment in trusted networks.

The PitBull product uses the CIPSO/RIPSO labeling protocol in order to do interop packet labeling with other trusted systems and for passing labels between our own systems. Because it is the standard, it is the protocol that government agencies use to do packet labeling across networks. Not having CIPSO in the mainline would mean that government agencies would either a) only use SELinux from a distro that supports the CIPSO patch (by maintaining it in their kernel themselves), if such a distro exists, b) have to patch the kernels themselves (unlikely), or c) not use SELinux at all.

Also, the port of PitBull to Linux that I'm working on is currently using the netlabel patch to handle the CIPSO/RIPSO labeling. Since the actual protocol for reading and writing out the IPSec option is independent from the security enforcment module it makes a lot of sense to have a generic handler in the kernel that LSM modules can use. So, in short, it makes my life a lot easier to have all that work already done :)

Signature · 8 lines
Ryan Pratt
Chief Solaris Engineer
Innovative Security Systems, Inc.
(dba Argus Systems Group)
1809 Woodfield Dr.
Savoy IL 61874
(217) 355-6308
www.argus-systems.com
#13 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

In reply to David Miller
Quoted 14 lines · David Miller

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:38 -0400

Quoted 6 lines

Add support for the Commercial IP Security Option (CIPSO) to the IPv4 network stack. CIPSO has become a de-facto standard for trusted/labeled networking amongst existing Trusted Operating Systems such as Trusted Solaris, HP-UX CMW, etc. This implementation is designed to be used with the NetLabel subsystem to provide explicit packet labeling to LSM developers.

The thing that concerns me most about CIPSO is that even once users migrate to a more SELINUX native approach from this CIPSO stuff, the CIPSO code, it's bloat, and it's maintainence burdon will remain.

Quoted 9 lines

It's easy to put stuff it, it's impossible to take stuff out even once it's largely unused by even it's original target audience.

And that's what I see happening here.

This is why, to be perfectly honest with you, I'd much rather something like this stay out-of-tree and people are strongly encouraged to use the more native stuff under Linux.

Realistically customers most likely to adopt use of SELinux are going to be ones that currently use other trusted OSs such as TSOL and HP-UX CMW. These users are unlikely to take an all (SELinux) or nothing approach. Also they are more than likely customers who will want a fully configured and supported distribution as opposed to one they'd have to patch themselves. With these points in mind I think CIPSO as a integrated interoperability mechanism is critical. FYI, over the last couple of weeks I've validated the interoperability of the CIPSO inplementation with TSOL and HP-UX CMW.

Ted

Quoted 4 lines

--
redhat-lspp mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/redhat-lspp

maintainer
#14 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

From: Ted <[email protected]>
Date: Fri, 23 Jun 2006 13:48:01 -0500

Quoted 3 lines

Realistically customers most likely to adopt use of SELinux are going to be ones that currently use other trusted OSs such as TSOL and HP-UX CMW.

Every single user who installs a modern distribution these days likely gets SELINUX enabled by default, and are therefore adopters of SELINUX. That's a lot of people.

The number of people with existing CIPSO infrastructure are miniscule in comparison.

Please do not even imply that CIPSO use is anything but fringe in the grand scheme of things. It most certainly is. And it will be replaced by IPSEC based labelling, that is a fact. If people cannot move over to IPSEC labelling simply because their HPUX/TSOL doesn't support it, I'm perfectly happy for those users to stick with HPUX and TSOL. A lot of people think Linux should try to be everything for everybody, I'm not one of those people :-)

For CIPSO we eat a non-trivial maintainence and bloat cost in order to support legacy stuff for this relatively tiny group of potential users.

I'd rather pay the bloat and development costs on something forward thinking like IPSEC labelling. Something people will actually be using years from now, rather than a dying technology that few people (relatively speaking) use as it is.

Finally, even if CIPSO is something we want to put in, don't worry about it as there's still time to discuss things. A couple days before the merge window of 2.6.18 development closes is not the time to be submitting half-finished work and expecting it to be integrated. If 2.6.18 integration is what the submitter desires, they should have finished their work and started this review process weeks if not months ago.

#15 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 7 lines · David Miller

From: Ted <[email protected]>
Date: Fri, 23 Jun 2006 13:48:01 -0500

Quoted 3 lines

Realistically customers most likely to adopt use of SELinux are going to be ones that currently use other trusted OSs such as TSOL and HP-UX CMW.

Quoted 7 lines

Every single user who installs a modern distribution these days likely gets SELINUX enabled by default, and are therefore adopters of SELINUX. That's a lot of people.

The number of people with existing CIPSO infrastructure are miniscule in comparison.

I think that except those who currently use and understand trusted OSs users will change SELinux to permissive mode because they won't have the expertise to deal with policy issues.

Quoted 8 lines

Please do not even imply that CIPSO use is anything but fringe in the grand scheme of things. It most certainly is. And it will be replaced by IPSEC based labelling, that is a fact. If people cannot move over to IPSEC labelling simply because their HPUX/TSOL doesn't support it, I'm perfectly happy for those users to stick with HPUX and TSOL. A lot of people think Linux should try to be everything for everybody, I'm not one of those people :-)

I can guarantee that initially SELinux adoption will be by those running trusted OSs and they will want their systems to be able to interoperate at level. The idea that IPSEC will fill this need in the near term is just not realistic.

Quoted 16 lines

For CIPSO we eat a non-trivial maintainence and bloat cost in order to support legacy stuff for this relatively tiny group of potential users.

I'd rather pay the bloat and development costs on something forward thinking like IPSEC labelling. Something people will actually be using years from now, rather than a dying technology that few people (relatively speaking) use as it is.

Finally, even if CIPSO is something we want to put in, don't worry about it as there's still time to discuss things. A couple days before the merge window of 2.6.18 development closes is not the time to be submitting half-finished work and expecting it to be integrated. If 2.6.18 integration is what the submitter desires, they should have finished their work and started this review process weeks if not months ago.

maintainer
#16 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 4 lines · Ted

I can guarantee that initially SELinux adoption will be by those running trusted OSs and they will want their systems to be able to interoperate at level. The idea that IPSEC will fill this need in the near term is just not realistic.

SELinux is already being adopted for all kinds of needs.

In many cases, people have been using MLS because that's all there is in terms of MAC operating systems, and would actually be much better off with Type Enforcement for new deployments.

MLS solves a very narrow (albeit important) case, whereas TE is designed to be generic. Typically, MLS is indicated when you have a very large number of domains to separate (e.g. many hundreds or thousands of compartments with hierarchical properites).

SELinux provides MLS support, and has a generic labeled networking framework ("xfrm labeling"). Some further work is needed for xfrm labeling to provide a complete MLS solution, which TCS and co have been working on.

The general idea is that we're working on new, inherently flexible security schemes for Linux, which will meet a wider range of requirements and be available as standard features of mainstream distros.

Support for interoperability with legacy CIPSO systems is something that I think would be nice to have, if it can be done in a way which doesn't impact deeply on core kernel code, and plays nicely with native Linux infrastructure.

- James

Signature · 2 lines
James Morris
<[email protected]>
author
#17 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 6 lines · James Morris

Support for interoperability with legacy CIPSO systems is something that I think would be nice to have, if it can be done in a way which doesn't impact deeply on core kernel code, and plays nicely with native Linux infrastructure.

I'm not sure if you have had a chance to look at the new patch set yet but I know you have seen earlier versions and are at least familiar with the approach I am taking ... in your opinion is the NetLabel patch acceptable in its approach?

Signature · 2 lines
paul moore
linux security @ hp
maintainer
#18 lore raw

Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 8 lines · Paul Moore
Quoted 6 lines · James Morris

Support for interoperability with legacy CIPSO systems is something that I think would be nice to have, if it can be done in a way which doesn't impact deeply on core kernel code, and plays nicely with native Linux infrastructure.

Quoted 4 lines

I'm not sure if you have had a chance to look at the new patch set yet but I know you have seen earlier versions and are at least familiar with the approach I am taking ... in your opinion is the NetLabel patch acceptable in its approach?

The approach basically seems ok, although the priority needs to be on getting the native xfrm labeling stuff implemented correctly first before really thinking about adding support for legacy schemes.

Here's a possible architectural strategy for all of this:

1. Generic xfrm labeling

2. General MLS infrastructure

3. MLS enhanchements to xfrm labeling

4. CIPSO/RIPSO infrastructure

5. HP and PitBull CIPSO implementations

We have (1) and TCS are working on (3).

(2) would include various intra-kernel and userland API support for any common MLS requirements across MLS xfrm labeling and CIPSO schemes. Also, I'm not sure how network namespaces might or might not play into this.

There's also the question of if/how secmark labeling might be used in conjunction with these distributed labeling schemes.

Also, the unresolved issue of whether to support CIPSO at all.

Even if the approach is technically acceptable, there's the issue of maintaining a lot of complicated code in mainline for a very narrow userbase to talk to near-obsolete legacy systems.

- James

Signature · 2 lines
James Morris
<[email protected]>
#19 lore raw

Re: [redhat-lspp] Re: [RFC 3/7] NetLabel: CIPSOv4 engine

In reply to David Miller
Quoted 14 lines · David Miller

From: [email protected]
Date: Wed, 21 Jun 2006 15:42:38 -0400

Quoted 6 lines

Add support for the Commercial IP Security Option (CIPSO) to the IPv4 network stack. CIPSO has become a de-facto standard for trusted/labeled networking amongst existing Trusted Operating Systems such as Trusted Solaris, HP-UX CMW, etc. This implementation is designed to be used with the NetLabel subsystem to provide explicit packet labeling to LSM developers.

The thing that concerns me most about CIPSO is that even once users migrate to a more SELINUX native approach from this CIPSO stuff, the CIPSO code, it's bloat, and it's maintainence burdon will remain.

Quoted 8 lines

It's easy to put stuff it, it's impossible to take stuff out even once it's largely unused by even it's original target audience.

And that's what I see happening here.

This is why, to be perfectly honest with you, I'd much rather something like this stay out-of-tree and people are strongly encouraged to use the more native stuff under Linux.

We are looking to replace a number of 20-60 node CMW networks with lots of applications with an SELinux based network. Since mainstream support for multilevel X Windows appears a ways off, we are looking to replace the servers first and use the current CMWs as fat clients. To make this work we need multilevel networking interoperability between the SELinux and CMW systems.

We have been testing Paul's CIPSO patch against our existing systems with good results.

For all of the EAL4 LSPP Linux evaluation work is being done by Red Hat/IBM/HP/atsec and others to be useful to integrators, there has to be basic (e.g. CIPSO) multilevel network interoperability with existing multilevel systems and good (e.g IPSec) multilevel networking between SELinux systems. Without that support, it will be like some early Microsoft evaluations (1,2) that were reported to have been done 'without a network card', a piece of paper describing the test of a brick.

joe

(1) http://support.novell.com/techcenter/articles/ana19970705.html (search for 'without')
(2) http://www.aaxnet.com/design/msanti.html (search for 'did not have a network card')

maintainer
#20 lore raw

Re: [redhat-lspp] Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 4 lines · Joe Nall

For all of the EAL4 LSPP Linux evaluation work is being done by Red Hat/IBM/HP/atsec and others to be useful to integrators, there has to be basic (e.g. CIPSO) multilevel network interoperability with existing multilevel systems and good (e.g IPSec) multilevel networking between SELinux systems.

Just to be clear, my understanding is that the native xfrm labeling is suitable for LSPP evaluation, as distinct from CIPSO being desired by system integrators from an interoperability point of view.

- James

Signature · 2 lines
James Morris
<[email protected]>
author
#21 lore raw

Re: [redhat-lspp] Re: [RFC 3/7] NetLabel: CIPSOv4 engine

Quoted 11 lines · James Morris
Quoted 5 lines · Joe Nall

For all of the EAL4 LSPP Linux evaluation work is being done by Red Hat/IBM/HP/atsec and others to be useful to integrators, there has to be basic (e.g. CIPSO) multilevel network interoperability with existing multilevel systems and good (e.g IPSec) multilevel networking between SELinux systems.

Just to be clear, my understanding is that the native xfrm labeling is suitable for LSPP evaluation, as distinct from CIPSO being desired by system integrators from an interoperability point of view.

True, but I believe the point Joe was trying to make was that providing support for only one labeling mechanism would limit the usefulness of the evaluated configuration. What good is a Common Criteria evaluation if it doesn't contain the features that user's require?

Signature · 2 lines
paul moore
linux security @ hp
#22 lore raw

Re: Re: [RFC 3/7] NetLabel: CIPSOv4 engine

In reply to James Morris
Quoted 9 lines · James Morris
Quoted 4 lines · Joe Nall

For all of the EAL4 LSPP Linux evaluation work is being done by Red Hat/IBM/HP/atsec and others to be useful to integrators, there has to be basic (e.g. CIPSO) multilevel network interoperability with existing multilevel systems and good (e.g IPSec) multilevel networking between SELinux systems.

Just to be clear, my understanding is that the native xfrm labeling is suitable for LSPP evaluation, as distinct from CIPSO being desired by system integrators from an interoperability point of view.

It's not quite that distinct, the two solutions overlap in some areas but neither can replace the other.

CIPSO would also be suitable for LSPP evaluation since it is capable of exporting and importing labeled data. It requires a trusted network since it doesn't encrypt or authenticate, so the evaluation would need to restrict the environment accordingly.

The native IPSEC/xfrm approach is useful for more hostile environments where you can't fully trust the network, but it's not interoperable with existing deployed systems so it's not a replacement for CIPSO.

Quoted 1 line

From an evaluation point of view, either CIPSO or IPSEC/xfrm would be

able to meet LSPP requirements but with different restrictions on the environment.

-Klaus

#23 lore raw

RFC 4/7 NetLabel: core NetLabel subsystem

In reply to [email protected]

Add a new kernel subsystem, NetLabel, to provide explicit packet labeling services (CIPSO, RIPSO, etc.) to LSM developers. NetLabel is designed to work in conjunction with a LSM to intercept and decode security labels on incoming network packets as well as ensure that outgoing network packets are labeled according to the security mechanism employed by the LSM. The NetLabel subsystem is configured through a NETLINK interface described in the header files included in this patch.

---
 include/net/netlabel.h             |  434 +++++++++++++++++++++++
 net/Kconfig                        |    2 
 net/Makefile                       |    3 
 net/netlabel/Kconfig               |   47 ++
 net/netlabel/Makefile              |   19 +
 net/netlabel/netlabel_domainhash.c |  629 +++++++++++++++++++++++++++++++++
 net/netlabel/netlabel_domainhash.h |   64 +++
 net/netlabel/netlabel_kapi.c       |  392 +++++++++++++++++++++
 net/netlabel/netlabel_mgmt.c       |  689 +++++++++++++++++++++++++++++++++++++
 net/netlabel/netlabel_mgmt.h       |  248 +++++++++++++
 net/netlabel/netlabel_user.c       |  162 ++++++++
 net/netlabel/netlabel_user.h       |   67 +++
 12 files changed, 2756 insertions(+)
include/net/netlabel.h new file +434 -0
Index: linux-2.6.17.i686-quilt/include/net/netlabel.h
===================================================================
@@ -0,0 +1,434 @@
+/*
+ * NetLabel System
+ *
+ * The NetLabel system manages static and dynamic label mappings for network
+ * protocols such as CIPSO and RIPSO.
+ *
+ * Author: Paul Moore <[email protected]>
+ *
+ */
+
+/*
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
+ *
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _NETLABEL_H
+#define _NETLABEL_H
+
+#include <linux/types.h>
+#include <linux/skbuff.h>
+#include <net/netlink.h>
+
+/*
+ * NetLabel - A management interface for maintaining network packet label
+ *            mapping tables for explicit packet labling protocols.
+ *
+ * Network protocols such as CIPSO and RIPSO require a label translation layer
+ * to convert the label on the packet into something meaningful on the host
+ * machine.  In the current Linux implementation these mapping tables live
+ * inside the kernel; NetLabel provides a mechanism for user space applications
+ * to manage these mapping tables.
+ *
+ * NetLabel makes use of NETLINK as a transport layer to send messages between
+ * kernel and user space.  The general format of a NetLabel message is shown
+ * below:
+ *
+ *  +----------+------------------+--------- --- -- -
+ *  | nlmsghdr | subsystem header | payload
+ *  +----------+------------------+--------- --- -- -
+ *
+ * The 'nlmsghdr' struct should be dealt with like any other NETLINK 'nlmsghdr'
+ * struct.  The subsystem header structure is dependent on the subsystem
+ * specified in the 'nlmsghdr->nlmsg_type' and should be defined below,
+ * supporting functions should be defined in the corresponding
+ * net/netlabel/netlabel_<subsys>.h|c file.
+ *
+ */
+
+/*
+ * NetLabel NETLINK protocol
+ */
+
+#define NETLBL_PROTO_VERSION        1
+
+/* NetLabel NETLINK groups */
+#define NETLBL_NLGRP_NONE           0x00000000
+#define NETLBL_NLGRP_MAX            0x00000000
+
+/* NetLabel NETLINK types */
+#define NETLBL_NLTYPE_NONE          0
+#define NETLBL_NLTYPE_MGMT          1
+#define NETLBL_NLTYPE_RIPSO         2
+#define NETLBL_NLTYPE_CIPSOV4       3
+#define NETLBL_NLTYPE_CIPSOV6       4
+#define NETLBL_NLTYPE_UNLABELED     5
+
+/* NetLabel return codes */
+#define NETLBL_E_OK                 0
+
+/*
+ * Helper functions
+ */
+
+/**
+ * netlbl_put_u8 - Write a u8 value into a buffer
+ * @buffer: the buffer
+ * @val: the value
+ *
+ * Description:
+ * Write the value specified in @val into the buffer specified by @buffer.
+ *
+ */
+static inline void netlbl_put_u8(unsigned char *buffer, const u8 val)
+{
+	*(u8 *)buffer = val;
+}
+
+/**
+ * netlbl_put_u32 - Write a u32 value into a buffer
+ * @buffer: the buffer
+ * @val: the value
+ *
+ * Description:
+ * Write the value specified in @val into the buffer specified by @buffer.
+ *
+ */
+static inline void netlbl_put_u32(unsigned char *buffer, const u32 val)
+{
+	*(u32 *)buffer = val;
+}
+
+/**
+ * netlbl_put_str - Write a string into a buffer
+ * @buffer: the buffer
+ * @val: the string
+ *
+ * Description:
+ * Write the string specified in @val into the buffer specified by @buffer.
+ *
+ */
+static inline void netlbl_put_str(unsigned char *buffer, const char *val)
+{
+	strcpy((char *)buffer, val);
+}
+
+/**
+ * netlbl_put_hdr - Write a NETLINK header into a buffer
+ * @buffer: the buffer
+ * @msg_type: the NETLINK message type
+ * @msg_len: the NETLINK message length
+ * @msg_flags: the NETLINK message flags
+ * @msg_pid: the NETLINK message PID
+ * @msg_seq: the NETLINK message sequence number
+ *
+ * Description:
+ * Use the given values to write a NETLINK header into the given buffer.
+ *
+ */
+static inline void netlbl_put_hdr(unsigned char *buffer,
+				  const u32 msg_type,
+				  const u16 msg_len,
+				  const u16 msg_flags,
+				  const u32 msg_pid,
+				  const u32 msg_seq)
+{
+	struct nlmsghdr *hdr = (struct nlmsghdr *)buffer;
+	hdr->nlmsg_len = msg_len;
+	hdr->nlmsg_type = msg_type;
+	hdr->nlmsg_flags = msg_flags;
+	hdr->nlmsg_seq = msg_seq;
+	hdr->nlmsg_pid = msg_pid;
+}
+
+/**
+ * netlbl_put_u8 - Write a u8 value into a buffer and increment the buffer
+ * @buffer: the buffer
+ * @val: the value
+ *
+ * Description:
+ * Write the value specified in @val into the buffer specified by @buffer
+ * and advance the buffer pointer past the newly written value.
+ *
+ */
+static inline void netlbl_putinc_u8(unsigned char **buffer, const u8 val)
+{
+	netlbl_put_u8(*buffer, val);
+	*buffer += sizeof(u8);
+}
+
+/**
+ * netlbl_put_u32 - Write a u32 value into a buffer and increment the buffer
+ * @buffer: the buffer
+ * @val: the value
+ *
+ * Description:
+ * Write the value specified in @val into the buffer specified by @buffer
+ * and advance the buffer pointer past the newly written value.
+ *
+ */
+static inline void netlbl_putinc_u32(unsigned char **buffer, const u32 val)
+{
+	netlbl_put_u32(*buffer, val);
+	*buffer += sizeof(u32);
+}
+
+/**
+ * netlbl_put_u8 - Write a string into a buffer and increment the buffer
+ * @buffer: the buffer
+ * @val: the value
+ *
+ * Description:
+ * Write the string specified in @val into the buffer specified by @buffer
+ * and advance the buffer pointer past the newly written value.
+ *
+ */
+static inline void netlbl_putinc_str(unsigned char **buffer, const char *val)
+{
+	netlbl_put_str(*buffer, val);
+	*buffer += strlen(val) + 1;
+}
+
+/**
+ * netlbl_put_hdr - Write a NETLINK header into a buffer and increment the ptr
+ * @buffer: the buffer
+ * @msg_type: the NETLINK message type
+ * @msg_len: the NETLINK message length
+ * @msg_flags: the NETLINK message flags
+ * @msg_pid: the NETLINK message PID
+ * @msg_seq: the NETLINK message sequence number
+ *
+ * Description:
+ * Use the given values to write a NETLINK header into the given buffer and
+ * then increment the buffer pointer past the header.
+ *
+ */
+static inline void netlbl_putinc_hdr(unsigned char **buffer,
+				     const u32 msg_type,
+				     const u16 msg_len,
+				     const u16 msg_flags,
+				     const u32 msg_pid,
+				     const u32 msg_seq)
+{
+	netlbl_put_hdr(*buffer,
+		       msg_type,
+		       msg_len,
+		       msg_flags,
+		       msg_pid,
+		       msg_seq);
+	*buffer += NLMSG_HDRLEN;
+}
+
+/**
+ * netlbl_get_u8 - Read a u8 value from a buffer
+ * @buffer: the buffer
+ *
+ * Description:
+ * Return a u8 value pointed to by @buffer.
+ *
+ */
+static inline u8 netlbl_get_u8(const unsigned char *buffer)
+{
+	return *(u8 *)buffer;
+}
+
+/**
+ * netlbl_get_u32 - Read a u32 value from a buffer
+ * @buffer: the buffer
+ *
+ * Description:
+ * Return a u8 value pointed to by @buffer.
+ *
+ */
+static inline u32 netlbl_get_u32(const unsigned char *buffer)
+{
+	return *(u32 *)buffer;
+}
+
+/**
+ * netlbl_getinc_u8 - Read a u8 value from a buffer and increment the buffer
+ * @buffer: the buffer
+ *
+ * Description:
+ * Return a u8 value pointed to by @buffer and increment the buffer pointer
+ * past the value.
+ *
+ */
+static inline u8 netlbl_getinc_u8(unsigned char **buffer)
+{
+	u8 val = netlbl_get_u8(*buffer);
+	*buffer += sizeof(u8);
+	return val;
+}
+
+/**
+ * netlbl_getinc_u32 - Read a u32 value from a buffer and increment the buffer
+ * @buffer: the buffer
+ *
+ * Description:
+ * Return a u32 value pointed to by @buffer and increment the buffer pointer
+ * past the value.
+ *
+ */
+static inline u32 netlbl_getinc_u32(unsigned char **buffer)
+{
+	u32 val = netlbl_get_u32(*buffer);
+	*buffer += sizeof(u32);
+	return val;
+}
+
+/*
+ * NetLabel - Kernel API for accessing the network packet label mappings.
+ *
+ * The following functions are provided for use by other kernel modules,
+ * specifically kernel LSM modules, to provide a consistent, transparent API
+ * for dealing with explicit packet labeling protocols such as CIPSO and
+ * RIPSO.  The functions defined here are implemented in the
+ * net/netlabel/netlabel_kapi.c file.
+ *
+ */
+
+/* Domain mapping definition struct */
+struct netlbl_dom_map;
+
+/* Domain mapping operations */
+int netlbl_domhsh_remove(const char *domain);
+
+/* LSM security attributes */
+struct netlbl_lsm_cache {
+	void (*free) (const void *data);
+	void *data;
+};
+struct netlbl_lsm_secattr {
+	char *domain;
+
+	u32 mls_lvl;
+	unsigned char *mls_cat;
+	u32 mls_cat_len;
+
+	struct netlbl_lsm_cache cache;
+
+	u32 set_domain:1,
+	    set_mls_lvl:1,
+	    set_mls_cat:1,
+	    set_cache:1,
+	    __unused:28;
+};
+
+/* LSM security attribute operations */
+
+/**
+ * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct
+ * @flags: the memory allocation flags
+ *
+ * Description:
+ * Allocate and initialize a netlbl_lsm_secattr struct.  Returns a valid
+ * pointer on success, or NULL on failure.
+ *
+ */
+static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(const int flags)
+{
+	return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
+}
+
+/**
+ * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct
+ * @secattr: the struct to free
+ *
+ * Description:
+ * Frees @secattr including all of the internal buffers.
+ *
+ */
+static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
+{
+	BUG_ON(secattr == NULL);
+	if (secattr->set_domain)
+		kfree(secattr->domain);
+	if (secattr->set_mls_cat)
+		kfree(secattr->mls_cat);
+	if (secattr->set_cache && secattr->cache.free)
+		secattr->cache.free(secattr->cache.data);
+	kfree(secattr);
+}
+
+/**
+ * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct
+ * @secattr: the struct to initialize
+ *
+ * Description:
+ * Initialize an already allocated netlbl_lsm_secattr struct.  Returns zero on
+ * success, negative values on error.
+ *
+ */
+static inline int netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
+{
+	BUG_ON(secattr == NULL);
+	memset(secattr, 0, sizeof(*secattr));
+	return 0;
+}
+
+/**
+ * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct
+ * @secattr: the struct to clear
+ *
+ * Description:
+ * Destroys the @secattr struct, including freeing all of the internal buffers.
+ * On return the struct is suitable for reuse.
+ *
+ */
+static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr)
+{
+	BUG_ON(secattr == NULL);
+	if (secattr->set_domain)
+		kfree(secattr->domain);
+	if (secattr->set_mls_cat)
+		kfree(secattr->mls_cat);
+	if (secattr->set_cache && secattr->cache.free)
+		secattr->cache.free(secattr->cache.data);
+	memset(secattr, 0, sizeof(*secattr));
+}
+
+/* LSM protocol operations */
+
+int netlbl_socket_setattr(const struct socket *sock,
+			  const struct netlbl_lsm_secattr *secattr);
+int netlbl_socket_peekattr(const struct socket *sock,
+			   struct netlbl_lsm_secattr *secattr);
+int netlbl_socket_getattr(const struct socket *sock,
+			  struct netlbl_lsm_secattr *secattr);
+int netlbl_skbuff_getattr(const struct sk_buff *skb,
+			  struct netlbl_lsm_secattr *secattr);
+int netlbl_skbuff_err(struct sk_buff *skb, int error);
+
+/* LSM label mapping cache operations */
+void netlbl_cache_invalidate(void);
+int netlbl_cache_add(const struct sk_buff *skb,
+		     const struct netlbl_lsm_secattr *secattr);
+
+/* Network stack operations */
+
+#ifdef CONFIG_NETLABEL
+void netlbl_socket_inet_accept(struct socket *sock, struct socket *newsock);
+#else
+static inline void netlbl_socket_inet_accept(struct socket *sock,
+					     struct socket *newsock)
+{
+	return;
+}
+#endif
+
+#endif /* _NETLABEL_H */
net/Kconfig +2 -0
Index: linux-2.6.17.i686-quilt/net/Kconfig
===================================================================
@@ -228,6 +228,8 @@ source "net/tux/Kconfig"
 config WIRELESS_EXT
 	bool
 
+source "net/netlabel/Kconfig"
+
 endif   # if NET
 endmenu # Networking
 
net/Makefile +3 -0
Index: linux-2.6.17.i686-quilt/net/Makefile
===================================================================
@@ -47,6 +47,9 @@ obj-$(CONFIG_IP_DCCP)		+= dccp/
 obj-$(CONFIG_IP_SCTP)		+= sctp/
 obj-$(CONFIG_IEEE80211)		+= ieee80211/
 obj-$(CONFIG_TIPC)		+= tipc/
+ifeq ($(CONFIG_NETLABEL),y)
+obj-y				+= netlabel/
+endif
 
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o
net/netlabel/Kconfig new file +47 -0

47 lines not on this page · raw message

net/netlabel/Makefile new file +19 -0
Index: linux-2.6.17.i686-quilt/net/netlabel/Makefile
===================================================================
@@ -0,0 +1,19 @@
+#
+# Makefile for the NetLabel subsystem.
+#
+# Feb 9, 2006, Paul Moore <[email protected]>
+#
+
+# base objects
+obj-y	:= netlabel_user.o netlabel_kapi.o netlabel_domainhash.o
+
+# management objects
+obj-y	+= netlabel_mgmt.o
+
+# protocol modules
+ifeq ($(CONFIG_NETLABEL_UNLABELED),y)
+obj-y	+= netlabel_unlabeled.o
+endif
+ifeq ($(CONFIG_NETLABEL_CIPSOV4),y)
+obj-y	+= netlabel_cipso_v4.o
+endif
net/netlabel/netlabel_domainhash.c new file +629 -0

629 lines not on this page · raw message

net/netlabel/netlabel_domainhash.h new file +64 -0

64 lines not on this page · raw message

net/netlabel/netlabel_kapi.c new file +392 -0

392 lines not on this page · raw message

net/netlabel/netlabel_mgmt.c new file +689 -0

689 lines not on this page · raw message

net/netlabel/netlabel_mgmt.h new file +248 -0

248 lines not on this page · raw message

net/netlabel/netlabel_user.c new file +162 -0

162 lines not on this page · raw message

net/netlabel/netlabel_user.h new file +67 -0

67 lines not on this page · raw message

--
paul moore
linux security @ hp

#24 lore raw

Re: [RFC 4/7] NetLabel: core NetLabel subsystem

Quoted 7 lines · On Wednesday 21 June 2006 15:42, [email protected] wrote:

Add a new kernel subsystem, NetLabel, to provide explicit packet labeling services (CIPSO, RIPSO, etc.) to LSM developers. NetLabel is designed to work in conjunction with a LSM to intercept and decode security labels on incoming network packets as well as ensure that outgoing network packets are labeled according to the security mechanism employed by the LSM. The NetLabel subsystem is configured through a NETLINK interface described in the header files included in this patch.

This patch doesn't build. It fails like this:

netlbl_netlink_exit' referenced in section .init.text' of net/built-in.o:
defined in discarded section .exit.text' of net/built-in.o netlbl_domhsh_exit' referenced in section `.init.text' of net/built-in.o:
defined in discarded section `.exit.text' of net/built-in.o

I deleted the __exit and __init for now so that the build procedes. But this needs to get fixed in next iteration.

Thanks,
-Steve

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

author
#25 lore raw

Re: [redhat-lspp] Re: [RFC 4/7] NetLabel: core NetLabel subsystem

Quoted 12 lines · Steve Grubb
Quoted 7 lines · On Wednesday 21 June 2006 15:42, [email protected] wrote:

Add a new kernel subsystem, NetLabel, to provide explicit packet labeling services (CIPSO, RIPSO, etc.) to LSM developers. NetLabel is designed to work in conjunction with a LSM to intercept and decode security labels on incoming network packets as well as ensure that outgoing network packets are labeled according to the security mechanism employed by the LSM. The NetLabel subsystem is configured through a NETLINK interface described in the header files included in this patch.

This patch doesn't build. It fails like this:

Quoted 7 lines

netlbl_netlink_exit' referenced in section .init.text' of net/built-in.o:
defined in discarded section .exit.text' of net/built-in.o netlbl_domhsh_exit' referenced in section `.init.text' of net/built-in.o:
defined in discarded section `.exit.text' of net/built-in.o

I deleted the __exit and __init for now so that the build procedes. But this needs to get fixed in next iteration.

I removed them from the *.c files but it looks like I forget to remove them from the *.h files. Sorry.

I'm still very confused as to why I never see these build errors, yet you do - can you tell me what compiler version you are using?

Signature · 7 lines
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#26 lore raw

Re: [redhat-lspp] Re: [RFC 4/7] NetLabel: core NetLabel subsystem

Quoted 2 lines · Paul Moore

I'm still very confused as to why I never see these build errors, yet you do - can you tell me what compiler version you are using?

gcc-4.1.1-5. I'm also building via rpmbuild fwiw.

-Steve

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#27 lore raw

RFC 5/7 NetLabel: SELinux support

In reply to [email protected]

Add NetLabel support to the SELinux LSM. The most significant part of this patch is the addition of NetLabel hooks into the following SELinux LSM hooks:

* selinux_file_permission()
* selinux_socket_sendmsg()
* selinux_socket_post_create()
* selinux_socket_post_accept() [NEW]
* selinux_socket_sock_rcv_skb()
* selinux_socket_getpeersec_stream()
* selinux_socket_getpeersec_dgram()

The basic reasoning behind this patch is that outgoing packets are "NetLabel'd" by labeling their socket and the NetLabel security attributes are checked via the additional hook in selinux_socket_sock_rcv_skb(). NetLabel itself is only a labeling mechanism, similar to filesystem extended attributes, it is up to the SELinux enforcement mechanism to perform the actual access checks.

In addition to the changes outlined above this patch also includes some changes to the extended bitmap (ebitmap) and multi-level security (mls) code to import and export SELinux TE/MLS attributes into and out of NetLabel.

---
 security/selinux/hooks.c                     |   59 ++
 security/selinux/include/av_inherit.h        |    1 
 security/selinux/include/av_perm_to_string.h |    1 
 security/selinux/include/av_permissions.h    |    1 
 security/selinux/include/flask.h             |    1 
 security/selinux/include/objsec.h            |   11 
 security/selinux/include/security.h          |    2 
 security/selinux/include/selinux_netlabel.h  |   94 ++++
 security/selinux/nlmsgtab.c                  |   15 
 security/selinux/ss/Makefile                 |    3 
 security/selinux/ss/ebitmap.c                |  155 +++++++
 security/selinux/ss/ebitmap.h                |    6 
 security/selinux/ss/mls.c                    |  160 +++++++
 security/selinux/ss/mls.h                    |   25 +
 security/selinux/ss/selinux_netlabel.c       |  574 +++++++++++++++++++++++++++
 security/selinux/ss/services.c               |   12 
 security/selinux/ss/services.h               |    2 
 17 files changed, 1109 insertions(+), 13 deletions(-)
security/selinux/hooks.c +47 -12
Index: linux-2.6.17.i686-quilt/security/selinux/hooks.c
===================================================================
@@ -12,6 +12,8 @@
  *  Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]>
  *  Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  *                          <[email protected]>
+ *  Copyright (C) 2006 Hewlett-Packard Development Company, L.P.
+ *                     Paul Moore, <[email protected]>
  *
  *	This program is free software; you can redistribute it and/or modify
  *	it under the terms of the GNU General Public License version 2,
@@ -74,6 +76,7 @@
 #include "objsec.h"
 #include "netif.h"
 #include "xfrm.h"
+#include "selinux_netlabel.h"
 
 #define XATTR_SELINUX_SUFFIX "selinux"
 #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
@@ -2293,6 +2296,7 @@ static int selinux_inode_listsecurity(st
 
 static int selinux_file_permission(struct file *file, int mask)
 {
+	int rc;
 	struct inode *inode = file->f_dentry->d_inode;
 
 	if (!mask) {
@@ -2304,8 +2308,12 @@ static int selinux_file_permission(struc
 	if ((file->f_flags & O_APPEND) && (mask & MAY_WRITE))
 		mask |= MAY_APPEND;
 
-	return file_has_perm(current, file,
-			     file_mask_to_av(inode->i_mode, mask));
+	rc = file_has_perm(current, file,
+			   file_mask_to_av(inode->i_mode, mask));
+	if (rc)
+		return rc;
+
+	return selinux_netlbl_inode_permission(inode, mask);
 }
 
 static int selinux_file_alloc_security(struct file *file)
@@ -2922,8 +2930,8 @@ out:
 	return err;
 }
 
-static void selinux_socket_post_create(struct socket *sock, int family,
-				       int type, int protocol, int kern)
+static int selinux_socket_post_create(struct socket *sock, int family,
+				      int type, int protocol, int kern)
 {
 	struct inode_security_struct *isec;
 	struct task_security_struct *tsec;
@@ -2935,7 +2943,7 @@ static void selinux_socket_post_create(s
 	isec->sid = kern ? SECINITSID_KERNEL : tsec->sid;
 	isec->initialized = 1;
 
-	return;
+	return selinux_netlbl_socket_create(sock, family, isec->sid);
 }
 
 /* Range of port numbers used to automatically bind.
@@ -3113,10 +3121,24 @@ static int selinux_socket_accept(struct 
 	return 0;
 }
 
+#ifdef CONFIG_NETLABEL
+static void selinux_socket_post_accept(struct socket *sock,
+				       struct socket *newsock)
+{
+	selinux_netlbl_socket_accept(sock, newsock);
+}
+#endif /* CONFIG_NETLABEL */
+
 static int selinux_socket_sendmsg(struct socket *sock, struct msghdr *msg,
  				  int size)
 {
-	return socket_has_perm(current, sock, SOCKET__WRITE);
+	int rc;
+
+	rc = socket_has_perm(current, sock, SOCKET__WRITE);
+	if (rc)
+		return rc;
+
+	return selinux_netlbl_inode_permission(SOCK_INODE(sock), MAY_WRITE);
 }
 
 static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,
@@ -3306,10 +3328,15 @@ static int selinux_socket_sock_rcv_skb(s
 
 		err = avc_has_perm(sock_sid, port_sid,
 				   sock_class, recv_perm, &ad);
+		if (err)
+			goto out;
 	}
 
-	if (!err)
-		err = selinux_xfrm_sock_rcv_skb(sock_sid, skb);
+	err = selinux_netlbl_sock_rcv_skb(sock_class, sock_sid, skb, &ad);
+	if (err)
+		goto out;
+
+	err = selinux_xfrm_sock_rcv_skb(sock_sid, skb);
 
 out:	
 	return err;
@@ -3333,8 +3360,9 @@ static int selinux_socket_getpeersec_str
 		peer_sid = ssec->peer_sid;
 	}
 	else if (isec->sclass == SECCLASS_TCP_SOCKET) {
-		peer_sid = selinux_socket_getpeer_stream(sock->sk);
-
+		err = selinux_netlbl_socket_getpeersec_stream(sock, &peer_sid);
+		if (err || peer_sid == SECSID_NULL)
+			peer_sid = selinux_socket_getpeer_stream(sock->sk);
 		if (peer_sid == SECSID_NULL) {
 			err = -ENOPROTOOPT;
 			goto out;
@@ -3369,8 +3397,12 @@ out:	
 
 static int selinux_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata, u32 *seclen)
 {
-	int err = 0;
-	u32 peer_sid = selinux_socket_getpeer_dgram(skb);
+	int err;
+	u32 peer_sid;
+
+	err = selinux_netlbl_socket_getpeersec_dgram(skb, &peer_sid);
+	if (err || peer_sid == SECSID_NULL)
+		peer_sid = selinux_socket_getpeer_dgram(skb);
 
 	if (peer_sid == SECSID_NULL)
 		return -EINVAL;
@@ -4353,6 +4385,9 @@ static struct security_operations selinu
 	.socket_connect =		selinux_socket_connect,
 	.socket_listen =		selinux_socket_listen,
 	.socket_accept =		selinux_socket_accept,
+#ifdef CONFIG_NETLABEL
+	.socket_post_accept =		selinux_socket_post_accept,
+#endif
 	.socket_sendmsg =		selinux_socket_sendmsg,
 	.socket_recvmsg =		selinux_socket_recvmsg,
 	.socket_getsockname =		selinux_socket_getsockname,
security/selinux/include/av_inherit.h +1 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/av_inherit.h
===================================================================
@@ -29,3 +29,4 @@
    S_(SECCLASS_NETLINK_IP6FW_SOCKET, socket, 0x00400000UL)
    S_(SECCLASS_NETLINK_DNRT_SOCKET, socket, 0x00400000UL)
    S_(SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET, socket, 0x00400000UL)
+   S_(SECCLASS_NETLINK_NETLABEL_SOCKET, socket, 0x00400000UL)
security/selinux/include/av_perm_to_string.h +1 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/av_perm_to_string.h
===================================================================
@@ -239,3 +239,4 @@
    S_(SECCLASS_ASSOCIATION, ASSOCIATION__SENDTO, "sendto")
    S_(SECCLASS_ASSOCIATION, ASSOCIATION__RECVFROM, "recvfrom")
    S_(SECCLASS_ASSOCIATION, ASSOCIATION__SETCONTEXT, "setcontext")
+   S_(SECCLASS_NETLINK_NETLABEL_SOCKET, NETLINK_NETLABEL_SOCKET__NLMSG_WRITE, "nlmsg_write")
security/selinux/include/av_permissions.h +1 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/av_permissions.h
===================================================================
@@ -933,3 +933,4 @@
 #define NETLINK_KOBJECT_UEVENT_SOCKET__SEND_MSG   0x00100000UL
 #define NETLINK_KOBJECT_UEVENT_SOCKET__NAME_BIND  0x00200000UL
 
+#define NETLINK_NETLABEL_SOCKET__NLMSG_WRITE      0x00000001UL
security/selinux/include/flask.h +1 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/flask.h
===================================================================
@@ -60,6 +60,7 @@
 #define SECCLASS_NSCD                                    53
 #define SECCLASS_ASSOCIATION                             54
 #define SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET           55
+#define SECCLASS_NETLINK_NETLABEL_SOCKET                 56
 
 /*
  * Security identifier indices for initial entities
security/selinux/include/objsec.h +11 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/objsec.h
===================================================================
@@ -35,6 +35,14 @@ struct task_security_struct {
 	u32 ptrace_sid;      /* SID of ptrace parent */
 };
 
+struct netlbl_security_struct {
+	u32 netlbl_sid;           /* SID used to set the NetLabel */
+	u32 peer_sid;             /* SID of the connected peer */
+	u32 req_netlbl:1,         /* socket requires a NetLabel label */
+	    labeled:1,            /* socket is labeled with NetLabel */
+	    __unused:30;
+};
+
 struct inode_security_struct {
         struct inode *inode;           /* back pointer to inode object */
 	struct list_head list;         /* list of inode_security_struct */
@@ -44,6 +52,9 @@ struct inode_security_struct {
 	unsigned char initialized;     /* initialization flag */
 	struct semaphore sem;
 	unsigned char inherit;         /* inherit SID from parent entry */
+#ifdef CONFIG_NETLABEL
+	struct netlbl_security_struct netlbl;
+#endif
 };
 
 struct file_security_struct {
security/selinux/include/security.h +2 -0
Index: linux-2.6.17.i686-quilt/security/selinux/include/security.h
===================================================================
@@ -8,6 +8,8 @@
 #ifndef _SELINUX_SECURITY_H_
 #define _SELINUX_SECURITY_H_
 
+#include <linux/skbuff.h>
+
 #include "flask.h"
 
 #define SECSID_NULL			0x00000000 /* unspecified SID */
security/selinux/include/selinux_netlabel.h new file +94 -0

94 lines not on this page · raw message

security/selinux/nlmsgtab.c +15 -0
Index: linux-2.6.17.i686-quilt/security/selinux/nlmsgtab.c
===================================================================
@@ -19,6 +19,7 @@
 #include <linux/inet_diag.h>
 #include <linux/xfrm.h>
 #include <linux/audit.h>
+#include <net/netlabel.h>
 
 #include "flask.h"
 #include "av_permissions.h"
@@ -116,6 +117,15 @@ static struct nlmsg_perm nlmsg_audit_per
 	{ AUDIT_WATCH_LIST,	NETLINK_AUDIT_SOCKET__NLMSG_READPRIV },
 };
 
+static struct nlmsg_perm nlmsg_netlabel_perms[] =
+{
+	{ NETLBL_NLTYPE_NONE,        NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+	{ NETLBL_NLTYPE_MGMT,        NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+	{ NETLBL_NLTYPE_RIPSO,       NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+	{ NETLBL_NLTYPE_CIPSOV4,     NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+	{ NETLBL_NLTYPE_CIPSOV6,     NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+	{ NETLBL_NLTYPE_UNLABELED,   NETLINK_NETLABEL_SOCKET__NLMSG_WRITE },
+};
 
 static int nlmsg_perm(u16 nlmsg_type, u32 *perm, struct nlmsg_perm *tab, size_t tabsize)
 {
@@ -169,6 +179,11 @@ int selinux_nlmsg_lookup(u16 sclass, u16
 		}
 		break;
 
+	case SECCLASS_NETLINK_NETLABEL_SOCKET:
+		err = nlmsg_perm(nlmsg_type, perm, nlmsg_netlabel_perms,
+				 sizeof(nlmsg_netlabel_perms));
+		break;
+
 	/* No messaging from userspace, or class unknown/unhandled */
 	default:
 		err = -ENOENT;
security/selinux/ss/Makefile +3 -0
Index: linux-2.6.17.i686-quilt/security/selinux/ss/Makefile
===================================================================
@@ -7,3 +7,6 @@ obj-y := ss.o
 
 ss-y := ebitmap.o hashtab.o symtab.o sidtab.o avtab.o policydb.o services.o conditional.o mls.o
 
+ifeq ($(CONFIG_NETLABEL),y)
+obj-y += selinux_netlabel.o
+endif
security/selinux/ss/ebitmap.c +155 -0

167 lines not on this page · raw message

security/selinux/ss/ebitmap.h +6 -0
Index: linux-2.6.17.i686-quilt/security/selinux/ss/ebitmap.h
===================================================================
@@ -69,6 +69,12 @@ static inline int ebitmap_node_get_bit(s
 
 int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2);
 int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src);
+int ebitmap_export(const struct ebitmap *src,
+		   unsigned char **dst,
+		   u32 *dst_len);
+int ebitmap_import(const unsigned char *src,
+		   const u32 src_len,
+		   struct ebitmap *dst);
 int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2);
 int ebitmap_get_bit(struct ebitmap *e, unsigned long bit);
 int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value);
security/selinux/ss/mls.c +160 -0

169 lines not on this page · raw message

security/selinux/ss/mls.h +25 -0
Index: linux-2.6.17.i686-quilt/security/selinux/ss/mls.h
===================================================================
@@ -10,6 +10,13 @@
  *
  * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
  */
+/*
+ * Updated: Hewlett-Packard <[email protected]>
+ *
+ *      Added support to import/export the MLS label
+ *
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
+ */
 
 #ifndef _SS_MLS_H_
 #define _SS_MLS_H_
@@ -42,5 +49,23 @@ int mls_compute_sid(struct context *scon
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
                          struct context *usercon);
 
+int mls_export_lvl(const struct context *context,
+		   u32 *lvl_low,
+		   u32 *lvl_high);
+int mls_import_lvl(struct context *context,
+		   const u32 lvl_low,
+		   const u32 lvl_high);
+
+int mls_export_cat(const struct context *context,
+                   unsigned char **cat_low,
+                   u32 *cat_low_len,
+                   unsigned char **cat_high,
+                   u32 *cat_high_len);
+int mls_import_cat(struct context *context,
+                   const unsigned char *cat_low,
+                   const u32 cat_low_len,
+                   const unsigned char *cat_high,
+                   const u32 cat_high_len);
+
 #endif	/* _SS_MLS_H */
 
security/selinux/ss/selinux_netlabel.c new file +574 -0

574 lines not on this page · raw message

security/selinux/ss/services.c +11 -1
Index: linux-2.6.17.i686-quilt/security/selinux/ss/services.c
===================================================================
@@ -13,6 +13,11 @@
  *
  * 	Added conditional policy language extensions
  *
+ * Updated: Hewlett-Packard <[email protected]>
+ *
+ *      Added support for NetLabel
+ *
+ * Copyright (C) 2006 Hewlett-Packard Development Company, L.P.
  * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2004 Tresys Technology, LLC
  * Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]>
@@ -29,6 +34,7 @@
 #include <linux/sched.h>
 #include <linux/audit.h>
 #include <linux/mutex.h>
+#include <net/sock.h>
 
 #include "flask.h"
 #include "avc.h"
@@ -40,6 +46,8 @@
 #include "services.h"
 #include "conditional.h"
 #include "mls.h"
+#include "objsec.h"
+#include "selinux_netlabel.h"
 
 extern void selnl_notify_policyload(u32 seqno);
 unsigned int policydb_loaded_version;
@@ -54,7 +62,7 @@ static DEFINE_MUTEX(load_mutex);
 #define LOAD_LOCK mutex_lock(&load_mutex)
 #define LOAD_UNLOCK mutex_unlock(&load_mutex)
 
-static struct sidtab sidtab;
+struct sidtab sidtab;
 struct policydb policydb;
 int ss_initialized = 0;
 
@@ -1241,6 +1249,7 @@ int security_load_policy(void *data, siz
 		selinux_complete_init();
 		avc_ss_reset(seqno);
 		selnl_notify_policyload(seqno);
+		selinux_netlbl_cache_invalidate();
 		return 0;
 	}
 
@@ -1295,6 +1304,7 @@ int security_load_policy(void *data, siz
 
 	avc_ss_reset(seqno);
 	selnl_notify_policyload(seqno);
+	selinux_netlbl_cache_invalidate();
 
 	return 0;
 
security/selinux/ss/services.h +2 -0
Index: linux-2.6.17.i686-quilt/security/selinux/ss/services.h
===================================================================
@@ -9,7 +9,9 @@
 #include "policydb.h"
 #include "sidtab.h"
 
+extern struct sidtab sidtab;
 extern struct policydb policydb;
+extern int ss_initialized;
 
 #endif	/* _SS_SERVICES_H_ */
 

--
paul moore
linux security @ hp

#28 lore raw

RFC 6/7 NetLabel: CIPSOv4 integration

In reply to [email protected]

Add CIPSO/IPv4 support and management to the NetLabel subsystem. These changes integrate the CIPSO/IPv4 configuration into the existing NetLabel code and enable the use of CIPSO/IPv4 within the overall NetLabel framework.

---
 net/netlabel/netlabel_cipso_v4.c |  583 +++++++++++++++++++++++++++++++++++++++
 net/netlabel/netlabel_cipso_v4.h |  201 +++++++++++++
 2 files changed, 784 insertions(+)
net/netlabel/netlabel_cipso_v4.c new file +583 -0
Index: linux-2.6.17.i686-quilt/net/netlabel/netlabel_cipso_v4.c
===================================================================
@@ -0,0 +1,583 @@
+/*
+ * NetLabel CIPSO/IPv4 Support
+ *
+ * This file defines the CIPSO/IPv4 functions for the NetLabel system.  The
+ * NetLabel system manages static and dynamic label mappings for network
+ * protocols such as CIPSO and RIPSO.
+ *
+ * Author: Paul Moore <[email protected]>
+ *
+ */
+
+/*
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
+ *
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/socket.h>
+#include <linux/string.h>
+#include <linux/skbuff.h>
+#include <net/sock.h>
+#include <net/netlink.h>
+#include <net/netlabel.h>
+#include <net/cipso_ipv4.h>
+
+#include "netlabel_user.h"
+#include "netlabel_cipso_v4.h"
+
+/*
+ * Local Prototypes
+ */
+
+static void netlbl_cipsov4_send_ack(const struct sk_buff *req_skb,
+				    const u32 ret_code);
+
+/*
+ * Helper Functions
+ */
+
+/**
+ * netlbl_cipsov4_put_hdr - Write a CIPSO NetLabel header into a buffer
+ * @buffer: the buffer
+ * @opcode: the NetLabel CIPSOv4 opcode
+ * @doi: the CIPSO DOI value
+ *
+ * Description:
+ * Use the given values to write a NetLabel CIPSOv4 header into the given
+ * buffer.
+ *
+ */
+static void netlbl_cipsov4_put_hdr(unsigned char *buffer,
+				   const u32 opcode,
+				   const u32 doi)
+{
+	struct netlbl_cipsov4_msghdr *hdr =
+		(struct netlbl_cipsov4_msghdr *)buffer;
+	hdr->opcode = opcode;
+	hdr->doi = doi;
+}
+
+/**
+ * netlbl_cipsov4_putinc_hdr - Write a CIPSO NetLabel header into a buffer
+ * @buffer: the buffer
+ * @opcode: the NetLabel CIPSOv4 opcode
+ * @doi: the CIPSO DOI value
+ *
+ * Description:
+ * Use the given values to write a NetLabel CIPSOv4 header into the given
+ * buffer and increment the buffer pointer past the header.
+ *
+ */
+static void netlbl_cipsov4_putinc_hdr(unsigned char **buffer,
+				      const u32 opcode,
+				      const u32 doi)
+{
+	netlbl_cipsov4_put_hdr(*buffer, opcode, doi);
+	*buffer += sizeof(struct netlbl_cipsov4_msghdr);
+}
+
+/**
+ * netlbl_cipsov4_payload_len - Return the length of the payload
+ * @skb: the NETLINK buffer
+ *
+ * Description:
+ * This function returns the length of the CIPSO V4 NetLabel payload.
+ *
+ */
+static u32 netlbl_cipsov4_payload_len(const struct sk_buff *skb)
+{
+	const struct nlmsghdr *nl_hdr = (struct nlmsghdr *)skb->data;
+
+	if (nlmsg_len(nl_hdr) <= sizeof(struct netlbl_cipsov4_msghdr))
+		return 0;
+	return nlmsg_len(nl_hdr) - sizeof(struct netlbl_cipsov4_msghdr);
+}
+
+/**
+ * netlbl_cipsov4_payload_data - Returns a pointer to the start of the data
+ * @skb: the NETLINK buffer
+ *
+ * Description:
+ * This function returns a pointer to the start of the CIPSO V4 NetLabel
+ * payload.
+ *
+ */
+static unsigned char *netlbl_cipsov4_payload_data(const struct sk_buff *skb)
+{
+	return nlmsg_data((struct nlmsghdr *)skb->data) +
+		sizeof(struct netlbl_cipsov4_msghdr);
+}
+
+/**
+ * netlbl_cipsov4_doi_free - Frees a CIPSO V4 DOI definition
+ * @entry: the entry's RCU field
+ *
+ * Description:
+ * This function is designed to be used as a callback to the call_rcu()
+ * function so that the memory allocated to the DOI definition can be released
+ * safely.
+ *
+ */
+static void netlbl_cipsov4_doi_free(struct rcu_head *entry)
+{
+	struct cipso_v4_doi *ptr;
+
+	ptr = container_of(entry, struct cipso_v4_doi, rcu);
+	switch (ptr->type) {
+	case CIPSO_V4_MAP_STD:
+		if (ptr->map.std->lvl.cipso_size > 0)
+			kfree(ptr->map.std->lvl.cipso);
+		if (ptr->map.std->lvl.local_size > 0)
+			kfree(ptr->map.std->lvl.local);
+		if (ptr->map.std->cat.cipso_size > 0)
+			kfree(ptr->map.std->cat.cipso);
+		if (ptr->map.std->cat.local_size > 0)
+			kfree(ptr->map.std->cat.local);
+		break;
+	}
+	kfree(ptr);
+}
+
+/*
+ * Label Mapping Functions
+ */
+
+/**
+ * netlbl_cipsov4_add_std - Adds a CIPSO V4 DOI definition
+ * @doi: the DOI value
+ * @msg: the ADD message data
+ * @msg_size: the size of the ADD message buffer
+ *
+ * Description:
+ * Create a new CIPSO_V4_MAP_STD DOI definition based on the given ADD message
+ * and add it to the CIPSO V4 engine.  Return zero on success and non-zero on
+ * error.
+ *
+ */
+static int netlbl_cipsov4_add_std(const u32 doi,
+				  const unsigned char *msg,
+				  const u32 msg_size)
+{
+	int ret_val = -EPERM;
+	unsigned char *msg_ptr = (unsigned char *)msg;
+	u32 msg_len = msg_size;
+	u32 num_tags;
+	u32 num_lvls;
+	u32 num_cats;
+	struct cipso_v4_doi *doi_def = NULL;
+	u32 iter;
+	u32 tmp_val_a;
+	u32 tmp_val_b;
+
+	if (msg_len < 4)
+		goto add_std_failure;
+	num_tags = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (num_tags == 0 || num_tags > CIPSO_V4_TAG_MAXCNT)
+		goto add_std_failure;
+
+	doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
+	if (doi_def == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+	doi_def->map.std = kzalloc(sizeof(*doi_def->map.std),
+				   GFP_KERNEL);
+	if (doi_def->map.std == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+	doi_def->type = CIPSO_V4_MAP_STD;
+
+	if (msg_len < num_tags)
+		goto add_std_failure;
+	msg_len -= num_tags;
+	for (iter = 0; iter < num_tags; iter++) {
+		doi_def->tags[iter] = netlbl_getinc_u8(&msg_ptr);
+		switch (doi_def->tags[iter]) {
+		case CIPSO_V4_TAG_RBITMAP:
+			break;
+		default:
+			goto add_std_failure;
+		}
+	}
+	if (iter < CIPSO_V4_TAG_MAXCNT)
+		doi_def->tags[iter] = CIPSO_V4_TAG_INVALID;
+
+	if (msg_len < 24)
+		goto add_std_failure;
+
+	num_lvls = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (num_lvls == 0)
+		goto add_std_failure;
+	doi_def->map.std->lvl.local_size = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (doi_def->map.std->lvl.local_size > CIPSO_V4_MAX_LOC_LVLS)
+		goto add_std_failure;
+	doi_def->map.std->lvl.local = kcalloc(doi_def->map.std->lvl.local_size,
+					      sizeof(u32), GFP_KERNEL);
+	if (doi_def->map.std->lvl.local == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+	doi_def->map.std->lvl.cipso_size = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (doi_def->map.std->lvl.cipso_size > CIPSO_V4_MAX_REM_LVLS)
+		goto add_std_failure;
+	doi_def->map.std->lvl.cipso = kcalloc(doi_def->map.std->lvl.cipso_size,
+					      sizeof(u32), GFP_KERNEL);
+	if (doi_def->map.std->lvl.cipso == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+
+	num_cats = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	doi_def->map.std->cat.local_size = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (doi_def->map.std->cat.local_size > CIPSO_V4_MAX_LOC_CATS)
+		goto add_std_failure;
+	doi_def->map.std->cat.local = kcalloc(doi_def->map.std->cat.local_size,
+					      sizeof(u32), GFP_KERNEL);
+	if (doi_def->map.std->cat.local == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+	doi_def->map.std->cat.cipso_size = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (doi_def->map.std->cat.cipso_size > CIPSO_V4_MAX_REM_CATS)
+		goto add_std_failure;
+	doi_def->map.std->cat.cipso = kcalloc(doi_def->map.std->cat.cipso_size,
+					      sizeof(u32), GFP_KERNEL);
+	if (doi_def->map.std->cat.cipso == NULL) {
+		ret_val = -ENOMEM;
+		goto add_std_failure;
+	}
+
+	if (msg_len < num_lvls * 8 + num_cats * 8)
+		goto add_std_failure;
+	msg_len -= num_lvls * 8 + num_cats * 8;
+
+	for (iter = 0; iter < doi_def->map.std->lvl.cipso_size; iter++)
+		doi_def->map.std->lvl.cipso[iter] = CIPSO_V4_INV_LVL;
+	for (iter = 0; iter < doi_def->map.std->lvl.local_size; iter++)
+		doi_def->map.std->lvl.local[iter] = CIPSO_V4_INV_LVL;
+	for (iter = 0; iter < doi_def->map.std->cat.cipso_size; iter++)
+		doi_def->map.std->cat.cipso[iter] = CIPSO_V4_INV_CAT;
+	for (iter = 0; iter < doi_def->map.std->cat.local_size; iter++)
+		doi_def->map.std->cat.local[iter] = CIPSO_V4_INV_CAT;
+
+	for (iter = 0; iter < num_lvls; iter++) {
+		tmp_val_a = netlbl_getinc_u32(&msg_ptr);
+		tmp_val_b = netlbl_getinc_u32(&msg_ptr);
+
+		if (tmp_val_a >= doi_def->map.std->lvl.local_size ||
+		    tmp_val_b >= doi_def->map.std->lvl.cipso_size)
+			goto add_std_failure;
+
+		doi_def->map.std->lvl.cipso[tmp_val_b] = tmp_val_a;
+		doi_def->map.std->lvl.local[tmp_val_a] = tmp_val_b;
+	}
+
+	for (iter = 0; iter < num_cats; iter++) {
+		tmp_val_a = netlbl_getinc_u32(&msg_ptr);
+		tmp_val_b = netlbl_getinc_u32(&msg_ptr);
+
+		if (tmp_val_a >= doi_def->map.std->cat.local_size ||
+		    tmp_val_b >= doi_def->map.std->cat.cipso_size)
+			goto add_std_failure;
+
+		doi_def->map.std->cat.cipso[tmp_val_b] = tmp_val_a;
+		doi_def->map.std->cat.local[tmp_val_a] = tmp_val_b;
+	}
+
+	doi_def->doi = doi;
+	ret_val = cipso_v4_doi_add(doi_def);
+	if (ret_val != 0)
+		goto add_std_failure;
+	return 0;
+
+add_std_failure:
+	if (doi_def)
+		netlbl_cipsov4_doi_free(&doi_def->rcu);
+	return ret_val;
+}
+
+/**
+ * netlbl_cipsov4_add_pass - Adds a CIPSO V4 DOI definition
+ * @doi: the DOI value
+ * @msg: the ADD message data
+ * @msg_size: the size of the ADD message buffer
+ *
+ * Description:
+ * Create a new CIPSO_V4_MAP_PASS DOI definition based on the given ADD message
+ * and add it to the CIPSO V4 engine.  Return zero on success and non-zero on
+ * error.
+ *
+ */
+static int netlbl_cipsov4_add_pass(const u32 doi,
+				   const unsigned char *msg,
+				   const u32 msg_size)
+{
+	int ret_val = -EPERM;
+	unsigned char *msg_ptr = (unsigned char *)msg;
+	u32 msg_len = msg_size;
+	u32 num_tags;
+	struct cipso_v4_doi *doi_def = NULL;
+	u32 iter;
+
+	if (msg_len < 4)
+		goto add_pass_failure;
+	num_tags = netlbl_getinc_u32(&msg_ptr);
+	msg_len -= 4;
+	if (num_tags == 0 || num_tags > CIPSO_V4_TAG_MAXCNT)
+		goto add_pass_failure;
+
+	doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
+	if (doi_def == NULL) {
+		ret_val = -ENOMEM;
+		goto add_pass_failure;
+	}
+	doi_def->type = CIPSO_V4_MAP_PASS;
+
+	if (msg_len < num_tags)
+		goto add_pass_failure;
+	msg_len -= num_tags;
+	for (iter = 0; iter < num_tags; iter++) {
+		doi_def->tags[iter] = netlbl_getinc_u8(&msg_ptr);
+		switch (doi_def->tags[iter]) {
+		case CIPSO_V4_TAG_RBITMAP:
+			break;
+		default:
+			goto add_pass_failure;
+		}
+	}
+	if (iter < CIPSO_V4_TAG_MAXCNT)
+		doi_def->tags[iter] = CIPSO_V4_TAG_INVALID;
+
+	doi_def->doi = doi;
+	ret_val = cipso_v4_doi_add(doi_def);
+	if (ret_val != 0)
+		goto add_pass_failure;
+	return 0;
+
+add_pass_failure:
+	if (doi_def)
+		netlbl_cipsov4_doi_free(&doi_def->rcu);
+	return ret_val;
+}
+
+/**
+ * netlbl_cipsov4_add - Handle an ADD message
+ * @req_skb: the NETLINK buffer
+ * @doi: the DOI
+ * @msg: the NetLabel CIPSO V4 message
+ *
+ * Description:
+ * Create a new DOI definition based on the given ADD message and add it to the
+ * CIPSO V4 engine.
+ *
+ */
+static void netlbl_cipsov4_add(const struct sk_buff *req_skb,
+			       const u32 doi,
+			       const unsigned char *msg)
+{
+	int ret_val = -EINVAL;
+	u32 map_type;
+	u32 msg_len = netlbl_cipsov4_payload_len(req_skb);
+
+	if (msg_len < 4) {
+		netlbl_cipsov4_send_ack(req_skb, EINVAL);
+		return;
+	}
+
+	map_type = netlbl_get_u32(msg);
+	switch (map_type) {
+	case CIPSO_V4_MAP_STD:
+		ret_val = netlbl_cipsov4_add_std(doi, msg + 4, msg_len - 4);
+		break;
+	case CIPSO_V4_MAP_PASS:
+		ret_val = netlbl_cipsov4_add_pass(doi, msg + 4, msg_len - 4);
+		break;
+	}
+	netlbl_cipsov4_send_ack(req_skb, -ret_val);
+}
+
+/**
+ * netlbl_cipsov4_list - Handle a LIST message
+ * @req_skb: the NETLINK buffer
+ * @doi: the DOI
+ * @msg: the NetLabel CIPSO V4 message
+ *
+ * Description:
+ * Process a user generated LIST message and respond accordingly.
+ *
+ */
+static void netlbl_cipsov4_list(const struct sk_buff *req_skb,
+				const u32 doi,
+				const unsigned char *msg)
+{
+	int ret_val = -ENOMEM;
+	struct sk_buff *skb;
+	unsigned char *buf_ptr;
+
+	skb = cipso_v4_doi_dump(doi, sizeof(struct netlbl_cipsov4_msghdr));
+	if (skb == NULL)
+		goto list_return;
+	buf_ptr = skb_push(skb,
+			   NLMSG_SPACE(sizeof(struct netlbl_cipsov4_msghdr)));
+	if (buf_ptr == NULL) {
+		kfree(skb);
+		ret_val = -EAGAIN;
+		goto list_return;
+	}
+	netlbl_putinc_hdr(&buf_ptr,
+			  NETLBL_NLTYPE_CIPSOV4,
+			  skb->len,
+			  0,
+			  NETLINK_CB(req_skb).pid,
+			  0);
+	netlbl_cipsov4_putinc_hdr(&buf_ptr, NL_CV4_LIST, 0);
+
+	ret_val = netlbl_netlink_snd(skb, NETLINK_CB(req_skb).pid);
+
+list_return:
+	if (ret_val != 0)
+		netlbl_cipsov4_send_ack(skb, -ret_val);
+}
+
+/**
+ * netlbl_cipsov4_remove - Handle a REMOVE message
+ * @req_skb: the NETLINK buffer
+ * @doi: the DOI
+ * @msg: the NetLabel CIPSO V4 message
+ *
+ * Description:
+ * Process a user generated REMOVE message and respond accordingly.
+ *
+ */
+static void netlbl_cipsov4_remove(const struct sk_buff *req_skb,
+				 const u32 doi,
+				 const unsigned char *msg)
+{
+	int ret_val;
+
+	ret_val = cipso_v4_doi_remove(doi, netlbl_cipsov4_doi_free);
+	netlbl_cipsov4_send_ack(req_skb, -ret_val);
+}
+
+/*
+ * NetLabel Protocol Handlers
+ */
+
+/**
+ * netlbl_cipsov4_send_ack - Send an ACK message
+ * @req_skb: the NETLINK buffer
+ * @ret_code: return code to use
+ *
+ * Description:
+ * This function sends an ACK message to the sender of the NETLINK message
+ * specified by @req_skb.
+ *
+ */
+static void netlbl_cipsov4_send_ack(const struct sk_buff *req_skb,
+				    const u32 ret_code)
+{
+	size_t msg_size;
+	size_t data_size;
+	struct sk_buff *skb;
+	struct nlmsghdr *nl_ack_hdr;
+	unsigned char *data;
+
+	data_size = sizeof(struct netlbl_cipsov4_msghdr) + 8;
+	msg_size = NLMSG_SPACE(data_size);
+
+	skb = alloc_skb(msg_size, GFP_KERNEL);
+	if (skb == NULL)
+		return;
+
+	nl_ack_hdr = NLMSG_PUT(skb,
+			       NETLINK_CB(req_skb).pid,
+			       0,
+			       NETLBL_NLTYPE_CIPSOV4,
+			       data_size);
+	nl_ack_hdr->nlmsg_len = msg_size;
+
+	data = NLMSG_DATA(nl_ack_hdr);
+	netlbl_cipsov4_putinc_hdr(&data, NL_CV4_ACK, 0);
+	netlbl_putinc_u32(&data,
+			  ((struct nlmsghdr *)req_skb->data)->nlmsg_seq);
+	netlbl_putinc_u32(&data, ret_code);
+
+	netlbl_netlink_snd(skb, NETLINK_CB(req_skb).pid);
+	return;
+
+nlmsg_failure:
+	kfree_skb(skb);
+}
+
+/**
+ * netlbl_cipsov4_rcv - Process incoming NetLabel packets
+ * @skb: the NETLINK buffer
+ * @msg: pointer to the start of the NetLabel data
+ *
+ * Description:
+ * This function is reponsibile for reading all of the incoming CIPSO V4
+ * NetLabel traffic and dispatching it to the correct CIPSO V4 functions.
+ *
+ */
+void netlbl_cipsov4_rcv(const struct sk_buff *skb, const unsigned char *msg)
+{
+	int ret_val;
+	struct netlbl_cipsov4_msghdr *nl_cv4_hdr;
+
+	if (nlmsg_len((struct nlmsghdr *)skb->data) <
+	    sizeof(struct netlbl_cipsov4_msghdr)) {
+		netlbl_cipsov4_send_ack(skb, EINVAL);
+		return;
+	}
+
+	nl_cv4_hdr = (struct netlbl_cipsov4_msghdr *)msg;
+	switch (nl_cv4_hdr->opcode) {
+	case NL_CV4_ADD:
+		ret_val = netlbl_netlink_cap_check(skb, CAP_NET_ADMIN);
+		if (ret_val != 0)
+			netlbl_cipsov4_send_ack(skb, ret_val);
+		netlbl_cipsov4_add(skb,
+				   nl_cv4_hdr->doi,
+				   netlbl_cipsov4_payload_data(skb));
+		break;
+	case NL_CV4_REMOVE:
+		ret_val = netlbl_netlink_cap_check(skb, CAP_NET_ADMIN);
+		if (ret_val != 0)
+			netlbl_cipsov4_send_ack(skb, ret_val);
+		netlbl_cipsov4_remove(skb,
+				      nl_cv4_hdr->doi,
+				      netlbl_cipsov4_payload_data(skb));
+		break;
+	case NL_CV4_LIST:
+		netlbl_cipsov4_list(skb,
+				    nl_cv4_hdr->doi,
+				    netlbl_cipsov4_payload_data(skb));
+		break;
+	default:
+		netlbl_cipsov4_send_ack(skb, EINVAL);
+		return;
+	}
+}
net/netlabel/netlabel_cipso_v4.h new file +201 -0

201 lines not on this page · raw message

--
paul moore
linux security @ hp

#29 lore raw

RFC 7/7 NetLabel: unlabeled packet handling

In reply to [email protected]

Add unlabeled packet support to the NetLabel subsystem. NetLabel does not do any processing on unlabled packets, but it must support passing unlabled packets on both the inbound and outbound sides.

---
 net/netlabel/netlabel_unlabeled.c |  287 ++++++++++++++++++++++++++++++++++++++
 net/netlabel/netlabel_unlabeled.h |   83 ++++++++++
 2 files changed, 370 insertions(+)
net/netlabel/netlabel_unlabeled.c new file +287 -0
Index: linux-2.6.17.i686-quilt/net/netlabel/netlabel_unlabeled.c
===================================================================
@@ -0,0 +1,287 @@
+/*
+ * NetLabel Unlabeled Support
+ *
+ * This file defines functions for dealing with unlabeled packets for the
+ * NetLabel system.  The NetLabel system manages static and dynamic label
+ * mappings for network protocols such as CIPSO and RIPSO.
+ *
+ * Author: Paul Moore <[email protected]>
+ *
+ */
+
+/*
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
+ *
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/rcupdate.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/socket.h>
+#include <linux/string.h>
+#include <linux/skbuff.h>
+#include <net/sock.h>
+#include <net/netlink.h>
+#include <net/netlabel.h>
+#include <asm/bug.h>
+
+#include "netlabel_user.h"
+#include "netlabel_domainhash.h"
+#include "netlabel_unlabeled.h"
+
+/* Accept unlabeled packets flag */
+static atomic_t netlabel_unlabel_accept_flg = ATOMIC_INIT(0);
+
+/*
+ * Local Prototypes
+ */
+
+static void netlbl_unlabel_send_ack(const struct sk_buff *req_skb,
+				    const u32 ret_code);
+
+/*
+ * Helper Functions
+ */
+
+/**
+ * netlbl_unlabel_put_hdr - Write a Unlabeled NetLabel header into a buffer
+ * @buffer: the buffer
+ * @opcode: the NetLabel Unlabeled opcode
+ *
+ * Description:
+ * Use the given values to write a NetLabel Unlabeled header into the given
+ * buffer.
+ *
+ */
+static void netlbl_unlabel_put_hdr(unsigned char *buffer, const u32 opcode)
+{
+	((struct netlbl_unlabel_msghdr *)buffer)->opcode = opcode;
+}
+
+/**
+ * netlbl_unlabel_putinc_hdr - Write a Unlabeled NetLabel header into a buffer
+ * @buffer: the buffer
+ * @opcode: the NetLabel Unlabeled opcode
+ *
+ * Description:
+ * Use the given values to write a NetLabel Unlabeled header into the given
+ * buffer and increment the buffer pointer past the header.
+ *
+ */
+static void netlbl_unlabel_putinc_hdr(unsigned char **buffer, const u32 opcode)
+{
+	netlbl_unlabel_put_hdr(*buffer, opcode);
+	*buffer += sizeof(struct netlbl_unlabel_msghdr);
+}
+
+/**
+ * netlbl_unlabel_payload_len - Return the length of the payload
+ * @skb: the NETLINK buffer
+ *
+ * Description:
+ * This function returns the length of the NetLabel unlabeled payload.
+ *
+ */
+static u32 netlbl_unlabel_payload_len(const struct sk_buff *skb)
+{
+	const struct nlmsghdr *nl_hdr = (struct nlmsghdr *)skb->data;
+
+	if (nlmsg_len(nl_hdr) <= sizeof(struct netlbl_unlabel_msghdr))
+		return 0;
+	return nlmsg_len(nl_hdr) - sizeof(struct netlbl_unlabel_msghdr);
+}
+
+/**
+ * netlbl_unlabel_payload_data - Returns a pointer to the start of the data
+ * @skb: the NETLINK buffer
+ *
+ * Description:
+ * This function returns a pointer to the start of the NetLabel unlabeled
+ * payload.
+ *
+ */
+static unsigned char *netlbl_unlabel_payload_data(const struct sk_buff *skb)
+{
+	return nlmsg_data((struct nlmsghdr *)skb->data)
+		+ sizeof(struct netlbl_unlabel_msghdr);
+}
+
+/*
+ * Label Mapping Functions
+ */
+
+/**
+ * netlbl_unlabel_accept - Handle an ACCEPT message
+ * @req_skb: the NETLINK buffer
+ * @msg: the NetLabel management message
+ *
+ * Description:
+ * Process a user generated ACCEPT message and set the accept flag accordingly.
+ *
+ */
+static void netlbl_unlabel_accept(const struct sk_buff *req_skb,
+				 const unsigned char *msg)
+{
+	u32 value;
+
+	if (netlbl_unlabel_payload_len(req_skb) == 4) {
+		value = netlbl_get_u32(msg);
+		if (value == 1 || value == 0) {
+			atomic_set(&netlabel_unlabel_accept_flg, value);
+			netlbl_unlabel_send_ack(req_skb, NETLBL_E_OK);
+			return;
+		}
+	}
+
+	netlbl_unlabel_send_ack(req_skb, EINVAL);
+	return;
+}
+
+/*
+ * NetLabel Protocol Handlers
+ */
+
+/**
+ * netlbl_unlabel_send_ack - Send an ACK message
+ * @req_skb: the NETLINK buffer
+ * @ret_code: return code to use
+ *
+ * Description:
+ * This function sends an ACK message to the sender of the NETLINK message
+ * specified by @req_skb.
+ *
+ */
+static void netlbl_unlabel_send_ack(const struct sk_buff *req_skb,
+				    const u32 ret_code)
+{
+	size_t msg_size;
+	size_t data_size;
+	struct sk_buff *skb;
+	struct nlmsghdr *nl_ack_hdr;
+	unsigned char *data;
+
+	data_size = sizeof(struct netlbl_unlabel_msghdr) + 8;
+	msg_size = NLMSG_SPACE(data_size);
+
+	skb = alloc_skb(msg_size, GFP_KERNEL);
+	if (skb == NULL)
+		return;
+
+	nl_ack_hdr = NLMSG_PUT(skb,
+			       NETLINK_CB(req_skb).pid,
+			       0,
+			       NETLBL_NLTYPE_UNLABELED,
+			       data_size);
+	nl_ack_hdr->nlmsg_len = msg_size;
+
+	data = NLMSG_DATA(nl_ack_hdr);
+	netlbl_unlabel_putinc_hdr(&data, NL_UNL_ACK);
+	netlbl_putinc_u32(&data,
+			  ((struct nlmsghdr *)req_skb->data)->nlmsg_seq);
+	netlbl_putinc_u32(&data, ret_code);
+
+	netlbl_netlink_snd(skb, NETLINK_CB(req_skb).pid);
+	return;
+
+nlmsg_failure:
+	kfree_skb(skb);
+}
+
+/**
+ * netlbl_unlabel_rcv - Process incoming NetLabel packets
+ * @skb: the NETLINK buffer
+ * @msg: pointer to the start of the NetLabel data
+ *
+ * Description:
+ * This function is reponsibile for reading all of the incoming Unlabeled
+ * NetLabel traffic and dispatching it to the correct Unlabeled functions.
+ *
+ */
+void netlbl_unlabel_rcv(const struct sk_buff *skb, const unsigned char *msg)
+{
+	int ret_val;
+
+	if (nlmsg_len((struct nlmsghdr *)skb->data) <
+	    sizeof(struct netlbl_unlabel_msghdr)) {
+		netlbl_unlabel_send_ack(skb, EINVAL);
+		return;
+	}
+
+	switch (((struct netlbl_unlabel_msghdr *)msg)->opcode) {
+	case NL_UNL_ACCEPT:
+		ret_val = netlbl_netlink_cap_check(skb, CAP_NET_ADMIN);
+		if (ret_val != 0)
+			netlbl_unlabel_send_ack(skb, ret_val);
+		netlbl_unlabel_accept(skb, netlbl_unlabel_payload_data(skb));
+		break;
+	default:
+		netlbl_unlabel_send_ack(skb, EINVAL);
+		return;
+	}
+}
+
+/*
+ * NetLabel KAPI Hooks
+ */
+
+/**
+ * netlbl_unlabel_getattr - Get the security attributes for an unlabled packet
+ * @secattr: the security attributes
+ *
+ * Description:
+ * Determine the security attributes, if any, for an unlabled packet and return
+ * them in @secattr.  Returns zero on success and negative values on failure.
+ *
+ */
+int netlbl_unlabel_getattr(struct netlbl_lsm_secattr *secattr)
+{
+	BUG_ON(secattr == NULL);
+
+	if (atomic_read(&netlabel_unlabel_accept_flg) == 1) {
+		memset(secattr, 0, sizeof(*secattr));
+		return 0;
+	}
+
+	return -ENOMSG;
+}
+
+/**
+ * netlbl_unlabel_defconf - Set the default config to allow unlabeled packets
+ *
+ * Description:
+ * Set the default NetLabel configuration to allow incoming unlabeled packets
+ * and to send unlabeled network traffic by default.
+ *
+ */
+int netlbl_unlabel_defconf(void)
+{
+	int ret_val;
+	struct netlbl_dom_map *entry;
+
+	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+	if (entry == NULL)
+		return -ENOMEM;
+	entry->type = NETLBL_NLTYPE_UNLABELED;
+	ret_val = netlbl_domhsh_add_default(entry);
+	if (ret_val != 0)
+		return ret_val;
+
+	atomic_set(&netlabel_unlabel_accept_flg, 1);
+
+	return 0;
+}
net/netlabel/netlabel_unlabeled.h new file +83 -0

83 lines not on this page · raw message

--
paul moore
linux security @ hp