diff options
| -rw-r--r-- | Documentation/SELinux.txt | 27 | ||||
| -rw-r--r-- | scripts/Makefile | 3 | ||||
| -rw-r--r-- | scripts/selinux/Makefile | 2 | ||||
| -rw-r--r-- | scripts/selinux/README | 2 | ||||
| -rw-r--r-- | scripts/selinux/install_policy.sh | 69 | ||||
| -rw-r--r-- | scripts/selinux/mdp/Makefile | 5 | ||||
| -rw-r--r-- | scripts/selinux/mdp/dbus_contexts | 6 | ||||
| -rw-r--r-- | scripts/selinux/mdp/mdp.c | 242 |
8 files changed, 355 insertions, 1 deletions
diff --git a/Documentation/SELinux.txt b/Documentation/SELinux.txt new file mode 100644 index 000000000000..07eae00f3314 --- /dev/null +++ b/Documentation/SELinux.txt | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | If you want to use SELinux, chances are you will want | ||
| 2 | to use the distro-provided policies, or install the | ||
| 3 | latest reference policy release from | ||
| 4 | http://oss.tresys.com/projects/refpolicy | ||
| 5 | |||
| 6 | However, if you want to install a dummy policy for | ||
| 7 | testing, you can do using 'mdp' provided under | ||
| 8 | scripts/selinux. Note that this requires the selinux | ||
| 9 | userspace to be installed - in particular you will | ||
| 10 | need checkpolicy to compile a kernel, and setfiles and | ||
| 11 | fixfiles to label the filesystem. | ||
| 12 | |||
| 13 | 1. Compile the kernel with selinux enabled. | ||
| 14 | 2. Type 'make' to compile mdp. | ||
| 15 | 3. Make sure that you are not running with | ||
| 16 | SELinux enabled and a real policy. If | ||
| 17 | you are, reboot with selinux disabled | ||
| 18 | before continuing. | ||
| 19 | 4. Run install_policy.sh: | ||
| 20 | cd scripts/selinux | ||
| 21 | sh install_policy.sh | ||
| 22 | |||
| 23 | Step 4 will create a new dummy policy valid for your | ||
| 24 | kernel, with a single selinux user, role, and type. | ||
| 25 | It will compile the policy, will set your SELINUXTYPE to | ||
| 26 | dummy in /etc/selinux/config, install the compiled policy | ||
| 27 | as 'dummy', and relabel your filesystem. | ||
diff --git a/scripts/Makefile b/scripts/Makefile index 1c73c5aea66b..aafdf064feef 100644 --- a/scripts/Makefile +++ b/scripts/Makefile | |||
| @@ -20,6 +20,7 @@ hostprogs-y += unifdef | |||
| 20 | 20 | ||
| 21 | subdir-$(CONFIG_MODVERSIONS) += genksyms | 21 | subdir-$(CONFIG_MODVERSIONS) += genksyms |
| 22 | subdir-y += mod | 22 | subdir-y += mod |
| 23 | subdir-$(CONFIG_SECURITY_SELINUX) += selinux | ||
| 23 | 24 | ||
| 24 | # Let clean descend into subdirs | 25 | # Let clean descend into subdirs |
| 25 | subdir- += basic kconfig package | 26 | subdir- += basic kconfig package selinux |
diff --git a/scripts/selinux/Makefile b/scripts/selinux/Makefile new file mode 100644 index 000000000000..ca4b1ec01822 --- /dev/null +++ b/scripts/selinux/Makefile | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | subdir-y := mdp | ||
| 2 | subdir- += mdp | ||
diff --git a/scripts/selinux/README b/scripts/selinux/README new file mode 100644 index 000000000000..a936315ba2c8 --- /dev/null +++ b/scripts/selinux/README | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | Please see Documentation/SELinux.txt for information on | ||
| 2 | installing a dummy SELinux policy. | ||
diff --git a/scripts/selinux/install_policy.sh b/scripts/selinux/install_policy.sh new file mode 100644 index 000000000000..7b9ccf61f8f9 --- /dev/null +++ b/scripts/selinux/install_policy.sh | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | if [ `id -u` -ne 0 ]; then | ||
| 3 | echo "$0: must be root to install the selinux policy" | ||
| 4 | exit 1 | ||
| 5 | fi | ||
| 6 | SF=`which setfiles` | ||
| 7 | if [ $? -eq 1 ]; then | ||
| 8 | if [ -f /sbin/setfiles ]; then | ||
| 9 | SF="/usr/setfiles" | ||
| 10 | else | ||
| 11 | echo "no selinux tools installed: setfiles" | ||
| 12 | exit 1 | ||
| 13 | fi | ||
| 14 | fi | ||
| 15 | |||
| 16 | cd mdp | ||
| 17 | |||
| 18 | CP=`which checkpolicy` | ||
| 19 | VERS=`$CP -V | awk '{print $1}'` | ||
| 20 | |||
| 21 | ./mdp policy.conf file_contexts | ||
| 22 | $CP -o policy.$VERS policy.conf | ||
| 23 | |||
| 24 | mkdir -p /etc/selinux/dummy/policy | ||
| 25 | mkdir -p /etc/selinux/dummy/contexts/files | ||
| 26 | |||
| 27 | cp file_contexts /etc/selinux/dummy/contexts/files | ||
| 28 | cp dbus_contexts /etc/selinux/dummy/contexts | ||
| 29 | cp policy.$VERS /etc/selinux/dummy/policy | ||
| 30 | FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts | ||
| 31 | |||
| 32 | if [ ! -d /etc/selinux ]; then | ||
| 33 | mkdir -p /etc/selinux | ||
| 34 | fi | ||
| 35 | if [ ! -f /etc/selinux/config ]; then | ||
| 36 | cat > /etc/selinux/config << EOF | ||
| 37 | SELINUX=enforcing | ||
| 38 | SELINUXTYPE=dummy | ||
| 39 | EOF | ||
| 40 | else | ||
| 41 | TYPE=`cat /etc/selinux/config | grep "^SELINUXTYPE" | tail -1 | awk -F= '{ print $2 '}` | ||
| 42 | if [ "eq$TYPE" != "eqdummy" ]; then | ||
| 43 | selinuxenabled | ||
| 44 | if [ $? -eq 0 ]; then | ||
| 45 | echo "SELinux already enabled with a non-dummy policy." | ||
| 46 | echo "Exiting. Please install policy by hand if that" | ||
| 47 | echo "is what you REALLY want." | ||
| 48 | exit 1 | ||
| 49 | fi | ||
| 50 | mv /etc/selinux/config /etc/selinux/config.mdpbak | ||
| 51 | grep -v "^SELINUXTYPE" /etc/selinux/config.mdpbak >> /etc/selinux/config | ||
| 52 | echo "SELINUXTYPE=dummy" >> /etc/selinux/config | ||
| 53 | fi | ||
| 54 | fi | ||
| 55 | |||
| 56 | cd /etc/selinux/dummy/contexts/files | ||
| 57 | $SF file_contexts / | ||
| 58 | |||
| 59 | mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}` | ||
| 60 | $SF file_contexts $mounts | ||
| 61 | |||
| 62 | |||
| 63 | dodev=`cat /proc/$$/mounts | grep "/dev "` | ||
| 64 | if [ "eq$dodev" != "eq" ]; then | ||
| 65 | mount --move /dev /mnt | ||
| 66 | $SF file_contexts /dev | ||
| 67 | mount --move /mnt /dev | ||
| 68 | fi | ||
| 69 | |||
diff --git a/scripts/selinux/mdp/Makefile b/scripts/selinux/mdp/Makefile new file mode 100644 index 000000000000..eb365b333441 --- /dev/null +++ b/scripts/selinux/mdp/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | hostprogs-y := mdp | ||
| 2 | HOST_EXTRACFLAGS += -Isecurity/selinux/include | ||
| 3 | |||
| 4 | always := $(hostprogs-y) | ||
| 5 | clean-files := $(hostprogs-y) policy.* file_contexts | ||
diff --git a/scripts/selinux/mdp/dbus_contexts b/scripts/selinux/mdp/dbus_contexts new file mode 100644 index 000000000000..116e684f9fc1 --- /dev/null +++ b/scripts/selinux/mdp/dbus_contexts | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" | ||
| 2 | "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
| 3 | <busconfig> | ||
| 4 | <selinux> | ||
| 5 | </selinux> | ||
| 6 | </busconfig> | ||
diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c new file mode 100644 index 000000000000..ca757d486187 --- /dev/null +++ b/scripts/selinux/mdp/mdp.c | |||
| @@ -0,0 +1,242 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * mdp - make dummy policy | ||
| 4 | * | ||
| 5 | * When pointed at a kernel tree, builds a dummy policy for that kernel | ||
| 6 | * with exactly one type with full rights to itself. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 21 | * | ||
| 22 | * Copyright (C) IBM Corporation, 2006 | ||
| 23 | * | ||
| 24 | * Authors: Serge E. Hallyn <serue@us.ibm.com> | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <stdio.h> | ||
| 28 | #include <stdlib.h> | ||
| 29 | #include <unistd.h> | ||
| 30 | #include <string.h> | ||
| 31 | |||
| 32 | #include "flask.h" | ||
| 33 | |||
| 34 | void usage(char *name) | ||
| 35 | { | ||
| 36 | printf("usage: %s [-m] policy_file context_file\n", name); | ||
| 37 | exit(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | void find_common_name(char *cname, char *dest, int len) | ||
| 41 | { | ||
| 42 | char *start, *end; | ||
| 43 | |||
| 44 | start = strchr(cname, '_')+1; | ||
| 45 | end = strchr(start, '_'); | ||
| 46 | if (!start || !end || start-cname > len || end-start > len) { | ||
| 47 | printf("Error with commons defines\n"); | ||
| 48 | exit(1); | ||
| 49 | } | ||
| 50 | strncpy(dest, start, end-start); | ||
| 51 | dest[end-start] = '\0'; | ||
| 52 | } | ||
| 53 | |||
| 54 | #define S_(x) x, | ||
| 55 | static char *classlist[] = { | ||
| 56 | #include "class_to_string.h" | ||
| 57 | NULL | ||
| 58 | }; | ||
