// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2010 IBM Corporation * * Authors: * Mimi Zohar <zohar@us.ibm.com> * * File: evm_secfs.c * - Used to signal when key is on keyring * - Get the key and enable EVM
*/
/** * evm_read_key - read() for <securityfs>/evm * * @filp: file pointer, not actually used * @buf: where to put the result * @count: maximum to send along * @ppos: where to start * * Returns number of bytes read or error code, as appropriate
*/ static ssize_t evm_read_key(struct file *filp, char __user *buf,
size_t count, loff_t *ppos)
{ char temp[80];
ssize_t rc;
/** * evm_write_key - write() for <securityfs>/evm * @file: file pointer, not actually used * @buf: where to get the data from * @count: bytes sent * @ppos: where to start * * Used to signal that key is on the kernel key ring. * - get the integrity hmac key from the kernel key ring * - create list of hmac protected extended attributes * Returns number of bytes written or error code, as appropriate
*/ static ssize_t evm_write_key(struct file *file, constchar __user *buf,
size_t count, loff_t *ppos)
{ unsignedint i; int ret;
if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP_COMPLETE)) return -EPERM;
ret = kstrtouint_from_user(buf, count, 0, &i);
if (ret) return ret;
/* Reject invalid values */ if (!i || (i & ~EVM_INIT_MASK) != 0) return -EINVAL;
/* * Don't allow a request to enable metadata writes if * an HMAC key is loaded.
*/ if ((i & EVM_ALLOW_METADATA_WRITES) &&
(evm_initialized & EVM_INIT_HMAC) != 0) return -EPERM;
if (i & EVM_INIT_HMAC) {
ret = evm_init_key(); if (ret != 0) return ret; /* Forbid further writes after the symmetric key is loaded */
i |= EVM_SETUP_COMPLETE;
}
evm_initialized |= i;
/* Don't allow protected metadata modification if a symmetric key * is loaded
*/ if (evm_initialized & EVM_INIT_HMAC)
evm_initialized &= ~(EVM_ALLOW_METADATA_WRITES);
#ifdef CONFIG_EVM_ADD_XATTRS /** * evm_read_xattrs - read() for <securityfs>/evm_xattrs * * @filp: file pointer, not actually used * @buf: where to put the result * @count: maximum to send along * @ppos: where to start * * Returns number of bytes read or error code, as appropriate
*/ static ssize_t evm_read_xattrs(struct file *filp, char __user *buf,
size_t count, loff_t *ppos)
{ char *temp; int offset = 0;
ssize_t rc, size = 0; struct xattr_list *xattr;
if (*ppos != 0) return 0;
rc = mutex_lock_interruptible(&xattr_list_mutex); if (rc) return -ERESTARTSYS;
list_for_each_entry(xattr, &evm_config_xattrnames, list) { if (!xattr->enabled) continue;
/** * evm_write_xattrs - write() for <securityfs>/evm_xattrs * @file: file pointer, not actually used * @buf: where to get the data from * @count: bytes sent * @ppos: where to start * * Returns number of bytes written or error code, as appropriate
*/ static ssize_t evm_write_xattrs(struct file *file, constchar __user *buf,
size_t count, loff_t *ppos)
{ int len, err; struct xattr_list *xattr, *tmp; struct audit_buffer *ab; struct iattr newattrs; struct inode *inode;
if (!capable(CAP_SYS_ADMIN) || evm_xattrs_locked) return -EPERM;
if (*ppos != 0) return -EINVAL;
if (count > XATTR_NAME_MAX) return -E2BIG;
ab = audit_log_start(audit_context(), GFP_KERNEL,
AUDIT_INTEGRITY_EVM_XATTR); if (!ab && IS_ENABLED(CONFIG_AUDIT)) return -ENOMEM;
/* * xattr_list_mutex guards against races in evm_read_xattrs(). * Entries are only added to the evm_config_xattrnames list * and never deleted. Therefore, the list is traversed * using list_for_each_entry_lockless() without holding * the mutex in evm_calc_hmac_or_hash(), evm_find_protected_xattrs() * and evm_protected_xattr().
*/
mutex_lock(&xattr_list_mutex);
list_for_each_entry(tmp, &evm_config_xattrnames, list) { if (strcmp(xattr->name, tmp->name) == 0) {
err = -EEXIST; if (!tmp->enabled) {
tmp->enabled = true;
err = count;
}
mutex_unlock(&xattr_list_mutex); goto out;
}
}
list_add_tail_rcu(&xattr->list, &evm_config_xattrnames);
mutex_unlock(&xattr_list_mutex);
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.