| 1 |
.TH "selinux_status_open" "3" "22 January 2011" "[email protected]" "SELinux API documentation" |
| 2 |
.SH "NAME" |
| 3 |
selinux_status_open, selinux_status_close, selinux_status_updated, |
| 4 |
selinux_status_getenforce, selinux_status_policyload and |
| 5 |
selinux_status_deny_unknown \- reference the SELinux kernel status |
| 6 |
without invocation of system calls |
| 7 |
. |
| 8 |
.SH "SYNOPSIS" |
| 9 |
.B #include <selinux/avc.h> |
| 10 |
.sp |
| 11 |
.BI "int selinux_status_open(int " fallback ");" |
| 12 |
.sp |
| 13 |
.BI "void selinux_status_close(void);" |
| 14 |
.sp |
| 15 |
.BI "int selinux_status_updated(void);" |
| 16 |
.sp |
| 17 |
.BI "int selinux_status_getenforce(void);" |
| 18 |
.sp |
| 19 |
.BI "int selinux_status_policyload(void);" |
| 20 |
.sp |
| 21 |
.BI "int selinux_status_deny_unknown(void);" |
| 22 |
. |
| 23 |
.SH "DESCRIPTION" |
| 24 |
Linux 2.6.37 or later provides a SELinux kernel status page; being mostly |
| 25 |
placed on |
| 26 |
.I /sys/fs/selinux/status |
| 27 |
entry. It enables userspace applications to mmap this page with read-only |
| 28 |
mode, then it informs some status without system call invocations. |
| 29 |
.sp |
| 30 |
In some cases that a userspace application tries to apply heavy frequent |
| 31 |
access control; such as row-level security in databases, it will face |
| 32 |
unignorable cost to communicate with kernel space to check invalidation |
| 33 |
of userspace avc. |
| 34 |
.sp |
| 35 |
These functions provides applications a way to know some kernel events |
| 36 |
without system-call invocation or worker thread for monitoring. |
| 37 |
.sp |
| 38 |
.BR selinux_status_open () |
| 39 |
tries to |
| 40 |
.BR open (2) |
| 41 |
.I /sys/fs/selinux/status |
| 42 |
and |
| 43 |
.BR mmap (2) |
| 44 |
it in read-only mode. The file-descriptor and pointer to the page shall |
| 45 |
be stored internally; Don't touch them directly. |
| 46 |
Set 1 on the |
| 47 |
.I fallback |
| 48 |
argument to handle a case of older kernels without kernel status page support. |
| 49 |
In this case, this function tries to open a netlink socket using |
| 50 |
.BR avc_netlink_open (3) |
| 51 |
and overwrite corresponding callbacks ( setenforce and policyload). |
| 52 |
Thus, we need to pay attention to the interaction with these interfaces, |
| 53 |
when fallback mode is enabled. |
| 54 |
.sp |
| 55 |
.BR selinux_status_close () |
| 56 |
unmap the kernel status page and close its file descriptor, or close the |
| 57 |
netlink socket if fallbacked. |
| 58 |
.sp |
| 59 |
.BR selinux_status_updated () |
| 60 |
informs us whether something has been updated since the last call. |
| 61 |
It returns 0 if nothing was happened, however, 1 if something has been |
| 62 |
updated in this duration, or \-1 on error. |
| 63 |
.sp |
| 64 |
.BR selinux_status_getenforce () |
| 65 |
returns 0 if SELinux is running in permissive mode, 1 if enforcing mode, |
| 66 |
or \-1 on error. |
| 67 |
Same as |
| 68 |
.BR security_getenforce (3) |
| 69 |
except with or without system call invocation. |
| 70 |
.sp |
| 71 |
.BR selinux_status_policyload () |
| 72 |
returns times of policy reloaded on the running system, or \-1 on error. |
| 73 |
Note that it is not a reliable value on fallback-mode until it receive |
| 74 |
the first event message via netlink socket. |
| 75 |
Thus, don't use this value to know actual times of policy reloaded. |
| 76 |
.sp |
| 77 |
.BR selinux_status_deny_unknown () |
| 78 |
returns 0 if SELinux treats policy queries on undefined object classes or |
| 79 |
permissions as being allowed, 1 if such queries are denied, or \-1 on error. |
| 80 |
.sp |
| 81 |
Also note that these interfaces are not thread-safe, so you have to protect |
| 82 |
them from concurrent calls using exclusive locks when multiple threads are |
| 83 |
performing. |
| 84 |
. |
| 85 |
.SH "RETURN VALUE" |
| 86 |
.BR selinux_status_open () |
| 87 |
returns 0 or 1 on success. 1 means we are ready to use these interfaces, |
| 88 |
but netlink socket was opened as fallback instead of the kernel status page. |
| 89 |
On error, \-1 shall be returned. |
| 90 |
.sp |
| 91 |
Any other functions with a return value shall return its characteristic |
| 92 |
value as described above, or \-1 on errors. |
| 93 |
. |
| 94 |
.SH "SEE ALSO" |
| 95 |
.ad l |
| 96 |
.nh |
| 97 |
.BR mmap (2), |
| 98 |
.BR avc_netlink_open (3), |
| 99 |
.BR security_getenforce (3), |
| 100 |
.BR security_deny_unknown (3) |