Skip to contentSkip to conversation

SELinux patches for 2.6.22

PATCH New James Morris 1 participant 13 messages Apr 26, 2007

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

cover SELinux patches for 2.6.22

The following changes since commit de46c33745f5e2ad594c72f2cf5f490861b16ce1:
Linus Torvalds (1):

        Linux 2.6.21

are found in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6.git#for-linus

James Carter (4):
selinux: export initial SID contexts via selinuxfs
selinux: explicitly number all selinuxfs inodes
selinux: remove unused enumeration constant from selinuxfs
selinux: change numbering of boolean directory inodes in selinuxfs

Paul Moore (5):
NetLabel: cleanup and document CIPSO constants
NetLabel: convert a BUG_ON in the CIPSO code to a runtime check
SELinux: extract the NetLabel SELinux support from the security server
SELinux: rename selinux_netlabel.h to netlabel.h
SELinux: move security_skb_extlbl_sid() out of the security server

Stephen Smalley (3):
MAINTAINERS: update selinux entry
selinux: remove userland security class and permission definitions
selinux: preserve boolean values across policy reloads

 MAINTAINERS                                        |    4 +-
 net/ipv4/cipso_ipv4.c                              |   41 ++-
 net/netlabel/netlabel_kapi.c                       |    3 -
 security/selinux/Makefile                          |    2 +
 security/selinux/avc.c                             |    2 +
 security/selinux/hooks.c                           |   38 ++-
 security/selinux/include/av_perm_to_string.h       |  102 ----
 security/selinux/include/av_permissions.h          |  179 -------
 security/selinux/include/class_to_string.h         |   34 +-
 security/selinux/include/flask.h                   |   16 -
 .../include/{selinux_netlabel.h => netlabel.h}     |   71 ++--
 security/selinux/include/security.h                |   29 +-
 security/selinux/netlabel.c                        |  363 ++++++++++++++
 security/selinux/selinuxfs.c                       |   85 +++-
 security/selinux/ss/services.c                     |  499 +++++---------------
 15 files changed, 695 insertions(+), 773 deletions(-)
 rename security/selinux/include/{selinux_netlabel.h => netlabel.h} (94%)
 create mode 100644 security/selinux/netlabel.c
Signature · 2 lines
James Morris
<[email protected]>
#1 lore raw

PATCH 1/12 NetLabel: cleanup and document CIPSO constants

From: Paul Moore <[email protected]>

This patch collects all of the CIPSO constants and puts them in one place; it also documents each value explaining how the value is derived.

---
 net/ipv4/cipso_ipv4.c |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)
net/ipv4/cipso_ipv4.c +29 -8
index 2ce5b69..d466bd5 100644
@@ -92,6 +92,33 @@ int cipso_v4_rbm_optfmt = 0;
 int cipso_v4_rbm_strictvalid = 1;
 
 /*
+ * Protocol Constants
+ */
+
+/* Maximum size of the CIPSO IP option, derived from the fact that the maximum
+ * IPv4 header size is 60 bytes and the base IPv4 header is 20 bytes long. */
+#define CIPSO_V4_OPT_LEN_MAX          40
+
+/* Length of the base CIPSO option, this includes the option type (1 byte), the
+ * option length (1 byte), and the DOI (4 bytes). */
+#define CIPSO_V4_HDR_LEN              6
+
+/* Base length of the restrictive category bitmap tag (tag #1). */
+#define CIPSO_V4_TAG_RBM_BLEN         4
+
+/* Base length of the enumerated category tag (tag #2). */
+#define CIPSO_V4_TAG_ENUM_BLEN        4
+
+/* Base length of the ranged categories bitmap tag (tag #5). */
+#define CIPSO_V4_TAG_RNG_BLEN         4
+/* The maximum number of category ranges permitted in the ranged category tag
+ * (tag #5).  You may note that the IETF draft states that the maximum number
+ * of category ranges is 7, but if the low end of the last category range is
+ * zero then it is possibile to fit 8 category ranges because the zero should
+ * be omitted. */
+#define CIPSO_V4_TAG_RNG_CAT_MAX      8
+
+/*
  * Helper Functions
  */
 
@@ -1109,15 +1136,12 @@ static int cipso_v4_map_cat_rng_hton(const struct cipso_v4_doi *doi_def,
 				     unsigned char *net_cat,
 				     u32 net_cat_len)
 {
-	/* The constant '16' is not random, it is the maximum number of
-	 * high/low category range pairs as permitted by the CIPSO draft based
-	 * on a maximum IPv4 header length of 60 bytes - the BUG_ON() assertion
-	 * does a sanity check to make sure we don't overflow the array. */
 	int iter = -1;
-	u16 array[16];
+	u16 array[CIPSO_V4_TAG_RNG_CAT_MAX * 2];
 	u32 array_cnt = 0;
 	u32 cat_size = 0;
 
+	/* make sure we don't overflow the 'array[]' variable */
 	BUG_ON(net_cat_len > 30);
 
 	for (;;) {
@@ -1196,9 +1220,6 @@ static int cipso_v4_map_cat_rng_ntoh(const struct cipso_v4_doi *doi_def,
  * Protocol Handling Functions
  */
 
-#define CIPSO_V4_OPT_LEN_MAX          40
-#define CIPSO_V4_HDR_LEN              6
-
 /**
  * cipso_v4_gentag_hdr - Generate a CIPSO option header
  * @doi_def: the DOI definition
Signature · 1 line
1.5.0.6
#2 lore raw

PATCH 2/12 NetLabel: convert a BUG_ON in the CIPSO code to a runtime check

In reply to James Morris

From: Paul Moore <[email protected]>

This patch changes a BUG_ON in the CIPSO code to a runtime check. It should also increase the readability of the code as it replaces an unexplained constant with a well defined macro.

---
 net/ipv4/cipso_ipv4.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/ipv4/cipso_ipv4.c +3 -1
index d466bd5..6afc398 100644
@@ -1142,7 +1142,9 @@ static int cipso_v4_map_cat_rng_hton(const struct cipso_v4_doi *doi_def,
 	u32 cat_size = 0;
 
 	/* make sure we don't overflow the 'array[]' variable */
-	BUG_ON(net_cat_len > 30);
+	if (net_cat_len >
+	    (CIPSO_V4_OPT_LEN_MAX - CIPSO_V4_HDR_LEN - CIPSO_V4_TAG_RNG_BLEN))
+		return -ENOSPC;
 
 	for (;;) {
 		iter = netlbl_secattr_catmap_walk(secattr->mls_cat, iter + 1);
Signature · 1 line
1.5.0.6
#3 lore raw

PATCH 3/12 SELinux: extract the NetLabel SELinux support from the security server

In reply to James Morris

From: Paul Moore <[email protected]>

Up until this patch the functions which have provided NetLabel support to SELinux have been integrated into the SELinux security server, which for various reasons is not really ideal. This patch makes an effort to extract as much of the NetLabel support from the security server as possibile and move it into it's own file within the SELinux directory structure.

---
 net/netlabel/netlabel_kapi.c                |    3 -
 security/selinux/Makefile                   |    2 +
 security/selinux/include/security.h         |   24 ++
 security/selinux/include/selinux_netlabel.h |   71 +++---
 security/selinux/netlabel.c                 |  363 +++++++++++++++++++++++
 security/selinux/ss/services.c              |  423 ++++-----------------------
 6 files changed, 481 insertions(+), 405 deletions(-)
 create mode 100644 security/selinux/netlabel.c
net/netlabel/netlabel_kapi.c +0 -3
index e03a328..f2535e7 100644
@@ -263,9 +263,6 @@ int netlbl_socket_setattr(const struct socket *sock,
 	int ret_val = -ENOENT;
 	struct netlbl_dom_map *dom_entry;
 
-	if ((secattr->flags & NETLBL_SECATTR_DOMAIN) == 0)
-		return -ENOENT;
-
 	rcu_read_lock();
 	dom_entry = netlbl_domhsh_getentry(secattr->domain);
 	if (dom_entry == NULL)
security/selinux/Makefile +2 -0
index faf2e02..dc3502e 100644
@@ -8,5 +8,7 @@ selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o exports.o
 
 selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o
 
+selinux-$(CONFIG_NETLABEL) += netlabel.o
+
 EXTRA_CFLAGS += -Isecurity/selinux/include
 
security/selinux/include/security.h +24 -0
index 210eec7..605b071 100644
@@ -35,6 +35,7 @@
 #endif
 
 struct sk_buff;
+struct netlbl_lsm_secattr;
 
 extern int selinux_enabled;
 extern int selinux_mls_enabled;
@@ -102,5 +103,28 @@ int security_fs_use(const char *fstype, unsigned int *behavior,
 int security_genfs_sid(const char *fstype, char *name, u16 sclass,
 	u32 *sid);
 
+#ifdef CONFIG_NETLABEL
+int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
+				   u32 base_sid,
+				   u32 *sid);
+
+int security_netlbl_sid_to_secattr(u32 sid,
+				   struct netlbl_lsm_secattr *secattr);
+#else
+static inline int security_netlbl_secattr_to_sid(
+					    struct netlbl_lsm_secattr *secattr,
+					    u32 base_sid,
+					    u32 *sid)
+{
+	return -EIDRM;
+}
+
+static inline int security_netlbl_sid_to_secattr(u32 sid,
+					   struct netlbl_lsm_secattr *secattr)
+{
+	return -ENOENT;
+}
+#endif /* CONFIG_NETLABEL */
+
 #endif /* _SELINUX_SECURITY_H_ */
 
security/selinux/include/selinux_netlabel.h +34 -37

112 lines not on this page · raw message

security/selinux/netlabel.c new file +363 -0

363 lines not on this page · raw message

security/selinux/ss/services.c +58 -365

518 lines not on this page · raw message

Signature · 1 line
1.5.0.6
#4 lore raw

PATCH 4/12 SELinux: rename selinux_netlabel.h to netlabel.h

In reply to James Morris

From: Paul Moore <[email protected]>

In the beginning I named the file selinux_netlabel.h to avoid potential namespace colisions. However, over time I have realized that there are several other similar cases of multiple header files with the same name so I'm changing the name to something which better fits with existing naming conventions.

---
 security/selinux/hooks.c                    |    2 +-
 security/selinux/include/netlabel.h         |  121 +++++++++++++++++++++++++++
 security/selinux/include/selinux_netlabel.h |  121 ---------------------------
 security/selinux/ss/services.c              |    2 +-
 4 files changed, 123 insertions(+), 123 deletions(-)
 create mode 100644 security/selinux/include/netlabel.h
 delete mode 100644 security/selinux/include/selinux_netlabel.h
security/selinux/hooks.c +1 -1
index d41e24d..7f8d0b1 100644
@@ -77,7 +77,7 @@
 #include "objsec.h"
 #include "netif.h"
 #include "xfrm.h"
-#include "selinux_netlabel.h"
+#include "netlabel.h"
 
 #define XATTR_SELINUX_SUFFIX "selinux"
 #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
security/selinux/include/netlabel.h new file +121 -0

121 lines not on this page · raw message

security/selinux/include/selinux_netlabel.h deleted +0 -121

121 lines not on this page · raw message

security/selinux/ss/services.c +1 -1
index c8913c5..f4129f5 100644
@@ -53,7 +53,7 @@
 #include "conditional.h"
 #include "mls.h"
 #include "objsec.h"
-#include "selinux_netlabel.h"
+#include "netlabel.h"
 #include "xfrm.h"
 #include "ebitmap.h"
 
Signature · 1 line
1.5.0.6
#5 lore raw

PATCH 5/12 MAINTAINERS: update selinux entry

In reply to James Morris

From: Stephen Smalley <[email protected]>

Add Eric Paris as an SELinux maintainer.

---
 MAINTAINERS |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
MAINTAINERS +3 -1
index 277877a..4d487c3 100644
@@ -2961,8 +2961,10 @@ P:	Stephen Smalley
 M:	[email protected]
 P:	James Morris
 M:	[email protected]
+P:	Eric Paris
+M:	[email protected]
 L:	[email protected] (kernel issues)
-L: 	[email protected] (general discussion)
+L: 	[email protected] (subscribers-only, general discussion)
 W:	http://www.nsa.gov/selinux
 S:	Supported
 
Signature · 1 line
1.5.0.6
#6 lore raw

PATCH 6/12 SELinux: move security_skb_extlbl_sid() out of the security server

In reply to James Morris

From: Paul Moore <[email protected]>

As suggested, move the security_skb_extlbl_sid() function out of the security server and into the SELinux hooks file.

---
 security/selinux/hooks.c            |   36 ++++++++++++++++++++++++++++++----
 security/selinux/include/security.h |    3 --
 security/selinux/ss/services.c      |   27 --------------------------
 3 files changed, 31 insertions(+), 35 deletions(-)
security/selinux/hooks.c +31 -5
index 7f8d0b1..68629aa 100644
@@ -3123,6 +3123,34 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,
 	return ret;
 }
 
+/**
+ * selinux_skb_extlbl_sid - Determine the external label of a packet
+ * @skb: the packet
+ * @base_sid: the SELinux SID to use as a context for MLS only external labels
+ * @sid: the packet's SID
+ *
+ * Description:
+ * Check the various different forms of external packet labeling and determine
+ * the external SID for the packet.
+ *
+ */
+static void selinux_skb_extlbl_sid(struct sk_buff *skb,
+				   u32 base_sid,
+				   u32 *sid)
+{
+	u32 xfrm_sid;
+	u32 nlbl_sid;
+
+	selinux_skb_xfrm_sid(skb, &xfrm_sid);
+	if (selinux_netlbl_skbuff_getsid(skb,
+					 (xfrm_sid == SECSID_NULL ?
+					  base_sid : xfrm_sid),
+					 &nlbl_sid) != 0)
+		nlbl_sid = SECSID_NULL;
+
+	*sid = (nlbl_sid == SECSID_NULL ? xfrm_sid : nlbl_sid);
+}
+
 /* socket security operations */
 static int socket_has_perm(struct task_struct *task, struct socket *sock,
 			   u32 perms)
@@ -3664,9 +3692,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
 	if (sock && sock->sk->sk_family == PF_UNIX)
 		selinux_get_inode_sid(SOCK_INODE(sock), &peer_secid);
 	else if (skb)
-		security_skb_extlbl_sid(skb,
-					SECINITSID_UNLABELED,
-					&peer_secid);
+		selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &peer_secid);
 
 	if (peer_secid == SECSID_NULL)
 		err = -EINVAL;
@@ -3727,7 +3753,7 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
 	u32 newsid;
 	u32 peersid;
 
-	security_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &peersid);
+	selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &peersid);
 	if (peersid == SECSID_NULL) {
 		req->secid = sksec->sid;
 		req->peer_secid = SECSID_NULL;
@@ -3765,7 +3791,7 @@ static void selinux_inet_conn_established(struct sock *sk,
 {
 	struct sk_security_struct *sksec = sk->sk_security;
 
-	security_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &sksec->peer_sid);
+	selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &sksec->peer_sid);
 }
 
 static void selinux_req_classify_flow(const struct request_sock *req,
security/selinux/include/security.h +0 -3
index 605b071..bfe562c 100644
@@ -34,7 +34,6 @@
 #define POLICYDB_VERSION_MAX	POLICYDB_VERSION_RANGETRANS
 #endif
 
-struct sk_buff;
 struct netlbl_lsm_secattr;
 
 extern int selinux_enabled;
@@ -83,8 +82,6 @@ int security_netif_sid(char *name, u32 *if_sid,
 int security_node_sid(u16 domain, void *addr, u32 addrlen,
 	u32 *out_sid);
 
-void security_skb_extlbl_sid(struct sk_buff *skb, u32 base_sid, u32 *sid);
-
 int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
                                  u16 tclass);
 
security/selinux/ss/services.c +0 -27
index f4129f5..8ee4aae 100644
@@ -39,7 +39,6 @@
 #include <linux/sched.h>
 #include <linux/audit.h>
 #include <linux/mutex.h>
-#include <net/sock.h>
 #include <net/netlabel.h>
 
 #include "flask.h"
@@ -2198,32 +2197,6 @@ void selinux_audit_set_callback(int (*callback)(void))
 	aurule_callback = callback;
 }
 
-/**
- * security_skb_extlbl_sid - Determine the external label of a packet
- * @skb: the packet
- * @base_sid: the SELinux SID to use as a context for MLS only external labels
- * @sid: the packet's SID
- *
- * Description:
- * Check the various different forms of external packet labeling and determine
- * the external SID for the packet.
- *
- */
-void security_skb_extlbl_sid(struct sk_buff *skb, u32 base_sid, u32 *sid)
-{
-	u32 xfrm_sid;
-	u32 nlbl_sid;
-
-	selinux_skb_xfrm_sid(skb, &xfrm_sid);
-	if (selinux_netlbl_skbuff_getsid(skb,
-					 (xfrm_sid == SECSID_NULL ?
-					  base_sid : xfrm_sid),
-					 &nlbl_sid) != 0)
-		nlbl_sid = SECSID_NULL;
-
-	*sid = (nlbl_sid == SECSID_NULL ? xfrm_sid : nlbl_sid);
-}
-
 #ifdef CONFIG_NETLABEL
 /*
  * NetLabel cache structure
Signature · 1 line
1.5.0.6
#7 lore raw

PATCH 7/12 selinux: remove userland security class and permission definitions

In reply to James Morris

From: Stephen Smalley <[email protected]>

Remove userland security class and permission definitions from the kernel as the kernel only needs to use and validate its own class and permission definitions and userland definitions may change.

---
 security/selinux/avc.c                       |    2 +
 security/selinux/include/av_perm_to_string.h |  102 ---------------
 security/selinux/include/av_permissions.h    |  179 --------------------------
 security/selinux/include/class_to_string.h   |   34 +++---
 security/selinux/include/flask.h             |   16 ---
 security/selinux/ss/services.c               |    2 +
 6 files changed, 21 insertions(+), 314 deletions(-)
security/selinux/avc.c +2 -0
index da8caf1..e4396a8 100644
@@ -217,6 +217,8 @@ static void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tcla
 		audit_log_format(ab, " tcontext=%s", scontext);
 		kfree(scontext);
 	}
+
+	BUG_ON(tclass >= ARRAY_SIZE(class_to_string) || !class_to_string[tclass]);
 	audit_log_format(ab, " tclass=%s", class_to_string[tclass]);
 }
 
security/selinux/include/av_perm_to_string.h +0 -102

119 lines not on this page · raw message

security/selinux/include/av_permissions.h +0 -179

476 lines not on this page · raw message

security/selinux/include/class_to_string.h +17 -17
index 9f3ebb1..3787990 100644
@@ -2,7 +2,7 @@
 /*
  * Security object class definitions
  */
-    S_("null")
+    S_(NULL)
     S_("security")
     S_("process")
     S_("system")
@@ -32,19 +32,19 @@
     S_("msgq")
     S_("shm")
     S_("ipc")
-    S_("passwd")
-    S_("drawable")
-    S_("window")
-    S_("gc")
-    S_("font")
-    S_("colormap")
-    S_("property")
-    S_("cursor")
-    S_("xclient")
-    S_("xinput")
-    S_("xserver")
-    S_("xextension")
-    S_("pax")
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
+    S_(NULL)
     S_("netlink_route_socket")
     S_("netlink_firewall_socket")
     S_("netlink_tcpdiag_socket")
@@ -54,12 +54,12 @@
     S_("netlink_audit_socket")
     S_("netlink_ip6fw_socket")
     S_("netlink_dnrt_socket")
-    S_("dbus")
-    S_("nscd")
+    S_(NULL)
+    S_(NULL)
     S_("association")
     S_("netlink_kobject_uevent_socket")
     S_("appletalk_socket")
     S_("packet")
     S_("key")
-    S_("context")
+    S_(NULL)
     S_("dccp_socket")
security/selinux/include/flask.h +0 -16
index 67cef37..35f309f 100644
@@ -34,19 +34,6 @@
 #define SECCLASS_MSGQ                                    27
 #define SECCLASS_SHM                                     28
 #define SECCLASS_IPC                                     29
-#define SECCLASS_PASSWD                                  30
-#define SECCLASS_DRAWABLE                                31
-#define SECCLASS_WINDOW                                  32
-#define SECCLASS_GC                                      33
-#define SECCLASS_FONT                                    34
-#define SECCLASS_COLORMAP                                35
-#define SECCLASS_PROPERTY                                36
-#define SECCLASS_CURSOR                                  37
-#define SECCLASS_XCLIENT                                 38
-#define SECCLASS_XINPUT                                  39
-#define SECCLASS_XSERVER                                 40
-#define SECCLASS_XEXTENSION                              41
-#define SECCLASS_PAX                                     42
 #define SECCLASS_NETLINK_ROUTE_SOCKET                    43
 #define SECCLASS_NETLINK_FIREWALL_SOCKET                 44
 #define SECCLASS_NETLINK_TCPDIAG_SOCKET                  45
@@ -56,14 +43,11 @@
 #define SECCLASS_NETLINK_AUDIT_SOCKET                    49
 #define SECCLASS_NETLINK_IP6FW_SOCKET                    50
 #define SECCLASS_NETLINK_DNRT_SOCKET                     51
-#define SECCLASS_DBUS                                    52
-#define SECCLASS_NSCD                                    53
 #define SECCLASS_ASSOCIATION                             54
 #define SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET           55
 #define SECCLASS_APPLETALK_SOCKET                        56
 #define SECCLASS_PACKET                                  57
 #define SECCLASS_KEY                                     58
-#define SECCLASS_CONTEXT                                 59
 #define SECCLASS_DCCP_SOCKET                             60
 
 /*
security/selinux/ss/services.c +2 -0
index 8ee4aae..d369856 100644
@@ -1049,6 +1049,8 @@ static int validate_classes(struct policydb *p)
 
 	for (i = 1; i < kdefs->cts_len; i++) {
 		def_class = kdefs->class_to_string[i];
+		if (!def_class)
+			continue;
 		if (i > p->p_classes.nprim) {
 			printk(KERN_INFO
 			       "security:  class %s not defined in policy\n",
Signature · 1 line
1.5.0.6
#8 lore raw

PATCH 8/12 selinux: export initial SID contexts via selinuxfs

In reply to James Morris

From: James Carter <[email protected]>

Make the initial SID contexts accessible to userspace via selinuxfs. An initial use of this support will be to make the unlabeled context available to libselinux for use for invalidated userspace SIDs.

---
 security/selinux/include/security.h |    2 +
 security/selinux/selinuxfs.c        |   67 +++++++++++++++++++++++++++++++++++
 security/selinux/ss/services.c      |    7 ++++
 3 files changed, 76 insertions(+), 0 deletions(-)
security/selinux/include/security.h +2 -0
index bfe562c..b94378a 100644
@@ -123,5 +123,7 @@ static inline int security_netlbl_sid_to_secattr(u32 sid,
 }
 #endif /* CONFIG_NETLABEL */
 
+const char *security_get_initial_sid_context(u32 sid);
+
 #endif /* _SELINUX_SECURITY_H_ */
 
security/selinux/selinuxfs.c +67 -0

85 lines not on this page · raw message

security/selinux/ss/services.c +7 -0
index d369856..21b8318 100644
@@ -593,6 +593,13 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
 
 #include "initial_sid_to_string.h"
 
+const char *security_get_initial_sid_context(u32 sid)
+{
+	if (unlikely(sid > SECINITSID_NUM))
+		return NULL;
+	return initial_sid_to_string[sid];
+}
+
 /**
  * security_sid_to_context - Obtain a context for a given SID.
  * @sid: security identifier, SID
Signature · 1 line
1.5.0.6
#9 lore raw

PATCH 9/12 selinux: explicitly number all selinuxfs inodes

In reply to James Morris

From: James Carter <[email protected]>

Explicitly number all selinuxfs inodes to prevent a conflict between inodes numbered using last_ino when created with new_inode() and those labeled explicitly.

---
 security/selinux/selinuxfs.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
security/selinux/selinuxfs.c +6 -0
index e24235c..1a786db 100644
@@ -100,8 +100,11 @@ enum sel_inos {
 	SEL_MEMBER,	/* compute polyinstantiation membership decision */
 	SEL_CHECKREQPROT, /* check requested protection, not kernel-applied one */
 	SEL_COMPAT_NET,	/* whether to use old compat network packet controls */
+	SEL_INO_NEXT,	/* The next inode number to use */
 };
 
+static unsigned long sel_last_ino = SEL_INO_NEXT - 1;
+
 #define SEL_INITCON_INO_OFFSET 	0x01000000
 #define SEL_INO_MASK		0x00ffffff
 
@@ -1237,6 +1240,7 @@ static int sel_make_avc_files(struct dentry *dir)
 			goto out;
 		}
 		inode->i_fop = files[i].ops;
+		inode->i_ino = ++sel_last_ino;
 		d_add(dentry, inode);
 	}
 out:
@@ -1304,6 +1308,7 @@ static int sel_make_dir(struct inode *dir, struct dentry *dentry)
 	}
 	inode->i_op = &simple_dir_inode_operations;
 	inode->i_fop = &simple_dir_operations;
+	inode->i_ino = ++sel_last_ino;
 	/* directory inodes start off with i_nlink == 2 (for "." entry) */
 	inc_nlink(inode);
 	d_add(dentry, inode);
@@ -1366,6 +1371,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
 		ret = -ENOMEM;
 		goto err;
 	}
+	inode->i_ino = ++sel_last_ino;
 	isec = (struct inode_security_struct*)inode->i_security;
 	isec->sid = SECINITSID_DEVNULL;
 	isec->sclass = SECCLASS_CHR_FILE;
Signature · 1 line
1.5.0.6
#10 lore raw

PATCH 10/12 selinux: remove unused enumeration constant from selinuxfs

In reply to James Morris

From: James Carter <[email protected]>

Remove the unused enumeration constant, SEL_AVC, from the sel_inos enumeration in selinuxfs.

---
 security/selinux/selinuxfs.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
security/selinux/selinuxfs.c +0 -1
index 1a786db..097bc04 100644
@@ -96,7 +96,6 @@ enum sel_inos {
 	SEL_COMMIT_BOOLS, /* commit new boolean values */
 	SEL_MLS,	/* return if MLS policy is enabled */
 	SEL_DISABLE,	/* disable SELinux until next reboot */
-	SEL_AVC,	/* AVC management directory */
 	SEL_MEMBER,	/* compute polyinstantiation membership decision */
 	SEL_CHECKREQPROT, /* check requested protection, not kernel-applied one */
 	SEL_COMPAT_NET,	/* whether to use old compat network packet controls */
Signature · 1 line
1.5.0.6
#11 lore raw

PATCH 11/12 selinux: change numbering of boolean directory inodes in selinuxfs

In reply to James Morris

From: James Carter <[email protected]>

Change the numbering of the booleans directory inodes in selinuxfs to provide more room for new inodes without a conflict in inode numbers and to be consistent with how inode numbering is done in the initial_contexts directory.

---
 security/selinux/selinuxfs.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
security/selinux/selinuxfs.c +5 -6
index 097bc04..aca099a 100644
@@ -105,6 +105,7 @@ enum sel_inos {
 static unsigned long sel_last_ino = SEL_INO_NEXT - 1;
 
 #define SEL_INITCON_INO_OFFSET 	0x01000000
+#define SEL_BOOL_INO_OFFSET	0x02000000
 #define SEL_INO_MASK		0x00ffffff
 
 #define TMPBUFLEN	12
@@ -782,8 +783,6 @@ static struct inode *sel_make_inode(struct super_block *sb, int mode)
 	return ret;
 }
 
-#define BOOL_INO_OFFSET 30
-
 static ssize_t sel_read_bool(struct file *filep, char __user *buf,
 			     size_t count, loff_t *ppos)
 {
@@ -811,14 +810,14 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,
 	}
 
 	inode = filep->f_path.dentry->d_inode;
-	cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET);
+	cur_enforcing = security_get_bool_value(inode->i_ino&SEL_INO_MASK);
 	if (cur_enforcing < 0) {
 		ret = cur_enforcing;
 		goto out;
 	}
 
 	length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
-			  bool_pending_values[inode->i_ino - BOOL_INO_OFFSET]);
+			  bool_pending_values[inode->i_ino&SEL_INO_MASK]);
 	ret = simple_read_from_buffer(buf, count, ppos, page, length);
 out:
 	mutex_unlock(&sel_mutex);
@@ -870,7 +869,7 @@ static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
 		new_value = 1;
 
 	inode = filep->f_path.dentry->d_inode;
-	bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value;
+	bool_pending_values[inode->i_ino&SEL_INO_MASK] = new_value;
 	length = count;
 
 out:
@@ -1034,7 +1033,7 @@ static int sel_make_bools(void)
 		isec->sid = sid;
 		isec->initialized = 1;
 		inode->i_fop = &sel_bool_ops;
-		inode->i_ino = i + BOOL_INO_OFFSET;
+		inode->i_ino = i|SEL_BOOL_INO_OFFSET;
 		d_add(dentry, inode);
 	}
 	bool_num = num;
Signature · 1 line
1.5.0.6
#12 lore raw

PATCH 12/12 selinux: preserve boolean values across policy reloads

In reply to James Morris

From: Stephen Smalley <[email protected]>

At present, the userland policy loading code has to go through contortions to preserve boolean values across policy reloads, and cannot do so atomically. As this is what we always want to do for reloads, let the kernel preserve them instead.

---
 security/selinux/ss/services.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
security/selinux/ss/services.c +38 -0
index 21b8318..40660ff 100644
@@ -1257,6 +1257,7 @@ bad:
 }
 
 extern void selinux_complete_init(void);
+static int security_preserve_bools(struct policydb *p);
 
 /**
  * security_load_policy - Load a security policy configuration.
@@ -1333,6 +1334,12 @@ int security_load_policy(void *data, size_t len)
 		goto err;
 	}
 
+	rc = security_preserve_bools(&newpolicydb);
+	if (rc) {
+		printk(KERN_ERR "security:  unable to preserve booleans\n");
+		goto err;
+	}
+
 	/* Clone the SID table. */
 	sidtab_shutdown(&sidtab);
 	if (sidtab_map(&sidtab, clone_sid, &newsidtab)) {
@@ -1890,6 +1897,37 @@ out:
 	return rc;
 }
 
+static int security_preserve_bools(struct policydb *p)
+{
+	int rc, nbools = 0, *bvalues = NULL, i;
+	char **bnames = NULL;
+	struct cond_bool_datum *booldatum;
+	struct cond_node *cur;
+
+	rc = security_get_bools(&nbools, &bnames, &bvalues);
+	if (rc)
+		goto out;
+	for (i = 0; i < nbools; i++) {
+		booldatum = hashtab_search(p->p_bools.table, bnames[i]);
+		if (booldatum)
+			booldatum->state = bvalues[i];
+	}
+	for (cur = p->cond_list; cur != NULL; cur = cur->next) {
+		rc = evaluate_cond_node(p, cur);
+		if (rc)
+			goto out;
+	}
+
+out:
+	if (bnames) {
+		for (i = 0; i < nbools; i++)
+			kfree(bnames[i]);
+	}
+	kfree(bnames);
+	kfree(bvalues);
+	return rc;
+}
+
 /*
  * security_sid_mls_copy() - computes a new sid based on the given
  * sid and the mls portion of mls_sid.
Signature · 1 line
1.5.0.6