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 static DECLARE_MUTEX(sel_sem);
39 /* global data for booleans */
40 static struct dentry *bool_dir = NULL;
41 static int bool_num = 0;
42 static int *bool_pending_values = NULL;
44 extern void selnl_notify_setenforce(int val);
46 /* Check whether a task is allowed to use a security operation. */
47 int task_has_security(struct task_struct *tsk,
50 struct task_security_struct *tsec;
56 return avc_has_perm(tsec->sid, SECINITSID_SECURITY,
57 SECCLASS_SECURITY, perms, NULL);
62 SEL_LOAD, /* load policy */
63 SEL_ENFORCE, /* get or set enforcing status */
64 SEL_CONTEXT, /* validate context */
65 SEL_ACCESS, /* compute access decision */
66 SEL_CREATE, /* compute create labeling decision */
67 SEL_RELABEL, /* compute relabeling decision */
68 SEL_USER, /* compute reachable user contexts */
69 SEL_POLICYVERS, /* return policy version for this kernel */
70 SEL_COMMIT_BOOLS, /* commit new boolean values */
71 SEL_MLS, /* return if MLS policy is enabled */
72 SEL_DISABLE, /* disable SELinux until next reboot */
73 SEL_AVC, /* AVC management directory */
74 SEL_MEMBER, /* compute polyinstantiation membership decision */
78 static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
79 size_t count, loff_t *ppos)
81 char tmpbuf[TMPBUFLEN];
84 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_enforcing);
85 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
88 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
89 static ssize_t sel_write_enforce(struct file * file, const char __user * buf,
90 size_t count, loff_t *ppos)
97 if (count < 0 || count >= PAGE_SIZE)
100 /* No partial writes. */
103 page = (char*)get_zeroed_page(GFP_KERNEL);
107 if (copy_from_user(page, buf, count))
111 if (sscanf(page, "%d", &new_value) != 1)
114 if (new_value != selinux_enforcing) {
115 length = task_has_security(current, SECURITY__SETENFORCE);
118 selinux_enforcing = new_value;
119 if (selinux_enforcing)
121 selnl_notify_setenforce(selinux_enforcing);
125 free_page((unsigned long) page);
129 #define sel_write_enforce NULL
132 static struct file_operations sel_enforce_ops = {
133 .read = sel_read_enforce,
134 .write = sel_write_enforce,
137 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
138 static ssize_t sel_write_disable(struct file * file, const char __user * buf,
139 size_t count, loff_t *ppos)
145 extern int selinux_disable(void);
147 if (count < 0 || count >= PAGE_SIZE)
150 /* No partial writes. */
153 page = (char*)get_zeroed_page(GFP_KERNEL);
157 if (copy_from_user(page, buf, count))
161 if (sscanf(page, "%d", &new_value) != 1)
165 length = selinux_disable();
172 free_page((unsigned long) page);
176 #define sel_write_disable NULL
179 static struct file_operations sel_disable_ops = {
180 .write = sel_write_disable,
183 static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
184 size_t count, loff_t *ppos)
186 char tmpbuf[TMPBUFLEN];
189 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);
190 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
193 static struct file_operations sel_policyvers_ops = {
194 .read = sel_read_policyvers,
197 /* declaration for sel_write_load */
198 static int sel_make_bools(void);
200 static ssize_t sel_read_mls(struct file *filp, char __user *buf,
201 size_t count, loff_t *ppos)
203 char tmpbuf[TMPBUFLEN];
206 length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_mls_enabled);
207 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
210 static struct file_operations sel_mls_ops = {
211 .read = sel_read_mls,
214 static ssize_t sel_write_load(struct file * file, const char __user * buf,
215 size_t count, loff_t *ppos)
224 length = task_has_security(current, SECURITY__LOAD_POLICY);
229 /* No partial writes. */
234 if ((count < 0) || (count > 64 * 1024 * 1024)
235 || (data = vmalloc(count)) == NULL) {
241 if (copy_from_user(data, buf, count) != 0)
244 length = security_load_policy(data, count);
248 ret = sel_make_bools();
259 static struct file_operations sel_load_ops = {
260 .write = sel_write_load,
264 static ssize_t sel_write_context(struct file * file, const char __user * buf,
265 size_t count, loff_t *ppos)
272 length = task_has_security(current, SECURITY__CHECK_CONTEXT);
276 if (count < 0 || count >= PAGE_SIZE)
279 /* No partial writes. */
282 page = (char*)get_zeroed_page(GFP_KERNEL);
286 if (copy_from_user(page, buf, count))
289 length = security_context_to_sid(page, count, &sid);
295 free_page((unsigned long) page);
299 static struct file_operations sel_context_ops = {
300 .write = sel_write_context,
305 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
307 static ssize_t sel_write_access(struct file * file, char *buf, size_t size);
308 static ssize_t sel_write_create(struct file * file, char *buf, size_t size);
309 static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size);
310 static ssize_t sel_write_user(struct file * file, char *buf, size_t size);
311 static ssize_t sel_write_member(struct file * file, char *buf, size_t size);
313 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
314 [SEL_ACCESS] = sel_write_access,
315 [SEL_CREATE] = sel_write_create,
316 [SEL_RELABEL] = sel_write_relabel,
317 [SEL_USER] = sel_write_user,
318 [SEL_MEMBER] = sel_write_member,
321 static ssize_t selinux_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
323 ino_t ino = file->f_dentry->d_inode->i_ino;
327 if (ino >= sizeof(write_op)/sizeof(write_op[0]) || !write_op[ino])
330 data = simple_transaction_get(file, buf, size);
332 return PTR_ERR(data);
334 rv = write_op[ino](file, data, size);
336 simple_transaction_set(file, rv);
342 static struct file_operations transaction_ops = {
343 .write = selinux_transaction_write,
344 .read = simple_transaction_read,
345 .release = simple_transaction_release,
349 * payload - write methods
350 * If the method has a response, the response should be put in buf,
351 * and the length returned. Otherwise return 0 or and -error.
354 static ssize_t sel_write_access(struct file * file, char *buf, size_t size)
360 struct av_decision avd;
363 length = task_has_security(current, SECURITY__COMPUTE_AV);
368 scon = kmalloc(size+1, GFP_KERNEL);
371 memset(scon, 0, size+1);
373 tcon = kmalloc(size+1, GFP_KERNEL);
376 memset(tcon, 0, size+1);
379 if (sscanf(buf, "%s %s %hu %x", scon, tcon, &tclass, &req) != 4)
382 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
385 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
389 length = security_compute_av(ssid, tsid, tclass, req, &avd);
393 length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT,
395 avd.allowed, avd.decided,
396 avd.auditallow, avd.auditdeny,
405 static ssize_t sel_write_create(struct file * file, char *buf, size_t size)
408 u32 ssid, tsid, newsid;
414 length = task_has_security(current, SECURITY__COMPUTE_CREATE);
419 scon = kmalloc(size+1, GFP_KERNEL);
422 memset(scon, 0, size+1);
424 tcon = kmalloc(size+1, GFP_KERNEL);
427 memset(tcon, 0, size+1);
430 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
433 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
436 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
440 length = security_transition_sid(ssid, tsid, tclass, &newsid);
444 length = security_sid_to_context(newsid, &newcon, &len);
448 if (len > SIMPLE_TRANSACTION_LIMIT) {
449 printk(KERN_ERR "%s: context size (%u) exceeds payload "
450 "max\n", __FUNCTION__, len);
455 memcpy(buf, newcon, len);
466 static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size)
469 u32 ssid, tsid, newsid;
475 length = task_has_security(current, SECURITY__COMPUTE_RELABEL);
480 scon = kmalloc(size+1, GFP_KERNEL);
483 memset(scon, 0, size+1);
485 tcon = kmalloc(size+1, GFP_KERNEL);
488 memset(tcon, 0, size+1);
491 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
494 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
497 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
501 length = security_change_sid(ssid, tsid, tclass, &newsid);
505 length = security_sid_to_context(newsid, &newcon, &len);
509 if (len > SIMPLE_TRANSACTION_LIMIT) {
514 memcpy(buf, newcon, len);
525 static ssize_t sel_write_user(struct file * file, char *buf, size_t size)
527 char *con, *user, *ptr;
534 length = task_has_security(current, SECURITY__COMPUTE_USER);
539 con = kmalloc(size+1, GFP_KERNEL);
542 memset(con, 0, size+1);
544 user = kmalloc(size+1, GFP_KERNEL);
547 memset(user, 0, size+1);
550 if (sscanf(buf, "%s %s", con, user) != 2)
553 length = security_context_to_sid(con, strlen(con)+1, &sid);
557 length = security_get_user_sids(sid, user, &sids, &nsids);
561 length = sprintf(buf, "%u", nsids) + 1;
563 for (i = 0; i < nsids; i++) {
564 rc = security_sid_to_context(sids[i], &newcon, &len);
569 if ((length + len) >= SIMPLE_TRANSACTION_LIMIT) {
574 memcpy(ptr, newcon, len);
588 static ssize_t sel_write_member(struct file * file, char *buf, size_t size)
591 u32 ssid, tsid, newsid;
597 length = task_has_security(current, SECURITY__COMPUTE_MEMBER);
602 scon = kmalloc(size+1, GFP_KERNEL);
605 memset(scon, 0, size+1);
607 tcon = kmalloc(size+1, GFP_KERNEL);
610 memset(tcon, 0, size+1);
613 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
616 length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
619 length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
623 length = security_member_sid(ssid, tsid, tclass, &newsid);
627 length = security_sid_to_context(newsid, &newcon, &len);
631 if (len > SIMPLE_TRANSACTION_LIMIT) {
632 printk(KERN_ERR "%s: context size (%u) exceeds payload "
633 "max\n", __FUNCTION__, len);
638 memcpy(buf, newcon, len);
649 static struct inode *sel_make_inode(struct super_block *sb, int mode)
651 struct inode *ret = new_inode(sb);
655 ret->i_uid = ret->i_gid = 0;
656 ret->i_blksize = PAGE_CACHE_SIZE;
658 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
663 #define BOOL_INO_OFFSET 30
665 static ssize_t sel_read_bool(struct file *filep, char __user *buf,
666 size_t count, loff_t *ppos)
679 /* check to see if this file has been deleted */
683 if (count < 0 || count > PAGE_SIZE) {
687 if (!(page = (char*)get_zeroed_page(GFP_KERNEL))) {
692 inode = filep->f_dentry->d_inode;
693 cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET);
694 if (cur_enforcing < 0) {
699 length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
700 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET]);
706 if (*ppos >= length) {
710 if (count + *ppos > length)
711 count = length - *ppos;
713 if (copy_to_user(buf, (char *) page + *ppos, count)) {
722 free_page((unsigned long)page);
726 static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
727 size_t count, loff_t *ppos)
730 ssize_t length = -EFAULT;
736 length = task_has_security(current, SECURITY__SETBOOL);
740 /* check to see if this file has been deleted */
744 if (count < 0 || count >= PAGE_SIZE) {
749 /* No partial writes. */
752 page = (char*)get_zeroed_page(GFP_KERNEL);
758 if (copy_from_user(page, buf, count))
762 if (sscanf(page, "%d", &new_value) != 1)
768 inode = filep->f_dentry->d_inode;
769 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value;
775 free_page((unsigned long) page);
779 static struct file_operations sel_bool_ops = {
780 .read = sel_read_bool,
781 .write = sel_write_bool,
784 static ssize_t sel_commit_bools_write(struct file *filep,
785 const char __user *buf,
786 size_t count, loff_t *ppos)
789 ssize_t length = -EFAULT;
794 length = task_has_security(current, SECURITY__SETBOOL);
798 /* check to see if this file has been deleted */
802 if (count < 0 || count >= PAGE_SIZE) {
807 /* No partial writes. */
810 page = (char*)get_zeroed_page(GFP_KERNEL);
816 if (copy_from_user(page, buf, count))
820 if (sscanf(page, "%d", &new_value) != 1)
824 security_set_bools(bool_num, bool_pending_values);
832 free_page((unsigned long) page);
836 static struct file_operations sel_commit_bools_ops = {
837 .write = sel_commit_bools_write,
840 /* delete booleans - partial revoke() from
841 * fs/proc/generic.c proc_kill_inodes */
842 static void sel_remove_bools(struct dentry *de)
844 struct list_head *p, *node;
845 struct super_block *sb = de->d_sb;
847 spin_lock(&dcache_lock);
848 node = de->d_subdirs.next;
849 while (node != &de->d_subdirs) {
850 struct dentry *d = list_entry(node, struct dentry, d_child);
855 spin_unlock(&dcache_lock);
857 simple_unlink(de->d_inode, d);
859 spin_lock(&dcache_lock);
861 node = de->d_subdirs.next;
864 spin_unlock(&dcache_lock);
867 list_for_each(p, &sb->s_files) {
868 struct file * filp = list_entry(p, struct file, f_list);
869 struct dentry * dentry = filp->f_dentry;
871 if (dentry->d_parent != de) {
879 #define BOOL_DIR_NAME "booleans"
881 static int sel_make_bools(void)
885 struct dentry *dentry = NULL;
886 struct dentry *dir = bool_dir;
887 struct inode *inode = NULL;
888 struct inode_security_struct *isec;
889 char **names = NULL, *page;
894 /* remove any existing files */
895 if (bool_pending_values)
896 kfree(bool_pending_values);
898 sel_remove_bools(dir);
900 if (!(page = (char*)get_zeroed_page(GFP_KERNEL)))
903 ret = security_get_bools(&num, &names, &values);
907 for (i = 0; i < num; i++) {
908 dentry = d_alloc_name(dir, names[i]);
913 inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
919 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
923 } else if (len >= PAGE_SIZE) {
927 isec = (struct inode_security_struct*)inode->i_security;
928 if ((ret = security_genfs_sid("selinuxfs", page, SECCLASS_FILE, &sid)))
931 isec->initialized = 1;
932 inode->i_fop = &sel_bool_ops;
933 inode->i_ino = i + BOOL_INO_OFFSET;
934 d_add(dentry, inode);
937 bool_pending_values = values;
939 free_page((unsigned long)page);
941 for (i = 0; i < num; i++) {
954 #define NULL_FILE_NAME "null"
956 struct dentry *selinux_null = NULL;
958 static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
959 size_t count, loff_t *ppos)
961 char tmpbuf[TMPBUFLEN];
964 length = scnprintf(tmpbuf, TMPBUFLEN, "%u", avc_cache_threshold);
965 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
968 static ssize_t sel_write_avc_cache_threshold(struct file * file,
969 const char __user * buf,
970 size_t count, loff_t *ppos)
977 if (count < 0 || count >= PAGE_SIZE) {
983 /* No partial writes. */
988 page = (char*)get_zeroed_page(GFP_KERNEL);
994 if (copy_from_user(page, buf, count)) {
999 if (sscanf(page, "%u", &new_value) != 1) {
1004 if (new_value != avc_cache_threshold) {
1005 ret = task_has_security(current, SECURITY__SETSECPARAM);
1008 avc_cache_threshold = new_value;
1012 free_page((unsigned long)page);
1017 static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
1018 size_t count, loff_t *ppos)
1023 page = (char *)__get_free_page(GFP_KERNEL);
1028 ret = avc_get_hash_stats(page);
1030 ret = simple_read_from_buffer(buf, count, ppos, page, ret);
1031 free_page((unsigned long)page);
1036 static struct file_operations sel_avc_cache_threshold_ops = {
1037 .read = sel_read_avc_cache_threshold,
1038 .write = sel_write_avc_cache_threshold,
1041 static struct file_operations sel_avc_hash_stats_ops = {
1042 .read = sel_read_avc_hash_stats,
1045 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1046 static struct avc_cache_stats *sel_avc_get_stat_idx(loff_t *idx)
1050 for (cpu = *idx; cpu < NR_CPUS; ++cpu) {
1051 if (!cpu_possible(cpu))
1054 return &per_cpu(avc_cache_stats, cpu);
1059 static void *sel_avc_stats_seq_start(struct seq_file *seq, loff_t *pos)
1061 loff_t n = *pos - 1;
1064 return SEQ_START_TOKEN;
1066 return sel_avc_get_stat_idx(&n);
1069 static void *sel_avc_stats_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1071 return sel_avc_get_stat_idx(pos);
1074 static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
1076 struct avc_cache_stats *st = v;
1078 if (v == SEQ_START_TOKEN)
1079 seq_printf(seq, "lookups hits misses allocations reclaims "
1082 seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
1083 st->hits, st->misses, st->allocations,
1084 st->reclaims, st->frees);
1088 static void sel_avc_stats_seq_stop(struct seq_file *seq, void *v)
1091 static struct seq_operations sel_avc_cache_stats_seq_ops = {
1092 .start = sel_avc_stats_seq_start,
1093 .next = sel_avc_stats_seq_next,
1094 .show = sel_avc_stats_seq_show,
1095 .stop = sel_avc_stats_seq_stop,
1098 static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
1100 return seq_open(file, &sel_avc_cache_stats_seq_ops);
1103 static struct file_operations sel_avc_cache_stats_ops = {
1104 .open = sel_open_avc_cache_stats,
1106 .llseek = seq_lseek,
1107 .release = seq_release,
1111 static int sel_make_avc_files(struct dentry *dir)
1114 static struct tree_descr files[] = {
1115 { "cache_threshold",
1116 &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR },
1117 { "hash_stats", &sel_avc_hash_stats_ops, S_IRUGO },
1118 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1119 { "cache_stats", &sel_avc_cache_stats_ops, S_IRUGO },
1123 for (i = 0; i < sizeof (files) / sizeof (files[0]); i++) {
1124 struct inode *inode;
1125 struct dentry *dentry;
1127 dentry = d_alloc_name(dir, files[i].name);
1133 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
1138 inode->i_fop = files[i].ops;
1139 d_add(dentry, inode);
1148 static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
1151 struct inode *inode;
1153 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1158 inode->i_op = &simple_dir_inode_operations;
1159 inode->i_fop = &simple_dir_operations;
1160 d_add(dentry, inode);
1165 static int sel_fill_super(struct super_block * sb, void * data, int silent)
1168 struct dentry *dentry;
1169 struct inode *inode;
1170 struct inode_security_struct *isec;
1172 static struct tree_descr selinux_files[] = {
1173 [SEL_LOAD] = {"load", &sel_load_ops, S_IRUSR|S_IWUSR},
1174 [SEL_ENFORCE] = {"enforce", &sel_enforce_ops, S_IRUGO|S_IWUSR},
1175 [SEL_CONTEXT] = {"context", &sel_context_ops, S_IRUGO|S_IWUGO},
1176 [SEL_ACCESS] = {"access", &transaction_ops, S_IRUGO|S_IWUGO},
1177 [SEL_CREATE] = {"create", &transaction_ops, S_IRUGO|S_IWUGO},
1178 [SEL_RELABEL] = {"relabel", &transaction_ops, S_IRUGO|S_IWUGO},
1179 [SEL_USER] = {"user", &transaction_ops, S_IRUGO|S_IWUGO},
1180 [SEL_POLICYVERS] = {"policyvers", &sel_policyvers_ops, S_IRUGO},
1181 [SEL_COMMIT_BOOLS] = {"commit_pending_bools", &sel_commit_bools_ops, S_IWUSR},
1182 [SEL_MLS] = {"mls", &sel_mls_ops, S_IRUGO},
1183 [SEL_DISABLE] = {"disable", &sel_disable_ops, S_IWUSR},
1184 [SEL_MEMBER] = {"member", &transaction_ops, S_IRUGO|S_IWUGO},
1187 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
1191 dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
1195 inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
1198 inode->i_op = &simple_dir_inode_operations;
1199 inode->i_fop = &simple_dir_operations;
1200 d_add(dentry, inode);
1202 ret = sel_make_bools();
1206 dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
1210 inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
1213 isec = (struct inode_security_struct*)inode->i_security;
1214 isec->sid = SECINITSID_DEVNULL;
1215 isec->sclass = SECCLASS_CHR_FILE;
1216 isec->initialized = 1;
1218 init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, MKDEV(MEM_MAJOR, 3));
1219 d_add(dentry, inode);
1220 selinux_null = dentry;
1222 dentry = d_alloc_name(sb->s_root, "avc");
1226 ret = sel_make_dir(sb, dentry);
1230 ret = sel_make_avc_files(dentry);
1237 printk(KERN_ERR "%s: failed while creating inodes\n", __FUNCTION__);
1241 static struct super_block *sel_get_sb(struct file_system_type *fs_type,
1242 int flags, const char *dev_name, void *data)
1244 return get_sb_single(fs_type, flags, data, sel_fill_super);
1247 static struct file_system_type sel_fs_type = {
1248 .name = "selinuxfs",
1249 .get_sb = sel_get_sb,
1250 .kill_sb = kill_litter_super,
1253 struct vfsmount *selinuxfs_mount;
1255 static int __init init_sel_fs(void)
1259 if (!selinux_enabled)
1261 err = register_filesystem(&sel_fs_type);
1263 selinuxfs_mount = kern_mount(&sel_fs_type);
1264 if (IS_ERR(selinuxfs_mount)) {
1265 printk(KERN_ERR "selinuxfs: could not mount!\n");
1266 err = PTR_ERR(selinuxfs_mount);
1267 selinuxfs_mount = NULL;
1273 __initcall(init_sel_fs);
1275 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1276 void exit_sel_fs(void)
1278 unregister_filesystem(&sel_fs_type);