CAPNG_APPLY(3)

πŸ“¦
version 0.9.6 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ CAPNG_APPLY ✨

okay bestie, gather round, because this is the capng_apply page from the Libcap-ng API and it's lowkey the moment where all your carefully hoarded capability settings actually get yeeted into the kernel. πŸ’…


🌸 NAME 🌸

capng_apply β€” apply the stored capabilities settings


πŸŽ€ SYNOPSIS πŸŽ€

#include <cap-ng.h>

int capng_apply(capng_select_t set);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: capng_apply transfers the internal POSIX capabilities settings you've been curating (slay) over to the kernel. it's the "go" button. the "post it" button. the "manifest it and it's real now" button. πŸ”₯

and you get to pick what gets applied with the set argument:

  • CAPNG_SELECT_CAPS β€” the traditional capabilities, classic behavior, iconic ✨
  • CAPNG_SELECT_BOUNDS β€” the bounding set
  • CAPNG_SELECT_BOTH β€” when you want both of them, because why choose 😌
  • CAPNG_SELECT_AMBIENT β€” if you're only operating on the ambient capabilities
  • CAPNG_SELECT_ALL β€” applying literally everything, main character energy, no crumbs left πŸ‘‘

πŸ’– RETURN VALUE πŸ’–

it returns 0 on success, and a negative value on failure. and babes, the negative values are specific. here's the whole roster, no skips:

  • -1 β€” not initialized
  • -2 β€” CAPNG_SELECT_BOUNDS and failure to drop a bounding set capability
  • -3 β€” CAPNG_SELECT_BOUNDS and failure to re-read bounding set
  • -4 β€” CAPNG_SELECT_BOUNDS and process does not have CAP_SETPCAP
  • -5 β€” CAPNG_SELECT_CAPS and failure in capset syscall
  • -6 β€” CAPNG_SELECT_AMBIENT and process has no capabilities and failed clearing ambient capabilities
  • -7 β€” CAPNG_SELECT_AMBIENT and process has capabilities and failed clearing ambient capabilities
  • -8 β€” CAPNG_SELECT_AMBIENT and process has capabilities and failed setting an ambient capability
  • -9 β€” Unable to acquire process capabilities to check if CAP_SETPCAP is set.
not me getting a -9 and spiraling 😭 every single one of these is a real, distinct vibe check failure, so read the number, don't just assume.

⭐ NOTES ⭐

okay this part is important, bestie, so sit up. 🫢

if you are doing multi-threaded programming, calling this function will only set capabilities on the calling thread. all other threads are unaffected. so if you want to set overall capabilities for a multi-threaded process, you will need to do that before creating any threads. periodt. see the capset syscall for more information on this topic.

also β€” and this is the part that gets people β€” bits in the bounding set can only be dropped. you cannot set them. it's giving one-way street, no u-turns, no take-backs πŸ’€ after dropping bounding set capabilities, the bounding set is synchronized with the kernel to reflect the true state in the kernel.


🌈 SEE ALSO 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Steve Grubb


and that's the whole page, bestie. this is CAPNG_APPLY(3) from the Libcap-ng API, brought to you by Red Hat, dated Sept 2023. go forth and apply those capabilities, you absolute icon πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from