bpf_lookup_system_key(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… bpf_lookup_system_key(9) β€” from the Kernel API Manual, bestie ✨

okay so picture this: you're deep in kernel land, the Kernel API Manual is open, and you need to find a key by a system-defined ID. That's the whole entire vibe of bpf_lookup_system_key. Let me walk you through it 🫢


🌸 NAME 🌸

bpf_lookup_system_key β€” lookup a key by a system-defined ID πŸ”‘


✨ SYNOPSIS ✨

__bpf_kfunc struct bpf_key * bpf_lookup_system_key (u64 id );

literally that's it. that's the whole signature. no cap πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • id β€” the key ID. that's it, that's the arg πŸ“

πŸ¦‹ DESCRIPTION πŸ¦‹

So what does it do? It obtains a bpf_key structure with a key pointer set to the passed key ID. Easy. Iconic. No notes. πŸ’–

But here's the spicy part: that key pointer is marked as invalid, on purpose, so that bpf_key_put won't try to decrement the key reference count on that pointer. yeah, it's giving "don't touch, i'm not a real ref". The key pointer set in such a way is currently understood only by verify_pkcs7_signature. So like, only that one function speaks this language. iykyk 😭

Now, set id to one of the values defined in include/linux/verification.h β€” here's the menu, bestie:

  • 0 β€” for the primary keyring (that's the immutable keyring of system keys) πŸ‘‘
  • VERIFY_USE_SECONDARY_KEYRING β€” for both the primary and secondary keyring (where keys can be added only if they are vouched for by existing keys in those keyrings) 🌈
  • VERIFY_USE_PLATFORM_KEYRING β€” for the platform keyring (primarily used by the integrity subsystem to verify a kexec'ed kerned image and, possibly, the initramfs signature) πŸ”₯
ngl the platform keyring one is doing a lot of heavy lifting in that sentence. read it twice. it's fine. it's beautiful. 🧚

πŸ’œ RETURN πŸ’œ

On success? a bpf_key pointer with an invalid key pointer set from the pre-determined ID. πŸ’«

Otherwise? a NULL pointer. and that's the tea πŸ’€


⭐ SEE ALSO ⭐

go read the kernel file ./kernel/bpf/helpers.c bestie, and while you're there, here's the whole friend group:


and that's the page!! πŸŽ€ mwah πŸ’‹

from the ./kernel/bpf corner of the world, dated October 2026 β€” go forth and look up those keys, bestie. slay πŸ’…βœ¨

πŸ“¦ where this page comes from