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/mutex.h>
19 #include <linux/init.h>
20 #include <linux/string.h>
21 #include <linux/security.h>
22 #include <linux/major.h>
23 #include <linux/seq_file.h>
24 #include <linux/percpu.h>
25 #include <linux/audit.h>
26 #include <asm/uaccess.h>
27 #include <asm/semaphore.h>
29 /* selinuxfs pseudo filesystem for exporting the security policy API.
30 Based on the proc code and the fs/nfsd/nfsctl.c code. */
37 #include "conditional.h"
39 unsigned int selinux_checkreqprot
= CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE
;
41 static int __init
checkreqprot_setup(char *str
)
43 selinux_checkreqprot
= simple_strtoul(str
,NULL
,0) ? 1 : 0;
46 __setup("checkreqprot=", checkreqprot_setup
);
49 static DEFINE_MUTEX(sel_mutex
);
51 /* global data for booleans */
52 static struct dentry
*bool_dir
= NULL
;
53 static int bool_num
= 0;
54 static int *bool_pending_values
= NULL
;
56 extern void selnl_notify_setenforce(int val
);
58 /* Check whether a task is allowed to use a security operation. */
59 static int task_has_security(struct task_struct
*tsk
,
62 struct task_security_struct
*tsec
;
68 return avc_has_perm(tsec
->sid
, SECINITSID_SECURITY
,
69 SECCLASS_SECURITY
, perms
, NULL
);
74 SEL_LOAD
, /* load policy */
75 SEL_ENFORCE
, /* get or set enforcing status */
76 SEL_CONTEXT
, /* validate context */
77 SEL_ACCESS
, /* compute access decision */
78 SEL_CREATE
, /* compute create labeling decision */
79 SEL_RELABEL
, /* compute relabeling decision */
80 SEL_USER
, /* compute reachable user contexts */
81 SEL_POLICYVERS
, /* return policy version for this kernel */
82 SEL_COMMIT_BOOLS
, /* commit new boolean values */
83 SEL_MLS
, /* return if MLS policy is enabled */
84 SEL_DISABLE
, /* disable SELinux until next reboot */
85 SEL_AVC
, /* AVC management directory */
86 SEL_MEMBER
, /* compute polyinstantiation membership decision */
87 SEL_CHECKREQPROT
, /* check requested protection, not kernel-applied one */
91 static ssize_t
sel_read_enforce(struct file
*filp
, char __user
*buf
,
92 size_t count
, loff_t
*ppos
)
94 char tmpbuf
[TMPBUFLEN
];
97 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", selinux_enforcing
);
98 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
101 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
102 static ssize_t
sel_write_enforce(struct file
* file
, const char __user
* buf
,
103 size_t count
, loff_t
*ppos
)
110 if (count
>= PAGE_SIZE
)
113 /* No partial writes. */
116 page
= (char*)get_zeroed_page(GFP_KERNEL
);
120 if (copy_from_user(page
, buf
, count
))
124 if (sscanf(page
, "%d", &new_value
) != 1)
127 if (new_value
!= selinux_enforcing
) {
128 length
= task_has_security(current
, SECURITY__SETENFORCE
);
131 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
132 "enforcing=%d old_enforcing=%d auid=%u", new_value
,
134 audit_get_loginuid(current
->audit_context
));
135 selinux_enforcing
= new_value
;
136 if (selinux_enforcing
)
138 selnl_notify_setenforce(selinux_enforcing
);
142 free_page((unsigned long) page
);
146 #define sel_write_enforce NULL
149 static struct file_operations sel_enforce_ops
= {
150 .read
= sel_read_enforce
,
151 .write
= sel_write_enforce
,
154 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
155 static ssize_t
sel_write_disable(struct file
* file
, const char __user
* buf
,
156 size_t count
, loff_t
*ppos
)
162 extern int selinux_disable(void);
164 if (count
>= PAGE_SIZE
)
167 /* No partial writes. */
170 page
= (char*)get_zeroed_page(GFP_KERNEL
);
174 if (copy_from_user(page
, buf
, count
))
178 if (sscanf(page
, "%d", &new_value
) != 1)
182 length
= selinux_disable();
185 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
187 audit_get_loginuid(current
->audit_context
));
192 free_page((unsigned long) page
);
196 #define sel_write_disable NULL
199 static struct file_operations sel_disable_ops
= {
200 .write
= sel_write_disable
,
203 static ssize_t
sel_read_policyvers(struct file
*filp
, char __user
*buf
,
204 size_t count
, loff_t
*ppos
)
206 char tmpbuf
[TMPBUFLEN
];
209 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", POLICYDB_VERSION_MAX
);
210 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
213 static struct file_operations sel_policyvers_ops
= {
214 .read
= sel_read_policyvers
,
217 /* declaration for sel_write_load */
218 static int sel_make_bools(void);
220 static ssize_t
sel_read_mls(struct file
*filp
, char __user
*buf
,
221 size_t count
, loff_t
*ppos
)
223 char tmpbuf
[TMPBUFLEN
];
226 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", selinux_mls_enabled
);
227 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
230 static struct file_operations sel_mls_ops
= {
231 .read
= sel_read_mls
,
234 static ssize_t
sel_write_load(struct file
* file
, const char __user
* buf
,
235 size_t count
, loff_t
*ppos
)
242 mutex_lock(&sel_mutex
);
244 length
= task_has_security(current
, SECURITY__LOAD_POLICY
);
249 /* No partial writes. */
254 if ((count
> 64 * 1024 * 1024)
255 || (data
= vmalloc(count
)) == NULL
) {
261 if (copy_from_user(data
, buf
, count
) != 0)
264 length
= security_load_policy(data
, count
);
268 ret
= sel_make_bools();
273 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_POLICY_LOAD
,
274 "policy loaded auid=%u",
275 audit_get_loginuid(current
->audit_context
));
277 mutex_unlock(&sel_mutex
);
282 static struct file_operations sel_load_ops
= {
283 .write
= sel_write_load
,
286 static ssize_t
sel_write_context(struct file
* file
, char *buf
, size_t size
)
292 length
= task_has_security(current
, SECURITY__CHECK_CONTEXT
);
296 length
= security_context_to_sid(buf
, size
, &sid
);
300 length
= security_sid_to_context(sid
, &canon
, &len
);
304 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
305 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
306 "max\n", __FUNCTION__
, len
);
311 memcpy(buf
, canon
, len
);
318 static ssize_t
sel_read_checkreqprot(struct file
*filp
, char __user
*buf
,
319 size_t count
, loff_t
*ppos
)
321 char tmpbuf
[TMPBUFLEN
];
324 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", selinux_checkreqprot
);
325 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
328 static ssize_t
sel_write_checkreqprot(struct file
* file
, const char __user
* buf
,
329 size_t count
, loff_t
*ppos
)
333 unsigned int new_value
;
335 length
= task_has_security(current
, SECURITY__SETCHECKREQPROT
);
339 if (count
>= PAGE_SIZE
)
342 /* No partial writes. */
345 page
= (char*)get_zeroed_page(GFP_KERNEL
);
349 if (copy_from_user(page
, buf
, count
))
353 if (sscanf(page
, "%u", &new_value
) != 1)
356 selinux_checkreqprot
= new_value
? 1 : 0;
359 free_page((unsigned long) page
);
362 static struct file_operations sel_checkreqprot_ops
= {
363 .read
= sel_read_checkreqprot
,
364 .write
= sel_write_checkreqprot
,
368 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
370 static ssize_t
sel_write_access(struct file
* file
, char *buf
, size_t size
);
371 static ssize_t
sel_write_create(struct file
* file
, char *buf
, size_t size
);
372 static ssize_t
sel_write_relabel(struct file
* file
, char *buf
, size_t size
);
373 static ssize_t
sel_write_user(struct file
* file
, char *buf
, size_t size
);
374 static ssize_t
sel_write_member(struct file
* file
, char *buf
, size_t size
);
376 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
377 [SEL_ACCESS
] = sel_write_access
,
378 [SEL_CREATE
] = sel_write_create
,
379 [SEL_RELABEL
] = sel_write_relabel
,
380 [SEL_USER
] = sel_write_user
,
381 [SEL_MEMBER
] = sel_write_member
,
382 [SEL_CONTEXT
] = sel_write_context
,
385 static ssize_t
selinux_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
387 ino_t ino
= file
->f_dentry
->d_inode
->i_ino
;
391 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
394 data
= simple_transaction_get(file
, buf
, size
);
396 return PTR_ERR(data
);
398 rv
= write_op
[ino
](file
, data
, size
);
400 simple_transaction_set(file
, rv
);
406 static struct file_operations transaction_ops
= {
407 .write
= selinux_transaction_write
,
408 .read
= simple_transaction_read
,
409 .release
= simple_transaction_release
,
413 * payload - write methods
414 * If the method has a response, the response should be put in buf,
415 * and the length returned. Otherwise return 0 or and -error.
418 static ssize_t
sel_write_access(struct file
* file
, char *buf
, size_t size
)
424 struct av_decision avd
;
427 length
= task_has_security(current
, SECURITY__COMPUTE_AV
);
432 scon
= kzalloc(size
+1, GFP_KERNEL
);
436 tcon
= kzalloc(size
+1, GFP_KERNEL
);
441 if (sscanf(buf
, "%s %s %hu %x", scon
, tcon
, &tclass
, &req
) != 4)
444 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
447 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
451 length
= security_compute_av(ssid
, tsid
, tclass
, req
, &avd
);
455 length
= scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
,
457 avd
.allowed
, avd
.decided
,
458 avd
.auditallow
, avd
.auditdeny
,
467 static ssize_t
sel_write_create(struct file
* file
, char *buf
, size_t size
)
470 u32 ssid
, tsid
, newsid
;
476 length
= task_has_security(current
, SECURITY__COMPUTE_CREATE
);
481 scon
= kzalloc(size
+1, GFP_KERNEL
);
485 tcon
= kzalloc(size
+1, GFP_KERNEL
);
490 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
493 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
496 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
500 length
= security_transition_sid(ssid
, tsid
, tclass
, &newsid
);
504 length
= security_sid_to_context(newsid
, &newcon
, &len
);
508 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
509 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
510 "max\n", __FUNCTION__
, len
);
515 memcpy(buf
, newcon
, len
);
526 static ssize_t
sel_write_relabel(struct file
* file
, char *buf
, size_t size
)
529 u32 ssid
, tsid
, newsid
;
535 length
= task_has_security(current
, SECURITY__COMPUTE_RELABEL
);
540 scon
= kzalloc(size
+1, GFP_KERNEL
);
544 tcon
= kzalloc(size
+1, GFP_KERNEL
);
549 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
552 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
555 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
559 length
= security_change_sid(ssid
, tsid
, tclass
, &newsid
);
563 length
= security_sid_to_context(newsid
, &newcon
, &len
);
567 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
572 memcpy(buf
, newcon
, len
);
583 static ssize_t
sel_write_user(struct file
* file
, char *buf
, size_t size
)
585 char *con
, *user
, *ptr
;
592 length
= task_has_security(current
, SECURITY__COMPUTE_USER
);
597 con
= kzalloc(size
+1, GFP_KERNEL
);
601 user
= kzalloc(size
+1, GFP_KERNEL
);
606 if (sscanf(buf
, "%s %s", con
, user
) != 2)
609 length
= security_context_to_sid(con
, strlen(con
)+1, &sid
);
613 length
= security_get_user_sids(sid
, user
, &sids
, &nsids
);
617 length
= sprintf(buf
, "%u", nsids
) + 1;
619 for (i
= 0; i
< nsids
; i
++) {
620 rc
= security_sid_to_context(sids
[i
], &newcon
, &len
);
625 if ((length
+ len
) >= SIMPLE_TRANSACTION_LIMIT
) {
630 memcpy(ptr
, newcon
, len
);
644 static ssize_t
sel_write_member(struct file
* file
, char *buf
, size_t size
)
647 u32 ssid
, tsid
, newsid
;
653 length
= task_has_security(current
, SECURITY__COMPUTE_MEMBER
);
658 scon
= kzalloc(size
+1, GFP_KERNEL
);
662 tcon
= kzalloc(size
+1, GFP_KERNEL
);
667 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
670 length
= security_context_to_sid(scon
, strlen(scon
)+1, &ssid
);
673 length
= security_context_to_sid(tcon
, strlen(tcon
)+1, &tsid
);
677 length
= security_member_sid(ssid
, tsid
, tclass
, &newsid
);
681 length
= security_sid_to_context(newsid
, &newcon
, &len
);
685 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
686 printk(KERN_ERR
"%s: context size (%u) exceeds payload "
687 "max\n", __FUNCTION__
, len
);
692 memcpy(buf
, newcon
, len
);
703 static struct inode
*sel_make_inode(struct super_block
*sb
, int mode
)
705 struct inode
*ret
= new_inode(sb
);
709 ret
->i_uid
= ret
->i_gid
= 0;
710 ret
->i_blksize
= PAGE_CACHE_SIZE
;
712 ret
->i_atime
= ret
->i_mtime
= ret
->i_ctime
= CURRENT_TIME
;
717 #define BOOL_INO_OFFSET 30
719 static ssize_t
sel_read_bool(struct file
*filep
, char __user
*buf
,
720 size_t count
, loff_t
*ppos
)
728 mutex_lock(&sel_mutex
);
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
]);
754 ret
= simple_read_from_buffer(buf
, count
, ppos
, page
, length
);
756 mutex_unlock(&sel_mutex
);
758 free_page((unsigned long)page
);
762 static ssize_t
sel_write_bool(struct file
*filep
, const char __user
*buf
,
763 size_t count
, loff_t
*ppos
)
766 ssize_t length
= -EFAULT
;
770 mutex_lock(&sel_mutex
);
772 length
= task_has_security(current
, SECURITY__SETBOOL
);
776 /* check to see if this file has been deleted */
780 if (count
>= PAGE_SIZE
) {
785 /* No partial writes. */
788 page
= (char*)get_zeroed_page(GFP_KERNEL
);
794 if (copy_from_user(page
, buf
, count
))
798 if (sscanf(page
, "%d", &new_value
) != 1)
804 inode
= filep
->f_dentry
->d_inode
;
805 bool_pending_values
[inode
->i_ino
- BOOL_INO_OFFSET
] = new_value
;
809 mutex_unlock(&sel_mutex
);
811 free_page((unsigned long) page
);
815 static struct file_operations sel_bool_ops
= {
816 .read
= sel_read_bool
,
817 .write
= sel_write_bool
,
820 static ssize_t
sel_commit_bools_write(struct file
*filep
,
821 const char __user
*buf
,
822 size_t count
, loff_t
*ppos
)
825 ssize_t length
= -EFAULT
;
828 mutex_lock(&sel_mutex
);
830 length
= task_has_security(current
, SECURITY__SETBOOL
);
834 /* check to see if this file has been deleted */
838 if (count
>= PAGE_SIZE
) {
843 /* No partial writes. */
846 page
= (char*)get_zeroed_page(GFP_KERNEL
);
852 if (copy_from_user(page
, buf
, count
))
856 if (sscanf(page
, "%d", &new_value
) != 1)
859 if (new_value
&& bool_pending_values
) {
860 security_set_bools(bool_num
, bool_pending_values
);
866 mutex_unlock(&sel_mutex
);
868 free_page((unsigned long) page
);
872 static struct file_operations sel_commit_bools_ops
= {
873 .write
= sel_commit_bools_write
,
876 /* delete booleans - partial revoke() from
877 * fs/proc/generic.c proc_kill_inodes */
878 static void sel_remove_bools(struct dentry
*de
)
880 struct list_head
*p
, *node
;
881 struct super_block
*sb
= de
->d_sb
;
883 spin_lock(&dcache_lock
);
884 node
= de
->d_subdirs
.next
;
885 while (node
!= &de
->d_subdirs
) {
886 struct dentry
*d
= list_entry(node
, struct dentry
, d_u
.d_child
);
891 spin_unlock(&dcache_lock
);
893 simple_unlink(de
->d_inode
, d
);
895 spin_lock(&dcache_lock
);
897 node
= de
->d_subdirs
.next
;
900 spin_unlock(&dcache_lock
);
903 list_for_each(p
, &sb
->s_files
) {
904 struct file
* filp
= list_entry(p
, struct file
, f_u
.fu_list
);
905 struct dentry
* dentry
= filp
->f_dentry
;
907 if (dentry
->d_parent
!= de
) {
915 #define BOOL_DIR_NAME "booleans"
917 static int sel_make_bools(void)
921 struct dentry
*dentry
= NULL
;
922 struct dentry
*dir
= bool_dir
;
923 struct inode
*inode
= NULL
;
924 struct inode_security_struct
*isec
;
925 char **names
= NULL
, *page
;
930 /* remove any existing files */
931 kfree(bool_pending_values
);
932 bool_pending_values
= NULL
;
934 sel_remove_bools(dir
);
936 if (!(page
= (char*)get_zeroed_page(GFP_KERNEL
)))
939 ret
= security_get_bools(&num
, &names
, &values
);
943 for (i
= 0; i
< num
; i
++) {
944 dentry
= d_alloc_name(dir
, names
[i
]);
949 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
| S_IRUGO
| S_IWUSR
);
955 len
= snprintf(page
, PAGE_SIZE
, "/%s/%s", BOOL_DIR_NAME
, names
[i
]);
959 } else if (len
>= PAGE_SIZE
) {
963 isec
= (struct inode_security_struct
*)inode
->i_security
;
964 if ((ret
= security_genfs_sid("selinuxfs", page
, SECCLASS_FILE
, &sid
)))
967 isec
->initialized
= 1;
968 inode
->i_fop
= &sel_bool_ops
;
969 inode
->i_ino
= i
+ BOOL_INO_OFFSET
;
970 d_add(dentry
, inode
);
973 bool_pending_values
= values
;
975 free_page((unsigned long)page
);
977 for (i
= 0; i
< num
; i
++)
984 sel_remove_bools(dir
);
989 #define NULL_FILE_NAME "null"
991 struct dentry
*selinux_null
= NULL
;
993 static ssize_t
sel_read_avc_cache_threshold(struct file
*filp
, char __user
*buf
,
994 size_t count
, loff_t
*ppos
)
996 char tmpbuf
[TMPBUFLEN
];
999 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", avc_cache_threshold
);
1000 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1003 static ssize_t
sel_write_avc_cache_threshold(struct file
* file
,
1004 const char __user
* buf
,
1005 size_t count
, loff_t
*ppos
)
1012 if (count
>= PAGE_SIZE
) {
1018 /* No partial writes. */
1023 page
= (char*)get_zeroed_page(GFP_KERNEL
);
1029 if (copy_from_user(page
, buf
, count
)) {
1034 if (sscanf(page
, "%u", &new_value
) != 1) {
1039 if (new_value
!= avc_cache_threshold
) {
1040 ret
= task_has_security(current
, SECURITY__SETSECPARAM
);
1043 avc_cache_threshold
= new_value
;
1047 free_page((unsigned long)page
);
1052 static ssize_t
sel_read_avc_hash_stats(struct file
*filp
, char __user
*buf
,
1053 size_t count
, loff_t
*ppos
)
1058 page
= (char *)__get_free_page(GFP_KERNEL
);
1063 ret
= avc_get_hash_stats(page
);
1065 ret
= simple_read_from_buffer(buf
, count
, ppos
, page
, ret
);
1066 free_page((unsigned long)page
);
1071 static struct file_operations sel_avc_cache_threshold_ops
= {
1072 .read
= sel_read_avc_cache_threshold
,
1073 .write
= sel_write_avc_cache_threshold
,
1076 static struct file_operations sel_avc_hash_stats_ops
= {
1077 .read
= sel_read_avc_hash_stats
,
1080 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1081 static struct avc_cache_stats
*sel_avc_get_stat_idx(loff_t
*idx
)
1085 for (cpu
= *idx
; cpu
< NR_CPUS
; ++cpu
) {
1086 if (!cpu_possible(cpu
))
1089 return &per_cpu(avc_cache_stats
, cpu
);
1094 static void *sel_avc_stats_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1096 loff_t n
= *pos
- 1;
1099 return SEQ_START_TOKEN
;
1101 return sel_avc_get_stat_idx(&n
);
1104 static void *sel_avc_stats_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1106 return sel_avc_get_stat_idx(pos
);
1109 static int sel_avc_stats_seq_show(struct seq_file
*seq
, void *v
)
1111 struct avc_cache_stats
*st
= v
;
1113 if (v
== SEQ_START_TOKEN
)
1114 seq_printf(seq
, "lookups hits misses allocations reclaims "
1117 seq_printf(seq
, "%u %u %u %u %u %u\n", st
->lookups
,
1118 st
->hits
, st
->misses
, st
->allocations
,
1119 st
->reclaims
, st
->frees
);
1123 static void sel_avc_stats_seq_stop(struct seq_file
*seq
, void *v
)
1126 static struct seq_operations sel_avc_cache_stats_seq_ops
= {
1127 .start
= sel_avc_stats_seq_start
,
1128 .next
= sel_avc_stats_seq_next
,
1129 .show
= sel_avc_stats_seq_show
,
1130 .stop
= sel_avc_stats_seq_stop
,
1133 static int sel_open_avc_cache_stats(struct inode
*inode
, struct file
*file
)
1135 return seq_open(file
, &sel_avc_cache_stats_seq_ops
);
1138 static struct file_operations sel_avc_cache_stats_ops
= {
1139 .open
= sel_open_avc_cache_stats
,
1141 .llseek
= seq_lseek
,
1142 .release
= seq_release
,
1146 static int sel_make_avc_files(struct dentry
*dir
)
1149 static struct tree_descr files
[] = {
1150 { "cache_threshold",
1151 &sel_avc_cache_threshold_ops
, S_IRUGO
|S_IWUSR
},
1152 { "hash_stats", &sel_avc_hash_stats_ops
, S_IRUGO
},
1153 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1154 { "cache_stats", &sel_avc_cache_stats_ops
, S_IRUGO
},
1158 for (i
= 0; i
< ARRAY_SIZE(files
); i
++) {
1159 struct inode
*inode
;
1160 struct dentry
*dentry
;
1162 dentry
= d_alloc_name(dir
, files
[i
].name
);
1168 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|files
[i
].mode
);
1173 inode
->i_fop
= files
[i
].ops
;
1174 d_add(dentry
, inode
);
1180 static int sel_make_dir(struct inode
*dir
, struct dentry
*dentry
)
1183 struct inode
*inode
;
1185 inode
= sel_make_inode(dir
->i_sb
, S_IFDIR
| S_IRUGO
| S_IXUGO
);
1190 inode
->i_op
= &simple_dir_inode_operations
;
1191 inode
->i_fop
= &simple_dir_operations
;
1192 /* directory inodes start off with i_nlink == 2 (for "." entry) */
1194 d_add(dentry
, inode
);
1195 /* bump link count on parent directory, too */
1201 static int sel_fill_super(struct super_block
* sb
, void * data
, int silent
)
1204 struct dentry
*dentry
;
1205 struct inode
*inode
, *root_inode
;
1206 struct inode_security_struct
*isec
;
1208 static struct tree_descr selinux_files
[] = {
1209 [SEL_LOAD
] = {"load", &sel_load_ops
, S_IRUSR
|S_IWUSR
},
1210 [SEL_ENFORCE
] = {"enforce", &sel_enforce_ops
, S_IRUGO
|S_IWUSR
},
1211 [SEL_CONTEXT
] = {"context", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1212 [SEL_ACCESS
] = {"access", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1213 [SEL_CREATE
] = {"create", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1214 [SEL_RELABEL
] = {"relabel", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1215 [SEL_USER
] = {"user", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1216 [SEL_POLICYVERS
] = {"policyvers", &sel_policyvers_ops
, S_IRUGO
},
1217 [SEL_COMMIT_BOOLS
] = {"commit_pending_bools", &sel_commit_bools_ops
, S_IWUSR
},
1218 [SEL_MLS
] = {"mls", &sel_mls_ops
, S_IRUGO
},
1219 [SEL_DISABLE
] = {"disable", &sel_disable_ops
, S_IWUSR
},
1220 [SEL_MEMBER
] = {"member", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1221 [SEL_CHECKREQPROT
] = {"checkreqprot", &sel_checkreqprot_ops
, S_IRUGO
|S_IWUSR
},
1224 ret
= simple_fill_super(sb
, SELINUX_MAGIC
, selinux_files
);
1228 root_inode
= sb
->s_root
->d_inode
;
1230 dentry
= d_alloc_name(sb
->s_root
, BOOL_DIR_NAME
);
1236 ret
= sel_make_dir(root_inode
, dentry
);
1242 dentry
= d_alloc_name(sb
->s_root
, NULL_FILE_NAME
);
1248 inode
= sel_make_inode(sb
, S_IFCHR
| S_IRUGO
| S_IWUGO
);
1253 isec
= (struct inode_security_struct
*)inode
->i_security
;
1254 isec
->sid
= SECINITSID_DEVNULL
;
1255 isec
->sclass
= SECCLASS_CHR_FILE
;
1256 isec
->initialized
= 1;
1258 init_special_inode(inode
, S_IFCHR
| S_IRUGO
| S_IWUGO
, MKDEV(MEM_MAJOR
, 3));
1259 d_add(dentry
, inode
);
1260 selinux_null
= dentry
;
1262 dentry
= d_alloc_name(sb
->s_root
, "avc");
1268 ret
= sel_make_dir(root_inode
, dentry
);
1272 ret
= sel_make_avc_files(dentry
);
1278 printk(KERN_ERR
"%s: failed while creating inodes\n", __FUNCTION__
);
1282 static struct super_block
*sel_get_sb(struct file_system_type
*fs_type
,
1283 int flags
, const char *dev_name
, void *data
)
1285 return get_sb_single(fs_type
, flags
, data
, sel_fill_super
);
1288 static struct file_system_type sel_fs_type
= {
1289 .name
= "selinuxfs",
1290 .get_sb
= sel_get_sb
,
1291 .kill_sb
= kill_litter_super
,
1294 struct vfsmount
*selinuxfs_mount
;
1296 static int __init
init_sel_fs(void)
1300 if (!selinux_enabled
)
1302 err
= register_filesystem(&sel_fs_type
);
1304 selinuxfs_mount
= kern_mount(&sel_fs_type
);
1305 if (IS_ERR(selinuxfs_mount
)) {
1306 printk(KERN_ERR
"selinuxfs: could not mount!\n");
1307 err
= PTR_ERR(selinuxfs_mount
);
1308 selinuxfs_mount
= NULL
;
1314 __initcall(init_sel_fs
);
1316 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1317 void exit_sel_fs(void)
1319 unregister_filesystem(&sel_fs_type
);