KEYCTL_READ(2const)
π KEYCTL_READ(2const) π
okay bestie so like... this is a page straight out of the Linux man-pages, section 2const (that's the "these are syscall constants, my love" corner of the manual), and no cap, it's actually kinda elegant once you get the vibe. sit down, grab a strawberry π, we're gonna read a key together.
β¨ NAME β¨
KEYCTL_READ β read a key. that's it. that's the whole job. iconic behavior honestly π
π LIBRARY π
Standard C library (libc, -lc). yeah girl, the regular one, nothing exotic π
πΈ SYNOPSIS πΈ
like a lil poem fr fr:
#include <linux/keyctl.h> /* Definition of KEY* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
long syscall(size_t size;
SYS_keyctl, KEYCTL_READ, key_serial_t key,
char buf[_Nullable size], size_t size);
yes the size_t size; at the top is real, it's not a typo, it's just how the page is written. we respect it. π
π¦ DESCRIPTION π¦
so what are we even doing here? we're reading the payload data of a key. that's the mission. the whole mission. π«Ά
The ID of the key whose payload you wanna read goes in key. and listen β key can totally be the ID of an existing key, OR it can be any of those special key IDs listed over in KEYCTL_GET_KEYRING_ID(2const). your choice, main character, the special IDs are right there waiting for you.
where does the payload go? into the buffer that buf points at. and the size of that buffer? you must specify it in size. like, you have to, it's not optional, it's the rules bestie. π§
here's the cute part: the returned data gets processed for presentation according to the key type. so like, the type of the key changes how the data shows up. for example:
- a keyring returns an array of
key_serial_tentries that represent the IDs of all the keys linked to it - the user key type just returns its data as is, no filter, raw and unbothered β¨
If buf is not NULL, then as much of the payload data as will actually fit gets copied into the buffer. and on a successful return, the return value is always the total size of the payload data. ALWAYS. not "how much fit" β the total. so if you're wondering whether your buffer was big enough, here's your vibe check: see if the return value is less than or equal to the value you supplied in size. that's it, that's the test. π
oh and the key has to grant you read permission, OR grant you search permission when it's searched for from the process keyrings β i.e. the key is possessed. no permission, no payload, no exceptions, periodt.
π RETURN VALUE π
On success: the amount of data that is available in the key, irrespective of the provided buffer size. yeah β even if your buffer is tiny, you get the full number. that's how you find out you need a bigger one. π
On error: -1 is returned, and errno is set to indicate the error. classic.
π ERRORS π
EOPNOTSUPPβ the key type does not support reading. (e.g. the type is"login". sorry girl, that one's not readable, nothing we can do π)
β VERSIONS β
A wrapper is provided in the libkeyutils library: keyctl_read(3). so if you don't wanna hand-roll the syscall, the girlies over at keyutils got you π
π STANDARDS π
Linux. just Linux. we stay on brand π§
πΈ HISTORY πΈ
Linux 2.6.10. ancient. vintage. still ate. π
π₯ SEE ALSO π₯
go read those too, they're all besties with this page π«Ά
and that's the whole vibe check, bestie β this was KEYCTL_READ(2const) from Linux man-pages 6.20, dated 2026-02-08. go read some keys, you're literally the main character now πβ¨π
π¦ 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: Linux-man-pages-copyleft
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- Copyright 2016, Eugene Syromyatnikov <evgsyr@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms