selinux/libselinux/man/man3/avc_open.3

100 lines
3.2 KiB
Groff
Raw Normal View History

.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2008
.TH "avc_open" "3" "12 Jun 2008" "" "SELinux API documentation"
.SH "NAME"
avc_open, avc_destroy, avc_reset, avc_cleanup \- userspace SELinux AVC setup and teardown
.
.SH "SYNOPSIS"
.B #include <selinux/selinux.h>
.br
.B #include <selinux/avc.h>
.sp
.BI "int avc_open(struct selinux_opt *" options ", unsigned " nopt ");"
.sp
.BI "void avc_destroy(void);"
.sp
.BI "int avc_reset(void);"
.sp
.BI "void avc_cleanup(void);"
.
.SH "DESCRIPTION"
.BR avc_open ()
initializes the userspace AVC and must be called before any other AVC operation can be performed.
.BR avc_destroy ()
destroys the userspace AVC, freeing all internal memory structures. After this call has been made,
.BR avc_open ()
must be called again before any AVC operations can be performed.
.BR avc_reset ()
flushes the userspace AVC, causing it to forget any cached access decisions. The userspace AVC normally calls this function automatically when needed, see
.B NETLINK NOTIFICATION
below.
.BR avc_cleanup ()
attempts to free unused memory within the userspace AVC, but does not flush any cached access decisions. Under normal operation, calling this function should not be necessary.
.SH "OPTIONS"
The userspace AVC obeys callbacks set via
.BR selinux_set_callback (3),
in particular the logging and audit callbacks.
The options which may be passed to
.BR avc_open ()
include the following:
.TP
.B AVC_OPT_SETENFORCE
This option forces the userspace AVC into enforcing mode if the option value is non-NULL; permissive mode otherwise. The system enforcing mode will be ignored.
.
libselinux: use kernel status page by default Commit bc2a8f418e3b ("libselinux: add selinux_status_* interfaces for /selinux/status") introduced the sestatus mechanism, which allows for mmap()'ing of the kernel status page as a replacement for avc_netlink. The mechanism was initially intended for userspace object managers that were calculating access decisions within their application and did not rely on the libselinux AVC implementation. In order to properly make use of sestatus within avc_has_perm(), the status mechanism needs to properly set avc internals during status events; else, avc_enforcing is never updated upon sestatus changes. This commit gets rid of the default avc_netlink_open() in avc_init_internal(), replacing it with selinux_status_open(). In the event that the kernel status page cannot be mapped, the netlink fallback will be used. By default, avc_has_perm_noaudit() and selinux_check_access() will now attempt to read the kernel status page, which removes a system call from two critical code paths. Since the AVC thread create/stop callbacks were intended to avoid a system call in the critical code path, they no longer need to be created by default. In the event that the kernel status page is successfully mapped, threads will not be created. Threads will still be created/stopped for the sestatus fallback codepaths. Userspace object managers that still need a netlink socket can call avc_netlink_acquire_fd() to open and/or obtain one. Update the manpage to reflect the new avc_netlink_acquire_fd() functionality. Signed-off-by: Mike Palmiotto <mike.palmiotto@crunchydata.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
2020-08-05 19:43:12 +00:00
.SH "KERNEL STATUS PAGE"
Linux kernel version 2.6.37 supports the SELinux kernel status page, enabling userspace applications to
.BR mmap (2)
SELinux status state in read-only mode to avoid system calls during the cache hit code path.
.BR avc_open ()
calls
.BR selinux_status_open (3)
to initialize the selinux status state.
.BR avc_has_perm (3)
libselinux: use kernel status page by default Commit bc2a8f418e3b ("libselinux: add selinux_status_* interfaces for /selinux/status") introduced the sestatus mechanism, which allows for mmap()'ing of the kernel status page as a replacement for avc_netlink. The mechanism was initially intended for userspace object managers that were calculating access decisions within their application and did not rely on the libselinux AVC implementation. In order to properly make use of sestatus within avc_has_perm(), the status mechanism needs to properly set avc internals during status events; else, avc_enforcing is never updated upon sestatus changes. This commit gets rid of the default avc_netlink_open() in avc_init_internal(), replacing it with selinux_status_open(). In the event that the kernel status page cannot be mapped, the netlink fallback will be used. By default, avc_has_perm_noaudit() and selinux_check_access() will now attempt to read the kernel status page, which removes a system call from two critical code paths. Since the AVC thread create/stop callbacks were intended to avoid a system call in the critical code path, they no longer need to be created by default. In the event that the kernel status page is successfully mapped, threads will not be created. Threads will still be created/stopped for the sestatus fallback codepaths. Userspace object managers that still need a netlink socket can call avc_netlink_acquire_fd() to open and/or obtain one. Update the manpage to reflect the new avc_netlink_acquire_fd() functionality. Signed-off-by: Mike Palmiotto <mike.palmiotto@crunchydata.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
2020-08-05 19:43:12 +00:00
and
.BR selinux_check_access (3)
both check for status updates through calls to
.BR selinux_status_updated (3)
at the start of each permission query and take the appropriate action.
Two status types are currently implemented.
.B setenforce
events will change the effective enforcing state used within the AVC, and
.B policyload
events will result in a cache flush.
.
.SH "NETLINK NOTIFICATION"
In the event that the kernel status page is not successfully
.BR mmap (2)'ed
the AVC will default to the netlink fallback mechanism, which opens a netlink socket for receiving status updates.
.B setenforce
and
.B policyload
events will have the same results as for the status page implementation, but all status update checks will now require a system call.
.
.SH "RETURN VALUE"
Functions with a return value return zero on success. On error, \-1 is returned and
.I errno
is set appropriately.
.
.SH "AUTHOR"
Eamon Walsh <ewalsh@tycho.nsa.gov>
.
.SH "SEE ALSO"
.BR selinux (8),
libselinux: use kernel status page by default Commit bc2a8f418e3b ("libselinux: add selinux_status_* interfaces for /selinux/status") introduced the sestatus mechanism, which allows for mmap()'ing of the kernel status page as a replacement for avc_netlink. The mechanism was initially intended for userspace object managers that were calculating access decisions within their application and did not rely on the libselinux AVC implementation. In order to properly make use of sestatus within avc_has_perm(), the status mechanism needs to properly set avc internals during status events; else, avc_enforcing is never updated upon sestatus changes. This commit gets rid of the default avc_netlink_open() in avc_init_internal(), replacing it with selinux_status_open(). In the event that the kernel status page cannot be mapped, the netlink fallback will be used. By default, avc_has_perm_noaudit() and selinux_check_access() will now attempt to read the kernel status page, which removes a system call from two critical code paths. Since the AVC thread create/stop callbacks were intended to avoid a system call in the critical code path, they no longer need to be created by default. In the event that the kernel status page is successfully mapped, threads will not be created. Threads will still be created/stopped for the sestatus fallback codepaths. Userspace object managers that still need a netlink socket can call avc_netlink_acquire_fd() to open and/or obtain one. Update the manpage to reflect the new avc_netlink_acquire_fd() functionality. Signed-off-by: Mike Palmiotto <mike.palmiotto@crunchydata.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
2020-08-05 19:43:12 +00:00
.BR selinux_check_access (3),
.BR avc_has_perm (3),
.BR avc_context_to_sid (3),
.BR avc_cache_stats (3),
.BR avc_add_callback (3),
libselinux: use kernel status page by default Commit bc2a8f418e3b ("libselinux: add selinux_status_* interfaces for /selinux/status") introduced the sestatus mechanism, which allows for mmap()'ing of the kernel status page as a replacement for avc_netlink. The mechanism was initially intended for userspace object managers that were calculating access decisions within their application and did not rely on the libselinux AVC implementation. In order to properly make use of sestatus within avc_has_perm(), the status mechanism needs to properly set avc internals during status events; else, avc_enforcing is never updated upon sestatus changes. This commit gets rid of the default avc_netlink_open() in avc_init_internal(), replacing it with selinux_status_open(). In the event that the kernel status page cannot be mapped, the netlink fallback will be used. By default, avc_has_perm_noaudit() and selinux_check_access() will now attempt to read the kernel status page, which removes a system call from two critical code paths. Since the AVC thread create/stop callbacks were intended to avoid a system call in the critical code path, they no longer need to be created by default. In the event that the kernel status page is successfully mapped, threads will not be created. Threads will still be created/stopped for the sestatus fallback codepaths. Userspace object managers that still need a netlink socket can call avc_netlink_acquire_fd() to open and/or obtain one. Update the manpage to reflect the new avc_netlink_acquire_fd() functionality. Signed-off-by: Mike Palmiotto <mike.palmiotto@crunchydata.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
2020-08-05 19:43:12 +00:00
.BR selinux_status_open (3),
.BR selinux_status_updated (3),
.BR selinux_set_callback (3),
.BR security_compute_av (3)