avc_open(3)

πŸ“¦
version 3.11 Β· 2 versions
, in alpine 3.24, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 call avc_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 by selinux_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() calls selinux_status_open(3) to initialize the selinux status state.
  • avc_has_perm(3) and selinux_check_access(3) both check for status updates through calls to selinux_status_updated(3) at the start of each permission query and take the appropriate action.
  • two status types are currently implemented: setenforce events will change the effective enforcing state used within the AVC, and policyload events will result in a cache flush.

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 πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ