1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: dmsetup measure support for IMA

Add support for DM_IMA_MEASUREMENT_FLAG with
DM_TABLE_STATUS_CMD.

This feature requires DM version 4.45  (5.15+ kernels)
This commit is contained in:
Alasdair G Kergon 2021-07-13 02:06:04 +01:00 committed by Zdenek Kabelac
parent 707e7d762e
commit f853a1bc7a
9 changed files with 51 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.181 - Version 1.02.181 -
=================================== ===================================
Add IMA support with 'dmsetup measure' command.
Add defines DM_NAME_LIST_FLAG_HAS_UUID, DM_NAME_LIST_FLAG_DOESNT_HAVE_UUID. Add defines DM_NAME_LIST_FLAG_HAS_UUID, DM_NAME_LIST_FLAG_DOESNT_HAVE_UUID.
Enhance tracking of activated devices when preloading dm tree. Enhance tracking of activated devices when preloading dm tree.
Fix bug in construction of cache table line (regression from 1.02.159). Fix bug in construction of cache table line (regression from 1.02.159).

View File

@ -0,0 +1 @@
dm_task_ima_measurement

View File

@ -2446,6 +2446,9 @@ static int _status(CMD_ARGS)
if (_switches[NOFLUSH_ARG] && !dm_task_no_flush(dmt)) if (_switches[NOFLUSH_ARG] && !dm_task_no_flush(dmt))
goto_out; goto_out;
if (!dm_task_ima_measurement(dmt))
goto_out;
if (!_task_run(dmt)) if (!_task_run(dmt))
goto_out; goto_out;
@ -6255,6 +6258,7 @@ static struct command _dmsetup_commands[] = {
{"reload", "<device> [<table>|<table_file>]", 0, 2, 0, 0, _load}, {"reload", "<device> [<table>|<table_file>]", 0, 2, 0, 0, _load},
{"wipe_table", "[-f|--force] [--noflush] [--nolockfs] <device>...", 0, -1, 2, 0, _error_device}, {"wipe_table", "[-f|--force] [--noflush] [--nolockfs] <device>...", 0, -1, 2, 0, _error_device},
{"rename", "<device> [--setuuid] <new_name_or_uuid>", 1, 2, 0, 0, _rename}, {"rename", "<device> [--setuuid] <new_name_or_uuid>", 1, 2, 0, 0, _rename},
{"measure", "[<device>...]", 0, -1, 2, 0, _status},
{"message", "<device> <sector> <message>", 2, -1, 0, 0, _message}, {"message", "<device> <sector> <message>", 2, -1, 0, 0, _message},
{"ls", "[--target <target_type>] [--exec <command>] [-o <options>] [--tree]", 0, 0, 0, 0, _ls}, {"ls", "[--target <target_type>] [--exec <command>] [-o <options>] [--tree]", 0, 0, 0, 0, _ls},
{"info", "[<device>...]", 0, -1, 1, 0, _info}, {"info", "[<device>...]", 0, -1, 1, 0, _info},

View File

@ -929,6 +929,13 @@ int dm_task_secure_data(struct dm_task *dmt)
return 1; return 1;
} }
int dm_task_ima_measurement(struct dm_task *dmt)
{
dmt->ima_measurement = 1;
return 1;
}
int dm_task_retry_remove(struct dm_task *dmt) int dm_task_retry_remove(struct dm_task *dmt)
{ {
dmt->retry_remove = 1; dmt->retry_remove = 1;
@ -1288,6 +1295,14 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
} }
dmi->flags |= DM_UUID_FLAG; dmi->flags |= DM_UUID_FLAG;
} }
if (dmt->ima_measurement) {
if (_dm_version_minor < 45) {
log_error("WARNING: IMA measurement unsupported by "
"kernel. Aborting operation.");
goto bad;
}
dmi->flags |= DM_IMA_MEASUREMENT_FLAG;
}
dmi->target_count = count; dmi->target_count = count;
dmi->event_nr = dmt->event_nr; dmi->event_nr = dmt->event_nr;
@ -1489,6 +1504,7 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->head = dmt->head; task->head = dmt->head;
task->tail = dmt->tail; task->tail = dmt->tail;
task->secure_data = dmt->secure_data; task->secure_data = dmt->secure_data;
task->ima_measurement = dmt->ima_measurement;
r = dm_task_run(task); r = dm_task_run(task);
@ -1877,7 +1893,7 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
} }
log_debug_activation("dm %s %s%s %s%s%s %s%.0d%s%.0d%s" log_debug_activation("dm %s %s%s %s%s%s %s%.0d%s%.0d%s"
"%s[ %s%s%s%s%s%s%s%s%s] %.0" PRIu64 " %s [%u] (*%u)", "%s[ %s%s%s%s%s%s%s%s%s%s] %.0" PRIu64 " %s [%u] (*%u)",
_cmd_data_v4[dmt->type].name, _cmd_data_v4[dmt->type].name,
dmt->new_uuid ? "UUID " : "", dmt->new_uuid ? "UUID " : "",
dmi->name, dmi->uuid, dmt->newname ? " " : "", dmi->name, dmi->uuid, dmt->newname ? " " : "",
@ -1895,6 +1911,7 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
dmt->retry_remove ? "retryremove " : "", dmt->retry_remove ? "retryremove " : "",
dmt->deferred_remove ? "deferredremove " : "", dmt->deferred_remove ? "deferredremove " : "",
dmt->secure_data ? "securedata " : "", dmt->secure_data ? "securedata " : "",
dmt->ima_measurement ? "ima_measurement " : "",
dmt->query_inactive_table ? "inactive " : "", dmt->query_inactive_table ? "inactive " : "",
dmt->enable_checks ? "enablechecks " : "", dmt->enable_checks ? "enablechecks " : "",
dmt->sector, _sanitise_message(dmt->message), dmt->sector, _sanitise_message(dmt->message),

View File

@ -69,6 +69,7 @@ struct dm_task {
int enable_checks; int enable_checks;
int expected_errno; int expected_errno;
int ioctl_errno; int ioctl_errno;
int ima_measurement;
int record_timestamp; int record_timestamp;

View File

@ -235,6 +235,7 @@ int dm_task_suppress_identical_reload(struct dm_task *dmt);
int dm_task_secure_data(struct dm_task *dmt); int dm_task_secure_data(struct dm_task *dmt);
int dm_task_retry_remove(struct dm_task *dmt); int dm_task_retry_remove(struct dm_task *dmt);
int dm_task_deferred_remove(struct dm_task *dmt); int dm_task_deferred_remove(struct dm_task *dmt);
int dm_task_ima_measurement(struct dm_task *dmt);
/* /*
* Record timestamp immediately after the ioctl returns. * Record timestamp immediately after the ioctl returns.

View File

@ -336,6 +336,7 @@ struct dm_task *dm_task_create(int type)
dmt->new_uuid = 0; dmt->new_uuid = 0;
dmt->secure_data = 0; dmt->secure_data = 0;
dmt->record_timestamp = 0; dmt->record_timestamp = 0;
dmt->ima_measurement = 0;
return dmt; return dmt;
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2001 - 2003 Sistina Software (UK) Limited. * Copyright (C) 2001 - 2003 Sistina Software (UK) Limited.
* Copyright (C) 2004 - 2017 Red Hat, Inc. All rights reserved. * Copyright (C) 2004 - 2021 Red Hat, Inc. All rights reserved.
* *
* This file is released under the LGPL. * This file is released under the LGPL.
*/ */
@ -287,9 +287,9 @@ enum {
#define DM_GET_TARGET_VERSION _IOWR(DM_IOCTL, DM_GET_TARGET_VERSION_CMD, struct dm_ioctl) #define DM_GET_TARGET_VERSION _IOWR(DM_IOCTL, DM_GET_TARGET_VERSION_CMD, struct dm_ioctl)
#define DM_VERSION_MAJOR 4 #define DM_VERSION_MAJOR 4
#define DM_VERSION_MINOR 36 #define DM_VERSION_MINOR 45
#define DM_VERSION_PATCHLEVEL 0 #define DM_VERSION_PATCHLEVEL 0
#define DM_VERSION_EXTRA "-ioctl (2017-06-09)" #define DM_VERSION_EXTRA "-ioctl (2021-03-22)"
/* Status bits */ /* Status bits */
#define DM_READONLY_FLAG (1 << 0) /* In/Out */ #define DM_READONLY_FLAG (1 << 0) /* In/Out */
@ -377,4 +377,10 @@ enum {
*/ */
#define DM_INTERNAL_SUSPEND_FLAG (1 << 18) /* Out */ #define DM_INTERNAL_SUSPEND_FLAG (1 << 18) /* Out */
/*
* If set, returns in the in buffer passed by UM, the raw table information
* that would be measured by IMA subsystem on device state change.
*/
#define DM_IMA_MEASUREMENT_FLAG (1 << 19) /* In */
#endif /* _LINUX_DM_IOCTL_H */ #endif /* _LINUX_DM_IOCTL_H */

View File

@ -140,6 +140,14 @@ dmsetup \(em low level logical volume management
. .
.HP .HP
.B dmsetup .B dmsetup
.de CMD_MEASURE
. BR measure
. RI [ device_name ...]
..
.CMD_MEASURE
.
.HP
.B dmsetup
.de CMD_MESSAGE .de CMD_MESSAGE
. BR message . BR message
. IR device_name . IR device_name
@ -710,6 +718,13 @@ must be manually corrected by deactivating the device first and then
reactivating it with proper mangling mode used (see also \fB--manglename\fP). reactivating it with proper mangling mode used (see also \fB--manglename\fP).
. .
.HP .HP
.CMD_MEASURE
.br
Show the data that \fIdevice_name\fP would report to the IMA subsystem
if a measurement was triggered at the current time.
This is for debugging and does not actually trigger a measurement.
.
.HP
.CMD_MESSAGE .CMD_MESSAGE
.br .br
Send message to target. If sector not needed use 0. Send message to target. If sector not needed use 0.