security_load_policy(3)
π security_load_policy β SELinux API documentation, section 3 π
okay bestie, sit down, hydrate, and let me tell you about the three little functions that swap out your SELinux policy like it's a whole new wardrobe β¨
πΈ NAME πΈ
security_load_policy β load a new SELinux policy. that's it, that's the whole vibe. a fresh policy, served hot π₯
π SYNOPSIS π
#include <selinux/selinux.h>
int security_load_policy(const void *data, size_t len);
int selinux_mkload_policy(int preservebools);
int selinux_init_load_policy(int *enforce);
three functions, one header, zero drama (okay maybe a little drama, it's SELinux) π
π DESCRIPTION π
β¨ security_load_policy β¨
security_load_policy() loads a new policy. that's the whole job. it returns 0 when everything's slay and -1 when it's a flop π
π¦ selinux_mkload_policy π¦
selinux_mkload_policy() makes a policy image and loads it. this one is the high-level bestie β a way comfier interface for loading policy than security_load_policy(). it's out here doing the most, internally:
- determining the right policy version
- locating and opening the policy file
- mapping it into memory
- manipulating it as needed for current boolean settings and/or local definitions
- and then calling
security_load_policyto actually load it
preservebools is a boolean flag, and it's basically asking "are we keeping the current policy boolean values?" β so if it's 1, yes, the current policy boolean values get preserved into the new policy. if it's 0, nope, they get reset to the saved policy settings instead. and listen, the 1 case is the default for policy reloads, while the 0 case is an option for policy reloads too, but it's primarily used for the initial policy load. two moods, both valid π«Ά
π selinux_init_load_policy π
selinux_init_load_policy() performs the initial policy load. main character energy fr fr. this function:
- determines the desired enforcing mode
- sets the
enforceargument accordingly so the caller can use it - sets the SELinux kernel enforcing status to match it
- and loads the policy
it also internally handles the initial selinuxfs mount that's required to do all of the above. lowkey doing a lot of work behind the scenes, respect π
β οΈ okay this part matters so pay attention bestie. it should also be noted that after the initial policy load, the SELinux kernel code cannot anymore be disabled, and theselinuxfscannot be unmounted using a call tosecurity_disable(3). so likeβ¦ that door closes. therefore, after the initial policy load, the only operational changes are those permitted bysecurity_setenforce(3)β i.e. eventually setting the framework in permissive mode rather than in enforcing one. that's the whole menu after that point. no take-backs, no cap π
π RETURN VALUE π
returns zero on success, or -1 on error. simple as that, periodt β¨
π AUTHOR π
this manual page has been written by Guido Trentalancia <guido@trentalancia.com>. king behaviour, we love a credited author π
β SEE ALSO β
and that's the page!! π this was written by guido@trentalancia.com, dated 3 November 2009, and it lives in section 3 as security_load_policy(3) β go forth and load policies responsibly, bestie ππ¦πΈ
π¦ 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
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· 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 noble: libselinux1-dev 3.5-2ubuntu2 Β· LicenseRef-public-domain
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2.1 Β· LicenseRef-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