forked from Minki/linux
8ec456629d
For device mapper targets to take advantage of IMA's measurement capabilities, the status functions for the individual targets need to be updated to handle the status_type_t case for value STATUSTYPE_IMA. Update status functions for the following target types, to log their respective attributes to be measured using IMA. 01. cache 02. crypt 03. integrity 04. linear 05. mirror 06. multipath 07. raid 08. snapshot 09. striped 10. verity For rest of the targets, handle the STATUSTYPE_IMA case by setting the measurement buffer to NULL. For IMA to measure the data on a given system, the IMA policy on the system needs to be updated to have the following line, and the system needs to be restarted for the measurements to take effect. /etc/ima/ima-policy measure func=CRITICAL_DATA label=device-mapper template=ima-buf The measurements will be reflected in the IMA logs, which are located at: /sys/kernel/security/integrity/ima/ascii_runtime_measurements /sys/kernel/security/integrity/ima/binary_runtime_measurements These IMA logs can later be consumed by various attestation clients running on the system, and send them to external services for attesting the system. The DM target data measured by IMA subsystem can alternatively be queried from userspace by setting DM_IMA_MEASUREMENT_FLAG with DM_TABLE_STATUS_CMD. Signed-off-by: Tushar Sugandhi <tusharsu@linux.microsoft.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
157 lines
3.7 KiB
C
157 lines
3.7 KiB
C
/*
|
|
* Copyright (C) 2001-2002 Sistina Software (UK) Limited.
|
|
* Copyright (C) 2006-2008 Red Hat GmbH
|
|
*
|
|
* This file is released under the GPL.
|
|
*/
|
|
|
|
#include "dm-exception-store.h"
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/export.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/dm-io.h>
|
|
|
|
#define DM_MSG_PREFIX "transient snapshot"
|
|
|
|
/*-----------------------------------------------------------------
|
|
* Implementation of the store for non-persistent snapshots.
|
|
*---------------------------------------------------------------*/
|
|
struct transient_c {
|
|
sector_t next_free;
|
|
};
|
|
|
|
static void transient_dtr(struct dm_exception_store *store)
|
|
{
|
|
kfree(store->context);
|
|
}
|
|
|
|
static int transient_read_metadata(struct dm_exception_store *store,
|
|
int (*callback)(void *callback_context,
|
|
chunk_t old, chunk_t new),
|
|
void *callback_context)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int transient_prepare_exception(struct dm_exception_store *store,
|
|
struct dm_exception *e)
|
|
{
|
|
struct transient_c *tc = store->context;
|
|
sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev);
|
|
|
|
if (size < (tc->next_free + store->chunk_size))
|
|
return -1;
|
|
|
|
e->new_chunk = sector_to_chunk(store, tc->next_free);
|
|
tc->next_free += store->chunk_size;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void transient_commit_exception(struct dm_exception_store *store,
|
|
struct dm_exception *e, int valid,
|
|
void (*callback) (void *, int success),
|
|
void *callback_context)
|
|
{
|
|
/* Just succeed */
|
|
callback(callback_context, valid);
|
|
}
|
|
|
|
static void transient_usage(struct dm_exception_store *store,
|
|
sector_t *total_sectors,
|
|
sector_t *sectors_allocated,
|
|
sector_t *metadata_sectors)
|
|
{
|
|
*sectors_allocated = ((struct transient_c *) store->context)->next_free;
|
|
*total_sectors = get_dev_size(dm_snap_cow(store->snap)->bdev);
|
|
*metadata_sectors = 0;
|
|
}
|
|
|
|
static int transient_ctr(struct dm_exception_store *store, char *options)
|
|
{
|
|
struct transient_c *tc;
|
|
|
|
tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
|
|
if (!tc)
|
|
return -ENOMEM;
|
|
|
|
tc->next_free = 0;
|
|
store->context = tc;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static unsigned transient_status(struct dm_exception_store *store,
|
|
status_type_t status, char *result,
|
|
unsigned maxlen)
|
|
{
|
|
unsigned sz = 0;
|
|
|
|
switch (status) {
|
|
case STATUSTYPE_INFO:
|
|
break;
|
|
case STATUSTYPE_TABLE:
|
|
DMEMIT(" N %llu", (unsigned long long)store->chunk_size);
|
|
break;
|
|
case STATUSTYPE_IMA:
|
|
*result = '\0';
|
|
break;
|
|
}
|
|
|
|
return sz;
|
|
}
|
|
|
|
static struct dm_exception_store_type _transient_type = {
|
|
.name = "transient",
|
|
.module = THIS_MODULE,
|
|
.ctr = transient_ctr,
|
|
.dtr = transient_dtr,
|
|
.read_metadata = transient_read_metadata,
|
|
.prepare_exception = transient_prepare_exception,
|
|
.commit_exception = transient_commit_exception,
|
|
.usage = transient_usage,
|
|
.status = transient_status,
|
|
};
|
|
|
|
static struct dm_exception_store_type _transient_compat_type = {
|
|
.name = "N",
|
|
.module = THIS_MODULE,
|
|
.ctr = transient_ctr,
|
|
.dtr = transient_dtr,
|
|
.read_metadata = transient_read_metadata,
|
|
.prepare_exception = transient_prepare_exception,
|
|
.commit_exception = transient_commit_exception,
|
|
.usage = transient_usage,
|
|
.status = transient_status,
|
|
};
|
|
|
|
int dm_transient_snapshot_init(void)
|
|
{
|
|
int r;
|
|
|
|
r = dm_exception_store_type_register(&_transient_type);
|
|
if (r) {
|
|
DMWARN("Unable to register transient exception store type");
|
|
return r;
|
|
}
|
|
|
|
r = dm_exception_store_type_register(&_transient_compat_type);
|
|
if (r) {
|
|
DMWARN("Unable to register old-style transient "
|
|
"exception store type");
|
|
dm_exception_store_type_unregister(&_transient_type);
|
|
return r;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
void dm_transient_snapshot_exit(void)
|
|
{
|
|
dm_exception_store_type_unregister(&_transient_type);
|
|
dm_exception_store_type_unregister(&_transient_compat_type);
|
|
}
|