KEYCTL_LINK(2const)

okay bestie, gather round, because this is KEYCTL_LINK(2const) and it's literally so iconic. it's from the Linux man-pages, and yes, we're doing this properly. πŸŽ€


πŸ“š 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_LINK, key_serial_t key,
             key_serial_t keyring);

πŸ’… DESCRIPTION

so what we're doing here is creating a link from a keyring to a key. that's it, that's the whole vibe. 🫢

the key that's getting linked? that's your key. the keyring it's getting linked to? that's your keyring.

now here's the little plot twist: if a key with the same type and description is already linked in the keyring, then that key gets displaced from the keyring. not me kicking out the old one to make room for the new 😭✨

and before creating the link, the kernel does a little vibe check on the nesting of the keyrings. if your link would produce a cycle, or if the nesting of keyrings would be too deep, you get appropriate errors. (the nesting limit is determined by the kernel constant KEYRING_SEARCH_MAX_DEPTH, defined with the value 6, and it's necessary to prevent overflows on the kernel stack when recursively searching keyrings. protecting the stack, we love to see it πŸ’–)

permissions, because of course: the caller must have link permission on the key being added, and write permission on the keyring. no permission, no link, periodt. πŸ’…


πŸ”₯ RETURN VALUE

  • on success, 0 is returned. slay. πŸŽ‰
  • on error, -1 is returned, and errno is set to indicate the error.

πŸ‘‘ ERRORS

  • EDEADLK β€” the requested link would result in a cycle. circular keyring situationship… we don't do those. πŸ’€
  • ELOOP β€” the requested link would cause the maximum nesting depth for keyrings to be exceeded. too deep, bestie, the kernel said no. πŸ™ˆ
  • ENFILE (before Linux 3.13) β€” the keyring is full. (before Linux 3.13, the available space for storing keyring links was limited to a single page of memory; since Linux 3.13, there is no fixed limit.) the glow-up was real. ✨

🌸 VERSIONS

a wrapper is provided in the libkeyutils library: keyctl_link(3). convenient? we love convenient. 🫢


⭐ STANDARDS

Linux. πŸ’…


πŸ¦„ HISTORY

Linux 2.6.10. ancient. vintage. a legend, fr fr. πŸ‘‘


🌈 SEE ALSO


and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2026-02-08 β€” so if you're quoting me, cite the source like the academic weapon you are. πŸ’œβœ¨ mwah, go link some keys. πŸŽ€πŸ¦‹

πŸ“¦ 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms