selinux_set_callback(3)
β¨ selinux_set_callback β the SELinux API documentation era β¨
okay bestie, gather round, because we're talking about selinux_set_callback(3) from the SELinux API documentation and it's giving "let me hook up your own little functions into SELinux" energy π
πΈ NAME πΈ
selinux_set_callback β userspace SELinux callback facilities π
π¦ SYNOPSIS π¦
#include <selinux/selinux.h>
void selinux_set_callback(int type, union selinux_callback callback);
π DESCRIPTION π
so selinux_set_callback() does the thing where it sets the callback that type points at, to the value of callback. and callback? it should be passed as a function pointer cast to type union selinux_callback. slay, we love a union. β¨
lowkey important: all callback functions should return a negative value with errno set appropriately on error. no cap, that's the rule.
the available values for type are, and this is the whole menu bestie, no skips:
SELINUX_CB_LOGβ this one's the logging callback ποΈ
int (*func_log) (int type, const char *fmt, ...);
it's used for logging, and it should process the printf(3) style fmt string and its arguments however makes sense for you. the type argument tells you what kind of message it is, and it'll be set to one of these:
SELINUX_ERRORSELINUX_WARNINGSELINUX_INFOSELINUX_AVCSELINUX_POLICYLOADSELINUX_SETENFORCE
SELINUX_ERROR, SELINUX_WARNING, and SELINUX_INFO are your standard log severity levels and, important, they are not auditable messages.
the SELINUX_AVC, SELINUX_POLICYLOAD, and SELINUX_SETENFORCE message types can be audited with the AUDIT_USER_AVC, AUDIT_USER_MAC_POLICY_LOAD, and AUDIT_USER_MAC_STATUS values from libaudit, respectively. and if they are not audited? then SELINUX_AVC should be considered equivalent to SELINUX_ERROR, and similarly SELINUX_POLICYLOAD and SELINUX_SETENFORCE should be considered equivalent to SELINUX_INFO. periodt. π
SELINUX_CB_AUDITβ the supplemental auditing one π
int (*func_audit) (void *auditdata, security_class_t cls,
char *msgbuf, size_t msgbufsize);
used for supplemental auditing in AVC messages. the auditdata and cls arguments are literally the values that got passed to avc_has_perm(3). and you should print a human-readable interpretation into msgbuf, using no more than msgbufsize characters. don't overflow bestie, i'm begging π
SELINUX_CB_VALIDATEβ context validation, main character energy π
int (*func_validate) (char **ctx);
used for context validation. the callback may optionally modify the input context by setting the target of the ctx pointer to a new context. and if you do that? then the old value should be freed with freecon(3). also you should set errno to EINVAL to indicate an invalid context.
SELINUX_CB_SETENFORCEβ enforcing state change alert π¨
int (*func_setenforce) (int enforcing);
this one gets invoked whenever the system enforcing state changes. the enforcing argument is the new value, and it's set to 1 for enforcing mode and 0 for permissive mode. so like, 1 = locked in, 0 = vibes only.
SELINUX_CB_POLICYLOADβ policy reload notification π
int (*func_policyload) (int seqno);
this gets invoked when the system security policy is reloaded. the seqno argument is the current sequential number of the policy generation in the system.
π RETURN VALUE π
None. that's it, that's the whole thing. π
π ERRORS π
None. nothing to report, we're chilling. β¨
π AUTHOR π
Eamon Walsh <ewalsh@tycho.nsa.gov> β ty for your service king π«Ά
β SEE ALSO β
and that's the whole page bestie!! this was 20 Jun 2007 energy from the SELinux API documentation files, and honestly? iconic. go set some callbacks, you got this π§ππΈ
π¦ 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 bookworm: libselinux1-dev 3.4-1+b6
- 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 jammy: libselinux1-dev 3.3-1build2
- 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