Path: blob/master/security/integrity/ima/ima_asymmetric_keys.c
26439 views
// SPDX-License-Identifier: GPL-2.0+1/*2* Copyright (C) 2019 Microsoft Corporation3*4* Author: Lakshmi Ramasubramanian ([email protected])5*6* File: ima_asymmetric_keys.c7* Defines an IMA hook to measure asymmetric keys on key8* create or update.9*/1011#include <keys/asymmetric-type.h>12#include <linux/user_namespace.h>13#include <linux/ima.h>14#include "ima.h"1516/**17* ima_post_key_create_or_update - measure asymmetric keys18* @keyring: keyring to which the key is linked to19* @key: created or updated key20* @payload: The data used to instantiate or update the key.21* @payload_len: The length of @payload.22* @flags: key flags23* @create: flag indicating whether the key was created or updated24*25* Keys can only be measured, not appraised.26* The payload data used to instantiate or update the key is measured.27*/28void ima_post_key_create_or_update(struct key *keyring, struct key *key,29const void *payload, size_t payload_len,30unsigned long flags, bool create)31{32bool queued = false;3334/* Only asymmetric keys are handled by this hook. */35if (key->type != &key_type_asymmetric)36return;3738if (!payload || (payload_len == 0))39return;4041if (ima_should_queue_key())42queued = ima_queue_key(keyring, payload, payload_len);4344if (queued)45return;4647/*48* keyring->description points to the name of the keyring49* (such as ".builtin_trusted_keys", ".ima", etc.) to50* which the given key is linked to.51*52* The name of the keyring is passed in the "eventname"53* parameter to process_buffer_measurement() and is set54* in the "eventname" field in ima_event_data for55* the key measurement IMA event.56*57* The name of the keyring is also passed in the "keyring"58* parameter to process_buffer_measurement() to check59* if the IMA policy is configured to measure a key linked60* to the given keyring.61*/62process_buffer_measurement(&nop_mnt_idmap, NULL, payload, payload_len,63keyring->description, KEY_CHECK, 0,64keyring->description, false, NULL, 0);65}666768