ocontext_to_sid(9)
π ocontext_to_sid(9) β like, the SELinux kernel API manual bestie β¨
okay so welcome to the ocontext_to_sid(9) page, straight out of the Kernel API Manual π this is the one that teaches you how to get a SID out of an ocontext without everything catching fire. stay with me, it's actually so good.
β¨ NAME β¨
ocontext_to_sid β the helper that safely gets a sid for an ocontext π«Ά yes "safely" is doing a lot of work in that sentence and we love her for it.
β¨ SYNOPSIS β¨
int ocontext_to_sid (struct sidtab *sidtab , struct ocontext *c , size_t
index , u32 *out_sid );
look at that signature. so clean. so many arguments. she's giving function-prototype realness π
β¨ ARGUMENTS β¨
sidtabβ the SID table πΈ that's the big book of SIDs, you're working inside her.cβ the ocontext structure π¦ the actual context thing you're pulling a SID out of.indexβ index of the context entry π₯ and heads up, it's literally0or1, that's the whole range, no in-between.out_sidβ pointer to the resulting SID value β this is where the answer lands. pointer. so you gotta give her somewhere to write.
β¨ DESCRIPTION β¨
okay so here's the vibe π for all ocontexts except OCON_ISID, the SID fields are populated on-demand, like, when they're needed. not before. she's not doing extra work for nobody π
and because updating the SID value is an SMP-sensitive operation, you must use this helper to do that safely. no cap. do not go around it, do not do it yourself in a corner, use the helper π
WARNING β οΈ this function may return -ESTALE, which means the caller must retry the operation after re-acquiring the policy pointer! like, actually re-acquire it. don't just loop and hope π it's telling you the policy pointer situation changed, so go get it again and then try once more.
the way this is genuinely just "here's a safe helper, also please handle -ESTALE" β iconic, honestly.
β¨ SEE ALSO β¨
literally the whole security crew, all gathered in one place π«Ά and the kernel file she lives in: ./security/selinux/ss/services.c
security_compute_av(9)security_sid_to_context(9)security_sid_to_context_inval(9)security_context_to_sid(9)security_context_to_sid_default(9)security_transition_sid(9)security_member_sid(9)security_change_sid(9)services_convert_context(9)security_load_policy(9)security_port_sid(9)security_ib_pkey_sid(9)security_ib_endport_sid(9)security_netif_sid(9)security_node_sid(9)__security_genfs_sid(9)security_genfs_sid(9)security_fs_use(9)security_net_peersid_resolve(9)security_policycap_supported(9)security_netlbl_cache_add(9)security_netlbl_secattr_to_sid(9)security_netlbl_sid_to_secattr(9)__security_read_policy(9)security_read_policy(9)security_read_state_kernel(9)
like, read them. all of them. iykyk π
and that's the page, bestie! π this little legend lives over in ./security/selinux/ss, and the version we're looking at is dated October 2026 π go forth, get your SIDs, respect the -ESTALE, slay β¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms