avc_open(3)
π avc_open β the SELinux AVC glow-up guide π
okay bestie, so this is the avc_open(3) page from the SELinux API documentation, and it's literally all about setting up and tearing down the userspace AVC. it's giving "behind the scenes crew" energy β nobody claps for it but nothing works without it. let's get into it π«Ά
β¨ NAME β¨
avc_open, avc_destroy, avc_reset, avc_cleanup β userspace SELinux AVC setup and teardown. the whole lifecycle, start to finish, no cap. π
πΈ SYNOPSIS πΈ
#include <selinux/selinux.h>
#include <selinux/avc.h>
int avc_open(const struct selinux_opt *options, unsigned nopt);
void avc_destroy(void);
int avc_reset(void);
void avc_cleanup(void);
π¦ DESCRIPTION π¦
so here's the tea on each one:
avc_open()initializes the userspace AVC. and bestie, this is not optional β it must be called before any other AVC operation can be performed. it's the main character that has to walk in first. πavc_destroy()destroys the userspace AVC and frees all the internal memory structures. after this call has been made, you gotta callavc_open()again before any AVC operations can be performed β it's a hard reset, not a nap. π΄ also,avc_destroy()closes the SELinux status page, which might have been opened manually byselinux_status_open(3).avc_reset()flushes the userspace AVC, causing it to forget any cached access decisions. like a memory wipe but make it β¨intentionalβ¨. the userspace AVC normally calls this function automatically when needed β see NETLINK NOTIFICATION below.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. it's the "tidy up just in case" friend that you honestly don't need to invite to the party. π
π OPTIONS π
the userspace AVC obeys callbacks set via selinux_set_callback(3) β in particular the logging and audit callbacks. iykyk.
the options which may be passed to avc_open() include the following:
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. like, fully ignored. the AVC said "i don't see it" π
π KERNEL STATUS PAGE π
Linux kernel version 2.6.37 supports the SELinux kernel status page, enabling userspace applications to mmap(2) SELinux status state in read-only mode to avoid system calls during the cache hit code path. faster. smoother. iconic. π₯
avc_open()callsselinux_status_open(3)to initialize the selinux status state.avc_has_perm(3)andselinux_check_access(3)both check for status updates through calls toselinux_status_updated(3)at the start of each permission query and take the appropriate action.- two status types are currently implemented:
setenforceevents will change the effective enforcing state used within the AVC, andpolicyloadevents will result in a cache flush.
π NETLINK NOTIFICATION π
in the event that the kernel status page is not successfully mmap(2)'ed, the AVC will default to the netlink fallback mechanism β which opens a netlink socket for receiving status updates. setenforce and policyload events will have the same results as for the status page implementation, but all status update checks will now require a system call. same vibe, extra syscall tax. π
β RETURN VALUE β
functions with a return value return zero on success. on error, -1 is returned and errno is set appropriately. classic. periodt. π
π AUTHOR π
Eamon Walsh <ewalsh@tycho.nsa.gov> β thank you for your service, legend. π«Ά
πΈ SEE ALSO πΈ
selinux(8), selinux_check_access(3), avc_has_perm(3), avc_context_to_sid(3), avc_cache_stats(3), avc_add_callback(3), selinux_status_open(3), selinux_status_updated(3), selinux_set_callback(3), security_compute_av(3)
and that's the whole page, bestie β dated 12 Jun 2008, from the avc_open(3) SELinux API documentation era. go forth and initialize responsibly πβ¨ππ¦πΈ
π¦ where this page comes from
- alpine 3.24: libselinux-doc 3.10-r1 Β· Public-Domain
- centos-stream 10: libselinux-devel 3.11-3.el10 Β· LicenseRef-Fedora-Public-Domain
- debian trixie: libselinux1-dev 3.8.1-1 Β· LicenseRef-public-domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- nixos 26.05: libselinux 3.10
- nixpkgs unstable: libselinux 3.11
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- ubuntu questing: libselinux1-dev 3.8.1-1build1
- ubuntu resolute: libselinux-dev 3.9-4build1 Β· LicenseRef-public-domain
- ubuntu stonking: libselinux-dev 3.11-2.1 Β· LicenseRef-public-domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms