1 /* Updated: Karl MacMillan <kmacmillan@tresys.com>
3 * Added conditional policy language extensions
5 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
6 * Copyright (C) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2.
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/pagemap.h>
15 #include <linux/slab.h>
16 #include <linux/vmalloc.h>
18 #include <linux/init.h>
19 #include <linux/string.h>
20 #include <linux/security.h>
21 #include <linux/major.h>
22 #include <linux/seq_file.h>
23 #include <linux/percpu.h>
24 #include <asm/uaccess.h>
25 #include <asm/semaphore.h>
27 /* selinuxfs pseudo filesystem for exporting the security policy API.
28 Based on the proc code and the fs/nfsd/nfsctl.c code. */
35 #include "conditional.h"
37 unsigned int selinux_checkreqprot = CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE;
39 static int __init checkreqprot_setup(char *str)
41 selinux_checkreqprot = simple_strtoul(str,NULL,0) ? 1 : 0;
44 __setup("checkreqprot=", checkreqprot_setup);
47 static DECLARE_MUTEX(sel_sem);
49 /* global data for booleans */
50 static struct dentry *bool_dir = NULL;
51 static int bool_num = 0;
52 static int *bool_pending_values = NULL;
54 extern void selnl_notify_setenforce(int val);
56 /* Check whether a task is allowed to use a security operation. */
57 static int task_has_security(struct task_struct *tsk,
60 struct task_security_struct *tsec;
66 return avc_has_perm(tsec->sid, SECINITSID_SECURITY,
67 SECCLASS_SECURITY, perms, NULL);
72 SEL_LOAD, /* load policy */
73 SEL_ENFORCE, /* get or set enforcing status */
74 SEL_CONTEXT, /* validate context */
75 SEL_ACCESS, /* compute access decision */
76 SEL_CREATE, /* compute create labeling decision */
77 SEL_RELABEL, /* compute relabeling decision */
78 SEL_USER, /* compute reachable user contexts */
79 SEL_POLICYVERS, /* return policy version for this kernel */
80 SEL_COMMIT_BOOLS, /* commit new boolean values */
81 SEL_MLS, /* return if MLS policy is enabled */
82 SEL_DISABLE, /* disable SELinux until next reboot */
83 SEL_AVC, /* AVC management directory */
84 SEL_MEMBER, /* compute polyinstantiation membership decision */
85 SEL_CHECKREQPROT, /* check requested protection, not kernel-applied one */
89 static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
90 size_t count, loff_t *ppos)
92 char tmpbuf[TMPBUFLEN];
95 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_enforcing);
96 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
99 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
100 static ssize_t sel_write_enforce(struct file * file, const char __user * buf,
101 size_t count, loff_t *ppos)
108 if (count < 0 || count >= PAGE_SIZE)
111 /* No partial writes. */
114 page = (char*)get_zeroed_page(GFP_KERNEL);
118 if (copy_from_user(page, buf, count))
122 if (sscanf(page, "%d", &new_value) != 1)
125 if (new_value != selinux_enforcing) {
126 length = task_has_security(current, SECURITY__SETENFORCE);
129 selinux_enforcing = new_value;
130 if (selinux_enforcing)
132 selnl_notify_setenforce(selinux_enforcing);
136 free_page((unsigned long) page);
140 #define sel_write_enforce NULL
143 static struct file_operations sel_enforce_ops = {
144 .read = sel_read_enforce,
145 .write = sel_write_enforce,
148 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
149 static ssize_t sel_write_disable(struct file * file, const char __user * buf,
150 size_t count, loff_t *ppos)
156 extern int selinux_disable(void);
158 if (count < 0 || count >= PAGE_SIZE)
161 /* No partial writes. */
164 page = (char*)get_zeroed_page(GFP_KERNEL);
168 if (copy_from_user(page, buf, count))
172 if (sscanf(page, "%d", &new_value) != 1)
176 length = selinux_disable();
183 free_page((unsigned long) page);
187 #define sel_write_disable NULL
190 static struct file_operations sel_disable_ops = {
191 .write = sel_write_disable,
194 static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
195 size_t count, loff_t *ppos)
197 char tmpbuf[TMPBUFLEN];
200 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);
201 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
204 static struct file_operations sel_policyvers_ops = {
205 .read = sel_read_policyvers,
208 /* declaration for sel_write_load */
209 static int sel_make_bools(void);
211 static ssize_t sel_read_mls(struct file *filp, char __user *buf,
212 size_t count, loff_t *ppos)
214 char tmpbuf[TMPBUFLEN];
217 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_mls_enabled);
218 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
221 static struct file_operations sel_mls_ops = {
222 .read = sel_read_mls,
225 static ssize_t sel_write_load(struct file * file, const char __user * buf,
226 size_t count, loff_t *ppos)
235 length = task_has_security(current, SECURITY__LOAD_POLICY);
240 /* No partial writes. */
245 if ((count < 0) || (count > 64 * 1024 * 1024)
246 || (data = vmalloc(count)) == NULL) {
252 if (copy_from_user(data, buf, count) != 0)
255 length = security_load_policy(data, count);
259 ret = sel_make_bools();
270 static struct file_operations sel_load_ops = {
271 .write = sel_write_load,
275 static ssize_t sel_write_context(struct file * file, const char __user * buf,
276 size_t count, loff_t *ppos)
283 length = task_has_security(current, SECURITY__CHECK_CONTEXT);
287 if (count < 0 || count >= PAGE_SIZE)
290 /* No partial writes. */
293 page = (char*)get_zeroed_page(GFP_KERNEL);
297 if (copy_from_user(page, buf, count))
300 length = security_context_to_sid(page, count, &sid);
306 free_page((unsigned long) page);
310 static struct file_operations sel_context_ops = {
311 .write = sel_write_context,
314 static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,
315 size_t count, loff_t *ppos)
317 char tmpbuf[TMPBUFLEN];
320 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", selinux_checkreqprot);
321 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
324 static ssize_t sel_write_checkreqprot(struct file * file, const char __user * buf,
325 size_t count, loff_t *ppos)
329 unsigned int new_value;
331 length = task_has_security(current, SECURITY__SETCHECKREQPROT);
335 if (count < 0 || count >= PAGE_SIZE)
338 /* No partial writes. */
341 page = (char*)get_zeroed_page(GFP_KERNEL);
345 if (copy_from_user(page, buf, count))
349 if (sscanf(page, "%u", &new_value) != 1)
352 selinux_checkreqprot = new_value ? 1 : 0;
355 free_page((unsigned long) page);
358 static struct file_operations sel_checkreqprot_ops = {
359 .read = sel_read_checkreqprot,
360 .write = sel_write_checkreqprot,
364 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
366 static ssize_t sel_write_access(struct file * file, char *buf, size_t size);
367 static ssize_t sel_write_create(struct file * file, char *buf, size_t size);
368 static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size);
369 static ssize_t sel_write_user(struct file * file, char *buf, size_t size);
370 static ssize_t sel_write_member(struct file * file, char *buf, size_t size);
372 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
373 [SEL_ACCESS] = sel_write_access,
374 [SEL_CREATE] = sel_write_create,
375 [SEL_RELABEL] = sel_write_relabel,
376 [SEL_USER] = sel_write_user,
377 [SEL_MEMBER] = sel_write_member,
380 static ssize_t selinux_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
382 ino_t ino = file->f_dentry->d_inode->i_ino;
386 if (ino >= sizeof(write_op)/sizeof(write_op[0]) || !write_op[ino])
389 data = simple_transaction_get(file, buf, size);
391 return PTR_ERR(data);
393 rv = write_op[ino](file, data, size);
395 simple_transaction_set(file, rv);
401 static struct file_operations transaction_ops = {
402 .write = selinux_transaction_write,
403 .read = simple_transaction_read,
404 .release = simple_transaction_release,
408 * payload - write methods
409 * If the method has a response, the response should be put in buf,
410 * and the length returned. Otherwise return 0 or and -error.
413 static ssize_t sel_write_access(struct file * file, char *buf, size_t size)
419 struct av_decision avd;
422 length = task_has_security(current, SECURITY__COMPUTE_AV);
427 scon = kmalloc(size+1, GFP_KERNEL);
430 memset(scon, 0, size+1);
432 tcon = kmalloc(size+1, GFP_KERNEL);
435 memset(tcon, 0, size+1);
438 if (sscanf(buf, "%s %s %hu %x", scon, tcon, &tclass, &req) != 4)
441 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
444 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
448 length = security_compute_av(ssid, tsid, tclass, req, &avd);
452 length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT,
454 avd.allowed, avd.decided,
455 avd.auditallow, avd.auditdeny,
464 static ssize_t sel_write_create(struct file * file, char *buf, size_t size)
467 u32 ssid, tsid, newsid;
473 length = task_has_security(current, SECURITY__COMPUTE_CREATE);
478 scon = kmalloc(size+1, GFP_KERNEL);
481 memset(scon, 0, size+1);
483 tcon = kmalloc(size+1, GFP_KERNEL);
486 memset(tcon, 0, size+1);
489 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
492 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
495 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
499 length = security_transition_sid(ssid, tsid, tclass, &newsid);
503 length = security_sid_to_context(newsid, &newcon, &len);
507 if (len > SIMPLE_TRANSACTION_LIMIT) {
508 printk(KERN_ERR "%s: context size (%u) exceeds payload "
509 "max\n", __FUNCTION__, len);
514 memcpy(buf, newcon, len);
525 static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size)
528 u32 ssid, tsid, newsid;
534 length = task_has_security(current, SECURITY__COMPUTE_RELABEL);
539 scon = kmalloc(size+1, GFP_KERNEL);
542 memset(scon, 0, size+1);
544 tcon = kmalloc(size+1, GFP_KERNEL);
547 memset(tcon, 0, size+1);
550 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
553 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
556 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
560 length = security_change_sid(ssid, tsid, tclass, &newsid);
564 length = security_sid_to_context(newsid, &newcon, &len);
568 if (len > SIMPLE_TRANSACTION_LIMIT) {
573 memcpy(buf, newcon, len);
584 static ssize_t sel_write_user(struct file * file, char *buf, size_t size)
586 char *con, *user, *ptr;
593 length = task_has_security(current, SECURITY__COMPUTE_USER);
598 con = kmalloc(size+1, GFP_KERNEL);
601 memset(con, 0, size+1);
603 user = kmalloc(size+1, GFP_KERNEL);
606 memset(user, 0, size+1);
609 if (sscanf(buf, "%s %s", con, user) != 2)
612 length = security_context_to_sid(con, strlen(con)+1, &sid);
616 length = security_get_user_sids(sid, user, &sids, &nsids);
620 length = sprintf(buf, "%u", nsids) + 1;
622 for (i = 0; i < nsids; i++) {
623 rc = security_sid_to_context(sids[i], &newcon, &len);
628 if ((length + len) >= SIMPLE_TRANSACTION_LIMIT) {
633 memcpy(ptr, newcon, len);
647 static ssize_t sel_write_member(struct file * file, char *buf, size_t size)
650 u32 ssid, tsid, newsid;
656 length = task_has_security(current, SECURITY__COMPUTE_MEMBER);
661 scon = kmalloc(size+1, GFP_KERNEL);
664 memset(scon, 0, size+1);
666 tcon = kmalloc(size+1, GFP_KERNEL);
669 memset(tcon, 0, size+1);
672 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
675 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
678 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
682 length = security_member_sid(ssid, tsid, tclass, &newsid);
686 length = security_sid_to_context(newsid, &newcon, &len);
690 if (len > SIMPLE_TRANSACTION_LIMIT) {
691 printk(KERN_ERR "%s: context size (%u) exceeds payload "
692 "max\n", __FUNCTION__, len);
697 memcpy(buf, newcon, len);
708 static struct inode *sel_make_inode(struct super_block *sb, int mode)
710 struct inode *ret = new_inode(sb);
714 ret->i_uid = ret->i_gid = 0;
715 ret->i_blksize = PAGE_CACHE_SIZE;
717 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
722 #define BOOL_INO_OFFSET 30
724 static ssize_t sel_read_bool(struct file *filep, char __user *buf,
725 size_t count, loff_t *ppos)
738 /* check to see if this file has been deleted */
742 if (count < 0 || count > PAGE_SIZE) {
746 if (!(page = (char*)get_zeroed_page(GFP_KERNEL))) {
751 inode = filep->f_dentry->d_inode;
752 cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET);
753 if (cur_enforcing < 0) {
758 length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
759 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET]);
765 if (*ppos >= length) {
769 if (count + *ppos > length)
770 count = length - *ppos;
772 if (copy_to_user(buf, (char *) page + *ppos, count)) {
781 free_page((unsigned long)page);
785 static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
786 size_t count, loff_t *ppos)
789 ssize_t length = -EFAULT;
795 length = task_has_security(current, SECURITY__SETBOOL);
799 /* check to see if this file has been deleted */
803 if (count < 0 || count >= PAGE_SIZE) {
808 /* No partial writes. */
811 page = (char*)get_zeroed_page(GFP_KERNEL);
817 if (copy_from_user(page, buf, count))
821 if (sscanf(page, "%d", &new_value) != 1)
827 inode = filep->f_dentry->d_inode;
828 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value;
834 free_page((unsigned long) page);
838 static struct file_operations sel_bool_ops = {
839 .read = sel_read_bool,
840 .write = sel_write_bool,
843 static ssize_t sel_commit_bools_write(struct file *filep,
844 const char __user *buf,
845 size_t count, loff_t *ppos)
848 ssize_t length = -EFAULT;
853 length = task_has_security(current, SECURITY__SETBOOL);
857 /* check to see if this file has been deleted */
861 if (count < 0 || count >= PAGE_SIZE) {
866 /* No partial writes. */
869 page = (char*)get_zeroed_page(GFP_KERNEL);
875 if (copy_from_user(page, buf, count))
879 if (sscanf(page, "%d", &new_value) != 1)
883 security_set_bools(bool_num, bool_pending_values);
891 free_page((unsigned long) page);
895 static struct file_operations sel_commit_bools_ops = {
896 .write = sel_commit_bools_write,
899 /* delete booleans - partial revoke() from
900 * fs/proc/generic.c proc_kill_inodes */
901 static void sel_remove_bools(struct dentry *de)
903 struct list_head *p, *node;
904 struct super_block *sb = de->d_sb;
906 spin_lock(&dcache_lock);
907 node = de->d_subdirs.next;
908 while (node != &de->d_subdirs) {
909 struct dentry *d = list_entry(node, struct dentry, d_child);
914 spin_unlock(&dcache_lock);
916 simple_unlink(de->d_inode, d);
918 spin_lock(&dcache_lock);
920 node = de->d_subdirs.next;
923 spin_unlock(&dcache_lock);
926 list_for_each(p, &sb->s_files) {
927 struct file * filp = list_entry(p, struct file, f_list);
928 struct dentry * dentry = filp->f_dentry;
930 if (dentry->d_parent != de) {
938 #define BOOL_DIR_NAME "booleans"
940 static int sel_make_bools(void)
944 struct dentry *dentry = NULL;
945 struct dentry *dir = bool_dir;
946 struct inode *inode = NULL;
947 struct inode_security_struct *isec;
948 char **names = NULL, *page;
953 /* remove any existing files */
954 kfree(bool_pending_values);
956 sel_remove_bools(dir);
958 if (!(page = (char*)get_zeroed_page(GFP_KERNEL)))
961 ret = security_get_bools(&num, &names, &values);
965 for (i = 0; i < num; i++) {
966 dentry = d_alloc_name(dir, names[i]);
971 inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
977 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
981 } else if (len >= PAGE_SIZE) {
985 isec = (struct inode_security_struct*)inode->i_security;
986 if ((ret = security_genfs_sid("selinuxfs", page, SECCLASS_FILE, &sid)))
989 isec->initialized = 1;
990 inode->i_fop = &sel_bool_ops;
991 inode->i_ino = i + BOOL_INO_OFFSET;
992 d_add(dentry, inode);
995 bool_pending_values = values;
997 free_page((unsigned long)page);
999 for (i = 0; i < num; i++)
1010 #define NULL_FILE_NAME "null"
1012 struct dentry *selinux_null = NULL;
1014 static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
1015 size_t count, loff_t *ppos)
1017 char tmpbuf[TMPBUFLEN];
1020 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", avc_cache_threshold);
1021 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
1024 static ssize_t sel_write_avc_cache_threshold(struct file * file,
1025 const char __user * buf,
1026 size_t count, loff_t *ppos)
1033 if (count < 0 || count >= PAGE_SIZE) {
1039 /* No partial writes. */
1044 page = (char*)get_zeroed_page(GFP_KERNEL);
1050 if (copy_from_user(page, buf, count)) {
1055 if (sscanf(page, "%u", &new_value) != 1) {
1060 if (new_value != avc_cache_threshold) {
1061 ret = task_has_security(current, SECURITY__SETSECPARAM);
1064 avc_cache_threshold = new_value;
1068 free_page((unsigned long)page);
1073 static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
1074 size_t count, loff_t *ppos)
1079 page = (char *)__get_free_page(GFP_KERNEL);
1084 ret = avc_get_hash_stats(page);
1086 ret = simple_read_from_buffer(buf, count, ppos, page, ret);
1087 free_page((unsigned long)page);
1092 static struct file_operations sel_avc_cache_threshold_ops = {
1093 .read = sel_read_avc_cache_threshold,
1094 .write = sel_write_avc_cache_threshold,
1097 static struct file_operations sel_avc_hash_stats_ops = {
1098 .read = sel_read_avc_hash_stats,
1101 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1102 static struct avc_cache_stats *sel_avc_get_stat_idx(loff_t *idx)
1106 for (cpu = *idx; cpu < NR_CPUS; ++cpu) {
1107 if (!cpu_possible(cpu))
1110 return &per_cpu(avc_cache_stats, cpu);
1115 static void *sel_avc_stats_seq_start(struct seq_file *seq, loff_t *pos)
1117 loff_t n = *pos - 1;
1120 return SEQ_START_TOKEN;
1122 return sel_avc_get_stat_idx(&n);
1125 static void *sel_avc_stats_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1127 return sel_avc_get_stat_idx(pos);
1130 static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
1132 struct avc_cache_stats *st = v;
1134 if (v == SEQ_START_TOKEN)
1135 seq_printf(seq, "lookups hits misses allocations reclaims "
1138 seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
1139 st->hits, st->misses, st->allocations,
1140 st->reclaims, st->frees);
1144 static void sel_avc_stats_seq_stop(struct seq_file *seq, void *v)
1147 static struct seq_operations sel_avc_cache_stats_seq_ops = {
1148 .start = sel_avc_stats_seq_start,
1149 .next = sel_avc_stats_seq_next,
1150 .show = sel_avc_stats_seq_show,
1151 .stop = sel_avc_stats_seq_stop,
1154 static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
1156 return seq_open(file, &sel_avc_cache_stats_seq_ops);
1159 static struct file_operations sel_avc_cache_stats_ops = {
1160 .open = sel_open_avc_cache_stats,
1162 .llseek = seq_lseek,
1163 .release = seq_release,
1167 static int sel_make_avc_files(struct dentry *dir)
1170 static struct tree_descr files[] = {
1171 { "cache_threshold",
1172 &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR },
1173 { "hash_stats", &sel_avc_hash_stats_ops, S_IRUGO },
1174 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1175 { "cache_stats", &sel_avc_cache_stats_ops, S_IRUGO },
1179 for (i = 0; i < sizeof (files) / sizeof (files[0]); i++) {
1180 struct inode *inode;
1181 struct dentry *dentry;
1183 dentry = d_alloc_name(dir, files[i].name);
1189 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
1194 inode->i_fop = files[i].ops;
1195 d_add(dentry, inode);
1204 static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
1207 struct inode *inode;
1209 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1214 inode->i_op = &simple_dir_inode_operations;
1215 inode->i_fop = &simple_dir_operations;
1216 d_add(dentry, inode);
1221 static int sel_fill_super(struct super_block * sb, void * data, int silent)
1224 struct dentry *dentry;
1225 struct inode *inode;
1226 struct inode_security_struct *isec;
1228 static struct tree_descr selinux_files[] = {
1229 [SEL_LOAD] = {"load", &sel_load_ops, S_IRUSR|S_IWUSR},
1230 [SEL_ENFORCE] = {"enforce", &sel_enforce_ops, S_IRUGO|S_IWUSR},
1231 [SEL_CONTEXT] = {"context", &sel_context_ops, S_IRUGO|S_IWUGO},
1232 [SEL_ACCESS] = {"access", &transaction_ops, S_IRUGO|S_IWUGO},
1233 [SEL_CREATE] = {"create", &transaction_ops, S_IRUGO|S_IWUGO},
1234 [SEL_RELABEL] = {"relabel", &transaction_ops, S_IRUGO|S_IWUGO},
1235 [SEL_USER] = {"user", &transaction_ops, S_IRUGO|S_IWUGO},
1236 [SEL_POLICYVERS] = {"policyvers", &sel_policyvers_ops, S_IRUGO},
1237 [SEL_COMMIT_BOOLS] = {"commit_pending_bools", &sel_commit_bools_ops, S_IWUSR},
1238 [SEL_MLS] = {"mls", &sel_mls_ops, S_IRUGO},
1239 [SEL_DISABLE] = {"disable", &sel_disable_ops, S_IWUSR},
1240 [SEL_MEMBER] = {"member", &transaction_ops, S_IRUGO|S_IWUGO},
1241 [SEL_CHECKREQPROT] = {"checkreqprot", &sel_checkreqprot_ops, S_IRUGO|S_IWUSR},
1244 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
1248 dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
1252 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1255 inode->i_op = &simple_dir_inode_operations;
1256 inode->i_fop = &simple_dir_operations;
1257 d_add(dentry, inode);
1259 ret = sel_make_bools();
1263 dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
1267 inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
1270 isec = (struct inode_security_struct*)inode->i_security;
1271 isec->sid = SECINITSID_DEVNULL;
1272 isec->sclass = SECCLASS_CHR_FILE;
1273 isec->initialized = 1;
1275 init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, MKDEV(MEM_MAJOR, 3));
1276 d_add(dentry, inode);
1277 selinux_null = dentry;
1279 dentry = d_alloc_name(sb->s_root, "avc");
1283 ret = sel_make_dir(sb, dentry);
1287 ret = sel_make_avc_files(dentry);
1294 printk(KERN_ERR "%s: failed while creating inodes\n", __FUNCTION__);
1298 static struct super_block *sel_get_sb(struct file_system_type *fs_type,
1299 int flags, const char *dev_name, void *data)
1301 return get_sb_single(fs_type, flags, data, sel_fill_super);
1304 static struct file_system_type sel_fs_type = {
1305 .name = "selinuxfs",
1306 .get_sb = sel_get_sb,
1307 .kill_sb = kill_litter_super,
1310 struct vfsmount *selinuxfs_mount;
1312 static int __init init_sel_fs(void)
1316 if (!selinux_enabled)
1318 err = register_filesystem(&sel_fs_type);
1320 selinuxfs_mount = kern_mount(&sel_fs_type);
1321 if (IS_ERR(selinuxfs_mount)) {
1322 printk(KERN_ERR "selinuxfs: could not mount!\n");
1323 err = PTR_ERR(selinuxfs_mount);
1324 selinuxfs_mount = NULL;
1330 __initcall(init_sel_fs);
1332 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1333 void exit_sel_fs(void)
1335 unregister_filesystem(&sel_fs_type);