include/linux/key.h
Source file repositories/reference/linux-study-clean/include/linux/key.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/key.h- Extension
.h- Size
- 16447 bytes
- Lines
- 521
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/list.hlinux/rbtree.hlinux/rcupdate.hlinux/sysctl.hlinux/rwsem.hlinux/atomic.hlinux/assoc_array.hlinux/refcount.hlinux/time64.hlinux/uidgid.h
Detected Declarations
struct keystruct netstruct seq_filestruct user_structstruct signal_structstruct credstruct key_typestruct key_ownerstruct key_tagstruct keyring_liststruct keyring_namestruct key_tagstruct keyring_index_keystruct key_restrictionstruct keyenum key_need_permenum key_lookup_flagenum key_statefunction make_key_reffunction is_key_possessedfunction key_ref_putfunction request_key_tagfunction key_serialfunction key_read_statefunction key_is_positivefunction key_is_negative
Annotated Snippet
struct key_tag {
struct rcu_head rcu;
refcount_t usage;
bool removed; /* T when subject removed */
};
struct keyring_index_key {
/* [!] If this structure is altered, the union in struct key must change too! */
unsigned long hash; /* Hash value */
union {
struct {
#ifdef __LITTLE_ENDIAN /* Put desc_len at the LSB of x */
u16 desc_len;
char desc[sizeof(long) - 2]; /* First few chars of description */
#else
char desc[sizeof(long) - 2]; /* First few chars of description */
u16 desc_len;
#endif
};
unsigned long x;
};
struct key_type *type;
struct key_tag *domain_tag; /* Domain of operation */
const char *description;
};
union key_payload {
void __rcu *rcu_data0;
void *data[4];
};
/*****************************************************************************/
/*
* key reference with possession attribute handling
*
* NOTE! key_ref_t is a typedef'd pointer to a type that is not actually
* defined. This is because we abuse the bottom bit of the reference to carry a
* flag to indicate whether the calling process possesses that key in one of
* its keyrings.
*
* the key_ref_t has been made a separate type so that the compiler can reject
* attempts to dereference it without proper conversion.
*
* the three functions are used to assemble and disassemble references
*/
typedef struct __key_reference_with_attributes *key_ref_t;
static inline key_ref_t make_key_ref(const struct key *key,
bool possession)
{
return (key_ref_t) ((unsigned long) key | possession);
}
static inline struct key *key_ref_to_ptr(const key_ref_t key_ref)
{
return (struct key *) ((unsigned long) key_ref & ~1UL);
}
static inline bool is_key_possessed(const key_ref_t key_ref)
{
return (unsigned long) key_ref & 1UL;
}
typedef int (*key_restrict_link_func_t)(struct key *dest_keyring,
const struct key_type *type,
const union key_payload *payload,
struct key *restriction_key);
struct key_restriction {
key_restrict_link_func_t check;
struct key *key;
struct key_type *keytype;
};
enum key_state {
KEY_IS_UNINSTANTIATED,
KEY_IS_POSITIVE, /* Positively instantiated */
};
/*****************************************************************************/
/*
* authentication token / access credential / keyring
* - types of key include:
* - keyrings
* - disk encryption IDs
* - Kerberos TGTs and tickets
*/
struct key {
refcount_t usage; /* number of references */
key_serial_t serial; /* key serial number */
Annotation
- Immediate include surface: `linux/types.h`, `linux/list.h`, `linux/rbtree.h`, `linux/rcupdate.h`, `linux/sysctl.h`, `linux/rwsem.h`, `linux/atomic.h`, `linux/assoc_array.h`.
- Detected declarations: `struct key`, `struct net`, `struct seq_file`, `struct user_struct`, `struct signal_struct`, `struct cred`, `struct key_type`, `struct key_owner`, `struct key_tag`, `struct keyring_list`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.