capget(2)
๐ capget, capset ๐
okay bestie, buckle UP, because this one is from the System Calls Manual and it is so deep in the kernel weeds it's basically living in the soil. we're talking capget(2) and capset(2) โ the raw, unfiltered, no-glibc-wrapper system calls for getting and setting thread capabilities. yeah. those ones. ๐ฅ
โจ NAME โจ
capget, capset โ set/get capabilities of thread(s)
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <linux/capability.h> /* Definition of CAP_* and
_LINUX_CAPABILITY_* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
int syscall(SYS_capget, cap_user_header_t hdrp,
cap_user_data_t datap);
int syscall(SYS_capset, cap_user_header_t hdrp,
const cap_user_data_t datap);
Note: glibc does not give you wrappers for these system calls, bestie, so you literally have to go through syscall(2). it's giving "we don't do convenience here." ๐
๐ธ DESCRIPTION ๐ธ
so these two system calls are the raw kernel interface for getting and setting thread capabilities. and likeโฆ not only are they Linux-specific (no portability, sorry babes), but the kernel API here is likely to change, and using these system calls โ especially the format of the cap_user_*_t types โ is subject to extension with each and every kernel revision. but hey: old programs will keep working. so that's the vibe. ๐ฆ
the portable interfaces are cap_set_proc(3) and cap_get_proc(3). if possible, you should use those in applications โ see NOTES. periodt.
๐ Current details ๐
okay so now that you've been warned (dramatically), here are some current kernel details. the structures are defined like this:
#define _LINUX_CAPABILITY_VERSION_1 0x19980330
#define _LINUX_CAPABILITY_U32S_1 1
/* V2 added in Linux 2.6.25; deprecated */
#define _LINUX_CAPABILITY_VERSION_2 0x20071026
#define _LINUX_CAPABILITY_U32S_2 2
/* V3 added in Linux 2.6.26 */
#define _LINUX_CAPABILITY_VERSION_3 0x20080522
#define _LINUX_CAPABILITY_U32S_3 2
typedef struct __user_cap_header_struct {
__u32 version;
int pid;
} *cap_user_header_t;
typedef struct __user_cap_data_struct {
__u32 effective;
__u32 permitted;
__u32 inheritable;
} *cap_user_data_t;
the effective, permitted, and inheritable fields are bit masks of the capabilities defined in capabilities(7). and heads up โ: the CAP_* values are bit indexes, so you have to bit-shift them before ORing them into the bit fields. to define the structures for passing to the system call, you have to use the struct __user_cap_header_struct and struct __user_cap_data_struct names, because the typedefs are only pointers. iykyk. ๐
kernels before Linux 2.6.25 preferred 32-bit capabilities with version _LINUX_CAPABILITY_VERSION_1. then Linux 2.6.25 added 64-bit capability sets with version _LINUX_CAPABILITY_VERSION_2. but there was, however, an API glitch ๐ญ and Linux 2.6.26 added _LINUX_CAPABILITY_VERSION_3 to fix the problem. iconic recovery honestly.
note that 64-bit capabilities use datap[0] and datap[1], whereas 32-bit capabilities use only datap[0].
on kernels that support file capabilities (VFS capabilities support), these system calls behave slightly differently. this support was added as an option in Linux 2.6.24, and became fixed (nonoptional) in Linux 2.6.33.
for capget() calls, you can probe the capabilities of any process by specifying its process ID with the hdrp->pid field value. cute little spy moment. ๐ต๏ธโ๏ธ
for details on the data, see capabilities(7).
๐ With VFS capabilities support ๐
VFS capabilities employ a file extended attribute (see xattr(7)) to let capabilities be attached to executables. this privilege model obsoletes kernel support for one process asynchronously setting the capabilities of another. so like: on kernels that have VFS capabilities support, when you call capset(), the only permitted values for hdrp->pid are 0, or equivalently, the value returned by gettid(2). no sneaky side-eye capability changes for other threads. ๐
๐ง Without VFS capabilities support ๐ง
on older kernels that do not provide VFS capabilities support, capset() can โ if the caller has the CAP_SETPCAP capability โ be used to change not only the caller's own capabilities, but also the capabilities of other threads.
the call operates on the capabilities of the thread specified by the pid field of hdrp when that is nonzero, or on the capabilities of the calling thread if pid is 0.
- if
pidrefers to a single-threaded process, thenpidcan be specified as a traditional process ID. - operating on a thread of a multithreaded process requires a thread ID of the type returned by
gettid(2).
for capset(), pid can also be:
- -1 โ meaning perform the change on all threads except the caller and
init(1). - a value less than -1 โ in which case the change is applied to all members of the process group whose ID is
-pid. (yes, the minus is the whole point. slay.) ๐
โญ RETURN VALUE โญ
on success, zero is returned. on error, -1 is returned, and errno is set to indicate the error.
the calls fail with the error EINVAL, and set the version field of hdrp to the kernel preferred value of _LINUX_CAPABILITY_VERSION_? when an unsupported version value is specified. so in this way, you can probe what the current preferred capability revision is. lowkey a fun little trick. โจ
๐ ERRORS ๐
EFAULTโ bad memory address.hdrpmust not be NULL.datapmay be NULL only when the user is trying to determine the preferred capability version format supported by the kernel.EINVALโ one of the arguments was invalid.EPERMโ an attempt was made to add a capability to the permitted set, or to set a capability in the effective set that is not in the permitted set.EPERMโ an attempt was made to add a capability to the inheritable set, and either:- that capability was not in the caller's bounding set; or
- the capability was not in the caller's permitted set and the caller lacked the
CAP_SETPCAPcapability in its effective set.
EPERMโ the caller attempted to usecapset()to modify the capabilities of a thread other than itself, but lacked sufficient privilege. for kernels supporting VFS capabilities, this is never permitted. for kernels lacking VFS support, theCAP_SETPCAPcapability is required.
bug alert ๐ a bug in kernels before Linux 2.6.11 meant that this error could also occur if a thread without this capability tried to change its own capabilities by specifying thepidfield as a nonzero value (i.e., the value returned bygetpid(2)) instead of 0.
ESRCHโ no such thread.
๐ STANDARDS ๐
Linux. (just Linux. that's the whole standard. ๐)
๐ NOTES ๐
the portable interface to the capability querying and setting functions is provided by the libcap library and is available right here:
http://git.kernel.org/cgit/linux/kernel/git/morgan/libcap.git
๐ซถ SEE ALSO ๐ซถ
clone(2), gettid(2), capabilities(7)
and that's the whole page, bestie!! ๐ this was pulled straight from Linux man-pages 6.20, dated 2026-02-08 โ so go forth, shift those bits, and remember: use the portable interfaces if you can, because the raw kernel API is giving "I might change tomorrow." take care of your capability sets and they'll take care of you. mwah ๐โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-1.0-or-later
- Copyright 2006-2008, Michael Kerrisk <tmk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms