blob: b8c3b614670be271c80f4d46938d68b4c66963eb [file] [log] [blame]
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -07001/* SPDX-License-Identifier: GPL-2.0
2 *
3 * Copyright (C) 2021 Microsoft Corporation
4 *
5 * Author: Tushar Sugandhi <tusharsu@linux.microsoft.com>
6 *
7 * File: dm-ima.h
8 * Header file for device mapper IMA measurements.
9 */
10
11#ifndef DM_IMA_H
12#define DM_IMA_H
13
14#define DM_IMA_MEASUREMENT_BUF_LEN 4096
15#define DM_IMA_DEVICE_BUF_LEN 1024
16#define DM_IMA_TARGET_METADATA_BUF_LEN 128
17#define DM_IMA_TARGET_DATA_BUF_LEN 2048
Tushar Sugandhi8eb6fab2021-07-12 17:48:59 -070018#define DM_IMA_DEVICE_CAPACITY_BUF_LEN 128
Tushar Sugandhi8f509fd2021-08-13 14:37:56 -070019#define DM_IMA_TABLE_HASH_ALG "sha256"
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -070020
Tushar Sugandhidc7b79c2021-08-13 14:37:57 -070021#define __dm_ima_stringify(s) #s
22#define __dm_ima_str(s) __dm_ima_stringify(s)
23
24#define DM_IMA_VERSION_STR "dm_version=" \
25 __dm_ima_str(DM_VERSION_MAJOR) "." \
26 __dm_ima_str(DM_VERSION_MINOR) "." \
27 __dm_ima_str(DM_VERSION_PATCHLEVEL) ";"
28
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -070029#ifdef CONFIG_IMA
30
31struct dm_ima_device_table_metadata {
32 /*
33 * Contains data specific to the device which is common across
34 * all the targets in the table (e.g. name, uuid, major, minor, etc).
35 * The values are stored in comma separated list of key1=val1,key2=val2;
36 * pairs delimited by a semicolon at the end of the list.
37 */
38 char *device_metadata;
39 unsigned int device_metadata_len;
40 unsigned int num_targets;
41
42 /*
43 * Contains the sha256 hashes of the IMA measurements of the target
44 * attributes' key-value pairs from the active/inactive tables.
45 */
46 char *hash;
47 unsigned int hash_len;
48};
49
50/*
51 * This structure contains device metadata, and table hash for
52 * active and inactive tables for ima measurements.
53 */
54struct dm_ima_measurements {
55 struct dm_ima_device_table_metadata active_table;
56 struct dm_ima_device_table_metadata inactive_table;
Tushar Sugandhidc7b79c2021-08-13 14:37:57 -070057 unsigned int dm_version_str_len;
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -070058};
59
60void dm_ima_reset_data(struct mapped_device *md);
61void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags);
Tushar Sugandhi8eb6fab2021-07-12 17:48:59 -070062void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap);
Tushar Sugandhi84010e52021-07-12 17:49:00 -070063void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all);
Tushar Sugandhi99169b92021-07-12 17:49:01 -070064void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map);
Tushar Sugandhi7d1d1df2021-07-12 17:49:02 -070065void dm_ima_measure_on_device_rename(struct mapped_device *md);
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -070066
67#else
68
69static inline void dm_ima_reset_data(struct mapped_device *md) {}
70static inline void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags) {}
Tushar Sugandhi8eb6fab2021-07-12 17:48:59 -070071static inline void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap) {}
Tushar Sugandhi84010e52021-07-12 17:49:00 -070072static inline void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all) {}
Tushar Sugandhi99169b92021-07-12 17:49:01 -070073static inline void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map) {}
Tushar Sugandhi7d1d1df2021-07-12 17:49:02 -070074static inline void dm_ima_measure_on_device_rename(struct mapped_device *md) {}
Tushar Sugandhi91ccbba2021-07-12 17:48:58 -070075
76#endif /* CONFIG_IMA */
77
78#endif /* DM_IMA_H */