// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2021 - Google LLC * Author: David Brazdil <dbrazdil@google.com> * * Driver for Open Profile for DICE. * * This driver takes ownership of a reserved memory region containing data * generated by the Open Profile for DICE measured boot protocol. The memory * contents are not interpreted by the kernel but can be mapped into a userspace * process via a misc device. Userspace can also request a wipe of the memory. * * Userspace can access the data with (w/o error handling): * * fd = open("/dev/open-dice0", O_RDWR); * read(fd, &size, sizeof(unsigned long)); * data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); * write(fd, NULL, 0); // wipe * close(fd);
*/
/* * Copies the size of the reserved memory region to the user-provided buffer.
*/ static ssize_t open_dice_read(struct file *filp, char __user *ptr, size_t len,
loff_t *off)
{ unsignedlong val = to_open_dice_drvdata(filp)->rmem->size;
/* * Triggers a wipe of the reserved memory region. The user-provided pointer * is never dereferenced.
*/ static ssize_t open_dice_write(struct file *filp, constchar __user *ptr,
size_t len, loff_t *off)
{ if (open_dice_wipe(to_open_dice_drvdata(filp))) return -EIO;
/* Consume the input buffer. */ return len;
}
/* * Creates a mapping of the reserved memory region in user address space.
*/ staticint open_dice_mmap(struct file *filp, struct vm_area_struct *vma)
{ struct open_dice_drvdata *drvdata = to_open_dice_drvdata(filp);
if (vma->vm_flags & VM_MAYSHARE) { /* Do not allow userspace to modify the underlying data. */ if (vma->vm_flags & VM_WRITE) return -EPERM; /* Ensure userspace cannot acquire VM_WRITE later. */
vm_flags_clear(vma, VM_MAYWRITE);
}
/* Create write-combine mapping so all clients observe a wipe. */
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
vm_flags_set(vma, VM_DONTCOPY | VM_DONTDUMP); return vm_iomap_memory(vma, drvdata->rmem->base, drvdata->rmem->size);
}
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.