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
>= 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
>= 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
> 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
,
274 static ssize_t
sel_write_context(struct file
* file
, char *buf
, size_t size
)
280 length
= task_has_security(current
, SECURITY__CHECK_CONTEXT
);
284 length
= security_context_to_sid(buf
, size
, &sid
);
288 length
= security_sid_to_context(sid
, &canon
, &len
);
292 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
293 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
294 "max\n", __FUNCTION__
, len
);
299 memcpy(buf
, canon
, len
);
306 static ssize_t
sel_read_checkreqprot(struct file
*filp
, char __user
*buf
,
307 size_t count
, loff_t
*ppos
)
309 char tmpbuf
[TMPBUFLEN
];
312 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", selinux_checkreqprot
);
313 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
316 static ssize_t
sel_write_checkreqprot(struct file
* file
, const char __user
* buf
,
317 size_t count
, loff_t
*ppos
)
321 unsigned int new_value
;
323 length
= task_has_security(current
, SECURITY__SETCHECKREQPROT
);
327 if (count
>= PAGE_SIZE
)
330 /* No partial writes. */
333 page
= (char*)get_zeroed_page(GFP_KERNEL
);
337 if (copy_from_user(page
, buf
, count
))
341 if (sscanf(page
, "%u", &new_value
) != 1)
344 selinux_checkreqprot
= new_value
? 1 : 0;
347 free_page((unsigned long) page
);
350 static struct file_operations sel_checkreqprot_ops
= {
351 .read
= sel_read_checkreqprot
,
352 .write
= sel_write_checkreqprot
,
356 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
358 static ssize_t
sel_write_access(struct file
* file
, char *buf
, size_t size
);
359 static ssize_t
sel_write_create(struct file
* file
, char *buf
, size_t size
);
360 static ssize_t
sel_write_relabel(struct file
* file
, char *buf
, size_t size
);
361 static ssize_t
sel_write_user(struct file
* file
, char *buf
, size_t size
);
362 static ssize_t
sel_write_member(struct file
* file
, char *buf
, size_t size
);
364 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
365 [SEL_ACCESS
] = sel_write_access
,
366 [SEL_CREATE
] = sel_write_create
,
367 [SEL_RELABEL
] = sel_write_relabel
,
368 [SEL_USER
] = sel_write_user
,
369 [SEL_MEMBER
] = sel_write_member
,
370 [SEL_CONTEXT
] = sel_write_context
,
373 static ssize_t
selinux_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
375 ino_t ino
= file
->f_dentry
->d_inode
->i_ino
;
379 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
382 data
= simple_transaction_get(file
, buf
, size
);
384 return PTR_ERR(data
);
386 rv
= write_op
[ino
](file
, data
, size
);
388 simple_transaction_set(file
, rv
);
394 static struct file_operations transaction_ops
= {
395 .write
= selinux_transaction_write
,
396 .read
= simple_transaction_read
,
397 .release
= simple_transaction_release
,
401 * payload - write methods
402 * If the method has a response, the response should be put in buf,
403 * and the length returned. Otherwise return 0 or and -error.
406 static ssize_t
sel_write_access(struct file
* file
, char *buf
, size_t size
)
412 struct av_decision avd
;
415 length
= task_has_security(current
, SECURITY__COMPUTE_AV
);
420 scon
= kzalloc(size
+1, GFP_KERNEL
);
424 tcon
= kzalloc(size
+1, GFP_KERNEL
);
429 if (sscanf(buf
, "%s %s %hu %x", scon
, tcon
, &tclass
, &req
) != 4)
432 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
435 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
439 length
= security_compute_av(ssid
, tsid
, tclass
, req
, &avd
);
443 length
= scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
,
445 avd
.allowed
, avd
.decided
,
446 avd
.auditallow
, avd
.auditdeny
,
455 static ssize_t
sel_write_create(struct file
* file
, char *buf
, size_t size
)
458 u32 ssid
, tsid
, newsid
;
464 length
= task_has_security(current
, SECURITY__COMPUTE_CREATE
);
469 scon
= kzalloc(size
+1, GFP_KERNEL
);
473 tcon
= kzalloc(size
+1, GFP_KERNEL
);
478 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
481 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
484 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
488 length
= security_transition_sid(ssid
, tsid
, tclass
, &newsid
);
492 length
= security_sid_to_context(newsid
, &newcon
, &len
);
496 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
497 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
498 "max\n", __FUNCTION__
, len
);
503 memcpy(buf
, newcon
, len
);
514 static ssize_t
sel_write_relabel(struct file
* file
, char *buf
, size_t size
)
517 u32 ssid
, tsid
, newsid
;
523 length
= task_has_security(current
, SECURITY__COMPUTE_RELABEL
);
528 scon
= kzalloc(size
+1, GFP_KERNEL
);
532 tcon
= kzalloc(size
+1, GFP_KERNEL
);
537 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
540 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
543 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
547 length
= security_change_sid(ssid
, tsid
, tclass
, &newsid
);
551 length
= security_sid_to_context(newsid
, &newcon
, &len
);
555 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
560 memcpy(buf
, newcon
, len
);
571 static ssize_t
sel_write_user(struct file
* file
, char *buf
, size_t size
)
573 char *con
, *user
, *ptr
;
580 length
= task_has_security(current
, SECURITY__COMPUTE_USER
);
585 con
= kzalloc(size
+1, GFP_KERNEL
);
589 user
= kzalloc(size
+1, GFP_KERNEL
);
594 if (sscanf(buf
, "%s %s", con
, user
) != 2)
597 length
= security_context_to_sid(con
, strlen(con
)+1, &sid
);
601 length
= security_get_user_sids(sid
, user
, &sids
, &nsids
);
605 length
= sprintf(buf
, "%u", nsids
) + 1;
607 for (i
= 0; i
< nsids
; i
++) {
608 rc
= security_sid_to_context(sids
[i
], &newcon
, &len
);
613 if ((length
+ len
) >= SIMPLE_TRANSACTION_LIMIT
) {
618 memcpy(ptr
, newcon
, len
);
632 static ssize_t
sel_write_member(struct file
* file
, char *buf
, size_t size
)
635 u32 ssid
, tsid
, newsid
;
641 length
= task_has_security(current
, SECURITY__COMPUTE_MEMBER
);
646 scon
= kzalloc(size
+1, GFP_KERNEL
);
650 tcon
= kzalloc(size
+1, GFP_KERNEL
);
655 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
658 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
661 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
665 length
= security_member_sid(ssid
, tsid
, tclass
, &newsid
);
669 length
= security_sid_to_context(newsid
, &newcon
, &len
);
673 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
674 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
675 "max\n", __FUNCTION__
, len
);
680 memcpy(buf
, newcon
, len
);
691 static struct inode
*sel_make_inode(struct super_block
*sb
, int mode
)
693 struct inode
*ret
= new_inode(sb
);
697 ret
->i_uid
= ret
->i_gid
= 0;
698 ret
->i_blksize
= PAGE_CACHE_SIZE
;
700 ret
->i_atime
= ret
->i_mtime
= ret
->i_ctime
= CURRENT_TIME
;
705 #define BOOL_INO_OFFSET 30
707 static ssize_t
sel_read_bool(struct file
*filep
, char __user
*buf
,
708 size_t count
, loff_t
*ppos
)
721 /* check to see if this file has been deleted */
725 if (count
> PAGE_SIZE
) {
729 if (!(page
= (char*)get_zeroed_page(GFP_KERNEL
))) {
734 inode
= filep
->f_dentry
->d_inode
;
735 cur_enforcing
= security_get_bool_value(inode
->i_ino
- BOOL_INO_OFFSET
);
736 if (cur_enforcing
< 0) {
741 length
= scnprintf(page
, PAGE_SIZE
, "%d %d", cur_enforcing
,
742 bool_pending_values
[inode
->i_ino
- BOOL_INO_OFFSET
]);
748 if (*ppos
>= length
) {
752 if (count
+ *ppos
> length
)
753 count
= length
- *ppos
;
755 if (copy_to_user(buf
, (char *) page
+ *ppos
, count
)) {
764 free_page((unsigned long)page
);
768 static ssize_t
sel_write_bool(struct file
*filep
, const char __user
*buf
,
769 size_t count
, loff_t
*ppos
)
772 ssize_t length
= -EFAULT
;
778 length
= task_has_security(current
, SECURITY__SETBOOL
);
782 /* check to see if this file has been deleted */
786 if (count
>= PAGE_SIZE
) {
791 /* No partial writes. */
794 page
= (char*)get_zeroed_page(GFP_KERNEL
);
800 if (copy_from_user(page
, buf
, count
))
804 if (sscanf(page
, "%d", &new_value
) != 1)
810 inode
= filep
->f_dentry
->d_inode
;
811 bool_pending_values
[inode
->i_ino
- BOOL_INO_OFFSET
] = new_value
;
817 free_page((unsigned long) page
);
821 static struct file_operations sel_bool_ops
= {
822 .read
= sel_read_bool
,
823 .write
= sel_write_bool
,
826 static ssize_t
sel_commit_bools_write(struct file
*filep
,
827 const char __user
*buf
,
828 size_t count
, loff_t
*ppos
)
831 ssize_t length
= -EFAULT
;
836 length
= task_has_security(current
, SECURITY__SETBOOL
);
840 /* check to see if this file has been deleted */
844 if (count
>= PAGE_SIZE
) {
849 /* No partial writes. */
852 page
= (char*)get_zeroed_page(GFP_KERNEL
);
858 if (copy_from_user(page
, buf
, count
))
862 if (sscanf(page
, "%d", &new_value
) != 1)
865 if (new_value
&& bool_pending_values
) {
866 security_set_bools(bool_num
, bool_pending_values
);
874 free_page((unsigned long) page
);
878 static struct file_operations sel_commit_bools_ops
= {
879 .write
= sel_commit_bools_write
,
882 /* delete booleans - partial revoke() from
883 * fs/proc/generic.c proc_kill_inodes */
884 static void sel_remove_bools(struct dentry
*de
)
886 struct list_head
*p
, *node
;
887 struct super_block
*sb
= de
->d_sb
;
889 spin_lock(&dcache_lock
);
890 node
= de
->d_subdirs
.next
;
891 while (node
!= &de
->d_subdirs
) {
892 struct dentry
*d
= list_entry(node
, struct dentry
, d_u
.d_child
);
897 spin_unlock(&dcache_lock
);
899 simple_unlink(de
->d_inode
, d
);
901 spin_lock(&dcache_lock
);
903 node
= de
->d_subdirs
.next
;
906 spin_unlock(&dcache_lock
);
909 list_for_each(p
, &sb
->s_files
) {
910 struct file
* filp
= list_entry(p
, struct file
, f_u
.fu_list
);
911 struct dentry
* dentry
= filp
->f_dentry
;
913 if (dentry
->d_parent
!= de
) {
921 #define BOOL_DIR_NAME "booleans"
923 static int sel_make_bools(void)
927 struct dentry
*dentry
= NULL
;
928 struct dentry
*dir
= bool_dir
;
929 struct inode
*inode
= NULL
;
930 struct inode_security_struct
*isec
;
931 char **names
= NULL
, *page
;
936 /* remove any existing files */
937 kfree(bool_pending_values
);
938 bool_pending_values
= NULL
;
940 sel_remove_bools(dir
);
942 if (!(page
= (char*)get_zeroed_page(GFP_KERNEL
)))
945 ret
= security_get_bools(&num
, &names
, &values
);
949 for (i
= 0; i
< num
; i
++) {
950 dentry
= d_alloc_name(dir
, names
[i
]);
955 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
| S_IRUGO
| S_IWUSR
);
961 len
= snprintf(page
, PAGE_SIZE
, "/%s/%s", BOOL_DIR_NAME
, names
[i
]);
965 } else if (len
>= PAGE_SIZE
) {
969 isec
= (struct inode_security_struct
*)inode
->i_security
;
970 if ((ret
= security_genfs_sid("selinuxfs", page
, SECCLASS_FILE
, &sid
)))
973 isec
->initialized
= 1;
974 inode
->i_fop
= &sel_bool_ops
;
975 inode
->i_ino
= i
+ BOOL_INO_OFFSET
;
976 d_add(dentry
, inode
);
979 bool_pending_values
= values
;
981 free_page((unsigned long)page
);
983 for (i
= 0; i
< num
; i
++)
995 #define NULL_FILE_NAME "null"
997 struct dentry
*selinux_null
= NULL
;
999 static ssize_t
sel_read_avc_cache_threshold(struct file
*filp
, char __user
*buf
,
1000 size_t count
, loff_t
*ppos
)
1002 char tmpbuf
[TMPBUFLEN
];
1005 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", avc_cache_threshold
);
1006 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1009 static ssize_t
sel_write_avc_cache_threshold(struct file
* file
,
1010 const char __user
* buf
,
1011 size_t count
, loff_t
*ppos
)
1018 if (count
>= PAGE_SIZE
) {
1024 /* No partial writes. */
1029 page
= (char*)get_zeroed_page(GFP_KERNEL
);
1035 if (copy_from_user(page
, buf
, count
)) {
1040 if (sscanf(page
, "%u", &new_value
) != 1) {
1045 if (new_value
!= avc_cache_threshold
) {
1046 ret
= task_has_security(current
, SECURITY__SETSECPARAM
);
1049 avc_cache_threshold
= new_value
;
1053 free_page((unsigned long)page
);
1058 static ssize_t
sel_read_avc_hash_stats(struct file
*filp
, char __user
*buf
,
1059 size_t count
, loff_t
*ppos
)
1064 page
= (char *)__get_free_page(GFP_KERNEL
);
1069 ret
= avc_get_hash_stats(page
);
1071 ret
= simple_read_from_buffer(buf
, count
, ppos
, page
, ret
);
1072 free_page((unsigned long)page
);
1077 static struct file_operations sel_avc_cache_threshold_ops
= {
1078 .read
= sel_read_avc_cache_threshold
,
1079 .write
= sel_write_avc_cache_threshold
,
1082 static struct file_operations sel_avc_hash_stats_ops
= {
1083 .read
= sel_read_avc_hash_stats
,
1086 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1087 static struct avc_cache_stats
*sel_avc_get_stat_idx(loff_t
*idx
)
1091 for (cpu
= *idx
; cpu
< NR_CPUS
; ++cpu
) {
1092 if (!cpu_possible(cpu
))
1095 return &per_cpu(avc_cache_stats
, cpu
);
1100 static void *sel_avc_stats_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1102 loff_t n
= *pos
- 1;
1105 return SEQ_START_TOKEN
;
1107 return sel_avc_get_stat_idx(&n
);
1110 static void *sel_avc_stats_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1112 return sel_avc_get_stat_idx(pos
);
1115 static int sel_avc_stats_seq_show(struct seq_file
*seq
, void *v
)
1117 struct avc_cache_stats
*st
= v
;
1119 if (v
== SEQ_START_TOKEN
)
1120 seq_printf(seq
, "lookups hits misses allocations reclaims "
1123 seq_printf(seq
, "%u %u %u %u %u %u\n", st
->lookups
,
1124 st
->hits
, st
->misses
, st
->allocations
,
1125 st
->reclaims
, st
->frees
);
1129 static void sel_avc_stats_seq_stop(struct seq_file
*seq
, void *v
)
1132 static struct seq_operations sel_avc_cache_stats_seq_ops
= {
1133 .start
= sel_avc_stats_seq_start
,
1134 .next
= sel_avc_stats_seq_next
,
1135 .show
= sel_avc_stats_seq_show
,
1136 .stop
= sel_avc_stats_seq_stop
,
1139 static int sel_open_avc_cache_stats(struct inode
*inode
, struct file
*file
)
1141 return seq_open(file
, &sel_avc_cache_stats_seq_ops
);
1144 static struct file_operations sel_avc_cache_stats_ops
= {
1145 .open
= sel_open_avc_cache_stats
,
1147 .llseek
= seq_lseek
,
1148 .release
= seq_release
,
1152 static int sel_make_avc_files(struct dentry
*dir
)
1155 static struct tree_descr files
[] = {
1156 { "cache_threshold",
1157 &sel_avc_cache_threshold_ops
, S_IRUGO
|S_IWUSR
},
1158 { "hash_stats", &sel_avc_hash_stats_ops
, S_IRUGO
},
1159 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1160 { "cache_stats", &sel_avc_cache_stats_ops
, S_IRUGO
},
1164 for (i
= 0; i
< ARRAY_SIZE(files
); i
++) {
1165 struct inode
*inode
;
1166 struct dentry
*dentry
;
1168 dentry
= d_alloc_name(dir
, files
[i
].name
);
1174 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|files
[i
].mode
);
1179 inode
->i_fop
= files
[i
].ops
;
1180 d_add(dentry
, inode
);
1189 static int sel_make_dir(struct super_block
*sb
, struct dentry
*dentry
)
1192 struct inode
*inode
;
1194 inode
= sel_make_inode(sb
, S_IFDIR
| S_IRUGO
| S_IXUGO
);
1199 inode
->i_op
= &simple_dir_inode_operations
;
1200 inode
->i_fop
= &simple_dir_operations
;
1201 d_add(dentry
, inode
);
1206 static int sel_fill_super(struct super_block
* sb
, void * data
, int silent
)
1209 struct dentry
*dentry
;
1210 struct inode
*inode
;
1211 struct inode_security_struct
*isec
;
1213 static struct tree_descr selinux_files
[] = {
1214 [SEL_LOAD
] = {"load", &sel_load_ops
, S_IRUSR
|S_IWUSR
},
1215 [SEL_ENFORCE
] = {"enforce", &sel_enforce_ops
, S_IRUGO
|S_IWUSR
},
1216 [SEL_CONTEXT
] = {"context", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1217 [SEL_ACCESS
] = {"access", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1218 [SEL_CREATE
] = {"create", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1219 [SEL_RELABEL
] = {"relabel", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1220 [SEL_USER
] = {"user", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1221 [SEL_POLICYVERS
] = {"policyvers", &sel_policyvers_ops
, S_IRUGO
},
1222 [SEL_COMMIT_BOOLS
] = {"commit_pending_bools", &sel_commit_bools_ops
, S_IWUSR
},
1223 [SEL_MLS
] = {"mls", &sel_mls_ops
, S_IRUGO
},
1224 [SEL_DISABLE
] = {"disable", &sel_disable_ops
, S_IWUSR
},
1225 [SEL_MEMBER
] = {"member", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1226 [SEL_CHECKREQPROT
] = {"checkreqprot", &sel_checkreqprot_ops
, S_IRUGO
|S_IWUSR
},
1229 ret
= simple_fill_super(sb
, SELINUX_MAGIC
, selinux_files
);
1233 dentry
= d_alloc_name(sb
->s_root
, BOOL_DIR_NAME
);
1237 inode
= sel_make_inode(sb
, S_IFDIR
| S_IRUGO
| S_IXUGO
);
1240 inode
->i_op
= &simple_dir_inode_operations
;
1241 inode
->i_fop
= &simple_dir_operations
;
1242 d_add(dentry
, inode
);
1244 ret
= sel_make_bools();
1248 dentry
= d_alloc_name(sb
->s_root
, NULL_FILE_NAME
);
1252 inode
= sel_make_inode(sb
, S_IFCHR
| S_IRUGO
| S_IWUGO
);
1255 isec
= (struct inode_security_struct
*)inode
->i_security
;
1256 isec
->sid
= SECINITSID_DEVNULL
;
1257 isec
->sclass
= SECCLASS_CHR_FILE
;
1258 isec
->initialized
= 1;
1260 init_special_inode(inode
, S_IFCHR
| S_IRUGO
| S_IWUGO
, MKDEV(MEM_MAJOR
, 3));
1261 d_add(dentry
, inode
);
1262 selinux_null
= dentry
;
1264 dentry
= d_alloc_name(sb
->s_root
, "avc");
1268 ret
= sel_make_dir(sb
, dentry
);
1272 ret
= sel_make_avc_files(dentry
);
1279 printk(KERN_ERR
"%s: failed while creating inodes\n", __FUNCTION__
);
1283 static struct super_block
*sel_get_sb(struct file_system_type
*fs_type
,
1284 int flags
, const char *dev_name
, void *data
)
1286 return get_sb_single(fs_type
, flags
, data
, sel_fill_super
);
1289 static struct file_system_type sel_fs_type
= {
1290 .name
= "selinuxfs",
1291 .get_sb
= sel_get_sb
,
1292 .kill_sb
= kill_litter_super
,
1295 struct vfsmount
*selinuxfs_mount
;
1297 static int __init
init_sel_fs(void)
1301 if (!selinux_enabled
)
1303 err
= register_filesystem(&sel_fs_type
);
1305 selinuxfs_mount
= kern_mount(&sel_fs_type
);
1306 if (IS_ERR(selinuxfs_mount
)) {
1307 printk(KERN_ERR
"selinuxfs: could not mount!\n");
1308 err
= PTR_ERR(selinuxfs_mount
);
1309 selinuxfs_mount
= NULL
;
1315 __initcall(init_sel_fs
);
1317 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1318 void exit_sel_fs(void)
1320 unregister_filesystem(&sel_fs_type
);