CAPNG_LOCK(3)
π CAPNG_LOCK(3) π
okay bestie, we're in the Libcap-ng API section and this one is literally about locking your process's capability settings so nobody sneaks back in. it's capng_lock, and she's iconic. π
β¨ NAME β¨
capng_lock β lock the current process capabilities settings π
πΈ SYNOPSIS πΈ
#include <cap-ng.h>
int capng_lock(void);
π¦ DESCRIPTION π¦
so capng_lock takes steps to stop children of the current process from regaining full privileges if the uid is 0. yes, that's the whole vibe β no privilege glow-ups for the kids.
you should call this while you're holding the CAP_SETPCAP capability in the kernel, okay? that's the price of admission. π
if the kernel permits it, this function will do all of the following:
- Set the
NOROOToption on forPR_SET_SECUREBITS. - Set the
NOROOT_LOCKEDoption to on forPR_SET_SECUREBITS. - Set the
PR_NO_SETUID_FIXUPoption on forPR_SET_SECUREBITS. - Set the
PR_NO_SETUID_FIXUP_LOCKEDoption on forPR_SET_SECUREBITS.
now, important, bestie β it does not enable PR_SET_KEEPCAPS or the KEEP_CAPS/KEEP_CAPS_LOCKED securebits. not her job, not her problem. π
and the way she's respectful about it: existing securebits set by the caller are preserved, including securebits that were added after this version of libcap-ng was built. so nothing of yours gets thrown away. periodt. β¨
π RETURN VALUE π
she returns 0 on success and a negative number on failure. specifically:
-1means a failure reading or updating the securebits.-2means failure settingPR_SET_NO_NEW_PRIVS.
and these are additive, meaning -3 is a failure of both. both at once? that's a vibe check fail fr fr. π
π SEE ALSO π
π AUTHOR π
Steve Grubb π
and that's the whole page, bestie! this was the Libcap-ng API manual, brought to you by Red Hat, dated Mar 2026. go lock those capabilities down and slay responsibly. π«ΆπΈπ
π¦ where this page comes from
- arch rolling: libcap-ng 0.9.6-1 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 43: libcap-ng-devel 0.9.6-1.fc43 Β· LGPL-2.0-or-later
- fedora 43: libcap-ng-devel 0.9.6-1.fc43 Β· LGPL-2.0-or-later
- fedora 44: libcap-ng-devel 0.9.6-1.fc44 Β· LGPL-2.0-or-later
- fedora 44: libcap-ng-devel 0.9.6-1.fc44 Β· LGPL-2.0-or-later
- nixpkgs unstable: libcap-ng 0.9.6
- ubuntu stonking: libcap-ng-dev 0.9.6-1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms