security/keys/trusted-keys/trusted_core.c
Source file repositories/reference/linux-study-clean/security/keys/trusted-keys/trusted_core.c
File Facts
- System
- Linux kernel
- Corpus path
security/keys/trusted-keys/trusted_core.c- Extension
.c- Size
- 9743 bytes
- Lines
- 411
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
keys/user-type.hkeys/trusted-type.hkeys/trusted_tee.hkeys/trusted_caam.hkeys/trusted_dcp.hkeys/trusted_tpm.hkeys/trusted_pkwm.hlinux/capability.hlinux/err.hlinux/hex.hlinux/init.hlinux/key-type.hlinux/module.hlinux/parser.hlinux/random.hlinux/rcupdate.hlinux/slab.hlinux/static_call.hlinux/string.hlinux/uaccess.h
Detected Declarations
function datablob_parsefunction trusted_instantiatefunction trusted_rcu_freefunction trusted_updatefunction trusted_readfunction trusted_destroyfunction kernel_get_randomfunction init_trustedfunction cleanup_trustedexport key_type_trusted
Annotated Snippet
if (ret != key_len) {
pr_info("key_create failed (%d)\n", ret);
ret = -EIO;
goto out;
}
ret = static_call(trusted_key_seal)(payload, datablob);
if (ret < 0)
pr_info("key_seal failed (%d)\n", ret);
break;
default:
ret = -EINVAL;
}
out:
kfree_sensitive(orig_datablob);
if (!ret)
rcu_assign_keypointer(key, payload);
else
kfree_sensitive(payload);
return ret;
}
static void trusted_rcu_free(struct rcu_head *rcu)
{
struct trusted_key_payload *p;
p = container_of(rcu, struct trusted_key_payload, rcu);
kfree_sensitive(p);
}
/*
* trusted_update - reseal an existing key with new PCR values
*/
static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
{
struct trusted_key_payload *p;
struct trusted_key_payload *new_p;
size_t datalen = prep->datalen;
char *datablob, *orig_datablob;
int ret = 0;
if (key_is_negative(key))
return -ENOKEY;
p = key->payload.data[0];
if (!p->migratable)
return -EPERM;
if (datalen == 0 || datalen > 32767 || !prep->data)
return -EINVAL;
orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL);
if (!datablob)
return -ENOMEM;
new_p = trusted_payload_alloc(key);
if (!new_p) {
ret = -ENOMEM;
goto out;
}
memcpy(datablob, prep->data, datalen);
datablob[datalen] = '\0';
ret = datablob_parse(&datablob, new_p);
if (ret != Opt_update) {
ret = -EINVAL;
kfree_sensitive(new_p);
goto out;
}
/* copy old key values, and reseal with new pcrs */
new_p->migratable = p->migratable;
new_p->key_len = p->key_len;
memcpy(new_p->key, p->key, p->key_len);
dump_payload(p);
dump_payload(new_p);
ret = static_call(trusted_key_seal)(new_p, datablob);
if (ret < 0) {
pr_info("key_seal failed (%d)\n", ret);
kfree_sensitive(new_p);
goto out;
}
rcu_assign_keypointer(key, new_p);
call_rcu(&p->rcu, trusted_rcu_free);
out:
kfree_sensitive(orig_datablob);
return ret;
}
/*
Annotation
- Immediate include surface: `keys/user-type.h`, `keys/trusted-type.h`, `keys/trusted_tee.h`, `keys/trusted_caam.h`, `keys/trusted_dcp.h`, `keys/trusted_tpm.h`, `keys/trusted_pkwm.h`, `linux/capability.h`.
- Detected declarations: `function datablob_parse`, `function trusted_instantiate`, `function trusted_rcu_free`, `function trusted_update`, `function trusted_read`, `function trusted_destroy`, `function kernel_get_random`, `function init_trusted`, `function cleanup_trusted`, `export key_type_trusted`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: integration 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.