key_create_or_update(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ key_create_or_update ✨

okay so this is a page from the Kernel API Manual (yes, the kernel has lore too πŸ’…) and it's all about key_create_or_update β€” the function that either updates a key or creates one and instantiates it. literally both jobs in one icon, we love a multitasking main character 🫢


🌸 SYNOPSIS 🌸

key_ref_t key_create_or_update (key_ref_t keyring_ref , const char *type
, const char *description , const void *payload , size_t plen ,
key_perm_t perm , unsigned long flags );

that's the whole signature bestie, take it in 🧚


πŸŽ€ ARGUMENTS πŸŽ€

  • keyring_ref β€” a pointer to the destination keyring, and it's got the possession flag riding along with it πŸ’–
  • type β€” the type of key, like what kind of key we're dealing with ✨
  • description β€” the searchable description for the key, this is how you'll find it later, no cap πŸ”
  • payload β€” the data used to instantiate or update the key πŸ“
  • plen β€” the length of payload, keep it honest πŸ“
  • perm β€” the permissions mask for a new key πŸ”
  • flags β€” the quota flags for a new key πŸ’«

πŸ¦‹ DESCRIPTION πŸ¦‹

here's the vibe: it searches the destination keyring for a key with the same description. if one turns up, bestie, it gets updated. if not, it creates and instantiates a brand new one and makes a link to it from that keyring. it's giving "find or create", periodt πŸ‘‘

if perm is KEY_PERM_UNDEF then an appropriate key permissions mask will be concocted β€” like it just whips one up for you, iconic πŸ§ͺ✨

and now the return tea β˜• it returns a pointer to the new key if it's successful. but if things go sideways:

  • -ENODEV β€” the key type wasn't available 😭
  • -ENOTDIR β€” the thing you gave it wasn't a keyring, awkward πŸ’€
  • -EACCES β€” the caller isn't permitted to modify the keyring, or the LSM did not permit creation of the key πŸ™ˆ
on success, the possession flag from the keyring ref will be tacked on to the key ref before it's returned. so cute, it carries the flag with it 🌈

πŸ‘‘ SEE ALSO πŸ‘‘

the kernel file ./security/keys/key.c (iykyk) plus all these faves:


and that's the page, bestie! πŸŽ€ this one lives in ./security/keys and it's dated October 2026 β€” go off, future manual β­πŸ’œ

πŸ“¦ where this page comes from