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 <linux/audit.h>
25 #include <asm/uaccess.h>
26 #include <asm/semaphore.h>
28 /* selinuxfs pseudo filesystem for exporting the security policy API.
29 Based on the proc code and the fs/nfsd/nfsctl.c code. */
36 #include "conditional.h"
38 unsigned int selinux_checkreqprot = CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE;
40 static int __init checkreqprot_setup(char *str)
42 selinux_checkreqprot = simple_strtoul(str,NULL,0) ? 1 : 0;
45 __setup("checkreqprot=", checkreqprot_setup);
48 static DECLARE_MUTEX(sel_sem);
50 /* global data for booleans */
51 static struct dentry *bool_dir = NULL;
52 static int bool_num = 0;
53 static int *bool_pending_values = NULL;
55 extern void selnl_notify_setenforce(int val);
57 /* Check whether a task is allowed to use a security operation. */
58 static int task_has_security(struct task_struct *tsk,
61 struct task_security_struct *tsec;
67 return avc_has_perm(tsec->sid, SECINITSID_SECURITY,
68 SECCLASS_SECURITY, perms, NULL);
73 SEL_LOAD, /* load policy */
74 SEL_ENFORCE, /* get or set enforcing status */
75 SEL_CONTEXT, /* validate context */
76 SEL_ACCESS, /* compute access decision */
77 SEL_CREATE, /* compute create labeling decision */
78 SEL_RELABEL, /* compute relabeling decision */
79 SEL_USER, /* compute reachable user contexts */
80 SEL_POLICYVERS, /* return policy version for this kernel */
81 SEL_COMMIT_BOOLS, /* commit new boolean values */
82 SEL_MLS, /* return if MLS policy is enabled */
83 SEL_DISABLE, /* disable SELinux until next reboot */
84 SEL_AVC, /* AVC management directory */
85 SEL_MEMBER, /* compute polyinstantiation membership decision */
86 SEL_CHECKREQPROT, /* check requested protection, not kernel-applied one */
90 static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
91 size_t count, loff_t *ppos)
93 char tmpbuf[TMPBUFLEN];
96 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_enforcing);
97 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
100 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
101 static ssize_t sel_write_enforce(struct file * file, const char __user * buf,
102 size_t count, loff_t *ppos)
109 if (count >= PAGE_SIZE)
112 /* No partial writes. */
115 page = (char*)get_zeroed_page(GFP_KERNEL);
119 if (copy_from_user(page, buf, count))
123 if (sscanf(page, "%d", &new_value) != 1)
126 if (new_value != selinux_enforcing) {
127 length = task_has_security(current, SECURITY__SETENFORCE);
130 audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_STATUS,
131 "enforcing=%d old_enforcing=%d auid=%u", new_value,
133 audit_get_loginuid(current->audit_context));
134 selinux_enforcing = new_value;
135 if (selinux_enforcing)
137 selnl_notify_setenforce(selinux_enforcing);
141 free_page((unsigned long) page);
145 #define sel_write_enforce NULL
148 static struct file_operations sel_enforce_ops = {
149 .read = sel_read_enforce,
150 .write = sel_write_enforce,
153 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
154 static ssize_t sel_write_disable(struct file * file, const char __user * buf,
155 size_t count, loff_t *ppos)
161 extern int selinux_disable(void);
163 if (count >= PAGE_SIZE)
166 /* No partial writes. */
169 page = (char*)get_zeroed_page(GFP_KERNEL);
173 if (copy_from_user(page, buf, count))
177 if (sscanf(page, "%d", &new_value) != 1)
181 length = selinux_disable();
184 audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_STATUS,
186 audit_get_loginuid(current->audit_context));
191 free_page((unsigned long) page);
195 #define sel_write_disable NULL
198 static struct file_operations sel_disable_ops = {
199 .write = sel_write_disable,
202 static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
203 size_t count, loff_t *ppos)
205 char tmpbuf[TMPBUFLEN];
208 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);
209 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
212 static struct file_operations sel_policyvers_ops = {
213 .read = sel_read_policyvers,
216 /* declaration for sel_write_load */
217 static int sel_make_bools(void);
219 static ssize_t sel_read_mls(struct file *filp, char __user *buf,
220 size_t count, loff_t *ppos)
222 char tmpbuf[TMPBUFLEN];
225 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_mls_enabled);
226 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
229 static struct file_operations sel_mls_ops = {
230 .read = sel_read_mls,
233 static ssize_t sel_write_load(struct file * file, const char __user * buf,
234 size_t count, loff_t *ppos)
243 length = task_has_security(current, SECURITY__LOAD_POLICY);
248 /* No partial writes. */
253 if ((count > 64 * 1024 * 1024)
254 || (data = vmalloc(count)) == NULL) {
260 if (copy_from_user(data, buf, count) != 0)
263 length = security_load_policy(data, count);
267 ret = sel_make_bools();
272 audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
273 "policy loaded auid=%u",
274 audit_get_loginuid(current->audit_context));
281 static struct file_operations sel_load_ops = {
282 .write = sel_write_load,
285 static ssize_t sel_write_context(struct file * file, char *buf, size_t size)
291 length = task_has_security(current, SECURITY__CHECK_CONTEXT);
295 length = security_context_to_sid(buf, size, &sid);
299 length = security_sid_to_context(sid, &canon, &len);
303 if (len > SIMPLE_TRANSACTION_LIMIT) {
304 printk(KERN_ERR "%s: context size (%u) exceeds payload "
305 "max\n", __FUNCTION__, len);
310 memcpy(buf, canon, len);
317 static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,
318 size_t count, loff_t *ppos)
320 char tmpbuf[TMPBUFLEN];
323 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", selinux_checkreqprot);
324 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
327 static ssize_t sel_write_checkreqprot(struct file * file, const char __user * buf,
328 size_t count, loff_t *ppos)
332 unsigned int new_value;
334 length = task_has_security(current, SECURITY__SETCHECKREQPROT);
338 if (count >= PAGE_SIZE)
341 /* No partial writes. */
344 page = (char*)get_zeroed_page(GFP_KERNEL);
348 if (copy_from_user(page, buf, count))
352 if (sscanf(page, "%u", &new_value) != 1)
355 selinux_checkreqprot = new_value ? 1 : 0;
358 free_page((unsigned long) page);
361 static struct file_operations sel_checkreqprot_ops = {
362 .read = sel_read_checkreqprot,
363 .write = sel_write_checkreqprot,
367 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
369 static ssize_t sel_write_access(struct file * file, char *buf, size_t size);
370 static ssize_t sel_write_create(struct file * file, char *buf, size_t size);
371 static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size);
372 static ssize_t sel_write_user(struct file * file, char *buf, size_t size);
373 static ssize_t sel_write_member(struct file * file, char *buf, size_t size);
375 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
376 [SEL_ACCESS] = sel_write_access,
377 [SEL_CREATE] = sel_write_create,
378 [SEL_RELABEL] = sel_write_relabel,
379 [SEL_USER] = sel_write_user,
380 [SEL_MEMBER] = sel_write_member,
381 [SEL_CONTEXT] = sel_write_context,
384 static ssize_t selinux_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
386 ino_t ino = file->f_dentry->d_inode->i_ino;
390 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
393 data = simple_transaction_get(file, buf, size);
395 return PTR_ERR(data);
397 rv = write_op[ino](file, data, size);
399 simple_transaction_set(file, rv);
405 static struct file_operations transaction_ops = {
406 .write = selinux_transaction_write,
407 .read = simple_transaction_read,
408 .release = simple_transaction_release,
412 * payload - write methods
413 * If the method has a response, the response should be put in buf,
414 * and the length returned. Otherwise return 0 or and -error.
417 static ssize_t sel_write_access(struct file * file, char *buf, size_t size)
423 struct av_decision avd;
426 length = task_has_security(current, SECURITY__COMPUTE_AV);
431 scon = kzalloc(size+1, GFP_KERNEL);
435 tcon = kzalloc(size+1, GFP_KERNEL);
440 if (sscanf(buf, "%s %s %hu %x", scon, tcon, &tclass, &req) != 4)
443 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
446 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
450 length = security_compute_av(ssid, tsid, tclass, req, &avd);
454 length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT,
456 avd.allowed, avd.decided,
457 avd.auditallow, avd.auditdeny,
466 static ssize_t sel_write_create(struct file * file, char *buf, size_t size)
469 u32 ssid, tsid, newsid;
475 length = task_has_security(current, SECURITY__COMPUTE_CREATE);
480 scon = kzalloc(size+1, GFP_KERNEL);
484 tcon = kzalloc(size+1, GFP_KERNEL);
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 = kzalloc(size+1, GFP_KERNEL);
543 tcon = kzalloc(size+1, GFP_KERNEL);
548 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
551 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
554 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
558 length = security_change_sid(ssid, tsid, tclass, &newsid);
562 length = security_sid_to_context(newsid, &newcon, &len);
566 if (len > SIMPLE_TRANSACTION_LIMIT) {
571 memcpy(buf, newcon, len);
582 static ssize_t sel_write_user(struct file * file, char *buf, size_t size)
584 char *con, *user, *ptr;
591 length = task_has_security(current, SECURITY__COMPUTE_USER);
596 con = kzalloc(size+1, GFP_KERNEL);
600 user = kzalloc(size+1, GFP_KERNEL);
605 if (sscanf(buf, "%s %s", con, user) != 2)
608 length = security_context_to_sid(con, strlen(con)+1, &sid);
612 length = security_get_user_sids(sid, user, &sids, &nsids);
616 length = sprintf(buf, "%u", nsids) + 1;
618 for (i = 0; i < nsids; i++) {
619 rc = security_sid_to_context(sids[i], &newcon, &len);
624 if ((length + len) >= SIMPLE_TRANSACTION_LIMIT) {
629 memcpy(ptr, newcon, len);
643 static ssize_t sel_write_member(struct file * file, char *buf, size_t size)
646 u32 ssid, tsid, newsid;
652 length = task_has_security(current, SECURITY__COMPUTE_MEMBER);
657 scon = kzalloc(size+1, GFP_KERNEL);
661 tcon = kzalloc(size+1, GFP_KERNEL);
666 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
669 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
672 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
676 length = security_member_sid(ssid, tsid, tclass, &newsid);
680 length = security_sid_to_context(newsid, &newcon, &len);
684 if (len > SIMPLE_TRANSACTION_LIMIT) {
685 printk(KERN_ERR "%s: context size (%u) exceeds payload "
686 "max\n", __FUNCTION__, len);
691 memcpy(buf, newcon, len);
702 static struct inode *sel_make_inode(struct super_block *sb, int mode)
704 struct inode *ret = new_inode(sb);
708 ret->i_uid = ret->i_gid = 0;
709 ret->i_blksize = PAGE_CACHE_SIZE;
711 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
716 #define BOOL_INO_OFFSET 30
718 static ssize_t sel_read_bool(struct file *filep, char __user *buf,
719 size_t count, loff_t *ppos)
732 /* check to see if this file has been deleted */
736 if (count > PAGE_SIZE) {
740 if (!(page = (char*)get_zeroed_page(GFP_KERNEL))) {
745 inode = filep->f_dentry->d_inode;
746 cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET);
747 if (cur_enforcing < 0) {
752 length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
753 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET]);
759 if (*ppos >= length) {
763 if (count + *ppos > length)
764 count = length - *ppos;
766 if (copy_to_user(buf, (char *) page + *ppos, count)) {
775 free_page((unsigned long)page);
779 static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
780 size_t count, loff_t *ppos)
783 ssize_t length = -EFAULT;
789 length = task_has_security(current, SECURITY__SETBOOL);
793 /* check to see if this file has been deleted */
797 if (count >= PAGE_SIZE) {
802 /* No partial writes. */
805 page = (char*)get_zeroed_page(GFP_KERNEL);
811 if (copy_from_user(page, buf, count))
815 if (sscanf(page, "%d", &new_value) != 1)
821 inode = filep->f_dentry->d_inode;
822 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value;
828 free_page((unsigned long) page);
832 static struct file_operations sel_bool_ops = {
833 .read = sel_read_bool,
834 .write = sel_write_bool,
837 static ssize_t sel_commit_bools_write(struct file *filep,
838 const char __user *buf,
839 size_t count, loff_t *ppos)
842 ssize_t length = -EFAULT;
847 length = task_has_security(current, SECURITY__SETBOOL);
851 /* check to see if this file has been deleted */
855 if (count >= PAGE_SIZE) {
860 /* No partial writes. */
863 page = (char*)get_zeroed_page(GFP_KERNEL);
869 if (copy_from_user(page, buf, count))
873 if (sscanf(page, "%d", &new_value) != 1)
876 if (new_value && bool_pending_values) {
877 security_set_bools(bool_num, bool_pending_values);
885 free_page((unsigned long) page);
889 static struct file_operations sel_commit_bools_ops = {
890 .write = sel_commit_bools_write,
893 /* delete booleans - partial revoke() from
894 * fs/proc/generic.c proc_kill_inodes */
895 static void sel_remove_bools(struct dentry *de)
897 struct list_head *p, *node;
898 struct super_block *sb = de->d_sb;
900 spin_lock(&dcache_lock);
901 node = de->d_subdirs.next;
902 while (node != &de->d_subdirs) {
903 struct dentry *d = list_entry(node, struct dentry, d_u.d_child);
908 spin_unlock(&dcache_lock);
910 simple_unlink(de->d_inode, d);
912 spin_lock(&dcache_lock);
914 node = de->d_subdirs.next;
917 spin_unlock(&dcache_lock);
920 list_for_each(p, &sb->s_files) {
921 struct file * filp = list_entry(p, struct file, f_u.fu_list);
922 struct dentry * dentry = filp->f_dentry;
924 if (dentry->d_parent != de) {
932 #define BOOL_DIR_NAME "booleans"
934 static int sel_make_bools(void)
938 struct dentry *dentry = NULL;
939 struct dentry *dir = bool_dir;
940 struct inode *inode = NULL;
941 struct inode_security_struct *isec;
942 char **names = NULL, *page;
947 /* remove any existing files */
948 kfree(bool_pending_values);
949 bool_pending_values = NULL;
951 sel_remove_bools(dir);
953 if (!(page = (char*)get_zeroed_page(GFP_KERNEL)))
956 ret = security_get_bools(&num, &names, &values);
960 for (i = 0; i < num; i++) {
961 dentry = d_alloc_name(dir, names[i]);
966 inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
972 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
976 } else if (len >= PAGE_SIZE) {
980 isec = (struct inode_security_struct*)inode->i_security;
981 if ((ret = security_genfs_sid("selinuxfs", page, SECCLASS_FILE, &sid)))
984 isec->initialized = 1;
985 inode->i_fop = &sel_bool_ops;
986 inode->i_ino = i + BOOL_INO_OFFSET;
987 d_add(dentry, inode);
990 bool_pending_values = values;
992 free_page((unsigned long)page);
994 for (i = 0; i < num; i++)
1006 #define NULL_FILE_NAME "null"
1008 struct dentry *selinux_null = NULL;
1010 static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
1011 size_t count, loff_t *ppos)
1013 char tmpbuf[TMPBUFLEN];
1016 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", avc_cache_threshold);
1017 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
1020 static ssize_t sel_write_avc_cache_threshold(struct file * file,
1021 const char __user * buf,
1022 size_t count, loff_t *ppos)
1029 if (count >= PAGE_SIZE) {
1035 /* No partial writes. */
1040 page = (char*)get_zeroed_page(GFP_KERNEL);
1046 if (copy_from_user(page, buf, count)) {
1051 if (sscanf(page, "%u", &new_value) != 1) {
1056 if (new_value != avc_cache_threshold) {
1057 ret = task_has_security(current, SECURITY__SETSECPARAM);
1060 avc_cache_threshold = new_value;
1064 free_page((unsigned long)page);
1069 static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
1070 size_t count, loff_t *ppos)
1075 page = (char *)__get_free_page(GFP_KERNEL);
1080 ret = avc_get_hash_stats(page);
1082 ret = simple_read_from_buffer(buf, count, ppos, page, ret);
1083 free_page((unsigned long)page);
1088 static struct file_operations sel_avc_cache_threshold_ops = {
1089 .read = sel_read_avc_cache_threshold,
1090 .write = sel_write_avc_cache_threshold,
1093 static struct file_operations sel_avc_hash_stats_ops = {
1094 .read = sel_read_avc_hash_stats,
1097 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1098 static struct avc_cache_stats *sel_avc_get_stat_idx(loff_t *idx)
1102 for (cpu = *idx; cpu < NR_CPUS; ++cpu) {
1103 if (!cpu_possible(cpu))
1106 return &per_cpu(avc_cache_stats, cpu);
1111 static void *sel_avc_stats_seq_start(struct seq_file *seq, loff_t *pos)
1113 loff_t n = *pos - 1;
1116 return SEQ_START_TOKEN;
1118 return sel_avc_get_stat_idx(&n);
1121 static void *sel_avc_stats_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1123 return sel_avc_get_stat_idx(pos);
1126 static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
1128 struct avc_cache_stats *st = v;
1130 if (v == SEQ_START_TOKEN)
1131 seq_printf(seq, "lookups hits misses allocations reclaims "
1134 seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
1135 st->hits, st->misses, st->allocations,
1136 st->reclaims, st->frees);
1140 static void sel_avc_stats_seq_stop(struct seq_file *seq, void *v)
1143 static struct seq_operations sel_avc_cache_stats_seq_ops = {
1144 .start = sel_avc_stats_seq_start,
1145 .next = sel_avc_stats_seq_next,
1146 .show = sel_avc_stats_seq_show,
1147 .stop = sel_avc_stats_seq_stop,
1150 static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
1152 return seq_open(file, &sel_avc_cache_stats_seq_ops);
1155 static struct file_operations sel_avc_cache_stats_ops = {
1156 .open = sel_open_avc_cache_stats,
1158 .llseek = seq_lseek,
1159 .release = seq_release,
1163 static int sel_make_avc_files(struct dentry *dir)
1166 static struct tree_descr files[] = {
1167 { "cache_threshold",
1168 &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR },
1169 { "hash_stats", &sel_avc_hash_stats_ops, S_IRUGO },
1170 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1171 { "cache_stats", &sel_avc_cache_stats_ops, S_IRUGO },
1175 for (i = 0; i < ARRAY_SIZE(files); i++) {
1176 struct inode *inode;
1177 struct dentry *dentry;
1179 dentry = d_alloc_name(dir, files[i].name);
1185 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
1190 inode->i_fop = files[i].ops;
1191 d_add(dentry, inode);
1200 static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
1203 struct inode *inode;
1205 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1210 inode->i_op = &simple_dir_inode_operations;
1211 inode->i_fop = &simple_dir_operations;
1212 d_add(dentry, inode);
1217 static int sel_fill_super(struct super_block * sb, void * data, int silent)
1220 struct dentry *dentry;
1221 struct inode *inode;
1222 struct inode_security_struct *isec;
1224 static struct tree_descr selinux_files[] = {
1225 [SEL_LOAD] = {"load", &sel_load_ops, S_IRUSR|S_IWUSR},
1226 [SEL_ENFORCE] = {"enforce", &sel_enforce_ops, S_IRUGO|S_IWUSR},
1227 [SEL_CONTEXT] = {"context", &transaction_ops, S_IRUGO|S_IWUGO},
1228 [SEL_ACCESS] = {"access", &transaction_ops, S_IRUGO|S_IWUGO},
1229 [SEL_CREATE] = {"create", &transaction_ops, S_IRUGO|S_IWUGO},
1230 [SEL_RELABEL] = {"relabel", &transaction_ops, S_IRUGO|S_IWUGO},
1231 [SEL_USER] = {"user", &transaction_ops, S_IRUGO|S_IWUGO},
1232 [SEL_POLICYVERS] = {"policyvers", &sel_policyvers_ops, S_IRUGO},
1233 [SEL_COMMIT_BOOLS] = {"commit_pending_bools", &sel_commit_bools_ops, S_IWUSR},
1234 [SEL_MLS] = {"mls", &sel_mls_ops, S_IRUGO},
1235 [SEL_DISABLE] = {"disable", &sel_disable_ops, S_IWUSR},
1236 [SEL_MEMBER] = {"member", &transaction_ops, S_IRUGO|S_IWUGO},
1237 [SEL_CHECKREQPROT] = {"checkreqprot", &sel_checkreqprot_ops, S_IRUGO|S_IWUSR},
1240 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
1244 dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
1248 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1251 inode->i_op = &simple_dir_inode_operations;
1252 inode->i_fop = &simple_dir_operations;
1253 d_add(dentry, inode);
1255 ret = sel_make_bools();
1259 dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
1263 inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
1266 isec = (struct inode_security_struct*)inode->i_security;
1267 isec->sid = SECINITSID_DEVNULL;
1268 isec->sclass = SECCLASS_CHR_FILE;
1269 isec->initialized = 1;
1271 init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, MKDEV(MEM_MAJOR, 3));
1272 d_add(dentry, inode);
1273 selinux_null = dentry;
1275 dentry = d_alloc_name(sb->s_root, "avc");
1279 ret = sel_make_dir(sb, dentry);
1283 ret = sel_make_avc_files(dentry);
1290 printk(KERN_ERR "%s: failed while creating inodes\n", __FUNCTION__);
1294 static struct super_block *sel_get_sb(struct file_system_type *fs_type,
1295 int flags, const char *dev_name, void *data)
1297 return get_sb_single(fs_type, flags, data, sel_fill_super);
1300 static struct file_system_type sel_fs_type = {
1301 .name = "selinuxfs",
1302 .get_sb = sel_get_sb,
1303 .kill_sb = kill_litter_super,
1306 struct vfsmount *selinuxfs_mount;
1308 static int __init init_sel_fs(void)
1312 if (!selinux_enabled)
1314 err = register_filesystem(&sel_fs_type);
1316 selinuxfs_mount = kern_mount(&sel_fs_type);
1317 if (IS_ERR(selinuxfs_mount)) {
1318 printk(KERN_ERR "selinuxfs: could not mount!\n");
1319 err = PTR_ERR(selinuxfs_mount);
1320 selinuxfs_mount = NULL;
1326 __initcall(init_sel_fs);
1328 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1329 void exit_sel_fs(void)
1331 unregister_filesystem(&sel_fs_type);