KEYCTL_RESTRICT_KEYRING(2const)
π KEYCTL_RESTRICT_KEYRING β bestie edition π
okay so this is a page from the Linux man-pages, section 2const (that's "constants and stuff for syscalls", iykyk), and it's all about KEYCTL_RESTRICT_KEYRING, which is one of the keyctl(2) subcommands. Basically: it locks a keyring down so only certain keys are allowed in. iconic behaviour, honestly. πβ¨
β¨ NAME β¨
KEYCTL_RESTRICT_KEYRING β restrict which keys are allowed to get linked to a keyring π
π LIBRARY π
Standard C library (libc, -lc) π
πΈ SYNOPSIS πΈ
#include <linux/keyctl.h> /* Definition of KEY* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
long syscall(SYS_keyctl, KEYCTL_RESTRICT_KEYRING, key_serial_t keyring,
const char *_Nullable type, const char *restriction);
π¦ DESCRIPTION π¦
So you take the keyring whose ID you passed as keyring, and you slap a key-linking restriction on it. That's the whole vibe. The way that you must have setattr permission on the key though β no permission, no slay. π«Ά
If type is NULL, then literally any attempt to add a key to that keyring gets blocked. Full lockdown. Door closed, no notes. πͺπ
Otherwise, type is a pointer to a string holding a key type name, and restriction is a pointer to a string describing the type-specific restriction. And as of Linux 4.12, only one type actually has restrictions defined, and that type is "asymmetric":
builtin_trustedβ only allows keys that are signed by a key linked to the built-in keyring (".builtin_trusted_keys"). nothing else gets in bestie, periodt β¨builtin_and_secondary_trustedβ only allows keys that are signed by a key linked to the secondary keyring (".secondary_trusted_keys") or, by extension, a key in a built-in keyring, because the built-in one is linked to the secondary one. it's giving nepotism but make it cryptographically valid πkey_or_keyring:keykey_or_keyring:key:chain
and here's the tea for those two:
- If key specifies the ID of a key of type
"asymmetric", then only keys that are signed by this key are allowed. ποΈ - If key specifies the ID of a keyring, then only keys that are signed by a key linked to this keyring are allowed. π
- If
":chain"is specified, then keys that are signed by a keys linked to the destination keyring are also allowed. and yes β "destination keyring" means the keyring with the ID you passed in the keyring argument. π
π¨ VERY IMPORTANT, NO CAP: a restriction can only be configured once for a given keyring. Once it's set, it can't be overridden. Ever. Choose wisely bestie, that's a permanent decision. π
π RETURN VALUE π
- On success,
0is returned. slay! β - On error,
-1is returned, anderrnois set to indicate the error. π
π ERRORS π
EDEADLKβ the requested keyring restriction would result in a cycle. loops are NOT the move here. ππ«EEXISTβ keyring already has a restriction set. told you it was permanent. πENOENTβ the type provided in the type argument doesn't support setting key linking restrictions. wrong type, wrong vibe. πEOPNOTSUPPβ type was"asymmetric", and the key specified in the restriction specification provided in restriction has type other than"asymmetric"or"keyring". mismatch detected, not it. π€
π VERSIONS π
There's a wrapper for all of this in the libkeyutils library: keyctl_restrict_keyring(3). use that one if you don't wanna hand-roll the syscall, bestie, it's the low-effort high-reward route π§
β STANDARDS β
Linux. π§ (it's giving very Linux-core, because it is)
π HISTORY π
Linux 4.12. a classic, honestly. π₯
π«Ά SEE ALSO π«Ά
okay that's the whole page, go forth and restrict responsibly πβ¨
<xoxo> this was Linux man-pages 6.20, dated 2026-02-08 β KEYCTL_RESTRICT_KEYRING(2const), signing off ππ¦π
π¦ 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