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)
882 if (new_value && bool_pending_values) {
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);
955 bool_pending_values = NULL;
957 sel_remove_bools(dir);
959 if (!(page = (char*)get_zeroed_page(GFP_KERNEL)))
962 ret = security_get_bools(&num, &names, &values);
966 for (i = 0; i < num; i++) {
967 dentry = d_alloc_name(dir, names[i]);
972 inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
978 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
982 } else if (len >= PAGE_SIZE) {
986 isec = (struct inode_security_struct*)inode->i_security;
987 if ((ret = security_genfs_sid("selinuxfs", page, SECCLASS_FILE, &sid)))
990 isec->initialized = 1;
991 inode->i_fop = &sel_bool_ops;
992 inode->i_ino = i + BOOL_INO_OFFSET;
993 d_add(dentry, inode);
996 bool_pending_values = values;
998 free_page((unsigned long)page);
1000 for (i = 0; i < num; i++)
1012 #define NULL_FILE_NAME "null"
1014 struct dentry *selinux_null = NULL;
1016 static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
1017 size_t count, loff_t *ppos)
1019 char tmpbuf[TMPBUFLEN];
1022 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", avc_cache_threshold);
1023 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
1026 static ssize_t sel_write_avc_cache_threshold(struct file * file,
1027 const char __user * buf,
1028 size_t count, loff_t *ppos)
1035 if (count < 0 || count >= PAGE_SIZE) {
1041 /* No partial writes. */
1046 page = (char*)get_zeroed_page(GFP_KERNEL);
1052 if (copy_from_user(page, buf, count)) {
1057 if (sscanf(page, "%u", &new_value) != 1) {
1062 if (new_value != avc_cache_threshold) {
1063 ret = task_has_security(current, SECURITY__SETSECPARAM);
1066 avc_cache_threshold = new_value;
1070 free_page((unsigned long)page);
1075 static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
1076 size_t count, loff_t *ppos)
1081 page = (char *)__get_free_page(GFP_KERNEL);
1086 ret = avc_get_hash_stats(page);
1088 ret = simple_read_from_buffer(buf, count, ppos, page, ret);
1089 free_page((unsigned long)page);
1094 static struct file_operations sel_avc_cache_threshold_ops = {
1095 .read = sel_read_avc_cache_threshold,
1096 .write = sel_write_avc_cache_threshold,
1099 static struct file_operations sel_avc_hash_stats_ops = {
1100 .read = sel_read_avc_hash_stats,
1103 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1104 static struct avc_cache_stats *sel_avc_get_stat_idx(loff_t *idx)
1108 for (cpu = *idx; cpu < NR_CPUS; ++cpu) {
1109 if (!cpu_possible(cpu))
1112 return &per_cpu(avc_cache_stats, cpu);
1117 static void *sel_avc_stats_seq_start(struct seq_file *seq, loff_t *pos)
1119 loff_t n = *pos - 1;
1122 return SEQ_START_TOKEN;
1124 return sel_avc_get_stat_idx(&n);
1127 static void *sel_avc_stats_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1129 return sel_avc_get_stat_idx(pos);
1132 static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
1134 struct avc_cache_stats *st = v;
1136 if (v == SEQ_START_TOKEN)
1137 seq_printf(seq, "lookups hits misses allocations reclaims "
1140 seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
1141 st->hits, st->misses, st->allocations,
1142 st->reclaims, st->frees);
1146 static void sel_avc_stats_seq_stop(struct seq_file *seq, void *v)
1149 static struct seq_operations sel_avc_cache_stats_seq_ops = {
1150 .start = sel_avc_stats_seq_start,
1151 .next = sel_avc_stats_seq_next,
1152 .show = sel_avc_stats_seq_show,
1153 .stop = sel_avc_stats_seq_stop,
1156 static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
1158 return seq_open(file, &sel_avc_cache_stats_seq_ops);
1161 static struct file_operations sel_avc_cache_stats_ops = {
1162 .open = sel_open_avc_cache_stats,
1164 .llseek = seq_lseek,
1165 .release = seq_release,
1169 static int sel_make_avc_files(struct dentry *dir)
1172 static struct tree_descr files[] = {
1173 { "cache_threshold",
1174 &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR },
1175 { "hash_stats", &sel_avc_hash_stats_ops, S_IRUGO },
1176 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1177 { "cache_stats", &sel_avc_cache_stats_ops, S_IRUGO },
1181 for (i = 0; i < sizeof (files) / sizeof (files[0]); i++) {
1182 struct inode *inode;
1183 struct dentry *dentry;
1185 dentry = d_alloc_name(dir, files[i].name);
1191 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
1196 inode->i_fop = files[i].ops;
1197 d_add(dentry, inode);
1206 static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
1209 struct inode *inode;
1211 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1216 inode->i_op = &simple_dir_inode_operations;
1217 inode->i_fop = &simple_dir_operations;
1218 d_add(dentry, inode);
1223 static int sel_fill_super(struct super_block * sb, void * data, int silent)
1226 struct dentry *dentry;
1227 struct inode *inode;
1228 struct inode_security_struct *isec;
1230 static struct tree_descr selinux_files[] = {
1231 [SEL_LOAD] = {"load", &sel_load_ops, S_IRUSR|S_IWUSR},
1232 [SEL_ENFORCE] = {"enforce", &sel_enforce_ops, S_IRUGO|S_IWUSR},
1233 [SEL_CONTEXT] = {"context", &sel_context_ops, S_IRUGO|S_IWUGO},
1234 [SEL_ACCESS] = {"access", &transaction_ops, S_IRUGO|S_IWUGO},
1235 [SEL_CREATE] = {"create", &transaction_ops, S_IRUGO|S_IWUGO},
1236 [SEL_RELABEL] = {"relabel", &transaction_ops, S_IRUGO|S_IWUGO},
1237 [SEL_USER] = {"user", &transaction_ops, S_IRUGO|S_IWUGO},
1238 [SEL_POLICYVERS] = {"policyvers", &sel_policyvers_ops, S_IRUGO},
1239 [SEL_COMMIT_BOOLS] = {"commit_pending_bools", &sel_commit_bools_ops, S_IWUSR},
1240 [SEL_MLS] = {"mls", &sel_mls_ops, S_IRUGO},
1241 [SEL_DISABLE] = {"disable", &sel_disable_ops, S_IWUSR},
1242 [SEL_MEMBER] = {"member", &transaction_ops, S_IRUGO|S_IWUGO},
1243 [SEL_CHECKREQPROT] = {"checkreqprot", &sel_checkreqprot_ops, S_IRUGO|S_IWUSR},
1246 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
1250 dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
1254 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1257 inode->i_op = &simple_dir_inode_operations;
1258 inode->i_fop = &simple_dir_operations;
1259 d_add(dentry, inode);
1261 ret = sel_make_bools();
1265 dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
1269 inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
1272 isec = (struct inode_security_struct*)inode->i_security;
1273 isec->sid = SECINITSID_DEVNULL;
1274 isec->sclass = SECCLASS_CHR_FILE;
1275 isec->initialized = 1;
1277 init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, MKDEV(MEM_MAJOR, 3));
1278 d_add(dentry, inode);
1279 selinux_null = dentry;
1281 dentry = d_alloc_name(sb->s_root, "avc");
1285 ret = sel_make_dir(sb, dentry);
1289 ret = sel_make_avc_files(dentry);
1296 printk(KERN_ERR "%s: failed while creating inodes\n", __FUNCTION__);
1300 static struct super_block *sel_get_sb(struct file_system_type *fs_type,
1301 int flags, const char *dev_name, void *data)
1303 return get_sb_single(fs_type, flags, data, sel_fill_super);
1306 static struct file_system_type sel_fs_type = {
1307 .name = "selinuxfs",
1308 .get_sb = sel_get_sb,
1309 .kill_sb = kill_litter_super,
1312 struct vfsmount *selinuxfs_mount;
1314 static int __init init_sel_fs(void)
1318 if (!selinux_enabled)
1320 err = register_filesystem(&sel_fs_type);
1322 selinuxfs_mount = kern_mount(&sel_fs_type);
1323 if (IS_ERR(selinuxfs_mount)) {
1324 printk(KERN_ERR "selinuxfs: could not mount!\n");
1325 err = PTR_ERR(selinuxfs_mount);
1326 selinuxfs_mount = NULL;
1332 __initcall(init_sel_fs);
1334 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1335 void exit_sel_fs(void)
1337 unregister_filesystem(&sel_fs_type);