1 /* Updated: Karl MacMillan <kmacmillan@tresys.com>
3 * Added conditional policy language extensions
5 * Updated: Hewlett-Packard <paul@paul-moore.com>
7 * Added support for the policy capability bitmap
9 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
10 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
11 * Copyright (C) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, version 2.
17 #include <linux/kernel.h>
18 #include <linux/pagemap.h>
19 #include <linux/slab.h>
20 #include <linux/vmalloc.h>
22 #include <linux/mutex.h>
23 #include <linux/init.h>
24 #include <linux/string.h>
25 #include <linux/security.h>
26 #include <linux/major.h>
27 #include <linux/seq_file.h>
28 #include <linux/percpu.h>
29 #include <linux/audit.h>
30 #include <linux/uaccess.h>
31 #include <linux/kobject.h>
32 #include <linux/ctype.h>
34 /* selinuxfs pseudo filesystem for exporting the security policy API.
35 Based on the proc code and the fs/nfsd/nfsctl.c code. */
42 #include "conditional.h"
44 #if defined(CONFIG_TZ_ICCC)
45 #include <linux/security/Iccc_Interface.h>
48 /* Policy capability filenames */
49 static char *policycap_names
[] = {
50 "network_peer_controls",
54 unsigned int selinux_checkreqprot
= CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE
;
56 static int __init
checkreqprot_setup(char *str
)
58 unsigned long checkreqprot
;
59 if (!strict_strtoul(str
, 0, &checkreqprot
))
60 selinux_checkreqprot
= checkreqprot
? 1 : 0;
63 __setup("checkreqprot=", checkreqprot_setup
);
65 static DEFINE_MUTEX(sel_mutex
);
67 /* global data for booleans */
68 static struct dentry
*bool_dir
;
70 static char **bool_pending_names
;
71 static int *bool_pending_values
;
73 /* global data for classes */
74 static struct dentry
*class_dir
;
75 static unsigned long last_class_ino
;
77 static char policy_opened
;
79 /* global data for policy capabilities */
80 static struct dentry
*policycap_dir
;
82 /* Check whether a task is allowed to use a security operation. */
83 static int task_has_security(struct task_struct
*tsk
,
86 const struct task_security_struct
*tsec
;
90 tsec
= __task_cred(tsk
)->security
;
97 return avc_has_perm(sid
, SECINITSID_SECURITY
,
98 SECCLASS_SECURITY
, perms
, NULL
);
103 SEL_LOAD
, /* load policy */
104 SEL_ENFORCE
, /* get or set enforcing status */
105 SEL_CONTEXT
, /* validate context */
106 SEL_ACCESS
, /* compute access decision */
107 SEL_CREATE
, /* compute create labeling decision */
108 SEL_RELABEL
, /* compute relabeling decision */
109 SEL_USER
, /* compute reachable user contexts */
110 SEL_POLICYVERS
, /* return policy version for this kernel */
111 SEL_COMMIT_BOOLS
, /* commit new boolean values */
112 SEL_MLS
, /* return if MLS policy is enabled */
113 SEL_DISABLE
, /* disable SELinux until next reboot */
114 SEL_MEMBER
, /* compute polyinstantiation membership decision */
115 SEL_CHECKREQPROT
, /* check requested protection, not kernel-applied one */
116 SEL_COMPAT_NET
, /* whether to use old compat network packet controls */
117 SEL_REJECT_UNKNOWN
, /* export unknown reject handling to userspace */
118 SEL_DENY_UNKNOWN
, /* export unknown deny handling to userspace */
119 SEL_STATUS
, /* export current status using mmap() */
120 SEL_POLICY
, /* allow userspace to read the in kernel policy */
121 SEL_INO_NEXT
, /* The next inode number to use */
124 static unsigned long sel_last_ino
= SEL_INO_NEXT
- 1;
126 #define SEL_INITCON_INO_OFFSET 0x01000000
127 #define SEL_BOOL_INO_OFFSET 0x02000000
128 #define SEL_CLASS_INO_OFFSET 0x04000000
129 #define SEL_POLICYCAP_INO_OFFSET 0x08000000
130 #define SEL_INO_MASK 0x00ffffff
133 static ssize_t
sel_read_enforce(struct file
*filp
, char __user
*buf
,
134 size_t count
, loff_t
*ppos
)
136 char tmpbuf
[TMPBUFLEN
];
139 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", selinux_enforcing
);
140 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
143 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
144 static ssize_t
sel_write_enforce(struct file
*file
, const char __user
*buf
,
145 size_t count
, loff_t
*ppos
)
153 if (count
>= PAGE_SIZE
)
156 /* No partial writes. */
162 page
= (char *)get_zeroed_page(GFP_KERNEL
);
167 if (copy_from_user(page
, buf
, count
))
171 if (sscanf(page
, "%d", &new_value
) != 1)
174 if (new_value
!= selinux_enforcing
) {
175 length
= task_has_security(current
, SECURITY__SETENFORCE
);
178 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
179 "enforcing=%d old_enforcing=%d auid=%u ses=%u",
180 new_value
, selinux_enforcing
,
181 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
182 audit_get_sessionid(current
));
183 selinux_enforcing
= new_value
;
184 if (selinux_enforcing
)
186 selnl_notify_setenforce(selinux_enforcing
);
187 selinux_status_update_setenforce(selinux_enforcing
);
191 #if defined(CONFIG_TZ_ICCC)
192 if (selinux_enabled
&& selinux_enforcing
) {
193 if (0 != Iccc_SaveData_Kernel(SELINUX_STATUS
,0x0)) {
194 printk(KERN_ERR
"%s: Iccc_SaveData_Kernel failed, type = %x, value =%x\n", __func__
,SELINUX_STATUS
,0x0);
198 if (0 != Iccc_SaveData_Kernel(SELINUX_STATUS
,0x1)) {
199 printk(KERN_ERR
"%s: Iccc_SaveData_Kernel failed, type = %x, value =%x\n", __func__
,SELINUX_STATUS
,0x1);
205 free_page((unsigned long) page
);
209 #define sel_write_enforce NULL
212 static const struct file_operations sel_enforce_ops
= {
213 .read
= sel_read_enforce
,
214 .write
= sel_write_enforce
,
215 .llseek
= generic_file_llseek
,
218 static ssize_t
sel_read_handle_unknown(struct file
*filp
, char __user
*buf
,
219 size_t count
, loff_t
*ppos
)
221 char tmpbuf
[TMPBUFLEN
];
223 ino_t ino
= file_inode(filp
)->i_ino
;
224 int handle_unknown
= (ino
== SEL_REJECT_UNKNOWN
) ?
225 security_get_reject_unknown() : !security_get_allow_unknown();
227 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", handle_unknown
);
228 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
231 static const struct file_operations sel_handle_unknown_ops
= {
232 .read
= sel_read_handle_unknown
,
233 .llseek
= generic_file_llseek
,
236 static int sel_open_handle_status(struct inode
*inode
, struct file
*filp
)
238 struct page
*status
= selinux_kernel_status_page();
243 filp
->private_data
= status
;
248 static ssize_t
sel_read_handle_status(struct file
*filp
, char __user
*buf
,
249 size_t count
, loff_t
*ppos
)
251 struct page
*status
= filp
->private_data
;
255 return simple_read_from_buffer(buf
, count
, ppos
,
256 page_address(status
),
257 sizeof(struct selinux_kernel_status
));
260 static int sel_mmap_handle_status(struct file
*filp
,
261 struct vm_area_struct
*vma
)
263 struct page
*status
= filp
->private_data
;
264 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
268 /* only allows one page from the head */
269 if (vma
->vm_pgoff
> 0 || size
!= PAGE_SIZE
)
271 /* disallow writable mapping */
272 if (vma
->vm_flags
& VM_WRITE
)
274 /* disallow mprotect() turns it into writable */
275 vma
->vm_flags
&= ~VM_MAYWRITE
;
277 return remap_pfn_range(vma
, vma
->vm_start
,
279 size
, vma
->vm_page_prot
);
282 static const struct file_operations sel_handle_status_ops
= {
283 .open
= sel_open_handle_status
,
284 .read
= sel_read_handle_status
,
285 .mmap
= sel_mmap_handle_status
,
286 .llseek
= generic_file_llseek
,
289 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
290 static ssize_t
sel_write_disable(struct file
*file
, const char __user
*buf
,
291 size_t count
, loff_t
*ppos
)
299 if (count
>= PAGE_SIZE
)
302 /* No partial writes. */
308 page
= (char *)get_zeroed_page(GFP_KERNEL
);
313 if (copy_from_user(page
, buf
, count
))
317 if (sscanf(page
, "%d", &new_value
) != 1)
321 length
= selinux_disable();
324 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
325 "selinux=0 auid=%u ses=%u",
326 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
327 audit_get_sessionid(current
));
332 free_page((unsigned long) page
);
336 #define sel_write_disable NULL
339 static const struct file_operations sel_disable_ops
= {
340 .write
= sel_write_disable
,
341 .llseek
= generic_file_llseek
,
344 static ssize_t
sel_read_policyvers(struct file
*filp
, char __user
*buf
,
345 size_t count
, loff_t
*ppos
)
347 char tmpbuf
[TMPBUFLEN
];
350 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", POLICYDB_VERSION_MAX
);
351 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
354 static const struct file_operations sel_policyvers_ops
= {
355 .read
= sel_read_policyvers
,
356 .llseek
= generic_file_llseek
,
359 /* declaration for sel_write_load */
360 static int sel_make_bools(void);
361 static int sel_make_classes(void);
362 static int sel_make_policycap(void);
364 /* declaration for sel_make_class_dirs */
365 static struct dentry
*sel_make_dir(struct dentry
*dir
, const char *name
,
368 static ssize_t
sel_read_mls(struct file
*filp
, char __user
*buf
,
369 size_t count
, loff_t
*ppos
)
371 char tmpbuf
[TMPBUFLEN
];
374 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d",
375 security_mls_enabled());
376 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
379 static const struct file_operations sel_mls_ops
= {
380 .read
= sel_read_mls
,
381 .llseek
= generic_file_llseek
,
384 struct policy_load_memory
{
389 static int sel_open_policy(struct inode
*inode
, struct file
*filp
)
391 struct policy_load_memory
*plm
= NULL
;
394 BUG_ON(filp
->private_data
);
396 mutex_lock(&sel_mutex
);
398 rc
= task_has_security(current
, SECURITY__READ_POLICY
);
407 plm
= kzalloc(sizeof(*plm
), GFP_KERNEL
);
411 if (i_size_read(inode
) != security_policydb_len()) {
412 mutex_lock(&inode
->i_mutex
);
413 i_size_write(inode
, security_policydb_len());
414 mutex_unlock(&inode
->i_mutex
);
417 rc
= security_read_policy(&plm
->data
, &plm
->len
);
423 filp
->private_data
= plm
;
425 mutex_unlock(&sel_mutex
);
429 mutex_unlock(&sel_mutex
);
437 static int sel_release_policy(struct inode
*inode
, struct file
*filp
)
439 struct policy_load_memory
*plm
= filp
->private_data
;
451 static ssize_t
sel_read_policy(struct file
*filp
, char __user
*buf
,
452 size_t count
, loff_t
*ppos
)
454 struct policy_load_memory
*plm
= filp
->private_data
;
457 mutex_lock(&sel_mutex
);
459 ret
= task_has_security(current
, SECURITY__READ_POLICY
);
463 ret
= simple_read_from_buffer(buf
, count
, ppos
, plm
->data
, plm
->len
);
465 mutex_unlock(&sel_mutex
);
469 static int sel_mmap_policy_fault(struct vm_area_struct
*vma
,
470 struct vm_fault
*vmf
)
472 struct policy_load_memory
*plm
= vma
->vm_file
->private_data
;
473 unsigned long offset
;
476 if (vmf
->flags
& (FAULT_FLAG_MKWRITE
| FAULT_FLAG_WRITE
))
477 return VM_FAULT_SIGBUS
;
479 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
480 if (offset
>= roundup(plm
->len
, PAGE_SIZE
))
481 return VM_FAULT_SIGBUS
;
483 page
= vmalloc_to_page(plm
->data
+ offset
);
491 static struct vm_operations_struct sel_mmap_policy_ops
= {
492 .fault
= sel_mmap_policy_fault
,
493 .page_mkwrite
= sel_mmap_policy_fault
,
496 static int sel_mmap_policy(struct file
*filp
, struct vm_area_struct
*vma
)
498 if (vma
->vm_flags
& VM_SHARED
) {
499 /* do not allow mprotect to make mapping writable */
500 vma
->vm_flags
&= ~VM_MAYWRITE
;
502 if (vma
->vm_flags
& VM_WRITE
)
506 vma
->vm_flags
|= VM_DONTEXPAND
| VM_DONTDUMP
;
507 vma
->vm_ops
= &sel_mmap_policy_ops
;
512 static const struct file_operations sel_policy_ops
= {
513 .open
= sel_open_policy
,
514 .read
= sel_read_policy
,
515 .mmap
= sel_mmap_policy
,
516 .release
= sel_release_policy
,
517 .llseek
= generic_file_llseek
,
520 static ssize_t
sel_write_load(struct file
*file
, const char __user
*buf
,
521 size_t count
, loff_t
*ppos
)
527 mutex_lock(&sel_mutex
);
529 length
= task_has_security(current
, SECURITY__LOAD_POLICY
);
533 /* No partial writes. */
539 if (count
> 64 * 1024 * 1024)
543 data
= vmalloc(count
);
548 if (copy_from_user(data
, buf
, count
) != 0)
551 length
= security_load_policy(data
, count
);
555 length
= sel_make_bools();
559 length
= sel_make_classes();
563 length
= sel_make_policycap();
570 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_POLICY_LOAD
,
571 "policy loaded auid=%u ses=%u",
572 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
573 audit_get_sessionid(current
));
575 mutex_unlock(&sel_mutex
);
580 static const struct file_operations sel_load_ops
= {
581 .write
= sel_write_load
,
582 .llseek
= generic_file_llseek
,
585 static ssize_t
sel_write_context(struct file
*file
, char *buf
, size_t size
)
591 length
= task_has_security(current
, SECURITY__CHECK_CONTEXT
);
595 length
= security_context_to_sid(buf
, size
, &sid
);
599 length
= security_sid_to_context(sid
, &canon
, &len
);
604 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
605 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
606 "payload max\n", __func__
, len
);
610 memcpy(buf
, canon
, len
);
617 static ssize_t
sel_read_checkreqprot(struct file
*filp
, char __user
*buf
,
618 size_t count
, loff_t
*ppos
)
620 char tmpbuf
[TMPBUFLEN
];
623 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", selinux_checkreqprot
);
624 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
627 static ssize_t
sel_write_checkreqprot(struct file
*file
, const char __user
*buf
,
628 size_t count
, loff_t
*ppos
)
632 unsigned int new_value
;
634 length
= task_has_security(current
, SECURITY__SETCHECKREQPROT
);
639 if (count
>= PAGE_SIZE
)
642 /* No partial writes. */
648 page
= (char *)get_zeroed_page(GFP_KERNEL
);
653 if (copy_from_user(page
, buf
, count
))
657 if (sscanf(page
, "%u", &new_value
) != 1)
660 selinux_checkreqprot
= new_value
? 1 : 0;
663 free_page((unsigned long) page
);
666 static const struct file_operations sel_checkreqprot_ops
= {
667 .read
= sel_read_checkreqprot
,
668 .write
= sel_write_checkreqprot
,
669 .llseek
= generic_file_llseek
,
673 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
675 static ssize_t
sel_write_access(struct file
*file
, char *buf
, size_t size
);
676 static ssize_t
sel_write_create(struct file
*file
, char *buf
, size_t size
);
677 static ssize_t
sel_write_relabel(struct file
*file
, char *buf
, size_t size
);
678 static ssize_t
sel_write_user(struct file
*file
, char *buf
, size_t size
);
679 static ssize_t
sel_write_member(struct file
*file
, char *buf
, size_t size
);
681 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
682 [SEL_ACCESS
] = sel_write_access
,
683 [SEL_CREATE
] = sel_write_create
,
684 [SEL_RELABEL
] = sel_write_relabel
,
685 [SEL_USER
] = sel_write_user
,
686 [SEL_MEMBER
] = sel_write_member
,
687 [SEL_CONTEXT
] = sel_write_context
,
690 static ssize_t
selinux_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
692 ino_t ino
= file_inode(file
)->i_ino
;
696 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
699 data
= simple_transaction_get(file
, buf
, size
);
701 return PTR_ERR(data
);
703 rv
= write_op
[ino
](file
, data
, size
);
705 simple_transaction_set(file
, rv
);
711 static const struct file_operations transaction_ops
= {
712 .write
= selinux_transaction_write
,
713 .read
= simple_transaction_read
,
714 .release
= simple_transaction_release
,
715 .llseek
= generic_file_llseek
,
719 * payload - write methods
720 * If the method has a response, the response should be put in buf,
721 * and the length returned. Otherwise return 0 or and -error.
724 static ssize_t
sel_write_access(struct file
*file
, char *buf
, size_t size
)
726 char *scon
= NULL
, *tcon
= NULL
;
729 struct av_decision avd
;
732 length
= task_has_security(current
, SECURITY__COMPUTE_AV
);
737 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
742 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
747 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
750 length
= security_context_to_sid(scon
, strlen(scon
) + 1, &ssid
);
754 length
= security_context_to_sid(tcon
, strlen(tcon
) + 1, &tsid
);
758 security_compute_av_user(ssid
, tsid
, tclass
, &avd
);
760 length
= scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
,
762 avd
.allowed
, 0xffffffff,
763 avd
.auditallow
, avd
.auditdeny
,
764 avd
.seqno
, avd
.flags
);
771 static ssize_t
sel_write_create(struct file
*file
, char *buf
, size_t size
)
773 char *scon
= NULL
, *tcon
= NULL
;
774 char *namebuf
= NULL
, *objname
= NULL
;
775 u32 ssid
, tsid
, newsid
;
782 length
= task_has_security(current
, SECURITY__COMPUTE_CREATE
);
787 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
792 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
797 namebuf
= kzalloc(size
+ 1, GFP_KERNEL
);
802 nargs
= sscanf(buf
, "%s %s %hu %s", scon
, tcon
, &tclass
, namebuf
);
803 if (nargs
< 3 || nargs
> 4)
807 * If and when the name of new object to be queried contains
808 * either whitespace or multibyte characters, they shall be
809 * encoded based on the percentage-encoding rule.
810 * If not encoded, the sscanf logic picks up only left-half
811 * of the supplied name; splitted by a whitespace unexpectedly.
821 else if (c1
== '%') {
822 c1
= hex_to_bin(*r
++);
825 c2
= hex_to_bin(*r
++);
831 } while (c1
!= '\0');
836 length
= security_context_to_sid(scon
, strlen(scon
) + 1, &ssid
);
840 length
= security_context_to_sid(tcon
, strlen(tcon
) + 1, &tsid
);
844 length
= security_transition_sid_user(ssid
, tsid
, tclass
,
849 length
= security_sid_to_context(newsid
, &newcon
, &len
);
854 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
855 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
856 "payload max\n", __func__
, len
);
860 memcpy(buf
, newcon
, len
);
870 static ssize_t
sel_write_relabel(struct file
*file
, char *buf
, size_t size
)
872 char *scon
= NULL
, *tcon
= NULL
;
873 u32 ssid
, tsid
, newsid
;
879 length
= task_has_security(current
, SECURITY__COMPUTE_RELABEL
);
884 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
889 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
894 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
897 length
= security_context_to_sid(scon
, strlen(scon
) + 1, &ssid
);
901 length
= security_context_to_sid(tcon
, strlen(tcon
) + 1, &tsid
);
905 length
= security_change_sid(ssid
, tsid
, tclass
, &newsid
);
909 length
= security_sid_to_context(newsid
, &newcon
, &len
);
914 if (len
> SIMPLE_TRANSACTION_LIMIT
)
917 memcpy(buf
, newcon
, len
);
926 static ssize_t
sel_write_user(struct file
*file
, char *buf
, size_t size
)
928 char *con
= NULL
, *user
= NULL
, *ptr
;
929 u32 sid
, *sids
= NULL
;
935 length
= task_has_security(current
, SECURITY__COMPUTE_USER
);
940 con
= kzalloc(size
+ 1, GFP_KERNEL
);
945 user
= kzalloc(size
+ 1, GFP_KERNEL
);
950 if (sscanf(buf
, "%s %s", con
, user
) != 2)
953 length
= security_context_to_sid(con
, strlen(con
) + 1, &sid
);
957 length
= security_get_user_sids(sid
, user
, &sids
, &nsids
);
961 length
= sprintf(buf
, "%u", nsids
) + 1;
963 for (i
= 0; i
< nsids
; i
++) {
964 rc
= security_sid_to_context(sids
[i
], &newcon
, &len
);
969 if ((length
+ len
) >= SIMPLE_TRANSACTION_LIMIT
) {
974 memcpy(ptr
, newcon
, len
);
986 static ssize_t
sel_write_member(struct file
*file
, char *buf
, size_t size
)
988 char *scon
= NULL
, *tcon
= NULL
;
989 u32 ssid
, tsid
, newsid
;
995 length
= task_has_security(current
, SECURITY__COMPUTE_MEMBER
);
1000 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
1005 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
1010 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
1013 length
= security_context_to_sid(scon
, strlen(scon
) + 1, &ssid
);
1017 length
= security_context_to_sid(tcon
, strlen(tcon
) + 1, &tsid
);
1021 length
= security_member_sid(ssid
, tsid
, tclass
, &newsid
);
1025 length
= security_sid_to_context(newsid
, &newcon
, &len
);
1030 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
1031 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
1032 "payload max\n", __func__
, len
);
1036 memcpy(buf
, newcon
, len
);
1045 static struct inode
*sel_make_inode(struct super_block
*sb
, int mode
)
1047 struct inode
*ret
= new_inode(sb
);
1051 ret
->i_atime
= ret
->i_mtime
= ret
->i_ctime
= CURRENT_TIME
;
1056 static ssize_t
sel_read_bool(struct file
*filep
, char __user
*buf
,
1057 size_t count
, loff_t
*ppos
)
1063 unsigned index
= file_inode(filep
)->i_ino
& SEL_INO_MASK
;
1064 const char *name
= filep
->f_path
.dentry
->d_name
.name
;
1066 mutex_lock(&sel_mutex
);
1069 if (index
>= bool_num
|| strcmp(name
, bool_pending_names
[index
]))
1073 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1077 cur_enforcing
= security_get_bool_value(index
);
1078 if (cur_enforcing
< 0) {
1079 ret
= cur_enforcing
;
1082 length
= scnprintf(page
, PAGE_SIZE
, "%d %d", cur_enforcing
,
1083 bool_pending_values
[index
]);
1084 ret
= simple_read_from_buffer(buf
, count
, ppos
, page
, length
);
1086 mutex_unlock(&sel_mutex
);
1087 free_page((unsigned long)page
);
1091 static ssize_t
sel_write_bool(struct file
*filep
, const char __user
*buf
,
1092 size_t count
, loff_t
*ppos
)
1097 unsigned index
= file_inode(filep
)->i_ino
& SEL_INO_MASK
;
1098 const char *name
= filep
->f_path
.dentry
->d_name
.name
;
1100 mutex_lock(&sel_mutex
);
1102 length
= task_has_security(current
, SECURITY__SETBOOL
);
1107 if (index
>= bool_num
|| strcmp(name
, bool_pending_names
[index
]))
1111 if (count
>= PAGE_SIZE
)
1114 /* No partial writes. */
1120 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1125 if (copy_from_user(page
, buf
, count
))
1129 if (sscanf(page
, "%d", &new_value
) != 1)
1135 bool_pending_values
[index
] = new_value
;
1139 mutex_unlock(&sel_mutex
);
1140 free_page((unsigned long) page
);
1144 static const struct file_operations sel_bool_ops
= {
1145 .read
= sel_read_bool
,
1146 .write
= sel_write_bool
,
1147 .llseek
= generic_file_llseek
,
1150 static ssize_t
sel_commit_bools_write(struct file
*filep
,
1151 const char __user
*buf
,
1152 size_t count
, loff_t
*ppos
)
1158 mutex_lock(&sel_mutex
);
1160 length
= task_has_security(current
, SECURITY__SETBOOL
);
1165 if (count
>= PAGE_SIZE
)
1168 /* No partial writes. */
1174 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1179 if (copy_from_user(page
, buf
, count
))
1183 if (sscanf(page
, "%d", &new_value
) != 1)
1187 if (new_value
&& bool_pending_values
)
1188 length
= security_set_bools(bool_num
, bool_pending_values
);
1194 mutex_unlock(&sel_mutex
);
1195 free_page((unsigned long) page
);
1199 static const struct file_operations sel_commit_bools_ops
= {
1200 .write
= sel_commit_bools_write
,
1201 .llseek
= generic_file_llseek
,
1204 static void sel_remove_entries(struct dentry
*de
)
1206 struct list_head
*node
;
1208 spin_lock(&de
->d_lock
);
1209 node
= de
->d_subdirs
.next
;
1210 while (node
!= &de
->d_subdirs
) {
1211 struct dentry
*d
= list_entry(node
, struct dentry
, d_child
);
1213 spin_lock_nested(&d
->d_lock
, DENTRY_D_LOCK_NESTED
);
1214 list_del_init(node
);
1218 spin_unlock(&de
->d_lock
);
1219 spin_unlock(&d
->d_lock
);
1221 simple_unlink(de
->d_inode
, d
);
1223 spin_lock(&de
->d_lock
);
1225 spin_unlock(&d
->d_lock
);
1226 node
= de
->d_subdirs
.next
;
1229 spin_unlock(&de
->d_lock
);
1232 #define BOOL_DIR_NAME "booleans"
1234 static int sel_make_bools(void)
1238 struct dentry
*dentry
= NULL
;
1239 struct dentry
*dir
= bool_dir
;
1240 struct inode
*inode
= NULL
;
1241 struct inode_security_struct
*isec
;
1242 char **names
= NULL
, *page
;
1247 /* remove any existing files */
1248 for (i
= 0; i
< bool_num
; i
++)
1249 kfree(bool_pending_names
[i
]);
1250 kfree(bool_pending_names
);
1251 kfree(bool_pending_values
);
1253 bool_pending_names
= NULL
;
1254 bool_pending_values
= NULL
;
1256 sel_remove_entries(dir
);
1259 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1263 ret
= security_get_bools(&num
, &names
, &values
);
1267 for (i
= 0; i
< num
; i
++) {
1269 dentry
= d_alloc_name(dir
, names
[i
]);
1274 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
| S_IRUGO
| S_IWUSR
);
1278 ret
= -ENAMETOOLONG
;
1279 len
= snprintf(page
, PAGE_SIZE
, "/%s/%s", BOOL_DIR_NAME
, names
[i
]);
1280 if (len
>= PAGE_SIZE
)
1283 isec
= (struct inode_security_struct
*)inode
->i_security
;
1284 ret
= security_genfs_sid("selinuxfs", page
, SECCLASS_FILE
, &sid
);
1289 isec
->initialized
= 1;
1290 inode
->i_fop
= &sel_bool_ops
;
1291 inode
->i_ino
= i
|SEL_BOOL_INO_OFFSET
;
1292 d_add(dentry
, inode
);
1295 bool_pending_names
= names
;
1296 bool_pending_values
= values
;
1298 free_page((unsigned long)page
);
1301 free_page((unsigned long)page
);
1304 for (i
= 0; i
< num
; i
++)
1309 sel_remove_entries(dir
);
1314 #define NULL_FILE_NAME "null"
1316 struct path selinux_null
;
1318 static ssize_t
sel_read_avc_cache_threshold(struct file
*filp
, char __user
*buf
,
1319 size_t count
, loff_t
*ppos
)
1321 char tmpbuf
[TMPBUFLEN
];
1324 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", avc_cache_threshold
);
1325 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1328 static ssize_t
sel_write_avc_cache_threshold(struct file
*file
,
1329 const char __user
*buf
,
1330 size_t count
, loff_t
*ppos
)
1337 ret
= task_has_security(current
, SECURITY__SETSECPARAM
);
1342 if (count
>= PAGE_SIZE
)
1345 /* No partial writes. */
1351 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1356 if (copy_from_user(page
, buf
, count
))
1360 if (sscanf(page
, "%u", &new_value
) != 1)
1363 avc_cache_threshold
= new_value
;
1367 free_page((unsigned long)page
);
1371 static ssize_t
sel_read_avc_hash_stats(struct file
*filp
, char __user
*buf
,
1372 size_t count
, loff_t
*ppos
)
1377 page
= (char *)__get_free_page(GFP_KERNEL
);
1381 length
= avc_get_hash_stats(page
);
1383 length
= simple_read_from_buffer(buf
, count
, ppos
, page
, length
);
1384 free_page((unsigned long)page
);
1389 static const struct file_operations sel_avc_cache_threshold_ops
= {
1390 .read
= sel_read_avc_cache_threshold
,
1391 .write
= sel_write_avc_cache_threshold
,
1392 .llseek
= generic_file_llseek
,
1395 static const struct file_operations sel_avc_hash_stats_ops
= {
1396 .read
= sel_read_avc_hash_stats
,
1397 .llseek
= generic_file_llseek
,
1400 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1401 static struct avc_cache_stats
*sel_avc_get_stat_idx(loff_t
*idx
)
1405 for (cpu
= *idx
; cpu
< nr_cpu_ids
; ++cpu
) {
1406 if (!cpu_possible(cpu
))
1409 return &per_cpu(avc_cache_stats
, cpu
);
1414 static void *sel_avc_stats_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1416 loff_t n
= *pos
- 1;
1419 return SEQ_START_TOKEN
;
1421 return sel_avc_get_stat_idx(&n
);
1424 static void *sel_avc_stats_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1426 return sel_avc_get_stat_idx(pos
);
1429 static int sel_avc_stats_seq_show(struct seq_file
*seq
, void *v
)
1431 struct avc_cache_stats
*st
= v
;
1433 if (v
== SEQ_START_TOKEN
)
1434 seq_printf(seq
, "lookups hits misses allocations reclaims "
1437 unsigned int lookups
= st
->lookups
;
1438 unsigned int misses
= st
->misses
;
1439 unsigned int hits
= lookups
- misses
;
1440 seq_printf(seq
, "%u %u %u %u %u %u\n", lookups
,
1441 hits
, misses
, st
->allocations
,
1442 st
->reclaims
, st
->frees
);
1447 static void sel_avc_stats_seq_stop(struct seq_file
*seq
, void *v
)
1450 static const struct seq_operations sel_avc_cache_stats_seq_ops
= {
1451 .start
= sel_avc_stats_seq_start
,
1452 .next
= sel_avc_stats_seq_next
,
1453 .show
= sel_avc_stats_seq_show
,
1454 .stop
= sel_avc_stats_seq_stop
,
1457 static int sel_open_avc_cache_stats(struct inode
*inode
, struct file
*file
)
1459 return seq_open(file
, &sel_avc_cache_stats_seq_ops
);
1462 static const struct file_operations sel_avc_cache_stats_ops
= {
1463 .open
= sel_open_avc_cache_stats
,
1465 .llseek
= seq_lseek
,
1466 .release
= seq_release
,
1470 static int sel_make_avc_files(struct dentry
*dir
)
1473 static struct tree_descr files
[] = {
1474 { "cache_threshold",
1475 &sel_avc_cache_threshold_ops
, S_IRUGO
|S_IWUSR
},
1476 { "hash_stats", &sel_avc_hash_stats_ops
, S_IRUGO
},
1477 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1478 { "cache_stats", &sel_avc_cache_stats_ops
, S_IRUGO
},
1482 for (i
= 0; i
< ARRAY_SIZE(files
); i
++) {
1483 struct inode
*inode
;
1484 struct dentry
*dentry
;
1486 dentry
= d_alloc_name(dir
, files
[i
].name
);
1490 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|files
[i
].mode
);
1494 inode
->i_fop
= files
[i
].ops
;
1495 inode
->i_ino
= ++sel_last_ino
;
1496 d_add(dentry
, inode
);
1502 static ssize_t
sel_read_initcon(struct file
*file
, char __user
*buf
,
1503 size_t count
, loff_t
*ppos
)
1509 sid
= file_inode(file
)->i_ino
&SEL_INO_MASK
;
1510 ret
= security_sid_to_context(sid
, &con
, &len
);
1514 ret
= simple_read_from_buffer(buf
, count
, ppos
, con
, len
);
1519 static const struct file_operations sel_initcon_ops
= {
1520 .read
= sel_read_initcon
,
1521 .llseek
= generic_file_llseek
,
1524 static int sel_make_initcon_files(struct dentry
*dir
)
1528 for (i
= 1; i
<= SECINITSID_NUM
; i
++) {
1529 struct inode
*inode
;
1530 struct dentry
*dentry
;
1531 dentry
= d_alloc_name(dir
, security_get_initial_sid_context(i
));
1535 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1539 inode
->i_fop
= &sel_initcon_ops
;
1540 inode
->i_ino
= i
|SEL_INITCON_INO_OFFSET
;
1541 d_add(dentry
, inode
);
1547 static inline unsigned long sel_class_to_ino(u16
class)
1549 return (class * (SEL_VEC_MAX
+ 1)) | SEL_CLASS_INO_OFFSET
;
1552 static inline u16
sel_ino_to_class(unsigned long ino
)
1554 return (ino
& SEL_INO_MASK
) / (SEL_VEC_MAX
+ 1);
1557 static inline unsigned long sel_perm_to_ino(u16
class, u32 perm
)
1559 return (class * (SEL_VEC_MAX
+ 1) + perm
) | SEL_CLASS_INO_OFFSET
;
1562 static inline u32
sel_ino_to_perm(unsigned long ino
)
1564 return (ino
& SEL_INO_MASK
) % (SEL_VEC_MAX
+ 1);
1567 static ssize_t
sel_read_class(struct file
*file
, char __user
*buf
,
1568 size_t count
, loff_t
*ppos
)
1570 unsigned long ino
= file_inode(file
)->i_ino
;
1571 char res
[TMPBUFLEN
];
1572 ssize_t len
= snprintf(res
, sizeof(res
), "%d", sel_ino_to_class(ino
));
1573 return simple_read_from_buffer(buf
, count
, ppos
, res
, len
);
1576 static const struct file_operations sel_class_ops
= {
1577 .read
= sel_read_class
,
1578 .llseek
= generic_file_llseek
,
1581 static ssize_t
sel_read_perm(struct file
*file
, char __user
*buf
,
1582 size_t count
, loff_t
*ppos
)
1584 unsigned long ino
= file_inode(file
)->i_ino
;
1585 char res
[TMPBUFLEN
];
1586 ssize_t len
= snprintf(res
, sizeof(res
), "%d", sel_ino_to_perm(ino
));
1587 return simple_read_from_buffer(buf
, count
, ppos
, res
, len
);
1590 static const struct file_operations sel_perm_ops
= {
1591 .read
= sel_read_perm
,
1592 .llseek
= generic_file_llseek
,
1595 static ssize_t
sel_read_policycap(struct file
*file
, char __user
*buf
,
1596 size_t count
, loff_t
*ppos
)
1599 char tmpbuf
[TMPBUFLEN
];
1601 unsigned long i_ino
= file_inode(file
)->i_ino
;
1603 value
= security_policycap_supported(i_ino
& SEL_INO_MASK
);
1604 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", value
);
1606 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1609 static const struct file_operations sel_policycap_ops
= {
1610 .read
= sel_read_policycap
,
1611 .llseek
= generic_file_llseek
,
1614 static int sel_make_perm_files(char *objclass
, int classvalue
,
1620 rc
= security_get_permissions(objclass
, &perms
, &nperms
);
1624 for (i
= 0; i
< nperms
; i
++) {
1625 struct inode
*inode
;
1626 struct dentry
*dentry
;
1629 dentry
= d_alloc_name(dir
, perms
[i
]);
1634 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1638 inode
->i_fop
= &sel_perm_ops
;
1639 /* i+1 since perm values are 1-indexed */
1640 inode
->i_ino
= sel_perm_to_ino(classvalue
, i
+ 1);
1641 d_add(dentry
, inode
);
1645 for (i
= 0; i
< nperms
; i
++)
1651 static int sel_make_class_dir_entries(char *classname
, int index
,
1654 struct dentry
*dentry
= NULL
;
1655 struct inode
*inode
= NULL
;
1658 dentry
= d_alloc_name(dir
, "index");
1662 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1666 inode
->i_fop
= &sel_class_ops
;
1667 inode
->i_ino
= sel_class_to_ino(index
);
1668 d_add(dentry
, inode
);
1670 dentry
= sel_make_dir(dir
, "perms", &last_class_ino
);
1672 return PTR_ERR(dentry
);
1674 rc
= sel_make_perm_files(classname
, index
, dentry
);
1679 static void sel_remove_classes(void)
1681 struct list_head
*class_node
;
1683 list_for_each(class_node
, &class_dir
->d_subdirs
) {
1684 struct dentry
*class_subdir
= list_entry(class_node
,
1685 struct dentry
, d_child
);
1686 struct list_head
*class_subdir_node
;
1688 list_for_each(class_subdir_node
, &class_subdir
->d_subdirs
) {
1689 struct dentry
*d
= list_entry(class_subdir_node
,
1690 struct dentry
, d_child
);
1693 if (d
->d_inode
->i_mode
& S_IFDIR
)
1694 sel_remove_entries(d
);
1697 sel_remove_entries(class_subdir
);
1700 sel_remove_entries(class_dir
);
1703 static int sel_make_classes(void)
1705 int rc
, nclasses
, i
;
1708 /* delete any existing entries */
1709 sel_remove_classes();
1711 rc
= security_get_classes(&classes
, &nclasses
);
1715 /* +2 since classes are 1-indexed */
1716 last_class_ino
= sel_class_to_ino(nclasses
+ 2);
1718 for (i
= 0; i
< nclasses
; i
++) {
1719 struct dentry
*class_name_dir
;
1721 class_name_dir
= sel_make_dir(class_dir
, classes
[i
],
1723 if (IS_ERR(class_name_dir
)) {
1724 rc
= PTR_ERR(class_name_dir
);
1728 /* i+1 since class values are 1-indexed */
1729 rc
= sel_make_class_dir_entries(classes
[i
], i
+ 1,
1736 for (i
= 0; i
< nclasses
; i
++)
1742 static int sel_make_policycap(void)
1745 struct dentry
*dentry
= NULL
;
1746 struct inode
*inode
= NULL
;
1748 sel_remove_entries(policycap_dir
);
1750 for (iter
= 0; iter
<= POLICYDB_CAPABILITY_MAX
; iter
++) {
1751 if (iter
< ARRAY_SIZE(policycap_names
))
1752 dentry
= d_alloc_name(policycap_dir
,
1753 policycap_names
[iter
]);
1755 dentry
= d_alloc_name(policycap_dir
, "unknown");
1760 inode
= sel_make_inode(policycap_dir
->d_sb
, S_IFREG
| S_IRUGO
);
1764 inode
->i_fop
= &sel_policycap_ops
;
1765 inode
->i_ino
= iter
| SEL_POLICYCAP_INO_OFFSET
;
1766 d_add(dentry
, inode
);
1772 static struct dentry
*sel_make_dir(struct dentry
*dir
, const char *name
,
1775 struct dentry
*dentry
= d_alloc_name(dir
, name
);
1776 struct inode
*inode
;
1779 return ERR_PTR(-ENOMEM
);
1781 inode
= sel_make_inode(dir
->d_sb
, S_IFDIR
| S_IRUGO
| S_IXUGO
);
1784 return ERR_PTR(-ENOMEM
);
1787 inode
->i_op
= &simple_dir_inode_operations
;
1788 inode
->i_fop
= &simple_dir_operations
;
1789 inode
->i_ino
= ++(*ino
);
1790 /* directory inodes start off with i_nlink == 2 (for "." entry) */
1792 d_add(dentry
, inode
);
1793 /* bump link count on parent directory, too */
1794 inc_nlink(dir
->d_inode
);
1799 static int sel_fill_super(struct super_block
*sb
, void *data
, int silent
)
1802 struct dentry
*dentry
;
1803 struct inode
*inode
;
1804 struct inode_security_struct
*isec
;
1806 static struct tree_descr selinux_files
[] = {
1807 [SEL_LOAD
] = {"load", &sel_load_ops
, S_IRUSR
|S_IWUSR
},
1808 [SEL_ENFORCE
] = {"enforce", &sel_enforce_ops
, S_IRUGO
|S_IWUSR
},
1809 [SEL_CONTEXT
] = {"context", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1810 [SEL_ACCESS
] = {"access", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1811 [SEL_CREATE
] = {"create", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1812 [SEL_RELABEL
] = {"relabel", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1813 [SEL_USER
] = {"user", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1814 [SEL_POLICYVERS
] = {"policyvers", &sel_policyvers_ops
, S_IRUGO
},
1815 [SEL_COMMIT_BOOLS
] = {"commit_pending_bools", &sel_commit_bools_ops
, S_IWUSR
},
1816 [SEL_MLS
] = {"mls", &sel_mls_ops
, S_IRUGO
},
1817 [SEL_DISABLE
] = {"disable", &sel_disable_ops
, S_IWUSR
},
1818 [SEL_MEMBER
] = {"member", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1819 [SEL_CHECKREQPROT
] = {"checkreqprot", &sel_checkreqprot_ops
, S_IRUGO
|S_IWUSR
},
1820 [SEL_REJECT_UNKNOWN
] = {"reject_unknown", &sel_handle_unknown_ops
, S_IRUGO
},
1821 [SEL_DENY_UNKNOWN
] = {"deny_unknown", &sel_handle_unknown_ops
, S_IRUGO
},
1822 [SEL_STATUS
] = {"status", &sel_handle_status_ops
, S_IRUGO
},
1823 [SEL_POLICY
] = {"policy", &sel_policy_ops
, S_IRUGO
},
1826 ret
= simple_fill_super(sb
, SELINUX_MAGIC
, selinux_files
);
1830 bool_dir
= sel_make_dir(sb
->s_root
, BOOL_DIR_NAME
, &sel_last_ino
);
1831 if (IS_ERR(bool_dir
)) {
1832 ret
= PTR_ERR(bool_dir
);
1838 dentry
= d_alloc_name(sb
->s_root
, NULL_FILE_NAME
);
1843 inode
= sel_make_inode(sb
, S_IFCHR
| S_IRUGO
| S_IWUGO
);
1847 inode
->i_ino
= ++sel_last_ino
;
1848 isec
= (struct inode_security_struct
*)inode
->i_security
;
1849 isec
->sid
= SECINITSID_DEVNULL
;
1850 isec
->sclass
= SECCLASS_CHR_FILE
;
1851 isec
->initialized
= 1;
1853 init_special_inode(inode
, S_IFCHR
| S_IRUGO
| S_IWUGO
, MKDEV(MEM_MAJOR
, 3));
1854 d_add(dentry
, inode
);
1855 selinux_null
.dentry
= dentry
;
1857 dentry
= sel_make_dir(sb
->s_root
, "avc", &sel_last_ino
);
1858 if (IS_ERR(dentry
)) {
1859 ret
= PTR_ERR(dentry
);
1863 ret
= sel_make_avc_files(dentry
);
1867 dentry
= sel_make_dir(sb
->s_root
, "initial_contexts", &sel_last_ino
);
1868 if (IS_ERR(dentry
)) {
1869 ret
= PTR_ERR(dentry
);
1873 ret
= sel_make_initcon_files(dentry
);
1877 class_dir
= sel_make_dir(sb
->s_root
, "class", &sel_last_ino
);
1878 if (IS_ERR(class_dir
)) {
1879 ret
= PTR_ERR(class_dir
);
1884 policycap_dir
= sel_make_dir(sb
->s_root
, "policy_capabilities", &sel_last_ino
);
1885 if (IS_ERR(policycap_dir
)) {
1886 ret
= PTR_ERR(policycap_dir
);
1887 policycap_dir
= NULL
;
1892 printk(KERN_ERR
"SELinux: %s: failed while creating inodes\n",
1897 static struct dentry
*sel_mount(struct file_system_type
*fs_type
,
1898 int flags
, const char *dev_name
, void *data
)
1900 return mount_single(fs_type
, flags
, data
, sel_fill_super
);
1903 static struct file_system_type sel_fs_type
= {
1904 .name
= "selinuxfs",
1906 .kill_sb
= kill_litter_super
,
1909 struct vfsmount
*selinuxfs_mount
;
1910 static struct kobject
*selinuxfs_kobj
;
1912 static int __init
init_sel_fs(void)
1916 if (!selinux_enabled
)
1919 selinuxfs_kobj
= kobject_create_and_add("selinux", fs_kobj
);
1920 if (!selinuxfs_kobj
)
1923 err
= register_filesystem(&sel_fs_type
);
1925 kobject_put(selinuxfs_kobj
);
1929 selinux_null
.mnt
= selinuxfs_mount
= kern_mount(&sel_fs_type
);
1930 if (IS_ERR(selinuxfs_mount
)) {
1931 printk(KERN_ERR
"selinuxfs: could not mount!\n");
1932 err
= PTR_ERR(selinuxfs_mount
);
1933 selinuxfs_mount
= NULL
;
1939 __initcall(init_sel_fs
);
1941 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1942 void exit_sel_fs(void)
1944 kobject_put(selinuxfs_kobj
);
1945 kern_unmount(selinuxfs_mount
);
1946 unregister_filesystem(&sel_fs_type
);