// SPDX-License-Identifier: GPL-2.0-or-later /* Request key authorisation token key definition. * * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * See Documentation/security/keys/request-key.rst
*/
/* * Read the callout_info data (retrieves the callout information). * - the key's semaphore is read-locked
*/ staticlong request_key_auth_read(conststruct key *key, char *buffer, size_t buflen)
{ struct request_key_auth *rka = dereference_key_locked(key);
size_t datalen; long ret;
if (!rka) return -EKEYREVOKED;
datalen = rka->callout_len;
ret = datalen;
/* we can return the data as is */ if (buffer && buflen > 0) { if (buflen > datalen)
buflen = datalen;
memcpy(buffer, rka->callout_info, buflen);
}
return ret;
}
staticvoid free_request_key_auth(struct request_key_auth *rka)
{ if (!rka) return;
key_put(rka->target_key);
key_put(rka->dest_keyring); if (rka->cred)
put_cred(rka->cred);
kfree(rka->callout_info);
kfree(rka);
}
/* * Dispose of the request_key_auth record under RCU conditions
*/ staticvoid request_key_auth_rcu_disposal(struct rcu_head *rcu)
{ struct request_key_auth *rka =
container_of(rcu, struct request_key_auth, rcu);
free_request_key_auth(rka);
}
/* * Handle revocation of an authorisation token key. * * Called with the key sem write-locked.
*/ staticvoid request_key_auth_revoke(struct key *key)
{ struct request_key_auth *rka = dereference_key_locked(key);
/* * Create an authorisation token for /sbin/request-key or whoever to gain * access to the caller's security data.
*/ struct key *request_key_auth_new(struct key *target, constchar *op, constvoid *callout_info, size_t callout_len, struct key *dest_keyring)
{ struct request_key_auth *rka, *irka; conststruct cred *cred = current_cred(); struct key *authkey = NULL; char desc[20]; int ret = -ENOMEM;
kenter("%d,", target->serial);
/* allocate a auth record */
rka = kzalloc(sizeof(*rka), GFP_KERNEL); if (!rka) goto error;
rka->callout_info = kmemdup(callout_info, callout_len, GFP_KERNEL); if (!rka->callout_info) goto error_free_rka;
rka->callout_len = callout_len;
strscpy(rka->op, op, sizeof(rka->op));
/* see if the calling process is already servicing the key request of
* another process */ if (cred->request_key_auth) { /* it is - use that instantiation context here too */
down_read(&cred->request_key_auth->sem);
/* if the auth key has been revoked, then the key we're
* servicing is already instantiated */ if (test_bit(KEY_FLAG_REVOKED,
&cred->request_key_auth->flags)) {
up_read(&cred->request_key_auth->sem);
ret = -EKEYREVOKED; goto error_free_rka;
}
up_read(&cred->request_key_auth->sem);
} else { /* it isn't - use this process as the context */
rka->cred = get_cred(cred);
rka->pid = current->pid;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.