avc_netlink_loop(3)

okay bestie, welcome to the avc_netlink_loop(3) page from the SELinux API documentation β€” this is the one that's all about listening for SELinux gossip straight from the kernel. πŸ¦‹


✨ NAME ✨

avc_netlink_open, avc_netlink_close, avc_netlink_acquire_fd, avc_netlink_release_fd, avc_netlink_check_nb, avc_netlink_loop β€” SELinux netlink processing, aka the whole friend group of functions that handle your notification vibes πŸ’…


🌸 SYNOPSIS 🌸

#include <selinux/selinux.h>
#include <selinux/avc.h>

int avc_netlink_open(int blocking);

void avc_netlink_close(void);

int avc_netlink_acquire_fd(void);

void avc_netlink_release_fd(void);

void avc_netlink_loop(void);

int avc_netlink_check_nb(void);

πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea πŸ“ β€” these functions let your app handle notification of SELinux events via netlink. like, the kernel is texting, and this is how you read the messages.

normally the userspace AVC is the one doing the checking β€” it peeks at netlink messages on every single call to avc_has_perm(3). but maybe you're a main character who wants to override that behavior and check for notifications on your own terms, for example inside a select(2) loop. very valid. 😌

and not only that β€” these functions also let you do netlink monitoring without even needing a call to avc_open(3). no cap.

  • avc_netlink_open() β€” opens a netlink socket to receive SELinux notifications. the socket descriptor is stored internally, so if you want to actually own it in your app code, use avc_netlink_acquire_fd(3). the blocking argument controls whether the O_NONBLOCK flag gets set on the socket descriptor. also fun fact: avc_open(3) calls this function internally, and it specifies non-blocking behavior when it does. 🫢
  • avc_netlink_close() β€” closes the netlink socket. and guess what, you don't even have to remember to call it, because avc_destroy(3) calls it automatically for you. iconic teamwork. ✨
  • avc_netlink_acquire_fd() β€” returns the netlink socket descriptor number and informs the userspace AVC that it should not check the socket descriptor automatically on calls to avc_has_perm(3) anymore. and if no such socket descriptor exists yet? no stress β€” avc_netlink_acquire_fd(3) will first call avc_netlink_open(3) and then return the resulting fd. πŸ’…
  • avc_netlink_release_fd() β€” gives control of the netlink socket back to the userspace AVC, which re-enables automatic processing of notifications. it's giving "here, you take it back bestie." πŸŽ€
  • avc_netlink_check_nb() β€” checks the netlink socket for pending messages and processes them. callbacks for policyload and enforcing changes will get called; go see selinux_set_callback(3). and important: this function does not block. it's the "quick vibe check, no waiting" one. 🌈
  • avc_netlink_loop() β€” enters a loop, blocking on the netlink socket and processing messages as they are received.
⚠️ okay so listen: this function will not return unless an error occurs on the socket. and if an error does occur, the socket gets closed. so this is a "you live here now" function. commit to it. πŸ’€

⭐ RETURN VALUE ⭐

avc_netlink_acquire_fd() returns a non-negative file descriptor number on success. the other functions that have a return value return zero on success. and on error? -1 is returned and errno is set appropriately. classic. πŸ™ˆ


πŸ’œ AUTHOR πŸ’œ

Originally KaiGai Kohei. Updated by Mike Palmiotto <mike.palmiotto@crunchydata.com>


πŸ”₯ SEE ALSO πŸ”₯

avc_open(3), selinux_set_callback(3), selinux(8)


and that's the whole page, bestie β€” slay ✨ this was avc_netlink_loop(3) from the SELinux API documentation, dated 30 Mar 2009. go forth and loop responsibly πŸ’–πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from