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>
33 #include <linux/lsm_hooks.h>
35 /* selinuxfs pseudo filesystem for exporting the security policy API.
36 Based on the proc code and the fs/nfsd/nfsctl.c code. */
43 #include "conditional.h"
45 unsigned int selinux_checkreqprot
= CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE
;
47 static int __init
checkreqprot_setup(char *str
)
49 unsigned long checkreqprot
;
50 if (!kstrtoul(str
, 0, &checkreqprot
))
51 selinux_checkreqprot
= checkreqprot
? 1 : 0;
54 __setup("checkreqprot=", checkreqprot_setup
);
56 static DEFINE_MUTEX(sel_mutex
);
58 /* global data for booleans */
59 static struct dentry
*bool_dir
;
61 static char **bool_pending_names
;
62 static int *bool_pending_values
;
64 /* global data for classes */
65 static struct dentry
*class_dir
;
66 static unsigned long last_class_ino
;
68 static char policy_opened
;
70 /* global data for policy capabilities */
71 static struct dentry
*policycap_dir
;
75 SEL_LOAD
, /* load policy */
76 SEL_ENFORCE
, /* get or set enforcing status */
77 SEL_CONTEXT
, /* validate context */
78 SEL_ACCESS
, /* compute access decision */
79 SEL_CREATE
, /* compute create labeling decision */
80 SEL_RELABEL
, /* compute relabeling decision */
81 SEL_USER
, /* compute reachable user contexts */
82 SEL_POLICYVERS
, /* return policy version for this kernel */
83 SEL_COMMIT_BOOLS
, /* commit new boolean values */
84 SEL_MLS
, /* return if MLS policy is enabled */
85 SEL_DISABLE
, /* disable SELinux until next reboot */
86 SEL_MEMBER
, /* compute polyinstantiation membership decision */
87 SEL_CHECKREQPROT
, /* check requested protection, not kernel-applied one */
88 SEL_COMPAT_NET
, /* whether to use old compat network packet controls */
89 SEL_REJECT_UNKNOWN
, /* export unknown reject handling to userspace */
90 SEL_DENY_UNKNOWN
, /* export unknown deny handling to userspace */
91 SEL_STATUS
, /* export current status using mmap() */
92 SEL_POLICY
, /* allow userspace to read the in kernel policy */
93 SEL_VALIDATE_TRANS
, /* compute validatetrans decision */
94 SEL_INO_NEXT
, /* The next inode number to use */
97 static unsigned long sel_last_ino
= SEL_INO_NEXT
- 1;
99 #define SEL_INITCON_INO_OFFSET 0x01000000
100 #define SEL_BOOL_INO_OFFSET 0x02000000
101 #define SEL_CLASS_INO_OFFSET 0x04000000
102 #define SEL_POLICYCAP_INO_OFFSET 0x08000000
103 #define SEL_INO_MASK 0x00ffffff
106 static ssize_t
sel_read_enforce(struct file
*filp
, char __user
*buf
,
107 size_t count
, loff_t
*ppos
)
109 char tmpbuf
[TMPBUFLEN
];
112 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", selinux_enforcing
);
113 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
116 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
117 static ssize_t
sel_write_enforce(struct file
*file
, const char __user
*buf
,
118 size_t count
, loff_t
*ppos
)
125 if (count
>= PAGE_SIZE
)
128 /* No partial writes. */
132 page
= memdup_user_nul(buf
, count
);
134 return PTR_ERR(page
);
137 if (sscanf(page
, "%d", &new_value
) != 1)
140 new_value
= !!new_value
;
142 if (new_value
!= selinux_enforcing
) {
143 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
144 SECCLASS_SECURITY
, SECURITY__SETENFORCE
,
148 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
149 "enforcing=%d old_enforcing=%d auid=%u ses=%u",
150 new_value
, selinux_enforcing
,
151 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
152 audit_get_sessionid(current
));
153 selinux_enforcing
= new_value
;
154 if (selinux_enforcing
)
156 selnl_notify_setenforce(selinux_enforcing
);
157 selinux_status_update_setenforce(selinux_enforcing
);
158 if (!selinux_enforcing
)
159 call_lsm_notifier(LSM_POLICY_CHANGE
, NULL
);
167 #define sel_write_enforce NULL
170 static const struct file_operations sel_enforce_ops
= {
171 .read
= sel_read_enforce
,
172 .write
= sel_write_enforce
,
173 .llseek
= generic_file_llseek
,
176 static ssize_t
sel_read_handle_unknown(struct file
*filp
, char __user
*buf
,
177 size_t count
, loff_t
*ppos
)
179 char tmpbuf
[TMPBUFLEN
];
181 ino_t ino
= file_inode(filp
)->i_ino
;
182 int handle_unknown
= (ino
== SEL_REJECT_UNKNOWN
) ?
183 security_get_reject_unknown() : !security_get_allow_unknown();
185 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", handle_unknown
);
186 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
189 static const struct file_operations sel_handle_unknown_ops
= {
190 .read
= sel_read_handle_unknown
,
191 .llseek
= generic_file_llseek
,
194 static int sel_open_handle_status(struct inode
*inode
, struct file
*filp
)
196 struct page
*status
= selinux_kernel_status_page();
201 filp
->private_data
= status
;
206 static ssize_t
sel_read_handle_status(struct file
*filp
, char __user
*buf
,
207 size_t count
, loff_t
*ppos
)
209 struct page
*status
= filp
->private_data
;
213 return simple_read_from_buffer(buf
, count
, ppos
,
214 page_address(status
),
215 sizeof(struct selinux_kernel_status
));
218 static int sel_mmap_handle_status(struct file
*filp
,
219 struct vm_area_struct
*vma
)
221 struct page
*status
= filp
->private_data
;
222 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
226 /* only allows one page from the head */
227 if (vma
->vm_pgoff
> 0 || size
!= PAGE_SIZE
)
229 /* disallow writable mapping */
230 if (vma
->vm_flags
& VM_WRITE
)
232 /* disallow mprotect() turns it into writable */
233 vma
->vm_flags
&= ~VM_MAYWRITE
;
235 return remap_pfn_range(vma
, vma
->vm_start
,
237 size
, vma
->vm_page_prot
);
240 static const struct file_operations sel_handle_status_ops
= {
241 .open
= sel_open_handle_status
,
242 .read
= sel_read_handle_status
,
243 .mmap
= sel_mmap_handle_status
,
244 .llseek
= generic_file_llseek
,
247 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
248 static ssize_t
sel_write_disable(struct file
*file
, const char __user
*buf
,
249 size_t count
, loff_t
*ppos
)
256 if (count
>= PAGE_SIZE
)
259 /* No partial writes. */
263 page
= memdup_user_nul(buf
, count
);
265 return PTR_ERR(page
);
268 if (sscanf(page
, "%d", &new_value
) != 1)
272 length
= selinux_disable();
275 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_STATUS
,
276 "selinux=0 auid=%u ses=%u",
277 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
278 audit_get_sessionid(current
));
287 #define sel_write_disable NULL
290 static const struct file_operations sel_disable_ops
= {
291 .write
= sel_write_disable
,
292 .llseek
= generic_file_llseek
,
295 static ssize_t
sel_read_policyvers(struct file
*filp
, char __user
*buf
,
296 size_t count
, loff_t
*ppos
)
298 char tmpbuf
[TMPBUFLEN
];
301 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", POLICYDB_VERSION_MAX
);
302 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
305 static const struct file_operations sel_policyvers_ops
= {
306 .read
= sel_read_policyvers
,
307 .llseek
= generic_file_llseek
,
310 /* declaration for sel_write_load */
311 static int sel_make_bools(void);
312 static int sel_make_classes(void);
313 static int sel_make_policycap(void);
315 /* declaration for sel_make_class_dirs */
316 static struct dentry
*sel_make_dir(struct dentry
*dir
, const char *name
,
319 static ssize_t
sel_read_mls(struct file
*filp
, char __user
*buf
,
320 size_t count
, loff_t
*ppos
)
322 char tmpbuf
[TMPBUFLEN
];
325 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d",
326 security_mls_enabled());
327 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
330 static const struct file_operations sel_mls_ops
= {
331 .read
= sel_read_mls
,
332 .llseek
= generic_file_llseek
,
335 struct policy_load_memory
{
340 static int sel_open_policy(struct inode
*inode
, struct file
*filp
)
342 struct policy_load_memory
*plm
= NULL
;
345 BUG_ON(filp
->private_data
);
347 mutex_lock(&sel_mutex
);
349 rc
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
350 SECCLASS_SECURITY
, SECURITY__READ_POLICY
, NULL
);
359 plm
= kzalloc(sizeof(*plm
), GFP_KERNEL
);
363 if (i_size_read(inode
) != security_policydb_len()) {
365 i_size_write(inode
, security_policydb_len());
369 rc
= security_read_policy(&plm
->data
, &plm
->len
);
375 filp
->private_data
= plm
;
377 mutex_unlock(&sel_mutex
);
381 mutex_unlock(&sel_mutex
);
389 static int sel_release_policy(struct inode
*inode
, struct file
*filp
)
391 struct policy_load_memory
*plm
= filp
->private_data
;
403 static ssize_t
sel_read_policy(struct file
*filp
, char __user
*buf
,
404 size_t count
, loff_t
*ppos
)
406 struct policy_load_memory
*plm
= filp
->private_data
;
409 mutex_lock(&sel_mutex
);
411 ret
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
412 SECCLASS_SECURITY
, SECURITY__READ_POLICY
, NULL
);
416 ret
= simple_read_from_buffer(buf
, count
, ppos
, plm
->data
, plm
->len
);
418 mutex_unlock(&sel_mutex
);
422 static int sel_mmap_policy_fault(struct vm_fault
*vmf
)
424 struct policy_load_memory
*plm
= vmf
->vma
->vm_file
->private_data
;
425 unsigned long offset
;
428 if (vmf
->flags
& (FAULT_FLAG_MKWRITE
| FAULT_FLAG_WRITE
))
429 return VM_FAULT_SIGBUS
;
431 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
432 if (offset
>= roundup(plm
->len
, PAGE_SIZE
))
433 return VM_FAULT_SIGBUS
;
435 page
= vmalloc_to_page(plm
->data
+ offset
);
443 static const struct vm_operations_struct sel_mmap_policy_ops
= {
444 .fault
= sel_mmap_policy_fault
,
445 .page_mkwrite
= sel_mmap_policy_fault
,
448 static int sel_mmap_policy(struct file
*filp
, struct vm_area_struct
*vma
)
450 if (vma
->vm_flags
& VM_SHARED
) {
451 /* do not allow mprotect to make mapping writable */
452 vma
->vm_flags
&= ~VM_MAYWRITE
;
454 if (vma
->vm_flags
& VM_WRITE
)
458 vma
->vm_flags
|= VM_DONTEXPAND
| VM_DONTDUMP
;
459 vma
->vm_ops
= &sel_mmap_policy_ops
;
464 static const struct file_operations sel_policy_ops
= {
465 .open
= sel_open_policy
,
466 .read
= sel_read_policy
,
467 .mmap
= sel_mmap_policy
,
468 .release
= sel_release_policy
,
469 .llseek
= generic_file_llseek
,
472 static ssize_t
sel_write_load(struct file
*file
, const char __user
*buf
,
473 size_t count
, loff_t
*ppos
)
479 mutex_lock(&sel_mutex
);
481 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
482 SECCLASS_SECURITY
, SECURITY__LOAD_POLICY
, NULL
);
486 /* No partial writes. */
492 if (count
> 64 * 1024 * 1024)
496 data
= vmalloc(count
);
501 if (copy_from_user(data
, buf
, count
) != 0)
504 length
= security_load_policy(data
, count
);
506 pr_warn_ratelimited("SELinux: failed to load policy\n");
510 length
= sel_make_bools();
512 pr_err("SELinux: failed to load policy booleans\n");
516 length
= sel_make_classes();
518 pr_err("SELinux: failed to load policy classes\n");
522 length
= sel_make_policycap();
524 pr_err("SELinux: failed to load policy capabilities\n");
531 audit_log(current
->audit_context
, GFP_KERNEL
, AUDIT_MAC_POLICY_LOAD
,
532 "policy loaded auid=%u ses=%u",
533 from_kuid(&init_user_ns
, audit_get_loginuid(current
)),
534 audit_get_sessionid(current
));
536 mutex_unlock(&sel_mutex
);
541 static const struct file_operations sel_load_ops
= {
542 .write
= sel_write_load
,
543 .llseek
= generic_file_llseek
,
546 static ssize_t
sel_write_context(struct file
*file
, char *buf
, size_t size
)
552 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
553 SECCLASS_SECURITY
, SECURITY__CHECK_CONTEXT
, NULL
);
557 length
= security_context_to_sid(buf
, size
, &sid
, GFP_KERNEL
);
561 length
= security_sid_to_context(sid
, &canon
, &len
);
566 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
567 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
568 "payload max\n", __func__
, len
);
572 memcpy(buf
, canon
, len
);
579 static ssize_t
sel_read_checkreqprot(struct file
*filp
, char __user
*buf
,
580 size_t count
, loff_t
*ppos
)
582 char tmpbuf
[TMPBUFLEN
];
585 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", selinux_checkreqprot
);
586 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
589 static ssize_t
sel_write_checkreqprot(struct file
*file
, const char __user
*buf
,
590 size_t count
, loff_t
*ppos
)
594 unsigned int new_value
;
596 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
597 SECCLASS_SECURITY
, SECURITY__SETCHECKREQPROT
,
602 if (count
>= PAGE_SIZE
)
605 /* No partial writes. */
609 page
= memdup_user_nul(buf
, count
);
611 return PTR_ERR(page
);
614 if (sscanf(page
, "%u", &new_value
) != 1)
617 selinux_checkreqprot
= new_value
? 1 : 0;
623 static const struct file_operations sel_checkreqprot_ops
= {
624 .read
= sel_read_checkreqprot
,
625 .write
= sel_write_checkreqprot
,
626 .llseek
= generic_file_llseek
,
629 static ssize_t
sel_write_validatetrans(struct file
*file
,
630 const char __user
*buf
,
631 size_t count
, loff_t
*ppos
)
633 char *oldcon
= NULL
, *newcon
= NULL
, *taskcon
= NULL
;
635 u32 osid
, nsid
, tsid
;
639 rc
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
640 SECCLASS_SECURITY
, SECURITY__VALIDATE_TRANS
, NULL
);
645 if (count
>= PAGE_SIZE
)
648 /* No partial writes. */
653 req
= memdup_user_nul(buf
, count
);
661 oldcon
= kzalloc(count
+ 1, GFP_KERNEL
);
665 newcon
= kzalloc(count
+ 1, GFP_KERNEL
);
669 taskcon
= kzalloc(count
+ 1, GFP_KERNEL
);
674 if (sscanf(req
, "%s %s %hu %s", oldcon
, newcon
, &tclass
, taskcon
) != 4)
677 rc
= security_context_str_to_sid(oldcon
, &osid
, GFP_KERNEL
);
681 rc
= security_context_str_to_sid(newcon
, &nsid
, GFP_KERNEL
);
685 rc
= security_context_str_to_sid(taskcon
, &tsid
, GFP_KERNEL
);
689 rc
= security_validate_transition_user(osid
, nsid
, tsid
, tclass
);
700 static const struct file_operations sel_transition_ops
= {
701 .write
= sel_write_validatetrans
,
702 .llseek
= generic_file_llseek
,
706 * Remaining nodes use transaction based IO methods like nfsd/nfsctl.c
708 static ssize_t
sel_write_access(struct file
*file
, char *buf
, size_t size
);
709 static ssize_t
sel_write_create(struct file
*file
, char *buf
, size_t size
);
710 static ssize_t
sel_write_relabel(struct file
*file
, char *buf
, size_t size
);
711 static ssize_t
sel_write_user(struct file
*file
, char *buf
, size_t size
);
712 static ssize_t
sel_write_member(struct file
*file
, char *buf
, size_t size
);
714 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
715 [SEL_ACCESS
] = sel_write_access
,
716 [SEL_CREATE
] = sel_write_create
,
717 [SEL_RELABEL
] = sel_write_relabel
,
718 [SEL_USER
] = sel_write_user
,
719 [SEL_MEMBER
] = sel_write_member
,
720 [SEL_CONTEXT
] = sel_write_context
,
723 static ssize_t
selinux_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
725 ino_t ino
= file_inode(file
)->i_ino
;
729 if (ino
>= ARRAY_SIZE(write_op
) || !write_op
[ino
])
732 data
= simple_transaction_get(file
, buf
, size
);
734 return PTR_ERR(data
);
736 rv
= write_op
[ino
](file
, data
, size
);
738 simple_transaction_set(file
, rv
);
744 static const struct file_operations transaction_ops
= {
745 .write
= selinux_transaction_write
,
746 .read
= simple_transaction_read
,
747 .release
= simple_transaction_release
,
748 .llseek
= generic_file_llseek
,
752 * payload - write methods
753 * If the method has a response, the response should be put in buf,
754 * and the length returned. Otherwise return 0 or and -error.
757 static ssize_t
sel_write_access(struct file
*file
, char *buf
, size_t size
)
759 char *scon
= NULL
, *tcon
= NULL
;
762 struct av_decision avd
;
765 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
766 SECCLASS_SECURITY
, SECURITY__COMPUTE_AV
, NULL
);
771 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
776 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
781 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
784 length
= security_context_str_to_sid(scon
, &ssid
, GFP_KERNEL
);
788 length
= security_context_str_to_sid(tcon
, &tsid
, GFP_KERNEL
);
792 security_compute_av_user(ssid
, tsid
, tclass
, &avd
);
794 length
= scnprintf(buf
, SIMPLE_TRANSACTION_LIMIT
,
796 avd
.allowed
, 0xffffffff,
797 avd
.auditallow
, avd
.auditdeny
,
798 avd
.seqno
, avd
.flags
);
805 static ssize_t
sel_write_create(struct file
*file
, char *buf
, size_t size
)
807 char *scon
= NULL
, *tcon
= NULL
;
808 char *namebuf
= NULL
, *objname
= NULL
;
809 u32 ssid
, tsid
, newsid
;
816 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
817 SECCLASS_SECURITY
, SECURITY__COMPUTE_CREATE
,
823 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
828 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
833 namebuf
= kzalloc(size
+ 1, GFP_KERNEL
);
838 nargs
= sscanf(buf
, "%s %s %hu %s", scon
, tcon
, &tclass
, namebuf
);
839 if (nargs
< 3 || nargs
> 4)
843 * If and when the name of new object to be queried contains
844 * either whitespace or multibyte characters, they shall be
845 * encoded based on the percentage-encoding rule.
846 * If not encoded, the sscanf logic picks up only left-half
847 * of the supplied name; splitted by a whitespace unexpectedly.
857 else if (c1
== '%') {
858 c1
= hex_to_bin(*r
++);
861 c2
= hex_to_bin(*r
++);
867 } while (c1
!= '\0');
872 length
= security_context_str_to_sid(scon
, &ssid
, GFP_KERNEL
);
876 length
= security_context_str_to_sid(tcon
, &tsid
, GFP_KERNEL
);
880 length
= security_transition_sid_user(ssid
, tsid
, tclass
,
885 length
= security_sid_to_context(newsid
, &newcon
, &len
);
890 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
891 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
892 "payload max\n", __func__
, len
);
896 memcpy(buf
, newcon
, len
);
906 static ssize_t
sel_write_relabel(struct file
*file
, char *buf
, size_t size
)
908 char *scon
= NULL
, *tcon
= NULL
;
909 u32 ssid
, tsid
, newsid
;
915 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
916 SECCLASS_SECURITY
, SECURITY__COMPUTE_RELABEL
,
922 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
927 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
932 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
935 length
= security_context_str_to_sid(scon
, &ssid
, GFP_KERNEL
);
939 length
= security_context_str_to_sid(tcon
, &tsid
, GFP_KERNEL
);
943 length
= security_change_sid(ssid
, tsid
, tclass
, &newsid
);
947 length
= security_sid_to_context(newsid
, &newcon
, &len
);
952 if (len
> SIMPLE_TRANSACTION_LIMIT
)
955 memcpy(buf
, newcon
, len
);
964 static ssize_t
sel_write_user(struct file
*file
, char *buf
, size_t size
)
966 char *con
= NULL
, *user
= NULL
, *ptr
;
967 u32 sid
, *sids
= NULL
;
973 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
974 SECCLASS_SECURITY
, SECURITY__COMPUTE_USER
,
980 con
= kzalloc(size
+ 1, GFP_KERNEL
);
985 user
= kzalloc(size
+ 1, GFP_KERNEL
);
990 if (sscanf(buf
, "%s %s", con
, user
) != 2)
993 length
= security_context_str_to_sid(con
, &sid
, GFP_KERNEL
);
997 length
= security_get_user_sids(sid
, user
, &sids
, &nsids
);
1001 length
= sprintf(buf
, "%u", nsids
) + 1;
1003 for (i
= 0; i
< nsids
; i
++) {
1004 rc
= security_sid_to_context(sids
[i
], &newcon
, &len
);
1009 if ((length
+ len
) >= SIMPLE_TRANSACTION_LIMIT
) {
1014 memcpy(ptr
, newcon
, len
);
1026 static ssize_t
sel_write_member(struct file
*file
, char *buf
, size_t size
)
1028 char *scon
= NULL
, *tcon
= NULL
;
1029 u32 ssid
, tsid
, newsid
;
1032 char *newcon
= NULL
;
1035 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
1036 SECCLASS_SECURITY
, SECURITY__COMPUTE_MEMBER
,
1042 scon
= kzalloc(size
+ 1, GFP_KERNEL
);
1047 tcon
= kzalloc(size
+ 1, GFP_KERNEL
);
1052 if (sscanf(buf
, "%s %s %hu", scon
, tcon
, &tclass
) != 3)
1055 length
= security_context_str_to_sid(scon
, &ssid
, GFP_KERNEL
);
1059 length
= security_context_str_to_sid(tcon
, &tsid
, GFP_KERNEL
);
1063 length
= security_member_sid(ssid
, tsid
, tclass
, &newsid
);
1067 length
= security_sid_to_context(newsid
, &newcon
, &len
);
1072 if (len
> SIMPLE_TRANSACTION_LIMIT
) {
1073 printk(KERN_ERR
"SELinux: %s: context size (%u) exceeds "
1074 "payload max\n", __func__
, len
);
1078 memcpy(buf
, newcon
, len
);
1087 static struct inode
*sel_make_inode(struct super_block
*sb
, int mode
)
1089 struct inode
*ret
= new_inode(sb
);
1093 ret
->i_atime
= ret
->i_mtime
= ret
->i_ctime
= current_time(ret
);
1098 static ssize_t
sel_read_bool(struct file
*filep
, char __user
*buf
,
1099 size_t count
, loff_t
*ppos
)
1105 unsigned index
= file_inode(filep
)->i_ino
& SEL_INO_MASK
;
1106 const char *name
= filep
->f_path
.dentry
->d_name
.name
;
1108 mutex_lock(&sel_mutex
);
1111 if (index
>= bool_num
|| strcmp(name
, bool_pending_names
[index
]))
1115 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1119 cur_enforcing
= security_get_bool_value(index
);
1120 if (cur_enforcing
< 0) {
1121 ret
= cur_enforcing
;
1124 length
= scnprintf(page
, PAGE_SIZE
, "%d %d", cur_enforcing
,
1125 bool_pending_values
[index
]);
1126 ret
= simple_read_from_buffer(buf
, count
, ppos
, page
, length
);
1128 mutex_unlock(&sel_mutex
);
1129 free_page((unsigned long)page
);
1133 static ssize_t
sel_write_bool(struct file
*filep
, const char __user
*buf
,
1134 size_t count
, loff_t
*ppos
)
1139 unsigned index
= file_inode(filep
)->i_ino
& SEL_INO_MASK
;
1140 const char *name
= filep
->f_path
.dentry
->d_name
.name
;
1142 mutex_lock(&sel_mutex
);
1144 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
1145 SECCLASS_SECURITY
, SECURITY__SETBOOL
,
1151 if (index
>= bool_num
|| strcmp(name
, bool_pending_names
[index
]))
1155 if (count
>= PAGE_SIZE
)
1158 /* No partial writes. */
1163 page
= memdup_user_nul(buf
, count
);
1165 length
= PTR_ERR(page
);
1171 if (sscanf(page
, "%d", &new_value
) != 1)
1177 bool_pending_values
[index
] = new_value
;
1181 mutex_unlock(&sel_mutex
);
1186 static const struct file_operations sel_bool_ops
= {
1187 .read
= sel_read_bool
,
1188 .write
= sel_write_bool
,
1189 .llseek
= generic_file_llseek
,
1192 static ssize_t
sel_commit_bools_write(struct file
*filep
,
1193 const char __user
*buf
,
1194 size_t count
, loff_t
*ppos
)
1200 mutex_lock(&sel_mutex
);
1202 length
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
1203 SECCLASS_SECURITY
, SECURITY__SETBOOL
,
1209 if (count
>= PAGE_SIZE
)
1212 /* No partial writes. */
1217 page
= memdup_user_nul(buf
, count
);
1219 length
= PTR_ERR(page
);
1225 if (sscanf(page
, "%d", &new_value
) != 1)
1229 if (new_value
&& bool_pending_values
)
1230 length
= security_set_bools(bool_num
, bool_pending_values
);
1236 mutex_unlock(&sel_mutex
);
1241 static const struct file_operations sel_commit_bools_ops
= {
1242 .write
= sel_commit_bools_write
,
1243 .llseek
= generic_file_llseek
,
1246 static void sel_remove_entries(struct dentry
*de
)
1249 shrink_dcache_parent(de
);
1252 #define BOOL_DIR_NAME "booleans"
1254 static int sel_make_bools(void)
1258 struct dentry
*dentry
= NULL
;
1259 struct dentry
*dir
= bool_dir
;
1260 struct inode
*inode
= NULL
;
1261 struct inode_security_struct
*isec
;
1262 char **names
= NULL
, *page
;
1267 /* remove any existing files */
1268 for (i
= 0; i
< bool_num
; i
++)
1269 kfree(bool_pending_names
[i
]);
1270 kfree(bool_pending_names
);
1271 kfree(bool_pending_values
);
1273 bool_pending_names
= NULL
;
1274 bool_pending_values
= NULL
;
1276 sel_remove_entries(dir
);
1279 page
= (char *)get_zeroed_page(GFP_KERNEL
);
1283 ret
= security_get_bools(&num
, &names
, &values
);
1287 for (i
= 0; i
< num
; i
++) {
1289 dentry
= d_alloc_name(dir
, names
[i
]);
1294 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
| S_IRUGO
| S_IWUSR
);
1298 ret
= -ENAMETOOLONG
;
1299 len
= snprintf(page
, PAGE_SIZE
, "/%s/%s", BOOL_DIR_NAME
, names
[i
]);
1300 if (len
>= PAGE_SIZE
)
1303 isec
= (struct inode_security_struct
*)selinux_inode(inode
);
1304 ret
= security_genfs_sid("selinuxfs", page
, SECCLASS_FILE
, &sid
);
1306 pr_warn_ratelimited("SELinux: no sid found, defaulting to security isid for %s\n",
1308 sid
= SECINITSID_SECURITY
;
1312 isec
->initialized
= LABEL_INITIALIZED
;
1313 inode
->i_fop
= &sel_bool_ops
;
1314 inode
->i_ino
= i
|SEL_BOOL_INO_OFFSET
;
1315 d_add(dentry
, inode
);
1318 bool_pending_names
= names
;
1319 bool_pending_values
= values
;
1321 free_page((unsigned long)page
);
1324 free_page((unsigned long)page
);
1327 for (i
= 0; i
< num
; i
++)
1332 sel_remove_entries(dir
);
1337 #define NULL_FILE_NAME "null"
1339 struct path selinux_null
;
1341 static ssize_t
sel_read_avc_cache_threshold(struct file
*filp
, char __user
*buf
,
1342 size_t count
, loff_t
*ppos
)
1344 char tmpbuf
[TMPBUFLEN
];
1347 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u", avc_cache_threshold
);
1348 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1351 static ssize_t
sel_write_avc_cache_threshold(struct file
*file
,
1352 const char __user
*buf
,
1353 size_t count
, loff_t
*ppos
)
1358 unsigned int new_value
;
1360 ret
= avc_has_perm(current_sid(), SECINITSID_SECURITY
,
1361 SECCLASS_SECURITY
, SECURITY__SETSECPARAM
,
1366 if (count
>= PAGE_SIZE
)
1369 /* No partial writes. */
1373 page
= memdup_user_nul(buf
, count
);
1375 return PTR_ERR(page
);
1378 if (sscanf(page
, "%u", &new_value
) != 1)
1381 avc_cache_threshold
= new_value
;
1389 static ssize_t
sel_read_avc_hash_stats(struct file
*filp
, char __user
*buf
,
1390 size_t count
, loff_t
*ppos
)
1395 page
= (char *)__get_free_page(GFP_KERNEL
);
1399 length
= avc_get_hash_stats(page
);
1401 length
= simple_read_from_buffer(buf
, count
, ppos
, page
, length
);
1402 free_page((unsigned long)page
);
1407 static const struct file_operations sel_avc_cache_threshold_ops
= {
1408 .read
= sel_read_avc_cache_threshold
,
1409 .write
= sel_write_avc_cache_threshold
,
1410 .llseek
= generic_file_llseek
,
1413 static const struct file_operations sel_avc_hash_stats_ops
= {
1414 .read
= sel_read_avc_hash_stats
,
1415 .llseek
= generic_file_llseek
,
1418 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1419 static struct avc_cache_stats
*sel_avc_get_stat_idx(loff_t
*idx
)
1423 for (cpu
= *idx
; cpu
< nr_cpu_ids
; ++cpu
) {
1424 if (!cpu_possible(cpu
))
1427 return &per_cpu(avc_cache_stats
, cpu
);
1432 static void *sel_avc_stats_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1434 loff_t n
= *pos
- 1;
1437 return SEQ_START_TOKEN
;
1439 return sel_avc_get_stat_idx(&n
);
1442 static void *sel_avc_stats_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1444 return sel_avc_get_stat_idx(pos
);
1447 static int sel_avc_stats_seq_show(struct seq_file
*seq
, void *v
)
1449 struct avc_cache_stats
*st
= v
;
1451 if (v
== SEQ_START_TOKEN
) {
1453 "lookups hits misses allocations reclaims frees\n");
1455 unsigned int lookups
= st
->lookups
;
1456 unsigned int misses
= st
->misses
;
1457 unsigned int hits
= lookups
- misses
;
1458 seq_printf(seq
, "%u %u %u %u %u %u\n", lookups
,
1459 hits
, misses
, st
->allocations
,
1460 st
->reclaims
, st
->frees
);
1465 static void sel_avc_stats_seq_stop(struct seq_file
*seq
, void *v
)
1468 static const struct seq_operations sel_avc_cache_stats_seq_ops
= {
1469 .start
= sel_avc_stats_seq_start
,
1470 .next
= sel_avc_stats_seq_next
,
1471 .show
= sel_avc_stats_seq_show
,
1472 .stop
= sel_avc_stats_seq_stop
,
1475 static int sel_open_avc_cache_stats(struct inode
*inode
, struct file
*file
)
1477 return seq_open(file
, &sel_avc_cache_stats_seq_ops
);
1480 static const struct file_operations sel_avc_cache_stats_ops
= {
1481 .open
= sel_open_avc_cache_stats
,
1483 .llseek
= seq_lseek
,
1484 .release
= seq_release
,
1488 static int sel_make_avc_files(struct dentry
*dir
)
1491 static const struct tree_descr files
[] = {
1492 { "cache_threshold",
1493 &sel_avc_cache_threshold_ops
, S_IRUGO
|S_IWUSR
},
1494 { "hash_stats", &sel_avc_hash_stats_ops
, S_IRUGO
},
1495 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
1496 { "cache_stats", &sel_avc_cache_stats_ops
, S_IRUGO
},
1500 for (i
= 0; i
< ARRAY_SIZE(files
); i
++) {
1501 struct inode
*inode
;
1502 struct dentry
*dentry
;
1504 dentry
= d_alloc_name(dir
, files
[i
].name
);
1508 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|files
[i
].mode
);
1512 inode
->i_fop
= files
[i
].ops
;
1513 inode
->i_ino
= ++sel_last_ino
;
1514 d_add(dentry
, inode
);
1520 static ssize_t
sel_read_initcon(struct file
*file
, char __user
*buf
,
1521 size_t count
, loff_t
*ppos
)
1527 sid
= file_inode(file
)->i_ino
&SEL_INO_MASK
;
1528 ret
= security_sid_to_context(sid
, &con
, &len
);
1532 ret
= simple_read_from_buffer(buf
, count
, ppos
, con
, len
);
1537 static const struct file_operations sel_initcon_ops
= {
1538 .read
= sel_read_initcon
,
1539 .llseek
= generic_file_llseek
,
1542 static int sel_make_initcon_files(struct dentry
*dir
)
1546 for (i
= 1; i
<= SECINITSID_NUM
; i
++) {
1547 struct inode
*inode
;
1548 struct dentry
*dentry
;
1549 dentry
= d_alloc_name(dir
, security_get_initial_sid_context(i
));
1553 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1557 inode
->i_fop
= &sel_initcon_ops
;
1558 inode
->i_ino
= i
|SEL_INITCON_INO_OFFSET
;
1559 d_add(dentry
, inode
);
1565 static inline unsigned long sel_class_to_ino(u16
class)
1567 return (class * (SEL_VEC_MAX
+ 1)) | SEL_CLASS_INO_OFFSET
;
1570 static inline u16
sel_ino_to_class(unsigned long ino
)
1572 return (ino
& SEL_INO_MASK
) / (SEL_VEC_MAX
+ 1);
1575 static inline unsigned long sel_perm_to_ino(u16
class, u32 perm
)
1577 return (class * (SEL_VEC_MAX
+ 1) + perm
) | SEL_CLASS_INO_OFFSET
;
1580 static inline u32
sel_ino_to_perm(unsigned long ino
)
1582 return (ino
& SEL_INO_MASK
) % (SEL_VEC_MAX
+ 1);
1585 static ssize_t
sel_read_class(struct file
*file
, char __user
*buf
,
1586 size_t count
, loff_t
*ppos
)
1588 unsigned long ino
= file_inode(file
)->i_ino
;
1589 char res
[TMPBUFLEN
];
1590 ssize_t len
= snprintf(res
, sizeof(res
), "%d", sel_ino_to_class(ino
));
1591 return simple_read_from_buffer(buf
, count
, ppos
, res
, len
);
1594 static const struct file_operations sel_class_ops
= {
1595 .read
= sel_read_class
,
1596 .llseek
= generic_file_llseek
,
1599 static ssize_t
sel_read_perm(struct file
*file
, char __user
*buf
,
1600 size_t count
, loff_t
*ppos
)
1602 unsigned long ino
= file_inode(file
)->i_ino
;
1603 char res
[TMPBUFLEN
];
1604 ssize_t len
= snprintf(res
, sizeof(res
), "%d", sel_ino_to_perm(ino
));
1605 return simple_read_from_buffer(buf
, count
, ppos
, res
, len
);
1608 static const struct file_operations sel_perm_ops
= {
1609 .read
= sel_read_perm
,
1610 .llseek
= generic_file_llseek
,
1613 static ssize_t
sel_read_policycap(struct file
*file
, char __user
*buf
,
1614 size_t count
, loff_t
*ppos
)
1617 char tmpbuf
[TMPBUFLEN
];
1619 unsigned long i_ino
= file_inode(file
)->i_ino
;
1621 value
= security_policycap_supported(i_ino
& SEL_INO_MASK
);
1622 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%d", value
);
1624 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
1627 static const struct file_operations sel_policycap_ops
= {
1628 .read
= sel_read_policycap
,
1629 .llseek
= generic_file_llseek
,
1632 static int sel_make_perm_files(char *objclass
, int classvalue
,
1638 rc
= security_get_permissions(objclass
, &perms
, &nperms
);
1642 for (i
= 0; i
< nperms
; i
++) {
1643 struct inode
*inode
;
1644 struct dentry
*dentry
;
1647 dentry
= d_alloc_name(dir
, perms
[i
]);
1652 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1656 inode
->i_fop
= &sel_perm_ops
;
1657 /* i+1 since perm values are 1-indexed */
1658 inode
->i_ino
= sel_perm_to_ino(classvalue
, i
+ 1);
1659 d_add(dentry
, inode
);
1663 for (i
= 0; i
< nperms
; i
++)
1669 static int sel_make_class_dir_entries(char *classname
, int index
,
1672 struct dentry
*dentry
= NULL
;
1673 struct inode
*inode
= NULL
;
1676 dentry
= d_alloc_name(dir
, "index");
1680 inode
= sel_make_inode(dir
->d_sb
, S_IFREG
|S_IRUGO
);
1684 inode
->i_fop
= &sel_class_ops
;
1685 inode
->i_ino
= sel_class_to_ino(index
);
1686 d_add(dentry
, inode
);
1688 dentry
= sel_make_dir(dir
, "perms", &last_class_ino
);
1690 return PTR_ERR(dentry
);
1692 rc
= sel_make_perm_files(classname
, index
, dentry
);
1697 static int sel_make_classes(void)
1699 int rc
, nclasses
, i
;
1702 /* delete any existing entries */
1703 sel_remove_entries(class_dir
);
1705 rc
= security_get_classes(&classes
, &nclasses
);
1709 /* +2 since classes are 1-indexed */
1710 last_class_ino
= sel_class_to_ino(nclasses
+ 2);
1712 for (i
= 0; i
< nclasses
; i
++) {
1713 struct dentry
*class_name_dir
;
1715 class_name_dir
= sel_make_dir(class_dir
, classes
[i
],
1717 if (IS_ERR(class_name_dir
)) {
1718 rc
= PTR_ERR(class_name_dir
);
1722 /* i+1 since class values are 1-indexed */
1723 rc
= sel_make_class_dir_entries(classes
[i
], i
+ 1,
1730 for (i
= 0; i
< nclasses
; i
++)
1736 static int sel_make_policycap(void)
1739 struct dentry
*dentry
= NULL
;
1740 struct inode
*inode
= NULL
;
1742 sel_remove_entries(policycap_dir
);
1744 for (iter
= 0; iter
<= POLICYDB_CAPABILITY_MAX
; iter
++) {
1745 if (iter
< ARRAY_SIZE(selinux_policycap_names
))
1746 dentry
= d_alloc_name(policycap_dir
,
1747 selinux_policycap_names
[iter
]);
1749 dentry
= d_alloc_name(policycap_dir
, "unknown");
1754 inode
= sel_make_inode(policycap_dir
->d_sb
, S_IFREG
| S_IRUGO
);
1758 inode
->i_fop
= &sel_policycap_ops
;
1759 inode
->i_ino
= iter
| SEL_POLICYCAP_INO_OFFSET
;
1760 d_add(dentry
, inode
);
1766 static struct dentry
*sel_make_dir(struct dentry
*dir
, const char *name
,
1769 struct dentry
*dentry
= d_alloc_name(dir
, name
);
1770 struct inode
*inode
;
1773 return ERR_PTR(-ENOMEM
);
1775 inode
= sel_make_inode(dir
->d_sb
, S_IFDIR
| S_IRUGO
| S_IXUGO
);
1778 return ERR_PTR(-ENOMEM
);
1781 inode
->i_op
= &simple_dir_inode_operations
;
1782 inode
->i_fop
= &simple_dir_operations
;
1783 inode
->i_ino
= ++(*ino
);
1784 /* directory inodes start off with i_nlink == 2 (for "." entry) */
1786 d_add(dentry
, inode
);
1787 /* bump link count on parent directory, too */
1788 inc_nlink(d_inode(dir
));
1793 static int sel_fill_super(struct super_block
*sb
, void *data
, int silent
)
1796 struct dentry
*dentry
;
1797 struct inode
*inode
;
1798 struct inode_security_struct
*isec
;
1800 static const struct tree_descr selinux_files
[] = {
1801 [SEL_LOAD
] = {"load", &sel_load_ops
, S_IRUSR
|S_IWUSR
},
1802 [SEL_ENFORCE
] = {"enforce", &sel_enforce_ops
, S_IRUGO
|S_IWUSR
},
1803 [SEL_CONTEXT
] = {"context", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1804 [SEL_ACCESS
] = {"access", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1805 [SEL_CREATE
] = {"create", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1806 [SEL_RELABEL
] = {"relabel", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1807 [SEL_USER
] = {"user", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1808 [SEL_POLICYVERS
] = {"policyvers", &sel_policyvers_ops
, S_IRUGO
},
1809 [SEL_COMMIT_BOOLS
] = {"commit_pending_bools", &sel_commit_bools_ops
, S_IWUSR
},
1810 [SEL_MLS
] = {"mls", &sel_mls_ops
, S_IRUGO
},
1811 [SEL_DISABLE
] = {"disable", &sel_disable_ops
, S_IWUSR
},
1812 [SEL_MEMBER
] = {"member", &transaction_ops
, S_IRUGO
|S_IWUGO
},
1813 [SEL_CHECKREQPROT
] = {"checkreqprot", &sel_checkreqprot_ops
, S_IRUGO
|S_IWUSR
},
1814 [SEL_REJECT_UNKNOWN
] = {"reject_unknown", &sel_handle_unknown_ops
, S_IRUGO
},
1815 [SEL_DENY_UNKNOWN
] = {"deny_unknown", &sel_handle_unknown_ops
, S_IRUGO
},
1816 [SEL_STATUS
] = {"status", &sel_handle_status_ops
, S_IRUGO
},
1817 [SEL_POLICY
] = {"policy", &sel_policy_ops
, S_IRUGO
},
1818 [SEL_VALIDATE_TRANS
] = {"validatetrans", &sel_transition_ops
,
1822 ret
= simple_fill_super(sb
, SELINUX_MAGIC
, selinux_files
);
1826 bool_dir
= sel_make_dir(sb
->s_root
, BOOL_DIR_NAME
, &sel_last_ino
);
1827 if (IS_ERR(bool_dir
)) {
1828 ret
= PTR_ERR(bool_dir
);
1834 dentry
= d_alloc_name(sb
->s_root
, NULL_FILE_NAME
);
1839 inode
= sel_make_inode(sb
, S_IFCHR
| S_IRUGO
| S_IWUGO
);
1843 inode
->i_ino
= ++sel_last_ino
;
1844 isec
= (struct inode_security_struct
*)selinux_inode(inode
);
1845 isec
->sid
= SECINITSID_DEVNULL
;
1846 isec
->sclass
= SECCLASS_CHR_FILE
;
1847 isec
->initialized
= LABEL_INITIALIZED
;
1849 init_special_inode(inode
, S_IFCHR
| S_IRUGO
| S_IWUGO
, MKDEV(MEM_MAJOR
, 3));
1850 d_add(dentry
, inode
);
1851 selinux_null
.dentry
= dentry
;
1853 dentry
= sel_make_dir(sb
->s_root
, "avc", &sel_last_ino
);
1854 if (IS_ERR(dentry
)) {
1855 ret
= PTR_ERR(dentry
);
1859 ret
= sel_make_avc_files(dentry
);
1863 dentry
= sel_make_dir(sb
->s_root
, "initial_contexts", &sel_last_ino
);
1864 if (IS_ERR(dentry
)) {
1865 ret
= PTR_ERR(dentry
);
1869 ret
= sel_make_initcon_files(dentry
);
1873 class_dir
= sel_make_dir(sb
->s_root
, "class", &sel_last_ino
);
1874 if (IS_ERR(class_dir
)) {
1875 ret
= PTR_ERR(class_dir
);
1880 policycap_dir
= sel_make_dir(sb
->s_root
, "policy_capabilities", &sel_last_ino
);
1881 if (IS_ERR(policycap_dir
)) {
1882 ret
= PTR_ERR(policycap_dir
);
1883 policycap_dir
= NULL
;
1888 printk(KERN_ERR
"SELinux: %s: failed while creating inodes\n",
1893 static struct dentry
*sel_mount(struct file_system_type
*fs_type
,
1894 int flags
, const char *dev_name
, void *data
)
1896 return mount_single(fs_type
, flags
, data
, sel_fill_super
);
1899 static struct file_system_type sel_fs_type
= {
1900 .name
= "selinuxfs",
1902 .kill_sb
= kill_litter_super
,
1905 struct vfsmount
*selinuxfs_mount
;
1907 static int __init
init_sel_fs(void)
1911 if (!selinux_enabled
)
1914 err
= sysfs_create_mount_point(fs_kobj
, "selinux");
1918 err
= register_filesystem(&sel_fs_type
);
1920 sysfs_remove_mount_point(fs_kobj
, "selinux");
1924 selinux_null
.mnt
= selinuxfs_mount
= kern_mount(&sel_fs_type
);
1925 if (IS_ERR(selinuxfs_mount
)) {
1926 printk(KERN_ERR
"selinuxfs: could not mount!\n");
1927 err
= PTR_ERR(selinuxfs_mount
);
1928 selinuxfs_mount
= NULL
;
1934 __initcall(init_sel_fs
);
1936 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
1937 void exit_sel_fs(void)
1939 sysfs_remove_mount_point(fs_kobj
, "selinux");
1940 kern_unmount(selinuxfs_mount
);
1941 unregister_filesystem(&sel_fs_type
);